Browse Source

[generator] Improved processing for C++ inline namespaces.

pull/916/head
Joao Matos 8 years ago
parent
commit
09e568d0b3
  1. 4
      src/AST/Declaration.cs
  2. 2
      src/Generator/Generators/CLI/CLIHeaders.cs
  3. 4
      src/Generator/Generators/CSharp/CSharpSources.cs
  4. 3
      src/Generator/Generators/CSharp/CSharpTypePrinter.cs
  5. 4
      src/Generator/Types/Std/Stdlib.cs
  6. 6
      tests/Common/Common.Tests.cs
  7. 8
      tests/Common/Common.h

4
src/AST/Declaration.cs

@ -144,7 +144,9 @@ namespace CppSharp.AST
var currentNamespace = @namespace; var currentNamespace = @namespace;
while (currentNamespace != null) while (currentNamespace != null)
{ {
namespaces.Push(currentNamespace); var isInlineNamespace = currentNamespace is Namespace && ((Namespace)currentNamespace).IsInline;
if (!isInlineNamespace)
namespaces.Push(currentNamespace);
currentNamespace = currentNamespace.Namespace; currentNamespace = currentNamespace.Namespace;
} }

2
src/Generator/Generators/CLI/CLIHeaders.cs

@ -185,7 +185,7 @@ namespace CppSharp.Generators.CLI
public void GenerateNamespace(Namespace @namespace) public void GenerateNamespace(Namespace @namespace)
{ {
var isTopLevel = @namespace is TranslationUnit; var isTopLevel = @namespace is TranslationUnit;
var generateNamespace = !isTopLevel || var generateNamespace = !isTopLevel || !@namespace.IsInline &&
!string.IsNullOrEmpty(@namespace.TranslationUnit.Module.OutputNamespace); !string.IsNullOrEmpty(@namespace.TranslationUnit.Module.OutputNamespace);
if (generateNamespace) if (generateNamespace)

4
src/Generator/Generators/CSharp/CSharpSources.cs

@ -158,11 +158,9 @@ namespace CppSharp.Generators.CSharp
public override bool VisitNamespace(Namespace @namespace) public override bool VisitNamespace(Namespace @namespace)
{ {
var context = @namespace; var context = @namespace;
var isNamespace = context is Namespace;
var isTranslationUnit = context is TranslationUnit; var isTranslationUnit = context is TranslationUnit;
var shouldGenerateNamespace = isNamespace && !isTranslationUnit && var shouldGenerateNamespace = !@namespace.IsInline && !isTranslationUnit &&
context.Declarations.Any(d => d.IsGenerated || (d is Class && !d.IsIncomplete)); context.Declarations.Any(d => d.IsGenerated || (d is Class && !d.IsIncomplete));
if (shouldGenerateNamespace) if (shouldGenerateNamespace)

3
src/Generator/Generators/CSharp/CSharpTypePrinter.cs

@ -622,7 +622,8 @@ namespace CppSharp.Generators.CSharp
while (!(ctx is TranslationUnit)) while (!(ctx is TranslationUnit))
{ {
if (!string.IsNullOrWhiteSpace(ctx.Name)) var isInlineNamespace = ctx is Namespace && ((Namespace)ctx).IsInline;
if (!string.IsNullOrWhiteSpace(ctx.Name) && !isInlineNamespace)
names.Push(ctx.Name); names.Push(ctx.Name);
ctx = ctx.Namespace; ctx = ctx.Namespace;

4
src/Generator/Types/Std/Stdlib.cs

@ -123,7 +123,9 @@ namespace CppSharp.Types.Std
var names = new Stack<string>(); var names = new Stack<string>();
while (!(declContext is TranslationUnit)) while (!(declContext is TranslationUnit))
{ {
names.Push(declContext.Name); var isInlineNamespace = declContext is Namespace && ((Namespace)declContext).IsInline;
if (!isInlineNamespace)
names.Push(declContext.Name);
declContext = declContext.Namespace; declContext = declContext.Namespace;
} }
var qualifiedBasicString = string.Join(".", names); var qualifiedBasicString = string.Join(".", names);

6
tests/Common/Common.Tests.cs

@ -807,4 +807,10 @@ This is a very long string. This is a very long string. This is a very long stri
Assert.That(testProperties.RefToPrimitiveInSetter, Is.EqualTo(value)); Assert.That(testProperties.RefToPrimitiveInSetter, Is.EqualTo(value));
} }
} }
[Test]
public void TestInlineNamespaces()
{
Common.FunctionInsideInlineNamespace();
}
} }

8
tests/Common/Common.h

@ -1361,3 +1361,11 @@ template<typename T> void TemplatedFunction(T type)
{ {
} }
inline namespace InlineNamespace
{
void FunctionInsideInlineNamespace()
{
}
}
Loading…
Cancel
Save