@@ -39,16 +39,34 @@ def supported_types(self) -> list[str]:
39
39
"""
40
40
return list (analyzers .keys ())
41
41
42
- def create_hierarchy (self , analyzer : AbstractAnalyzer , file : File ):
43
- types = analyzer .get_top_level_entity_types ()
42
+ def create_entity_hierarchy (self , entity : Entity , file : File , analyzer : AbstractAnalyzer , graph : Graph ):
43
+ types = analyzer .get_entity_types ()
44
+ stack = list (entity .node .children )
45
+ while stack :
46
+ node = stack .pop ()
47
+ if node .type in types :
48
+ child = Entity (node )
49
+ child .id = graph .add_entity (analyzer .get_entity_label (node ), analyzer .get_entity_name (node ), analyzer .get_entity_docstring (node ), str (file .path ), node .start_point .row , node .end_point .row , {})
50
+ analyzer .add_symbols (child )
51
+ file .add_entity (entity )
52
+ entity .add_child (child )
53
+ graph .connect_entities ("DEFINES" , entity .id , child .id )
54
+ self .create_entity_hierarchy (child , file , analyzer , graph )
55
+ else :
56
+ stack .extend (node .children )
57
+
58
+ def create_hierarchy (self , file : File , analyzer : AbstractAnalyzer , graph : Graph ):
59
+ types = analyzer .get_entity_types ()
44
60
stack = [file .tree .root_node ]
45
61
while stack :
46
62
node = stack .pop ()
47
63
if node .type in types :
48
64
entity = Entity (node )
65
+ entity .id = graph .add_entity (analyzer .get_entity_label (node ), analyzer .get_entity_name (node ), analyzer .get_entity_docstring (node ), str (file .path ), node .start_point .row , node .end_point .row , {})
49
66
analyzer .add_symbols (entity )
50
- analyzer .add_children (entity )
51
67
file .add_entity (entity )
68
+ graph .connect_entities ("DEFINES" , file .id , entity .id )
69
+ self .create_entity_hierarchy (entity , file , analyzer , graph )
52
70
else :
53
71
stack .extend (node .children )
54
72
@@ -85,15 +103,8 @@ def first_pass(self, path: Path, ignore: list[str], graph: Graph) -> None:
85
103
self .files [file_path ] = file
86
104
87
105
# Walk thought the AST
88
- self .create_hierarchy (analyzer , file )
89
-
90
106
graph .add_file (file )
91
- for node , entity in file .entities .items ():
92
- entity .id = graph .add_entity (analyzer .get_entity_label (node ), analyzer .get_entity_name (node ), analyzer .get_entity_docstring (node ), str (file_path ), node .start_point .row , node .end_point .row , {})
93
- graph .connect_entities ("DEFINES" , file .id , entity .id )
94
- for child_node , child_entity in entity .children .items ():
95
- child_entity .id = graph .add_entity (analyzer .get_entity_label (child_node ), analyzer .get_entity_name (child_node ), analyzer .get_entity_docstring (child_node ), str (file_path ), child_node .start_point .row , child_node .end_point .row , {"src" : child_node .text .decode ("utf-8" )})
96
- graph .connect_entities ("DEFINES" , entity .id , child_entity .id )
107
+ self .create_hierarchy (file , analyzer , graph )
97
108
98
109
def second_pass (self , graph : Graph , path : Path ) -> None :
99
110
"""
0 commit comments