@@ -64,7 +64,7 @@ def _analyze(self):
6464 self ._extract_relationships (root , top_level_nodes )
6565
6666 def _extract_nodes (self , node , top_level_nodes , lines ):
67- """Recursively extract top-level nodes (functions and global variables)."""
67+ """Recursively extract top-level nodes (functions, structs, and global variables)."""
6868 node_type = None
6969 node_name = None
7070
@@ -76,6 +76,24 @@ def _extract_nodes(self, node, top_level_nodes, lines):
7676 identifier = next ((c for c in declarator .children if c .type == "identifier" ), None )
7777 if identifier :
7878 node_name = identifier .text .decode ()
79+ elif node .type == "struct_specifier" :
80+ # Extract struct definitions: struct Name { ... }
81+ node_type = "struct"
82+ # Find type_identifier that represents the struct name
83+ for child in node .children :
84+ if child .type == "type_identifier" :
85+ node_name = child .text .decode ()
86+ break
87+ elif node .type == "type_definition" :
88+ # Handle typedef struct definitions: typedef struct { ... } Name;
89+ # Check if this typedef contains a struct
90+ struct_spec = next ((c for c in node .children if c .type == "struct_specifier" ), None )
91+ if struct_spec :
92+ node_type = "struct"
93+ # The typedef name is the type_identifier at the end
94+ type_declarator = next ((c for c in node .children if c .type == "type_identifier" ), None )
95+ if type_declarator :
96+ node_name = type_declarator .text .decode ()
7997 elif node .type == "declaration" :
8098 if self ._is_global_variable (node ):
8199 node_type = "variable"
@@ -117,7 +135,7 @@ def _extract_nodes(self, node, top_level_nodes, lines):
117135 component_id = component_id
118136 )
119137
120- if node_type == "function" :
138+ if node_type in [ "function" , "struct" ] :
121139 self .nodes .append (node_obj )
122140 top_level_nodes [node_name ] = node_obj
123141
0 commit comments