@@ -589,6 +589,7 @@ class CppClass(dict):
589
589
* ``nested_classes`` - Classes and structs defined within this class
590
590
* ``final`` - True if final
591
591
* ``abstract`` - True if abstract
592
+ * ``parent`` - If not None, the class that this class is nested in
592
593
593
594
An example of how this could look is as follows::
594
595
@@ -713,7 +714,7 @@ def show(self):
713
714
if "doxygen" in list (self .keys ()):
714
715
rtn += self ["doxygen" ] + "\n "
715
716
if "parent" in list (self .keys ()) and self ["parent" ]:
716
- rtn += "parent class: " + self ["parent" ] + "\n "
717
+ rtn += "parent class: " + self ["parent" ][ "name" ] + "\n "
717
718
718
719
if "inherits" in list (self .keys ()):
719
720
rtn += " Inherits: "
@@ -759,7 +760,7 @@ def __str__(self):
759
760
if "doxygen" in list (self .keys ()):
760
761
rtn += self ["doxygen" ] + "\n "
761
762
if "parent" in list (self .keys ()) and self ["parent" ]:
762
- rtn += "parent class: " + self ["parent" ] + "\n "
763
+ rtn += "parent class: " + self ["parent" ][ "name" ] + "\n "
763
764
764
765
if "inherits" in list (self .keys ()) and len (self ["inherits" ]):
765
766
rtn += "Inherits: "
@@ -834,7 +835,7 @@ def __str__(self):
834
835
if "doxygen" in list (self .keys ()):
835
836
rtn += self ["doxygen" ] + "\n "
836
837
if "parent" in list (self .keys ()) and self ["parent" ]:
837
- rtn += "parent class: " + self ["parent" ] + "\n "
838
+ rtn += "parent class: " + self ["parent" ][ "name" ] + "\n "
838
839
839
840
rtn += "{\n "
840
841
for member in self ["members" ]:
@@ -898,6 +899,7 @@ def _params_helper1(self, stack):
898
899
def _params_helper2 (self , params ):
899
900
for p in params :
900
901
p ["method" ] = self # save reference in variable to parent method
902
+ p ["parent" ] = self
901
903
if "::" in p ["type" ]:
902
904
ns = p ["type" ].split ("::" )[0 ]
903
905
if ns not in Resolver .NAMESPACES and ns in Resolver .CLASSES :
@@ -914,6 +916,7 @@ class CppMethod(_CppMethod):
914
916
* ``name`` - Name of the method
915
917
* ``doxygen`` - Doxygen comments associated with the method if they exist
916
918
* ``parameters`` - List of :class:`.CppVariable`
919
+ * ``parent`` - If not None, the class this method belongs to
917
920
"""
918
921
919
922
def show (self ):
@@ -1538,14 +1541,16 @@ def finalize_vars(self):
1538
1541
nestedEnum = None
1539
1542
nestedStruct = None
1540
1543
nestedTypedef = None
1541
- if "method" in var and "parent" in list (var ["method" ].keys ()):
1542
- klass = var ["method" ]["parent" ]
1543
- if tag in var ["method" ]["parent" ]._public_enums :
1544
- nestedEnum = var ["method" ]["parent" ]._public_enums [tag ]
1545
- elif tag in var ["method" ]["parent" ]._public_typedefs :
1546
- nestedTypedef = var ["method" ]["parent" ]._public_typedefs [
1547
- tag
1548
- ]
1544
+
1545
+ parent = var ["parent" ]
1546
+ while parent :
1547
+ nestedEnum = getattr (parent , "_public_enums" , {}).get (tag )
1548
+ if nestedEnum :
1549
+ break
1550
+ nestedTypedef = getattr (parent , "_public_typedefs" , {}).get (tag )
1551
+ if nestedTypedef :
1552
+ break
1553
+ parent = parent ["parent" ]
1549
1554
1550
1555
if "<" in tag : # should also contain '>'
1551
1556
var ["template" ] = tag # do not resolve templates
@@ -1604,7 +1609,7 @@ def finalize_vars(self):
1604
1609
var ["enum" ] = enum ["namespace" ] + enum ["name" ]
1605
1610
var ["fundamental" ] = True
1606
1611
1607
- elif var ["parent" ]:
1612
+ elif var ["parent" ] and var [ "unresolved" ] :
1608
1613
warning_print ("WARN unresolved %s" , _tag )
1609
1614
var ["ctypes_type" ] = "ctypes.c_void_p"
1610
1615
var ["unresolved" ] = True
@@ -1750,17 +1755,15 @@ def finalize_vars(self):
1750
1755
var ["raw_type" ] = (
1751
1756
var ["class" ]["namespace" ] + "::" + var ["raw_type" ]
1752
1757
)
1753
- elif var [ "class" ][ "parent" ] in self . classes :
1754
- parent = self . classes [ var ["class" ]["parent" ] ]
1758
+ else :
1759
+ parent = var ["class" ]["parent" ]
1755
1760
var ["raw_type" ] = (
1756
1761
parent ["namespace" ]
1757
1762
+ "::"
1758
1763
+ var ["class" ]["name" ]
1759
1764
+ "::"
1760
1765
+ var ["raw_type" ]
1761
1766
)
1762
- else :
1763
- var ["unresolved" ] = True
1764
1767
1765
1768
elif (
1766
1769
"::" in var ["raw_type" ]
@@ -2166,6 +2169,7 @@ def _evaluate_method_stack(self):
2166
2169
self ._get_stmt_doxygen (),
2167
2170
self ._get_location (self .nameStack ),
2168
2171
)
2172
+ newMethod ["parent" ] = None
2169
2173
self .functions .append (newMethod )
2170
2174
global parseHistory
2171
2175
parseHistory .append (
@@ -2299,6 +2303,7 @@ def _evaluate_property_stack(self, clearStack=True, addToVar=None):
2299
2303
klass = self .classes [self .curClass ]
2300
2304
klass ["properties" ][self .curAccessSpecifier ].append (newVar )
2301
2305
newVar ["property_of_class" ] = klass ["name" ]
2306
+ newVar ["parent" ] = klass
2302
2307
parseHistory .append (
2303
2308
{"braceDepth" : self .braceDepth , "item_type" : "variable" , "item" : newVar }
2304
2309
)
@@ -2373,16 +2378,17 @@ def _evaluate_class_stack(self):
2373
2378
2374
2379
if parent :
2375
2380
newClass ["namespace" ] = self .classes [parent ]["namespace" ] + "::" + parent
2376
- newClass ["parent" ] = parent
2381
+ newClass ["parent" ] = self . classes [ parent ]
2377
2382
self .classes [parent ]["nested_classes" ].append (newClass )
2378
2383
## supports nested classes with the same name ##
2379
2384
self .curClass = key = parent + "::" + classKey
2380
2385
self ._classes_brace_level [key ] = self .braceDepth
2381
2386
2382
2387
elif newClass ["parent" ]: # nested class defined outside of parent. A::B {...}
2383
- parent = newClass ["parent" ]
2384
- newClass ["namespace" ] = self .classes [parent ]["namespace" ] + "::" + parent
2385
- self .classes [parent ]["nested_classes" ].append (newClass )
2388
+ pcls = newClass ["parent" ]
2389
+ parent = pcls ["name" ]
2390
+ newClass ["namespace" ] = pcls ["namespace" ] + "::" + parent
2391
+ pcls ["nested_classes" ].append (newClass )
2386
2392
## supports nested classes with the same name ##
2387
2393
self .curClass = key = parent + "::" + classKey
2388
2394
self ._classes_brace_level [key ] = self .braceDepth
@@ -2767,7 +2773,9 @@ def __init__(self, headerFileName, argType="file", encoding=None, **kwargs):
2767
2773
self .curAccessSpecifier = self .accessSpecifierStack [- 1 ]
2768
2774
self .accessSpecifierStack = self .accessSpecifierStack [:- 1 ]
2769
2775
if self .curClass and self .classes [self .curClass ]["parent" ]:
2770
- self .curClass = self .classes [self .curClass ]["parent" ]
2776
+ self .curClass = self .classes [self .curClass ]["parent" ][
2777
+ "name"
2778
+ ]
2771
2779
else :
2772
2780
self .curClass = ""
2773
2781
self .stack = []
0 commit comments