diff --git a/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs b/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs index 71f45bd4..b2386ea0 100644 --- a/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs +++ b/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs @@ -22,10 +22,6 @@ private void VisitDecl(Decl decl) { if (IsExcluded(decl)) { - if (decl.Kind == CX_DeclKind.CX_DeclKind_Typedef) - { - VisitTypedefDecl((TypedefDecl)decl, onlyHandleRemappings: true); - } return; } @@ -138,7 +134,7 @@ private void VisitDecl(Decl decl) case CX_DeclKind.CX_DeclKind_Typedef: { - VisitTypedefDecl((TypedefDecl)decl, onlyHandleRemappings: false); + VisitTypedefDecl((TypedefDecl)decl); break; } @@ -2830,13 +2826,13 @@ private void VisitTypeAliasDecl(TypeAliasDecl typeAliasDecl) // Nothing to generate for type alias declarations } - private void VisitTypedefDecl(TypedefDecl typedefDecl, bool onlyHandleRemappings) + private void VisitTypedefDecl(TypedefDecl typedefDecl) { - ForUnderlyingType(typedefDecl, typedefDecl.UnderlyingType, onlyHandleRemappings); + ForUnderlyingType(typedefDecl, typedefDecl.UnderlyingType); - void ForFunctionProtoType(TypedefDecl typedefDecl, FunctionProtoType functionProtoType, Type parentType, bool onlyHandleRemappings) + void ForFunctionProtoType(TypedefDecl typedefDecl, FunctionProtoType functionProtoType, Type parentType) { - if (!_config.ExcludeFnptrCodegen || onlyHandleRemappings) + if (!_config.ExcludeFnptrCodegen) { return; } @@ -2883,27 +2879,27 @@ void ForFunctionProtoType(TypedefDecl typedefDecl, FunctionProtoType functionPro StopUsingOutputBuilder(); } - void ForPointeeType(TypedefDecl typedefDecl, Type parentType, Type pointeeType, bool onlyHandleRemappings) + void ForPointeeType(TypedefDecl typedefDecl, Type parentType, Type pointeeType) { if (pointeeType is AttributedType attributedType) { - ForPointeeType(typedefDecl, attributedType, attributedType.ModifiedType, onlyHandleRemappings); + ForPointeeType(typedefDecl, attributedType, attributedType.ModifiedType); } else if (pointeeType is ElaboratedType elaboratedType) { - ForPointeeType(typedefDecl, elaboratedType, elaboratedType.NamedType, onlyHandleRemappings); + ForPointeeType(typedefDecl, elaboratedType, elaboratedType.NamedType); } else if (pointeeType is FunctionProtoType functionProtoType) { - ForFunctionProtoType(typedefDecl, functionProtoType, parentType, onlyHandleRemappings); + ForFunctionProtoType(typedefDecl, functionProtoType, parentType); } else if (pointeeType is PointerType pointerType) { - ForPointeeType(typedefDecl, pointerType, pointerType.PointeeType, onlyHandleRemappings); + ForPointeeType(typedefDecl, pointerType, pointerType.PointeeType); } else if (pointeeType is TypedefType typedefType) { - ForPointeeType(typedefDecl, typedefType, typedefType.Decl.UnderlyingType, onlyHandleRemappings); + ForPointeeType(typedefDecl, typedefType, typedefType.Decl.UnderlyingType); } else if (pointeeType is not ConstantArrayType and not BuiltinType and not TagType and not TemplateTypeParmType) { @@ -2911,7 +2907,7 @@ void ForPointeeType(TypedefDecl typedefDecl, Type parentType, Type pointeeType, } } - void ForUnderlyingType(TypedefDecl typedefDecl, Type underlyingType, bool onlyHandleRemappings) + void ForUnderlyingType(TypedefDecl typedefDecl, Type underlyingType) { if (underlyingType is ArrayType arrayType) { @@ -2919,7 +2915,7 @@ void ForUnderlyingType(TypedefDecl typedefDecl, Type underlyingType, bool onlyHa } else if (underlyingType is AttributedType attributedType) { - ForUnderlyingType(typedefDecl, attributedType.ModifiedType, onlyHandleRemappings); + ForUnderlyingType(typedefDecl, attributedType.ModifiedType); } else if (underlyingType is BuiltinType builtinType) { @@ -2931,19 +2927,19 @@ void ForUnderlyingType(TypedefDecl typedefDecl, Type underlyingType, bool onlyHa } else if (underlyingType is ElaboratedType elaboratedType) { - ForUnderlyingType(typedefDecl, elaboratedType.NamedType, onlyHandleRemappings); + ForUnderlyingType(typedefDecl, elaboratedType.NamedType); } else if (underlyingType is FunctionProtoType functionProtoType) { - ForFunctionProtoType(typedefDecl, functionProtoType, parentType: null, onlyHandleRemappings); + ForFunctionProtoType(typedefDecl, functionProtoType, parentType: null); } else if (underlyingType is PointerType pointerType) { - ForPointeeType(typedefDecl, parentType: null, pointerType.PointeeType, onlyHandleRemappings); + ForPointeeType(typedefDecl, parentType: null, pointeeType: pointerType.PointeeType); } else if (underlyingType is ReferenceType referenceType) { - ForPointeeType(typedefDecl, parentType: null, referenceType.PointeeType, onlyHandleRemappings); + ForPointeeType(typedefDecl, parentType: null, pointeeType: referenceType.PointeeType); } else if (underlyingType is TagType underlyingTagType) { @@ -2965,7 +2961,7 @@ void ForUnderlyingType(TypedefDecl typedefDecl, Type underlyingType, bool onlyHa { if (templateSpecializationType.IsTypeAlias) { - ForUnderlyingType(typedefDecl, templateSpecializationType.AliasedType, onlyHandleRemappings); + ForUnderlyingType(typedefDecl, templateSpecializationType.AliasedType); } else { @@ -2978,7 +2974,7 @@ void ForUnderlyingType(TypedefDecl typedefDecl, Type underlyingType, bool onlyHa } else if (underlyingType is TypedefType typedefType) { - ForUnderlyingType(typedefDecl, typedefType.Decl.UnderlyingType, onlyHandleRemappings); + ForUnderlyingType(typedefDecl, typedefType.Decl.UnderlyingType); } else { @@ -3636,7 +3632,7 @@ private bool IsPrimitiveValue(Type type) { return IsPrimitiveValue(autoType.CanonicalType); } - else if (type is BuiltinType builtinType) + else if (type is BuiltinType) { switch (type.Kind) { diff --git a/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.cs b/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.cs index 7635a7e9..8f2e20fc 100644 --- a/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.cs +++ b/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.cs @@ -3007,6 +3007,24 @@ private string GetTypeName(Cursor cursor, Cursor context, Type rootType, Type ty // can be treated correctly. Otherwise, they will resolve to a particular // platform size, based on whatever parameters were passed into clang. + var underlyingType = typedefType.Decl.UnderlyingType; + + if (underlyingType.AsTagDecl is TagDecl underlyingTagDecl) + { + var underlyingName = GetCursorName(underlyingTagDecl); + + if (underlyingName != result.typeName) + { + if (!_validNameRemappings.TryGetValue(underlyingName, out var remappings)) + { + remappings = new HashSet(); + _validNameRemappings[underlyingName] = remappings; + } + + _ = remappings.Add(result.typeName); + } + } + var remappedName = GetRemappedName(result.typeName, cursor, tryRemapOperatorName: false, out var wasRemapped, skipUsing: true); result.typeName = wasRemapped ? remappedName : GetTypeName(cursor, context, rootType, typedefType.Decl.UnderlyingType, ignoreTransparentStructsWhereRequired, out _); }