Browse Source

Fixed the C++ printing of classes nested in specializations.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/816/head
Dimitar Dobrev 8 years ago
parent
commit
6a43e82047
  1. 4
      src/AST/CppTypePrinter.cs
  2. 15
      src/Generator.Tests/AST/TestAST.cs
  3. 3
      tests/Native/AST.h

4
src/AST/CppTypePrinter.cs

@ -311,9 +311,13 @@ namespace CppSharp.AST @@ -311,9 +311,13 @@ namespace CppSharp.AST
return PrintLogicalNames ? declaration.LogicalOriginalName
: declaration.OriginalName;
case TypePrintScopeKind.Qualified:
if (declaration.Namespace is Class)
return $"{declaration.Namespace.Visit(this)}::{declaration.OriginalName}";
return PrintLogicalNames ? declaration.QualifiedLogicalOriginalName
: declaration.QualifiedOriginalName;
case TypePrintScopeKind.GlobalQualified:
if (declaration.Namespace is Class)
return $"{declaration.Namespace.Visit(this)}::{declaration.OriginalName}";
var qualifier = PrintFlavorKind == CppTypePrintFlavorKind.Cpp ? "::" : string.Empty;
return qualifier + GetDeclName(declaration, TypePrintScopeKind.Qualified);
}

15
src/Generator.Tests/AST/TestAST.cs

@ -303,13 +303,13 @@ namespace CppSharp.Generator.Tests.AST @@ -303,13 +303,13 @@ namespace CppSharp.Generator.Tests.AST
[Test]
public void TestLineNumber()
{
Assert.AreEqual(67, AstContext.FindClass("HiddenInNamespace").First().LineNumberStart);
Assert.AreEqual(70, AstContext.FindClass("HiddenInNamespace").First().LineNumberStart);
}
[Test]
public void TestLineNumberOfFriend()
{
Assert.AreEqual(90, AstContext.FindFunction("operator+").First().LineNumberStart);
Assert.AreEqual(93, AstContext.FindFunction("operator+").First().LineNumberStart);
}
static string StripWindowsNewLines(string text)
@ -351,7 +351,7 @@ namespace CppSharp.Generator.Tests.AST @@ -351,7 +351,7 @@ namespace CppSharp.Generator.Tests.AST
[Test]
public void TestMacroLineNumber()
{
Assert.AreEqual(100, AstContext.FindClass("HasAmbiguousFunctions").First().Specifiers.Last().LineNumberStart);
Assert.AreEqual(103, AstContext.FindClass("HasAmbiguousFunctions").First().Specifiers.Last().LineNumberStart);
}
[Test]
@ -495,5 +495,14 @@ namespace CppSharp.Generator.Tests.AST @@ -495,5 +495,14 @@ namespace CppSharp.Generator.Tests.AST
var function = AstContext.FindFunction("Math::function").FirstOrDefault();
Assert.That(function, Is.Not.Null);
}
[Test]
public void TestPrintNestedInSpecialization()
{
var template = AstContext.FindDecl<ClassTemplate>("TestTemplateClass").First();
var cppTypePrinter = new CppTypePrinter { PrintScopeKind = TypePrintScopeKind.Qualified };
Assert.That(template.Specializations[1].Classes[0].Visit(cppTypePrinter),
Is.EqualTo("TestTemplateClass<Math::Complex>::NestedInTemplate"));
}
}
}

3
tests/Native/AST.h

@ -36,6 +36,9 @@ public: @@ -36,6 +36,9 @@ public:
TestTemplateClass(T v);
T Identity(T x);
T value;
class NestedInTemplate
{
};
};
// Tests function templates

Loading…
Cancel
Save