Browse Source

Implemented name importing & exporting.

pull/408/head
Pyry Kontio 11 years ago
parent
commit
8a85058c48
  1. 14
      src/Generator/Driver.cs
  2. 2
      src/Generator/Generators/CSharp/CSharpTextTemplate.cs
  3. 3
      src/Generator/Generators/CSharp/CSharpTypePrinter.cs
  4. 37
      src/Generator/Passes/RenameRootNamespaces.cs
  5. 2
      tests/NamespacesBase/NamespacesBase.cs
  6. 2
      tests/NamespacesDerived/NamespacesDerived.cs

14
src/Generator/Driver.cs

@ -32,6 +32,18 @@ namespace CppSharp @@ -32,6 +32,18 @@ namespace CppSharp
public ASTContext ASTContext { get; private set; }
public SymbolContext Symbols { get; private set; }
public struct TranslationUnitRenameInfo
{
public string translationUnit;
public string rootNamespaceName;
}
public static Dictionary<string, TranslationUnitRenameInfo> RootNamespaceRenames { get; private set; }
static Driver()
{
Driver.RootNamespaceRenames = new Dictionary<string, TranslationUnitRenameInfo>();
}
public Driver(DriverOptions options, IDiagnosticConsumer diagnostics)
{
Options = options;
@ -279,6 +291,8 @@ namespace CppSharp @@ -279,6 +291,8 @@ namespace CppSharp
if (Options.GeneratePropertiesAdvanced)
TranslationUnitPasses.AddPass(new GetterSetterToPropertyAdvancedPass());
TranslationUnitPasses.AddPass(new RenameRootNamespacesPass());
}
public void ProcessCode()

2
src/Generator/Generators/CSharp/CSharpTextTemplate.cs

@ -1781,7 +1781,7 @@ namespace CppSharp.Generators.CSharp @@ -1781,7 +1781,7 @@ namespace CppSharp.Generators.CSharp
var hasBaseClass = @class.HasBaseClass && @class.BaseClass.IsRefType;
if (hasBaseClass)
WriteLineIndent(": base(({0}.Internal*) native{1})",
@class.BaseClass.Name, @class.IsAbstractImpl ? ", true" : string.Empty);
QualifiedIdentifier(@class.BaseClass), @class.IsAbstractImpl ? ", true" : string.Empty);
WriteStartBraceIndent();

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

@ -551,9 +551,6 @@ namespace CppSharp.Generators.CSharp @@ -551,9 +551,6 @@ namespace CppSharp.Generators.CSharp
var ctx = decl.Namespace;
while (ctx != null)
{
if (ctx is TranslationUnit)
break;
if (!string.IsNullOrWhiteSpace(ctx.Name))
names.Add(ctx.Name);

37
src/Generator/Passes/RenameRootNamespaces.cs

@ -0,0 +1,37 @@ @@ -0,0 +1,37 @@
using CppSharp.AST;
using System;
using System.Collections.Generic;
namespace CppSharp.Passes
{
// This pass visits all the translation units and checks if they originate from library being processed or
// from some other library that is being depended upon. It will rename the root namespaces of all the "foreign"
// libraries so that there wouldn't be clashes and so that the code generation phase would be able to generate
// names with fully qualified namespace prefixes.
public class RenameRootNamespacesPass : TranslationUnitPass
{
public override bool VisitTranslationUnit(TranslationUnit unit)
{
if (!base.VisitTranslationUnit(unit))
return false;
var fileName = unit.TranslationUnit.FileName;
if (Driver.RootNamespaceRenames.ContainsKey(fileName))
{
unit.Name = Driver.RootNamespaceRenames[fileName].rootNamespaceName;
}
else if (unit.GenerationKind == GenerationKind.Generate)
{
Driver.RootNamespaceRenames.Add(fileName, new Driver.TranslationUnitRenameInfo
{
translationUnit = fileName,
rootNamespaceName = Driver.Options.OutputNamespace,
});
}
return true;
}
}
}

2
tests/NamespacesBase/NamespacesBase.cs

@ -32,7 +32,5 @@ namespace CppSharp.Tests @@ -32,7 +32,5 @@ namespace CppSharp.Tests
{
ConsoleDriver.Run(new NamespacesBaseTests(GeneratorKind.CSharp));
}
}
}

2
tests/NamespacesDerived/NamespacesDerived.cs

@ -15,7 +15,6 @@ namespace CppSharp.Tests @@ -15,7 +15,6 @@ namespace CppSharp.Tests
public override void SetupPasses(Driver driver)
{
driver.Options.DependentNameSpaces.Add("NamespacesBase");
}
public override void Preprocess(Driver driver, ASTContext ctx)
@ -39,6 +38,7 @@ namespace CppSharp.Tests @@ -39,6 +38,7 @@ namespace CppSharp.Tests
public static void Main(string[] args)
{
ConsoleDriver.Run(new NamespacesBaseTests(GeneratorKind.CSharp));
ConsoleDriver.Run(new NamespacesDerivedTests(GeneratorKind.CSharp));
}

Loading…
Cancel
Save