xref: /linux/scripts/lib/kdoc/kdoc_item.py (revision 8d7338752d76c3854a5c54cf7df976c539baab5b)
1# SPDX-License-Identifier: GPL-2.0
2#
3# A class that will, eventually, encapsulate all of the parsed data that we
4# then pass into the output modules.
5#
6
7class KdocItem:
8    def __init__(self, name, type, start_line, **other_stuff):
9        self.name = name
10        self.type = type
11        self.declaration_start_line = start_line
12        self.sections = {}
13        self.sections_start_lines = {}
14        #
15        # Just save everything else into our own dict so that the output
16        # side can grab it directly as before.  As we move things into more
17        # structured data, this will, hopefully, fade away.
18        #
19        self.other_stuff = other_stuff
20
21    def get(self, key, default = None):
22        ret = self.other_stuff.get(key, default)
23        if ret == default:
24            return self.__dict__.get(key, default)
25        return ret
26
27    def __getitem__(self, key):
28        return self.get(key)
29
30    #
31    # Tracking of section information.
32    #
33    def set_sections(self, sections, start_lines):
34        self.sections = sections
35        self.section_start_lines = start_lines
36