@@ -21,6 +21,10 @@ private void VisitDecl(Decl decl)
2121 {
2222 if ( IsExcluded ( decl ) )
2323 {
24+ if ( decl . Kind == CX_DeclKind . CX_DeclKind_Typedef )
25+ {
26+ VisitTypedefDecl ( ( TypedefDecl ) decl , onlyHandleRemappings : true ) ;
27+ }
2428 return ;
2529 }
2630
@@ -133,7 +137,7 @@ private void VisitDecl(Decl decl)
133137
134138 case CX_DeclKind . CX_DeclKind_Typedef :
135139 {
136- VisitTypedefDecl ( ( TypedefDecl ) decl ) ;
140+ VisitTypedefDecl ( ( TypedefDecl ) decl , onlyHandleRemappings : false ) ;
137141 break ;
138142 }
139143
@@ -268,7 +272,7 @@ private void VisitEnumConstantDecl(EnumConstantDecl enumConstantDecl)
268272 var kind = isAnonymousEnum ? ValueKind . Primitive : ValueKind . Enumerator ;
269273 var flags = ValueFlags . Constant ;
270274
271- if ( enumConstantDecl . InitExpr is not null )
275+ if ( ( enumConstantDecl . InitExpr is not null ) || isAnonymousEnum )
272276 {
273277 flags |= ValueFlags . Initializer ;
274278 }
@@ -2411,13 +2415,13 @@ private void VisitTypeAliasDecl(TypeAliasDecl typeAliasDecl)
24112415 // Nothing to generate for type alias declarations
24122416 }
24132417
2414- private void VisitTypedefDecl ( TypedefDecl typedefDecl )
2418+ private void VisitTypedefDecl ( TypedefDecl typedefDecl , bool onlyHandleRemappings )
24152419 {
2416- ForUnderlyingType ( typedefDecl , typedefDecl . UnderlyingType ) ;
2420+ ForUnderlyingType ( typedefDecl , typedefDecl . UnderlyingType , onlyHandleRemappings ) ;
24172421
2418- void ForFunctionProtoType ( TypedefDecl typedefDecl , FunctionProtoType functionProtoType , Type parentType )
2422+ void ForFunctionProtoType ( TypedefDecl typedefDecl , FunctionProtoType functionProtoType , Type parentType , bool onlyHandleRemappings )
24192423 {
2420- if ( ! _config . ExcludeFnptrCodegen )
2424+ if ( ! _config . ExcludeFnptrCodegen || onlyHandleRemappings )
24212425 {
24222426 return ;
24232427 }
@@ -2457,43 +2461,43 @@ void ForFunctionProtoType(TypedefDecl typedefDecl, FunctionProtoType functionPro
24572461 StopUsingOutputBuilder ( ) ;
24582462 }
24592463
2460- void ForPointeeType ( TypedefDecl typedefDecl , Type parentType , Type pointeeType )
2464+ void ForPointeeType ( TypedefDecl typedefDecl , Type parentType , Type pointeeType , bool onlyHandleRemappings )
24612465 {
24622466 if ( pointeeType is AttributedType attributedType )
24632467 {
2464- ForPointeeType ( typedefDecl , attributedType , attributedType . ModifiedType ) ;
2468+ ForPointeeType ( typedefDecl , attributedType , attributedType . ModifiedType , onlyHandleRemappings ) ;
24652469 }
24662470 else if ( pointeeType is ElaboratedType elaboratedType )
24672471 {
2468- ForPointeeType ( typedefDecl , elaboratedType , elaboratedType . NamedType ) ;
2472+ ForPointeeType ( typedefDecl , elaboratedType , elaboratedType . NamedType , onlyHandleRemappings ) ;
24692473 }
24702474 else if ( pointeeType is FunctionProtoType functionProtoType )
24712475 {
2472- ForFunctionProtoType ( typedefDecl , functionProtoType , parentType ) ;
2476+ ForFunctionProtoType ( typedefDecl , functionProtoType , parentType , onlyHandleRemappings ) ;
24732477 }
24742478 else if ( pointeeType is PointerType pointerType )
24752479 {
2476- ForPointeeType ( typedefDecl , pointerType , pointerType . PointeeType ) ;
2480+ ForPointeeType ( typedefDecl , pointerType , pointerType . PointeeType , onlyHandleRemappings ) ;
24772481 }
24782482 else if ( pointeeType is TypedefType typedefType )
24792483 {
2480- ForPointeeType ( typedefDecl , typedefType , typedefType . Decl . UnderlyingType ) ;
2484+ ForPointeeType ( typedefDecl , typedefType , typedefType . Decl . UnderlyingType , onlyHandleRemappings ) ;
24812485 }
24822486 else if ( pointeeType is not ConstantArrayType and not BuiltinType and not TagType and not TemplateTypeParmType )
24832487 {
24842488 AddDiagnostic ( DiagnosticLevel . Error , $ "Unsupported pointee type: '{ pointeeType . TypeClassSpelling } '. Generating bindings may be incomplete.", typedefDecl ) ;
24852489 }
24862490 }
24872491
2488- void ForUnderlyingType ( TypedefDecl typedefDecl , Type underlyingType )
2492+ void ForUnderlyingType ( TypedefDecl typedefDecl , Type underlyingType , bool onlyHandleRemappings )
24892493 {
24902494 if ( underlyingType is ArrayType arrayType )
24912495 {
24922496 // Nothing to do for array types
24932497 }
24942498 else if ( underlyingType is AttributedType attributedType )
24952499 {
2496- ForUnderlyingType ( typedefDecl , attributedType . ModifiedType ) ;
2500+ ForUnderlyingType ( typedefDecl , attributedType . ModifiedType , onlyHandleRemappings ) ;
24972501 }
24982502 else if ( underlyingType is BuiltinType builtinType )
24992503 {
@@ -2505,46 +2509,41 @@ void ForUnderlyingType(TypedefDecl typedefDecl, Type underlyingType)
25052509 }
25062510 else if ( underlyingType is ElaboratedType elaboratedType )
25072511 {
2508- ForUnderlyingType ( typedefDecl , elaboratedType . NamedType ) ;
2512+ ForUnderlyingType ( typedefDecl , elaboratedType . NamedType , onlyHandleRemappings ) ;
25092513 }
25102514 else if ( underlyingType is FunctionProtoType functionProtoType )
25112515 {
2512- ForFunctionProtoType ( typedefDecl , functionProtoType , parentType : null ) ;
2516+ ForFunctionProtoType ( typedefDecl , functionProtoType , parentType : null , onlyHandleRemappings ) ;
25132517 }
25142518 else if ( underlyingType is PointerType pointerType )
25152519 {
2516- ForPointeeType ( typedefDecl , parentType : null , pointerType . PointeeType ) ;
2520+ ForPointeeType ( typedefDecl , parentType : null , pointerType . PointeeType , onlyHandleRemappings ) ;
25172521 }
25182522 else if ( underlyingType is ReferenceType referenceType )
25192523 {
2520- ForPointeeType ( typedefDecl , parentType : null , referenceType . PointeeType ) ;
2524+ ForPointeeType ( typedefDecl , parentType : null , referenceType . PointeeType , onlyHandleRemappings ) ;
25212525 }
25222526 else if ( underlyingType is TagType underlyingTagType )
25232527 {
2524- // See if there's a potential typedef remapping we want to log
2525- if ( _config . LogPotentialTypedefRemappings )
2526- {
2527- var typedefName = typedefDecl . UnderlyingDecl . Name ;
2528- var possibleNamesToRemap = new string [ ] { "_" + typedefName , "_tag" + typedefName , "tag" + typedefName , typedefName + "_tag" } ;
2529- var underlyingName = underlyingTagType . AsString ;
2528+ var underlyingName = GetCursorName ( underlyingTagType . AsTagDecl ) ;
2529+ var typedefName = GetCursorName ( typedefDecl ) ;
25302530
2531- foreach ( var possibleNameToRemap in possibleNamesToRemap )
2531+ if ( underlyingName != typedefName )
2532+ {
2533+ if ( ! _validNameRemappings . TryGetValue ( underlyingName , out var remappings ) )
25322534 {
2533- if ( ! _config . RemappedNames . ContainsKey ( possibleNameToRemap ) && ! _config . RemappedNames . ContainsKey ( possibleNameToRemap + "*" ) )
2534- {
2535- if ( possibleNameToRemap == underlyingName )
2536- {
2537- AddDiagnostic ( DiagnosticLevel . Info , $ "Potential remap: { possibleNameToRemap } ={ typedefName } ") ;
2538- }
2539- }
2535+ remappings = new HashSet < string > ( ) ;
2536+ _validNameRemappings [ underlyingName ] = remappings ;
25402537 }
2538+
2539+ _ = remappings . Add ( typedefName ) ;
25412540 }
25422541 }
25432542 else if ( underlyingType is TemplateSpecializationType templateSpecializationType )
25442543 {
25452544 if ( templateSpecializationType . IsTypeAlias )
25462545 {
2547- ForUnderlyingType ( typedefDecl , templateSpecializationType . AliasedType ) ;
2546+ ForUnderlyingType ( typedefDecl , templateSpecializationType . AliasedType , onlyHandleRemappings ) ;
25482547 }
25492548 else
25502549 {
@@ -2557,7 +2556,7 @@ void ForUnderlyingType(TypedefDecl typedefDecl, Type underlyingType)
25572556 }
25582557 else if ( underlyingType is TypedefType typedefType )
25592558 {
2560- ForUnderlyingType ( typedefDecl , typedefType . Decl . UnderlyingType ) ;
2559+ ForUnderlyingType ( typedefDecl , typedefType . Decl . UnderlyingType , onlyHandleRemappings ) ;
25612560 }
25622561 else
25632562 {
0 commit comments