tools/lib/python/kdoc/kdoc_item.py

Source file repositories/reference/linux-study-clean/tools/lib/python/kdoc/kdoc_item.py

File Facts

System
Linux kernel
Corpus path
tools/lib/python/kdoc/kdoc_item.py
Extension
.py
Size
2923 bytes
Lines
99
Domain
Support Tooling And Documentation
Bucket
tools
Inferred role
Support Tooling And Documentation: tools
Status
atlas-only

Why This File Exists

Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.

Dependency Surface

Detected Declarations

Annotated Snippet

# SPDX-License-Identifier: GPL-2.0
#
# A class that will, eventually, encapsulate all of the parsed data that we
# then pass into the output modules.
#

"""
Data class to store a kernel-doc Item.
"""

class KdocItem:
    """
    A class that will, eventually, encapsulate all of the parsed data that we
    then pass into the output modules.
    """

    def __init__(self, name, fname, type, start_line,
                 **other_stuff):
        self.name = name
        self.fname = fname
        self.type = type
        self.declaration_start_line = start_line
        self.sections = {}
        self.sections_start_lines = {}
        self.parameterlist = []
        self.parameterdesc_start_lines = {}
        self.parameterdescs = {}
        self.parametertypes = {}

        self.warnings = []

        #
        # Just save everything else into our own dict so that the output
        # side can grab it directly as before.  As we move things into more
        # structured data, this will, hopefully, fade away.
        #
        known_keys = {
            'declaration_start_line',
            'sections',
            'sections_start_lines',
            'parameterlist',
            'parameterdesc_start_lines',
            'parameterdescs',
            'parametertypes',
            'warnings',
        }

        self.other_stuff = {}
        for k, v in other_stuff.items():
            if k in known_keys:
                setattr(self, k, v)           # real attribute
            else:
                self.other_stuff[k] = v

    def get(self, key, default = None):
        """
        Get a value from optional keys.
        """
        return self.other_stuff.get(key, default)

    def __getitem__(self, key):
        return self.get(key)

    def __repr__(self):
        return f"KdocItem({self.name}, {self.fname}, {self.type}, {self.declaration_start_line})"

    @classmethod
    def from_dict(cls, d):
        """Create a KdocItem from a plain dict."""

Annotation

Implementation Notes