@@ -497,8 +497,13 @@ def _parse_cppclass_name(c, stack):
497
497
c ["namespace" ] = ""
498
498
499
499
# backwards compat
500
- if name .startswith ("anon-struct-" ):
501
- name = "<" + name + ">"
500
+ if name .startswith ("anon-" ):
501
+ if (
502
+ name .startswith ("anon-class-" )
503
+ or name .startswith ("anon-struct-" )
504
+ or name .startswith ("anon-union-" )
505
+ ):
506
+ name = "<" + name + ">"
502
507
c ["name" ] = name
503
508
c ["bare_name" ] = name
504
509
debug_print ("Found class '%s'" , name )
@@ -820,7 +825,6 @@ class CppUnion(CppClass):
820
825
821
826
def __init__ (self , nameStack , doxygen , location ):
822
827
CppClass .__init__ (self , nameStack , None , doxygen , location )
823
- self ["name" ] = "union " + self ["name" ]
824
828
self ["members" ] = self ["properties" ]["public" ]
825
829
826
830
def transform_to_union_keys (self ):
@@ -2435,14 +2439,24 @@ def _evaluate_class_stack(self):
2435
2439
# When dealing with typedefed structs, get rid of typedef keyword to handle later on
2436
2440
if self .nameStack [0 ] == "typedef" :
2437
2441
del self .nameStack [0 ]
2438
- if len (self .nameStack ) == 1 :
2442
+
2443
+ if len (self .nameStack ) == 1 :
2444
+ if self .nameStack [0 ] == "struct" :
2439
2445
self .anon_struct_counter += 1
2440
2446
# We cant handle more than 1 anonymous struct, so name them uniquely
2441
2447
self .nameStack .append ("anon-struct-%d" % self .anon_struct_counter )
2448
+ elif self .nameStack [0 ] == "union" :
2449
+ self .anon_union_counter += 1
2450
+ # We cant handle more than 1 anonymous union, so name them uniquely
2451
+ self .nameStack .append ("anon-union-%d" % self .anon_union_counter )
2452
+ elif self .nameStack [0 ] == "class" :
2453
+ self .anon_class_counter += 1
2454
+ # We cant handle more than 1 anonymous class, so name them uniquely
2455
+ self .nameStack .append ("anon-class-%d" % self .anon_class_counter )
2442
2456
2443
2457
if self .nameStack [0 ] == "class" :
2444
2458
self .curAccessSpecifier = "private"
2445
- else : # struct
2459
+ else : # struct/union
2446
2460
self .curAccessSpecifier = "public"
2447
2461
debug_print (
2448
2462
"curAccessSpecifier changed/defaulted to %s" , self .curAccessSpecifier
@@ -2453,19 +2467,13 @@ def _evaluate_class_stack(self):
2453
2467
self ._get_stmt_doxygen (),
2454
2468
self ._get_location (self .nameStack ),
2455
2469
)
2456
- if newClass ["name" ] == "union " :
2457
- self .anon_union_counter = [self .braceDepth , 2 ]
2458
- else :
2459
- self .anon_union_counter = [self .braceDepth , 1 ]
2460
- trace_print ("NEW UNION" , newClass ["name" ])
2461
2470
else :
2462
2471
newClass = CppClass (
2463
2472
self .nameStack ,
2464
2473
self .curTemplate ,
2465
2474
self ._get_stmt_doxygen (),
2466
2475
self ._get_location (self .nameStack ),
2467
2476
)
2468
- trace_print ("NEW CLASS" , newClass ["name" ])
2469
2477
newClass ["declaration_method" ] = self .nameStack [0 ]
2470
2478
self .classes_order .append (newClass ) # good idea to save ordering
2471
2479
self .stack = [] # fixes if class declared with ';' in closing brace
@@ -2639,7 +2647,8 @@ def __init__(self, headerFileName, argType="file", encoding=None, **kwargs):
2639
2647
# Old namestacks for a given level
2640
2648
self .nameStackHistory = []
2641
2649
self .anon_struct_counter = 0
2642
- self .anon_union_counter = [- 1 , 0 ]
2650
+ self .anon_union_counter = 0
2651
+ self .anon_class_counter = 0
2643
2652
2644
2653
#: Using directives in this header outside of class scope: key is
2645
2654
#: full name for lookup, value is :class:`.CppVariable`
@@ -2751,11 +2760,6 @@ def __init__(self, headerFileName, argType="file", encoding=None, **kwargs):
2751
2760
tok = lex .token (eof_ok = True )
2752
2761
if not tok :
2753
2762
break
2754
- if (
2755
- self .anon_union_counter [0 ] == self .braceDepth
2756
- and self .anon_union_counter [1 ]
2757
- ):
2758
- self .anon_union_counter [1 ] -= 1
2759
2763
tok .value = TagStr (tok .value , location = tok .location )
2760
2764
2761
2765
# debug_print("TOK: %s", tok)
@@ -2875,6 +2879,24 @@ def __init__(self, headerFileName, argType="file", encoding=None, **kwargs):
2875
2879
self .curClass = self .curClass [
2876
2880
: - (len (thisClass ["name" ]) + 2 )
2877
2881
]
2882
+
2883
+ # Detect anonymous union members
2884
+ if (
2885
+ self .curClass
2886
+ and thisClass ["declaration_method" ] == "union"
2887
+ and thisClass ["name" ].startswith ("<" )
2888
+ and self .lex .token_if (";" )
2889
+ ):
2890
+ debug_print ("Creating anonymous union" )
2891
+ # Force the processing of an anonymous union
2892
+ self .nameStack = ["" ]
2893
+ self .stack = self .nameStack + [";" ]
2894
+ debug_print ("pre eval anon stack" )
2895
+ self ._evaluate_stack (";" )
2896
+ debug_print ("post eval anon stack" )
2897
+ self .stack = []
2898
+ self .nameStack = []
2899
+ self .stmtTokens = []
2878
2900
else :
2879
2901
self .curClass = ""
2880
2902
self .stack = []
@@ -2891,8 +2913,6 @@ def __init__(self, headerFileName, argType="file", encoding=None, **kwargs):
2891
2913
self .nameStack .append (tok .value )
2892
2914
else :
2893
2915
self .nameStack .append (tok .value )
2894
- if self .anon_union_counter [0 ] == self .braceDepth :
2895
- self .anon_union_counter = [- 1 , 0 ]
2896
2916
elif tok .type == ":" :
2897
2917
if self .nameStack and self .nameStack [0 ] in supportedAccessSpecifier :
2898
2918
specifier = " " .join (self .nameStack )
@@ -2916,24 +2936,6 @@ def __init__(self, headerFileName, argType="file", encoding=None, **kwargs):
2916
2936
self .nameStack .append (tok .value )
2917
2937
2918
2938
elif tok .type == ";" :
2919
- if (
2920
- self .anon_union_counter [0 ] == self .braceDepth
2921
- and self .anon_union_counter [1 ]
2922
- ):
2923
- debug_print ("Creating anonymous union" )
2924
- # Force the processing of an anonymous union
2925
- saved_namestack = self .nameStack [:]
2926
- saved_stack = self .stack [:]
2927
- self .nameStack = ["" ]
2928
- self .stack = self .nameStack + [";" ]
2929
- self .nameStack = self .nameStack [0 :1 ]
2930
- debug_print ("pre eval anon stack" )
2931
- self ._evaluate_stack (tok .type )
2932
- debug_print ("post eval anon stack" )
2933
- self .nameStack = saved_namestack
2934
- self .stack = saved_stack
2935
- self .anon_union_counter = [- 1 , 0 ]
2936
-
2937
2939
self ._evaluate_stack (tok .type )
2938
2940
self .stack = []
2939
2941
self .nameStack = []
@@ -2995,6 +2997,7 @@ def __init__(self, headerFileName, argType="file", encoding=None, **kwargs):
2995
2997
"nameStackHistory" ,
2996
2998
"anon_struct_counter" ,
2997
2999
"anon_union_counter" ,
3000
+ "anon_class_counter" ,
2998
3001
"_classes_brace_level" ,
2999
3002
"_forward_decls" ,
3000
3003
"stack" ,
0 commit comments