diff --git a/changelog.md b/changelog.md index 8ea1113..67b03a5 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,8 @@ # Changelog +## 0.8.0-alpha-016 (13 Dec 2023) +- Fixed empty template parameter name specialization + ## 0.8.0-alpha-015 (13 Dec 2023) - Fixed partial template specialization diff --git a/src/CppAst.Tests/TestMisc.cs b/src/CppAst.Tests/TestMisc.cs index 89940b2..be3857d 100644 --- a/src/CppAst.Tests/TestMisc.cs +++ b/src/CppAst.Tests/TestMisc.cs @@ -112,6 +112,7 @@ class Vector3d : public VectorBase Assert.AreEqual(CppTemplateKind.PartialTemplateClass, compilation.Classes[1].TemplateKind); Assert.AreEqual(1, compilation.Classes[1].TemplateParameters.Count); Assert.AreEqual("T", compilation.Classes[1].TemplateParameters[0].FullName); + Assert.IsNotNull(compilation.Classes[1].PrimaryTemplate); Assert.AreEqual(1, compilation.Classes[1].TemplateSpecializedArguments.Count); Assert.AreEqual(CppTemplateArgumentKind.AsInteger, compilation.Classes[1].TemplateSpecializedArguments[0].ArgKind); Assert.AreEqual(2, compilation.Classes[1].TemplateSpecializedArguments[0].ArgAsInteger); @@ -135,6 +136,7 @@ class Vector3d : public VectorBase Assert.AreEqual(CppTemplateKind.PartialTemplateClass, compilation.Classes[4].TemplateKind); Assert.AreEqual(1, compilation.Classes[4].TemplateParameters.Count); Assert.AreEqual("T", compilation.Classes[4].TemplateParameters[0].FullName); + Assert.IsNotNull(compilation.Classes[4].PrimaryTemplate); Assert.AreEqual(1, compilation.Classes[4].TemplateSpecializedArguments.Count); Assert.AreEqual(CppTemplateArgumentKind.AsInteger, compilation.Classes[4].TemplateSpecializedArguments[0].ArgKind); Assert.AreEqual(3, compilation.Classes[4].TemplateSpecializedArguments[0].ArgAsInteger); diff --git a/src/CppAst/CppAst.csproj b/src/CppAst/CppAst.csproj index 1ad45b4..f8b1a33 100644 --- a/src/CppAst/CppAst.csproj +++ b/src/CppAst/CppAst.csproj @@ -3,7 +3,7 @@ net6.0 0.8.0 alpha - 015 + 016 CppAst.cgnx CppAst is a .NET library providing a C/C++ parser for header files with access to the full AST, comments and macros Alexandre Mutel @@ -26,7 +26,7 @@ true true snupkg - 0.8.0-alpha-015 + 0.8.0-alpha-016 diff --git a/src/CppAst/CppModelBuilder.cs b/src/CppAst/CppModelBuilder.cs index 29bc49e..af965e8 100644 --- a/src/CppAst/CppModelBuilder.cs +++ b/src/CppAst/CppModelBuilder.cs @@ -118,17 +118,16 @@ private void AddTemplateSpecializedArguments(List sourceArg } else { - /* This is quite impossible, just to make sure */ - if (existingParams.Count() > 1) + /** Don't really know what to do with the case if we have the same template parameter multiple times */ + if (existingParams.Count() == 1) { - throw new InvalidOperationException($"The same template parameter `{p.SourceParam.FullName}` exists more than one times"); - } - var existingParam = existingParams[0]; - if (!existingParam.IsSpecializedArgument && p.IsSpecializedArgument) - { - /* We need to replace the already existing non-specialized parameter with the new specialized one */ - var index = destinationArguments.IndexOf(existingParam); - destinationArguments[index] = p; + var existingParam = existingParams[0]; + if (!existingParam.IsSpecializedArgument && p.IsSpecializedArgument) + { + /* We need to replace the already existing non-specialized parameter with the new specialized one */ + var index = destinationArguments.IndexOf(existingParam); + destinationArguments[index] = p; + } } } } @@ -142,6 +141,22 @@ private void UpdateTemplateType(CppClass cppClass) if (cppClass.TemplateKind == CppTemplateKind.TemplateClass && cppClass.TemplateParameters.Count > 0 && cppClass.TemplateSpecializedArguments.Count > 0) { cppClass.TemplateKind = CppTemplateKind.PartialTemplateClass; + /** We need to set the primary template */ + if (cppClass.PrimaryTemplate == null && cppClass.BaseTypes.Count > 0) + { + foreach (var b in cppClass.BaseTypes) + { + if (b.Type is CppClass) + { + var clz = b.Type as CppClass; + if (clz.TemplateKind == CppTemplateKind.TemplateClass) + { + cppClass.PrimaryTemplate = clz; + break; + } + } + } + } } } @@ -265,7 +280,6 @@ private CppContainerContext GetOrCreateDeclarationContainer(CXCursor cursor, voi Debug.Assert(cppClass.PrimaryTemplate.TemplateParameters.Count == tempArgsCount); } - for (uint i = 0; i < tempArgsCount; i++) { var arg = cursor.GetTemplateArgument(i);