@@ -589,6 +589,8 @@ 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
+ * ``using`` - Using directives in this class scope: key is name for lookup,
593
+ value is :class:`.CppVariable`
592
594
* ``parent`` - If not None, the class that this class is nested in
593
595
594
596
An example of how this could look is as follows::
@@ -654,6 +656,7 @@ def __init__(self, nameStack, curTemplate, doxygen, location):
654
656
self ._public_typedefs = {}
655
657
self ._public_forward_declares = []
656
658
self ["namespace" ] = ""
659
+ self ["using" ] = {}
657
660
658
661
debug_print ("Class: %s" , nameStack )
659
662
debug_print ("Template: %s" , curTemplate )
@@ -1124,12 +1127,14 @@ class CppVariable(_CppVariable):
1124
1127
* ``default`` - Default value of the variable, this key will only
1125
1128
exist if there is a default value
1126
1129
* ``extern`` - True if its an extern, False if not
1130
+ * ``parent`` - If not None, either the class this is a property of, or the
1131
+ method this variable is a parameter in
1127
1132
"""
1128
1133
1129
1134
Vars = []
1130
1135
1131
1136
def __init__ (self , nameStack , doxygen , location , ** kwargs ):
1132
- debug_print ("trace %s" , nameStack )
1137
+ debug_print ("var trace %s" , nameStack )
1133
1138
if len (nameStack ) and nameStack [0 ] == "extern" :
1134
1139
self ["extern" ] = True
1135
1140
del nameStack [0 ]
@@ -1497,21 +1502,33 @@ def resolve_type(self, string, result): # recursive
1497
1502
result ["fundamental" ] = False
1498
1503
result ["class" ] = klass
1499
1504
result ["unresolved" ] = False
1500
- elif self .using :
1501
- # search for type in all enclosing namespaces
1502
- for ns in _iter_ns_str_reversed (result .get ("namespace" , "" )):
1503
- nsalias = ns + alias
1504
- used = self .using .get (nsalias )
1505
- if used :
1506
- for i in ("type" , "namespace" , "ctypes_type" , "raw_type" ):
1507
- if i in used :
1508
- result [i ] = used [i ]
1509
- result ["unresolved" ] = False
1510
- break
1511
- else :
1512
- result ["unresolved" ] = True
1513
1505
else :
1514
- result ["unresolved" ] = True
1506
+ used = None
1507
+
1508
+ # Search for using directives in parents
1509
+ parent = result ["parent" ]
1510
+ while parent :
1511
+ p_using = parent .get ("using" )
1512
+ if p_using :
1513
+ used = p_using .get (alias )
1514
+ if used :
1515
+ break
1516
+ parent = parent ["parent" ]
1517
+
1518
+ if not used and self .using :
1519
+ # search for type in all enclosing namespaces
1520
+ # TODO: would be nice if namespaces were an object?
1521
+ for ns in _iter_ns_str_reversed (result .get ("namespace" , "" )):
1522
+ nsalias = ns + alias
1523
+ used = self .using .get (nsalias )
1524
+ if used :
1525
+ break
1526
+
1527
+ if used :
1528
+ for i in ("type" , "namespace" , "ctypes_type" , "raw_type" ):
1529
+ if i in used :
1530
+ result [i ] = used [i ]
1531
+ result ["unresolved" ] = False
1515
1532
else :
1516
1533
result ["fundamental" ] = True
1517
1534
result ["unresolved" ] = False
@@ -2544,8 +2561,8 @@ def __init__(self, headerFileName, argType="file", encoding=None, **kwargs):
2544
2561
self .anon_struct_counter = 0
2545
2562
self .anon_union_counter = [- 1 , 0 ]
2546
2563
2547
- #: Using directives in this header: key is full name for lookup, value
2548
- #: is :class:`.CppVariable`
2564
+ #: Using directives in this header outside of class scope: key is
2565
+ #: full name for lookup, value is :class:`.CppVariable`
2549
2566
self .using = {}
2550
2567
2551
2568
if len (self .headerFileName ):
@@ -3116,23 +3133,40 @@ def _evaluate_stack(self, token=None):
3116
3133
else :
3117
3134
if len (self .nameStack ) > 3 and self .nameStack [2 ] == "=" :
3118
3135
# using foo = ns::bar
3136
+ # -> type alias: same behavior in all scopes
3119
3137
alias = self .nameStack [1 ]
3120
3138
ns , stack = _split_namespace (self .nameStack [3 :])
3121
3139
atype = CppVariable (
3122
3140
stack , self ._get_stmt_doxygen (), self ._get_location (stack )
3123
3141
)
3142
+
3143
+ # namespace refers to the embedded type
3144
+ atype ["namespace" ] = ns
3124
3145
else :
3125
3146
# using foo::bar
3147
+ # -> in global scope this is bringing in something
3148
+ # from a different namespace
3149
+ # -> in class scope this is bringing in a member
3150
+ # from a base class
3126
3151
ns , stack = _split_namespace (self .nameStack [1 :])
3127
3152
atype = CppVariable (
3128
3153
stack , self ._get_stmt_doxygen (), self ._get_location (stack )
3129
3154
)
3130
3155
alias = atype ["type" ]
3156
+ if self .curClass :
3157
+ atype ["baseclass" ] = ns
3158
+ else :
3159
+ atype ["namespace" ] = ns
3131
3160
3132
- atype ["namespace" ] = ns
3133
3161
atype ["raw_type" ] = ns + atype ["type" ]
3134
- alias = self .current_namespace () + alias
3135
- self .using [alias ] = atype
3162
+
3163
+ if self .curClass :
3164
+ klass = self .classes [self .curClass ]
3165
+ klass ["using" ][alias ] = atype
3166
+ else :
3167
+ # lookup is done
3168
+ alias = self .current_namespace () + alias
3169
+ self .using [alias ] = atype
3136
3170
elif is_method_namestack (self .stack ) and "(" in self .nameStack :
3137
3171
debug_print ("trace" )
3138
3172
self ._evaluate_method_stack ()
0 commit comments