@@ -43,6 +43,9 @@ class DocumentedObject:
4343 """
4444 A representation of a c object for documentation purposes.
4545
46+ Arguments:
47+ node (:class:`~clang.cindex.Cursor`): The node representing this object.
48+
4649 Attributes:
4750 type_ (str): The type of this item one of:
4851
@@ -69,15 +72,15 @@ class DocumentedObject:
6972 the type as well as the name.
7073 _line_range (Tuple[int, int]): The line range of the C construct,
7174 this will include any leading or trailing comments that may be
72- part of the constructs documentation.
75+ part of the construct's documentation.
7376 """
7477
7578 type_ = "object"
7679
77- def __init__ (self ) -> None :
80+ def __init__ (self , node : Cursor ) -> None :
7881 self .doc = ""
7982 self .name = ""
80- self .node : Cursor = None
83+ self .node = node
8184 self ._children : Optional [OrderedDict ] = None
8285 self ._soup : Optional [BeautifulSoup ] = None
8386 self ._declaration : Optional [str ] = None
@@ -88,7 +91,7 @@ def line_range(self) -> Tuple[int, int]:
8891 The lines in the source file that this object covers.
8992
9093 This will include any leading or trailing comments that may be part
91- of the constructs documentation.
94+ of the construct's documentation.
9295 """
9396 if self ._line_range is None :
9497 node_extent = self .node .extent
@@ -554,9 +557,9 @@ def get_parsed_declaration(self) -> str:
554557 # Function prototypes need to be handled different. When clang can't
555558 # successfully parse the file it falls back to naming the return type
556559 # as the display name.
557- # Unfortunatly some versions of clang behave a little differently, some
558- # will return a POINTER while others will return FUNCITONNOPROTO. The
559- # POINTER' s are easy to derive the real type from, but the test
560+ # Unfortunately some versions of clang behave a little differently, some
561+ # will return a ` POINTER` while others will return ` FUNCITONNOPROTO` . The
562+ # ` POINTER` s are easy to derive the real type from, but the test
560563 # environment doesn't use that version of clang.
561564 type_ = self .node .underlying_typedef_type
562565 if type_ .kind == cindex .TypeKind .POINTER : # pragma: no cover
@@ -753,14 +756,13 @@ def object_from_cursor(cursor: Cursor) -> Optional[DocumentedObject]:
753756
754757 nested_cursor = get_nested_node (cursor )
755758 class_ = CURSORKIND_TO_OBJECT_CLASS .get (nested_cursor .kind , DocumentedObject )
756- doc = class_ ()
759+ doc = class_ (nested_cursor )
757760
758761 doc .name = name
759762 psuedo_comment = PsuedoToken (
760763 nested_cursor .raw_comment , nested_cursor .comment_extent
761764 )
762765 doc .doc = parse_comment (psuedo_comment )
763- doc .node = nested_cursor
764766
765767 return doc
766768
@@ -821,7 +823,9 @@ def get_file_comment(cursor: Cursor, child: Optional[Cursor]) -> str:
821823 return ""
822824
823825
824- def get_compilation_args (filename : str , compilation_database : str = None ) -> List [str ]:
826+ def get_compilation_args (
827+ filename : str , compilation_database : Optional [str ] = None
828+ ) -> List [str ]:
825829 """
826830 Get the compilation args for `filename` for the compilation database found in
827831 `compilation_db_dir`
@@ -857,8 +861,8 @@ def get_compilation_args(filename: str, compilation_database: str = None) -> Lis
857861def load (
858862 filename : str ,
859863 contents : str ,
860- compilation_database : str = None ,
861- compilation_args : Sequence [str ] = None ,
864+ compilation_database : Optional [ str ] = None ,
865+ compilation_args : Optional [ Sequence [str ] ] = None ,
862866) -> DocumentedObject :
863867 """
864868 Load a C file into a tree of :class:`DocumentedObject`\' s
@@ -881,12 +885,14 @@ def load(
881885 tu = cindex .TranslationUnit .from_source (
882886 filename ,
883887 args = args ,
884- unsaved_files = ((filename , contents ),),
888+ unsaved_files = [
889+ (filename , contents ),
890+ ],
885891 options = cindex .TranslationUnit .PARSE_DETAILED_PROCESSING_RECORD ,
886892 )
887893 cursor = tu .cursor
888894
889- root_document = DocumentedFile ()
895+ root_document = DocumentedFile (cursor )
890896
891897 # Some nodes show up from header includes as well as compiler defines, so
892898 # skip those. Macro instantiations are the locations where macros are
@@ -903,7 +909,7 @@ def load(
903909 ]
904910
905911 # Macro definitions always come first in the child list, but that may not
906- # be their location in the file, so sort all of the nodes by location
912+ # be their location in the file, so sort all the nodes by location
907913 sorted_nodes = sorted (child_nodes , key = lambda x : x .extent .start .offset )
908914
909915 comment_nodes (cursor , sorted_nodes )
0 commit comments