From 716ae318a08354e77beebeb194f045c12d92531a Mon Sep 17 00:00:00 2001 From: ceresgalax Date: Sun, 11 Feb 2024 15:35:09 -0800 Subject: [PATCH 01/12] Fix crash when accessing property TemplateTypeParmDecl.DefaultArgument * hasDefaultArgType() must be called first. * Since the type may not have a default arg type, make the property nullable. --- .../ClangSharp/Cursors/Decls/TemplateTypeParmDecl.cs | 10 +++++++--- sources/libClangSharp/ClangSharp.cpp | 8 ++++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/sources/ClangSharp/Cursors/Decls/TemplateTypeParmDecl.cs b/sources/ClangSharp/Cursors/Decls/TemplateTypeParmDecl.cs index f68532c1..ca0f4b1f 100644 --- a/sources/ClangSharp/Cursors/Decls/TemplateTypeParmDecl.cs +++ b/sources/ClangSharp/Cursors/Decls/TemplateTypeParmDecl.cs @@ -5,13 +5,14 @@ using ClangSharp.Interop; using static ClangSharp.Interop.CXCursorKind; using static ClangSharp.Interop.CX_DeclKind; +using static ClangSharp.Interop.CXTypeKind; namespace ClangSharp; public sealed class TemplateTypeParmDecl : TypeDecl { private readonly Lazy> _associatedConstraints; - private readonly Lazy _defaultArgument; + private readonly Lazy _defaultArgument; internal TemplateTypeParmDecl(CXCursor handle) : base(handle, CXCursor_TemplateTypeParameter, CX_DeclKind_TemplateTypeParm) { @@ -27,12 +28,15 @@ internal TemplateTypeParmDecl(CXCursor handle) : base(handle, CXCursor_TemplateT return associatedConstraints; }); - _defaultArgument = new Lazy(() => TranslationUnit.GetOrCreate(Handle.DefaultArgType)); + _defaultArgument = new Lazy(() => { + CXType defaultArgType = Handle.DefaultArgType; + return defaultArgType.kind == CXType_Invalid ? null : TranslationUnit.GetOrCreate(defaultArgType); + }); } public IReadOnlyList AssociatedConstraints => _associatedConstraints.Value; - public Type DefaultArgument => _defaultArgument.Value; + public Type? DefaultArgument => _defaultArgument.Value; public bool DefaultArgumentWasInherited => Handle.HasInheritedDefaultArg; diff --git a/sources/libClangSharp/ClangSharp.cpp b/sources/libClangSharp/ClangSharp.cpp index 02c76f2d..372b54d0 100644 --- a/sources/libClangSharp/ClangSharp.cpp +++ b/sources/libClangSharp/ClangSharp.cpp @@ -1001,15 +1001,19 @@ CXCursor clangsharp_Cursor_getDefaultArg(CXCursor C) { } CXType clangsharp_Cursor_getDefaultArgType(CXCursor C) { + QualType QT; + if (isDeclOrTU(C.kind)) { const Decl* D = getCursorDecl(C); if (const TemplateTypeParmDecl* TTPD = dyn_cast(D)) { - return MakeCXType(TTPD->getDefaultArgument(), getCursorTU(C)); + if (TTPD->hasDefaultArgument()) { + QT = TTPD->getDefaultArgument(); + } } } - return MakeCXType(QualType(), getCursorTU(C)); + return MakeCXType(QT, getCursorTU(C)); } CXCursor clangsharp_Cursor_getDefinition(CXCursor C) { From 5b4f845bf3cd436366dd50860c322151001fad66 Mon Sep 17 00:00:00 2001 From: ceresgalax Date: Sun, 11 Feb 2024 15:41:41 -0800 Subject: [PATCH 02/12] Add AssociatedDecl property to SubstTemplateTypeParamType. * This calls getAssociatedDecl() on the underlying clang c++ type object. * Note: I added a function was added to clangsharp.cpp and .h, but the clangsharp.cs file was updated manually. I was having issues getting ClangSharpPInvokeGenerator output the .cs source files correctly. --- sources/ClangSharp.Interop/clangsharp/clangsharp.cs | 3 +++ sources/ClangSharp/Types/SubstTemplateTypeParmType.cs | 7 +++++++ sources/libClangSharp/ClangSharp.cpp | 11 +++++++++++ sources/libClangSharp/ClangSharp.h | 2 ++ 4 files changed, 23 insertions(+) diff --git a/sources/ClangSharp.Interop/clangsharp/clangsharp.cs b/sources/ClangSharp.Interop/clangsharp/clangsharp.cs index 1c675a8e..e2ad41ab 100644 --- a/sources/ClangSharp.Interop/clangsharp/clangsharp.cs +++ b/sources/ClangSharp.Interop/clangsharp/clangsharp.cs @@ -1032,6 +1032,9 @@ public static partial class @clangsharp [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Type_getOriginalType", ExactSpelling = true)] public static extern CXType Type_getOriginalType(CXType CT); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Type_getSubstTemplateTypeParamAssociatedDecl", ExactSpelling = true)] + public static extern CXCursor Type_getSubstTemplateTypeParamAssociatedDecl(CXType CT); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Type_getOwnedTagDecl", ExactSpelling = true)] public static extern CXCursor Type_getOwnedTagDecl(CXType CT); diff --git a/sources/ClangSharp/Types/SubstTemplateTypeParmType.cs b/sources/ClangSharp/Types/SubstTemplateTypeParmType.cs index 517d387b..d09e2a5c 100644 --- a/sources/ClangSharp/Types/SubstTemplateTypeParmType.cs +++ b/sources/ClangSharp/Types/SubstTemplateTypeParmType.cs @@ -9,14 +9,21 @@ namespace ClangSharp; public sealed class SubstTemplateTypeParmType : Type { + private readonly Lazy _associatedDecl; private readonly Lazy _replacedParameter; internal SubstTemplateTypeParmType(CXType handle) : base(handle, CXType_Unexposed, CX_TypeClass_SubstTemplateTypeParm) { + _associatedDecl = new Lazy(() => { + CXCursor cursor = clangsharp.Type_getSubstTemplateTypeParamAssociatedDecl(Handle); + return cursor.IsNull ? null : TranslationUnit.GetOrCreate(cursor); + }); _replacedParameter = new Lazy(() => TranslationUnit.GetOrCreate(Handle.OriginalType)); } public TemplateTypeParmType ReplacedParameter => _replacedParameter.Value; public Type ReplacementType => Desugar; + + public Decl? AssociatedDecl => _associatedDecl.Value; } diff --git a/sources/libClangSharp/ClangSharp.cpp b/sources/libClangSharp/ClangSharp.cpp index 02c76f2d..db92c86a 100644 --- a/sources/libClangSharp/ClangSharp.cpp +++ b/sources/libClangSharp/ClangSharp.cpp @@ -5366,6 +5366,17 @@ CXType clangsharp_Type_getOriginalType(CXType CT) { return MakeCXType(QualType(), GetTypeTU(CT)); } +CXCursor clangsharp_Type_getSubstTemplateTypeParamAssociatedDecl(CXType CT) { + QualType T = GetQualType(CT); + const Type* TP = T.getTypePtrOrNull(); + + if (const SubstTemplateTypeParmType* STTPT = dyn_cast(TP)) { + return MakeCXCursor(STTPT->getAssociatedDecl(), GetTypeTU(CT)); + } + + clang_getNullCursor(); +} + CXCursor clangsharp_Type_getOwnedTagDecl(CXType CT) { QualType T = GetQualType(CT); const Type* TP = T.getTypePtrOrNull(); diff --git a/sources/libClangSharp/ClangSharp.h b/sources/libClangSharp/ClangSharp.h index a79013e7..f5156131 100644 --- a/sources/libClangSharp/ClangSharp.h +++ b/sources/libClangSharp/ClangSharp.h @@ -817,6 +817,8 @@ CLANGSHARP_LINKAGE int clangsharp_Type_getNumRows(CXType CT); CLANGSHARP_LINKAGE CXType clangsharp_Type_getOriginalType(CXType CT); +CLANGSHARP_LINKAGE CXCursor clangsharp_Type_getSubstTemplateTypeParamAssociatedDecl(CXType CT); + CLANGSHARP_LINKAGE CXCursor clangsharp_Type_getOwnedTagDecl(CXType CT); CLANGSHARP_LINKAGE CXType clangsharp_Type_getPointeeType(CXType CT); From 0b62dece8446a33fe9cec6c6bc594277abfee440 Mon Sep 17 00:00:00 2001 From: Julien Lebosquain Date: Mon, 11 Nov 2024 11:35:52 +0100 Subject: [PATCH 03/12] Fix incorrect template argument kind --- sources/libClangSharp/ClangSharp.cpp | 30 ++++++++++++++++++- .../CursorTests/DeclTest.cs | 22 ++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/sources/libClangSharp/ClangSharp.cpp b/sources/libClangSharp/ClangSharp.cpp index 5880900c..8e5078ed 100644 --- a/sources/libClangSharp/ClangSharp.cpp +++ b/sources/libClangSharp/ClangSharp.cpp @@ -26,10 +26,38 @@ using namespace clang::cxstring; using namespace clang::cxtu; using namespace clang::cxtype; +CXTemplateArgumentKind ConvertTemplateArgumentKind(TemplateArgument::ArgKind kind) { + switch (kind) { + case TemplateArgument::Null: + return CXTemplateArgumentKind_Null; + case TemplateArgument::Type: + return CXTemplateArgumentKind_Type; + case TemplateArgument::Declaration: + return CXTemplateArgumentKind_Declaration; + case TemplateArgument::NullPtr: + return CXTemplateArgumentKind_NullPtr; + case TemplateArgument::Integral: + return CXTemplateArgumentKind_Integral; + case TemplateArgument::StructuralValue: + // Does not exist in CXTemplateArgumentKind + return CXTemplateArgumentKind_Invalid; + case TemplateArgument::Template: + return CXTemplateArgumentKind_Template; + case TemplateArgument::TemplateExpansion: + return CXTemplateArgumentKind_TemplateExpansion; + case TemplateArgument::Expression: + return CXTemplateArgumentKind_Expression; + case TemplateArgument::Pack: + return CXTemplateArgumentKind_Pack; + default: + return CXTemplateArgumentKind_Invalid; + } +} + CX_TemplateArgument MakeCXTemplateArgument(const TemplateArgument* TA, CXTranslationUnit TU, bool needsDispose = false) { if (TA) { assert(TU && "Invalid arguments!"); - return { static_cast(TA->getKind()), (needsDispose ? 1 : 0), TA, TU }; + return { ConvertTemplateArgumentKind(TA->getKind()), (needsDispose ? 1 : 0), TA, TU }; } return { }; diff --git a/tests/ClangSharp.UnitTests/CursorTests/DeclTest.cs b/tests/ClangSharp.UnitTests/CursorTests/DeclTest.cs index 067280f1..a8a49d9a 100644 --- a/tests/ClangSharp.UnitTests/CursorTests/DeclTest.cs +++ b/tests/ClangSharp.UnitTests/CursorTests/DeclTest.cs @@ -74,4 +74,26 @@ class MyClass var templateParameter = classTemplatePartialSpecializationDecl.TemplateParameters.Single(); Assert.That(templateParameter.Name, Is.EqualTo("U")); } + + [Test] + public void TemplateParameterPackTest() + { + var inputContents = $@"template +class tuple; + +tuple SomeFunction(); +"; + + using var translationUnit = CreateTranslationUnit(inputContents); + + var functionDecl = translationUnit.TranslationUnitDecl.Decls.OfType().Single(); + var tupleDecl = functionDecl.ReturnType.AsCXXRecordDecl as ClassTemplateSpecializationDecl; + Assert.That(tupleDecl, Is.Not.Null); + Assert.That(tupleDecl!.TemplateArgs.Count, Is.EqualTo(1)); + + var packElements = tupleDecl.TemplateArgs[0].PackElements; + Assert.That(packElements.Count, Is.EqualTo(2)); + Assert.That(packElements[0].AsType.AsString, Is.EqualTo("int")); + Assert.That(packElements[1].AsType.AsString, Is.EqualTo("long")); + } } From 74b88738093a82b94da92fd7ed873b744944c5cd Mon Sep 17 00:00:00 2001 From: Julien Lebosquain Date: Wed, 20 Nov 2024 16:10:43 +0100 Subject: [PATCH 04/12] Disable TemplateParameterPackTest for now --- tests/ClangSharp.UnitTests/CursorTests/DeclTest.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/ClangSharp.UnitTests/CursorTests/DeclTest.cs b/tests/ClangSharp.UnitTests/CursorTests/DeclTest.cs index a8a49d9a..e216b73b 100644 --- a/tests/ClangSharp.UnitTests/CursorTests/DeclTest.cs +++ b/tests/ClangSharp.UnitTests/CursorTests/DeclTest.cs @@ -76,6 +76,7 @@ class MyClass } [Test] + [Ignore("TODO: LibClangSharp needs to be recompiled first")] public void TemplateParameterPackTest() { var inputContents = $@"template From 43759a9a92d4acd65c144acd058f8cd4afd0196a Mon Sep 17 00:00:00 2001 From: Andrew Davis Date: Wed, 8 Jan 2025 13:21:14 -0500 Subject: [PATCH 05/12] Add Parameter Types to InheritDoc comments --- .../Abstractions/FunctionOrDelegateDesc.cs | 1 + .../CSharp/CSharpOutputBuilder.VisitDecl.cs | 3 +++ .../ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs | 1 + 3 files changed, 5 insertions(+) diff --git a/sources/ClangSharp.PInvokeGenerator/Abstractions/FunctionOrDelegateDesc.cs b/sources/ClangSharp.PInvokeGenerator/Abstractions/FunctionOrDelegateDesc.cs index d05c90b3..1e407441 100644 --- a/sources/ClangSharp.PInvokeGenerator/Abstractions/FunctionOrDelegateDesc.cs +++ b/sources/ClangSharp.PInvokeGenerator/Abstractions/FunctionOrDelegateDesc.cs @@ -21,6 +21,7 @@ internal struct FunctionOrDelegateDesc public bool HasBody { get; set; } public bool IsInherited { get; set; } public bool NeedsUnscopedRef { get; set; } + public string[] ParameterTypes { get; set; } public bool IsVirtual { diff --git a/sources/ClangSharp.PInvokeGenerator/CSharp/CSharpOutputBuilder.VisitDecl.cs b/sources/ClangSharp.PInvokeGenerator/CSharp/CSharpOutputBuilder.VisitDecl.cs index 712f8c81..ed30614a 100644 --- a/sources/ClangSharp.PInvokeGenerator/CSharp/CSharpOutputBuilder.VisitDecl.cs +++ b/sources/ClangSharp.PInvokeGenerator/CSharp/CSharpOutputBuilder.VisitDecl.cs @@ -372,6 +372,9 @@ public void BeginFunctionOrDelegate(in FunctionOrDelegateDesc desc, ref bool isM Write(desc.ParentName); Write('.'); Write(desc.EscapedName); + Write('('); + Write(string.Join(", ", desc.ParameterTypes)); + Write(')'); WriteLine("\" />"); } else diff --git a/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs b/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs index 23e40097..4661eb1f 100644 --- a/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs +++ b/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs @@ -622,6 +622,7 @@ private void VisitFunctionDecl(FunctionDecl functionDecl) } }, CustomAttrGeneratorData = (functionDecl, _outputBuilder, this), + ParameterTypes = functionDecl.Parameters.Select(param => GetTargetTypeName(param, out var _)).ToArray(), }; Debug.Assert(_outputBuilder is not null); From d5572740151b0cd1cfce03f7b9a7883d15ee3318 Mon Sep 17 00:00:00 2001 From: Andrew Davis Date: Thu, 30 Jan 2025 00:55:30 -0500 Subject: [PATCH 06/12] Adjust to only add parameters to inherit doc if necessary --- .../Abstractions/FunctionOrDelegateDesc.cs | 2 +- .../CSharp/CSharpOutputBuilder.VisitDecl.cs | 9 +++-- .../PInvokeGenerator.VisitDecl.cs | 5 ++- .../PInvokeGenerator.cs | 33 +++++++++++++++++++ 4 files changed, 44 insertions(+), 5 deletions(-) diff --git a/sources/ClangSharp.PInvokeGenerator/Abstractions/FunctionOrDelegateDesc.cs b/sources/ClangSharp.PInvokeGenerator/Abstractions/FunctionOrDelegateDesc.cs index 1e407441..0a33d680 100644 --- a/sources/ClangSharp.PInvokeGenerator/Abstractions/FunctionOrDelegateDesc.cs +++ b/sources/ClangSharp.PInvokeGenerator/Abstractions/FunctionOrDelegateDesc.cs @@ -21,7 +21,7 @@ internal struct FunctionOrDelegateDesc public bool HasBody { get; set; } public bool IsInherited { get; set; } public bool NeedsUnscopedRef { get; set; } - public string[] ParameterTypes { get; set; } + public string[]? ParameterTypes { get; set; } public bool IsVirtual { diff --git a/sources/ClangSharp.PInvokeGenerator/CSharp/CSharpOutputBuilder.VisitDecl.cs b/sources/ClangSharp.PInvokeGenerator/CSharp/CSharpOutputBuilder.VisitDecl.cs index ed30614a..1cfa2fd5 100644 --- a/sources/ClangSharp.PInvokeGenerator/CSharp/CSharpOutputBuilder.VisitDecl.cs +++ b/sources/ClangSharp.PInvokeGenerator/CSharp/CSharpOutputBuilder.VisitDecl.cs @@ -372,9 +372,12 @@ public void BeginFunctionOrDelegate(in FunctionOrDelegateDesc desc, ref bool isM Write(desc.ParentName); Write('.'); Write(desc.EscapedName); - Write('('); - Write(string.Join(", ", desc.ParameterTypes)); - Write(')'); + if (desc.ParameterTypes is not null && desc.ParameterTypes.Length > 0) + { + Write('('); + Write(string.Join(", ", desc.ParameterTypes)); + Write(')'); + } WriteLine("\" />"); } else diff --git a/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs b/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs index 4661eb1f..fa79a6f9 100644 --- a/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs +++ b/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs @@ -501,12 +501,15 @@ private void VisitFunctionDecl(FunctionDecl functionDecl) var name = GetRemappedCursorName(functionDecl); var cxxMethodDecl = functionDecl as CXXMethodDecl; + uint overloadCount = 0; if (cxxMethodDecl is not null and CXXConstructorDecl) { var parent = cxxMethodDecl.Parent; Debug.Assert(parent is not null); name = GetRemappedCursorName(parent); + + overloadCount = GetOverloadCount(cxxMethodDecl); } var isManualImport = _config.WithManualImports.Contains(name); @@ -622,7 +625,7 @@ private void VisitFunctionDecl(FunctionDecl functionDecl) } }, CustomAttrGeneratorData = (functionDecl, _outputBuilder, this), - ParameterTypes = functionDecl.Parameters.Select(param => GetTargetTypeName(param, out var _)).ToArray(), + ParameterTypes = overloadCount > 1 ? functionDecl.Parameters.Select(param => GetTargetTypeName(param, out var _)).ToArray() : null, }; Debug.Assert(_outputBuilder is not null); diff --git a/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.cs b/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.cs index 0d45f9de..ff5eab67 100644 --- a/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.cs +++ b/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.cs @@ -3096,6 +3096,39 @@ uint GetOverloadIndex(CXXMethodDecl cxxMethodDeclToMatch, CXXRecordDecl cxxRecor } } + private uint GetOverloadCount(CXXMethodDecl cxxMethodDeclToMatch) + { + var parent = cxxMethodDeclToMatch.Parent; + Debug.Assert(parent is not null); + + return GetOverloadIndex(cxxMethodDeclToMatch, parent, baseCount: 0); + + uint GetOverloadIndex(CXXMethodDecl cxxMethodDeclToMatch, CXXRecordDecl cxxRecordDecl, uint baseCount) + { + var count = baseCount; + + foreach (var cxxBaseSpecifier in cxxRecordDecl.Bases) + { + var baseCxxRecordDecl = GetRecordDecl(cxxBaseSpecifier); + count = GetOverloadIndex(cxxMethodDeclToMatch, baseCxxRecordDecl, count); + } + + foreach (var cxxMethodDecl in cxxRecordDecl.Methods) + { + if (IsExcluded(cxxMethodDecl)) + { + continue; + } + else if (cxxMethodDecl.Name == cxxMethodDeclToMatch.Name) + { + count++; + } + } + + return count; + } + } + private CXXRecordDecl GetRecordDecl(CXXBaseSpecifier cxxBaseSpecifier) { var baseType = cxxBaseSpecifier.Type; From b44596abe320573f631362d7d864c1c973ce81b0 Mon Sep 17 00:00:00 2001 From: Andrew Davis Date: Thu, 30 Jan 2025 01:00:41 -0500 Subject: [PATCH 07/12] removed an unnecessary check possibly could still cause problems if 0 params is not specified as well --- .../CSharp/CSharpOutputBuilder.VisitDecl.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sources/ClangSharp.PInvokeGenerator/CSharp/CSharpOutputBuilder.VisitDecl.cs b/sources/ClangSharp.PInvokeGenerator/CSharp/CSharpOutputBuilder.VisitDecl.cs index 1cfa2fd5..8380a582 100644 --- a/sources/ClangSharp.PInvokeGenerator/CSharp/CSharpOutputBuilder.VisitDecl.cs +++ b/sources/ClangSharp.PInvokeGenerator/CSharp/CSharpOutputBuilder.VisitDecl.cs @@ -372,7 +372,7 @@ public void BeginFunctionOrDelegate(in FunctionOrDelegateDesc desc, ref bool isM Write(desc.ParentName); Write('.'); Write(desc.EscapedName); - if (desc.ParameterTypes is not null && desc.ParameterTypes.Length > 0) + if (desc.ParameterTypes is not null) { Write('('); Write(string.Join(", ", desc.ParameterTypes)); From 98fcc166b2c5433c26637110dd70380cf10a6b77 Mon Sep 17 00:00:00 2001 From: Andrew Davis Date: Fri, 31 Jan 2025 14:10:08 -0500 Subject: [PATCH 08/12] move overloadCount out of constructor only if --- .../ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs b/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs index fa79a6f9..f5711355 100644 --- a/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs +++ b/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs @@ -508,7 +508,10 @@ private void VisitFunctionDecl(FunctionDecl functionDecl) var parent = cxxMethodDecl.Parent; Debug.Assert(parent is not null); name = GetRemappedCursorName(parent); + } + if (cxxMethodDecl is not null) + { overloadCount = GetOverloadCount(cxxMethodDecl); } From 4c866fbf76e46c3373d2df6093203acf08a376aa Mon Sep 17 00:00:00 2001 From: Tanner Gooding Date: Mon, 24 Feb 2025 15:37:46 -0800 Subject: [PATCH 09/12] Ensure properties expands to multiple options --- scripts/build.ps1 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/build.ps1 b/scripts/build.ps1 index 5558ed50..882eba52 100644 --- a/scripts/build.ps1 +++ b/scripts/build.ps1 @@ -20,7 +20,7 @@ $ErrorActionPreference = "Stop" function Build() { $logFile = Join-Path -Path $LogDir -ChildPath "$configuration\build.binlog" - & dotnet build -c "$configuration" --no-restore -v "$verbosity" /bl:"$logFile" /err "$properties" "$solution" + & dotnet build -c "$configuration" --no-restore -v "$verbosity" /bl:"$logFile" /err $properties "$solution" if ($LastExitCode -ne 0) { throw "'Build' failed for '$solution'" @@ -57,7 +57,7 @@ function Help() { function Pack() { $logFile = Join-Path -Path $LogDir -ChildPath "$configuration\pack.binlog" - & dotnet pack -c "$configuration" --no-build --no-restore -v "$verbosity" /bl:"$logFile" /err "$properties" "$solution" + & dotnet pack -c "$configuration" --no-build --no-restore -v "$verbosity" /bl:"$logFile" /err $properties "$solution" if ($LastExitCode -ne 0) { throw "'Pack' failed for '$solution'" @@ -66,7 +66,7 @@ function Pack() { function Restore() { $logFile = Join-Path -Path $LogDir -ChildPath "$configuration\restore.binlog" - & dotnet restore -v "$verbosity" /bl:"$logFile" /err "$properties" "$solution" + & dotnet restore -v "$verbosity" /bl:"$logFile" /err $properties "$solution" if ($LastExitCode -ne 0) { throw "'Restore' failed for '$solution'" @@ -75,7 +75,7 @@ function Restore() { function Test() { $logFile = Join-Path -Path $LogDir -ChildPath "$configuration\test.binlog" - & dotnet test -c "$configuration" --no-build --no-restore -v "$verbosity" /bl:"$logFile" /err "$properties" "$solution" + & dotnet test -c "$configuration" --no-build --no-restore -v "$verbosity" /bl:"$logFile" /err $properties "$solution" if ($LastExitCode -ne 0) { throw "'Test' failed for '$solution'" From 4da340c41a6a93b04b3f5ed1fd1a295ab7223e2b Mon Sep 17 00:00:00 2001 From: Andrew Davis Date: Fri, 14 Mar 2025 14:50:11 -0400 Subject: [PATCH 10/12] Add DontUseUsingStaticsForGuidMember --- .../PInvokeGenerator.VisitDecl.cs | 36 ++++++++++++++++--- .../PInvokeGeneratorConfiguration.cs | 2 ++ .../PInvokeGeneratorConfigurationOptions.cs | 2 ++ 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs b/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs index 1d771de4..2e37bb02 100644 --- a/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs +++ b/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.VisitDecl.cs @@ -1411,7 +1411,15 @@ private void VisitRecordDecl(RecordDecl recordDecl) var className = GetClass(uuidName); _testOutputBuilder.AddUsingDirective("System"); - _testOutputBuilder.AddUsingDirective($"static {GetNamespace(className)}.{className}"); + + if (_config.DontUseUsingStaticsForGuidMember) + { + _testOutputBuilder.AddUsingDirective($"{GetNamespace(className)}"); + } + else + { + _testOutputBuilder.AddUsingDirective($"static {GetNamespace(className)}.{className}"); + } _testOutputBuilder.WriteIndented("/// Validates that the of the ExcludedNames public bool StripEnumMemberTypeName => _options.HasFlag(PInvokeGeneratorConfigurationOptions.StripEnumMemberTypeName); + public bool DontUseUsingStaticsForGuidMember => _options.HasFlag(PInvokeGeneratorConfigurationOptions.DontUseUsingStaticsForGuidMember); + public string HeaderText => _headerText; [AllowNull] diff --git a/sources/ClangSharp.PInvokeGenerator/PInvokeGeneratorConfigurationOptions.cs b/sources/ClangSharp.PInvokeGenerator/PInvokeGeneratorConfigurationOptions.cs index c2a34293..cd77e71c 100644 --- a/sources/ClangSharp.PInvokeGenerator/PInvokeGeneratorConfigurationOptions.cs +++ b/sources/ClangSharp.PInvokeGenerator/PInvokeGeneratorConfigurationOptions.cs @@ -88,4 +88,6 @@ public enum PInvokeGeneratorConfigurationOptions : long GenerateGenericPointerWrapper = 1L << 38, StripEnumMemberTypeName = 1L << 39, + + DontUseUsingStaticsForGuidMember = 1L << 40, } From 969491251309f3fba346a1dff9d599836f7e4ef8 Mon Sep 17 00:00:00 2001 From: Andrew Davis Date: Fri, 14 Mar 2025 15:56:25 -0400 Subject: [PATCH 11/12] add missing code to read rsp files --- sources/ClangSharpPInvokeGenerator/Program.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/sources/ClangSharpPInvokeGenerator/Program.cs b/sources/ClangSharpPInvokeGenerator/Program.cs index 322ef1e4..8bad0657 100644 --- a/sources/ClangSharpPInvokeGenerator/Program.cs +++ b/sources/ClangSharpPInvokeGenerator/Program.cs @@ -444,6 +444,13 @@ public static void Run(InvocationContext context) break; } + case "exclude-using-statics-for-guid-members": + case "dont-use-using-statics-for-guid-members": + { + configOptions |= PInvokeGeneratorConfigurationOptions.DontUseUsingStaticsForGuidMember; + break; + } + // VTBL Options case "explicit-vtbls": From 233d46d6e4b60fd71723748ac8834d6e7dd4caaa Mon Sep 17 00:00:00 2001 From: Tanner Gooding Date: Mon, 7 Apr 2025 12:20:35 -0700 Subject: [PATCH 12/12] Update version to v18.1.0.4 --- Directory.Build.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Directory.Build.props b/Directory.Build.props index 4797b4f0..39a8f51d 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -47,7 +47,7 @@ 17.0.0 ClangSharp ClangSharp - 18.1.0.3 + 18.1.0.4 rc1 pr