Skip to content

Commit ec2c8fd

Browse files
author
roman_yakovenko
committed
fix for "get dependencies" functionality
1 parent 1b1fc48 commit ec2c8fd

File tree

1 file changed

+27
-13
lines changed

1 file changed

+27
-13
lines changed

pygccxml/declarations/dependencies.py

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,28 @@
99

1010
import cpptypes
1111

12+
class impl_details:
13+
@staticmethod
14+
def dig_declarations( depend_on_it ):
15+
#prevent recursive import
16+
from pygccxml import declarations
17+
18+
if isinstance( depend_on_it, declarations.declaration_t ):
19+
return [depend_on_it]
20+
base_type = declarations.base_type( declarations.remove_alias( depend_on_it ) )
21+
if isinstance( base_type, cpptypes.declarated_t ):
22+
return [base_type.declaration]
23+
elif isinstance( base_type, cpptypes.calldef_type_t ):
24+
result = []
25+
result.extend( impl_details.dig_declarations( base_type.return_type ) )
26+
for argtype in base_type.arguments_types:
27+
result.extend( impl_details.dig_declarations( argtype ) )
28+
if isinstance( base_type, cpptypes.member_function_type_t ):
29+
result.extend( impl_details.dig_declarations( base_type.class_inst ) )
30+
return result
31+
return []
32+
33+
1234
class dependency_info_t( object ):
1335
def __init__( self, declaration, depend_on_it, access_type=None, hint=None ):
1436
object.__init__( self )
@@ -46,19 +68,11 @@ def hint(self):
4668
about dependency. It can be used later"""
4769
return self._hint
4870

49-
def find_out_depend_on_declaration( self ):
71+
def find_out_depend_on_it_declarations( self ):
5072
"""if declaration depends on other declaration and not on some type
5173
this function will return reference to it. Otherwise None will be returned
5274
"""
53-
#prevent recursive import
54-
from pygccxml import declarations
55-
56-
if isinstance( self.depend_on_it, declarations.declaration_t ):
57-
return self.depend_on_it
58-
base_type = declarations.base_type( declarations.remove_alias( self.depend_on_it ) )
59-
if isinstance( base_type, cpptypes.declarated_t ):
60-
return base_type.declaration
61-
return None
75+
return impl_details.dig_declarations( self.depend_on_it )
6276

6377
@staticmethod
6478
def i_depend_on_them( decl ):
@@ -67,9 +81,9 @@ def i_depend_on_them( decl ):
6781
import class_declaration #prevent cyclic imports
6882
to_be_included = set()
6983
for dependency_info in decl.i_depend_on_them():
70-
ddecl = dependency_info.find_out_depend_on_declaration()
71-
if ddecl:
72-
to_be_included.add( ddecl )
84+
for ddecl in dependency_info.find_out_depend_on_it_declarations():
85+
if ddecl:
86+
to_be_included.add( ddecl )
7387

7488
if isinstance( decl.parent, class_declaration.class_t ):
7589
to_be_included.add( decl.parent )

0 commit comments

Comments
 (0)