mirror of https://github.com/mono/CppSharp.git
12 changed files with 238 additions and 24 deletions
@ -0,0 +1,39 @@
@@ -0,0 +1,39 @@
|
||||
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)) |
||||
{ |
||||
var rootNamespace = Driver.RootNamespaceRenames[fileName].rootNamespaceName; |
||||
if (this.Driver.Options.OutputNamespace != rootNamespace) |
||||
unit.Name = rootNamespace; |
||||
} |
||||
else if (unit.GenerationKind == GenerationKind.Generate) |
||||
{ |
||||
Driver.RootNamespaceRenames.Add(fileName, new Driver.TranslationUnitRenameInfo |
||||
{ |
||||
translationUnit = fileName, |
||||
rootNamespaceName = Driver.Options.OutputNamespace, |
||||
}); |
||||
} |
||||
return true; |
||||
} |
||||
|
||||
} |
||||
} |
||||
@ -1,6 +1,60 @@
@@ -1,6 +1,60 @@
|
||||
#include "NamespacesDerived.h" |
||||
|
||||
|
||||
Derived::Derived() : Base(10), component(5) |
||||
OverlappingNamespace::InDerivedLib::InDerivedLib() : parentNSComponent(), color(black) |
||||
{ |
||||
} |
||||
|
||||
Derived::Derived() : Base(10), baseComponent(5), nestedNSComponent(), color(OverlappingNamespace::blue) |
||||
{ |
||||
} |
||||
|
||||
Base Derived::getBase() |
||||
{ |
||||
return baseComponent; |
||||
} |
||||
|
||||
void Derived::setBase(Base b) |
||||
{ |
||||
baseComponent = b; |
||||
} |
||||
|
||||
OverlappingNamespace::InBaseLib Derived::getNestedNSComponent() |
||||
{ |
||||
return nestedNSComponent; |
||||
} |
||||
|
||||
void Derived::setNestedNSComponent(OverlappingNamespace::InBaseLib c) |
||||
{ |
||||
nestedNSComponent = c; |
||||
} |
||||
|
||||
|
||||
Base2::Base2() |
||||
{ |
||||
} |
||||
|
||||
|
||||
Derived2::Derived2() : Base2() |
||||
{ |
||||
} |
||||
|
||||
Base2 Derived2::getBase() |
||||
{ |
||||
return baseComponent; |
||||
} |
||||
|
||||
void Derived2::setBase(Base2 b) |
||||
{ |
||||
baseComponent = b; |
||||
} |
||||
|
||||
OverlappingNamespace::InDerivedLib Derived2::getNestedNSComponent() |
||||
{ |
||||
return nestedNSComponent; |
||||
} |
||||
|
||||
void Derived2::setNestedNSComponent(OverlappingNamespace::InDerivedLib c) |
||||
{ |
||||
nestedNSComponent = c; |
||||
} |
||||
|
||||
@ -1,13 +1,60 @@
@@ -1,13 +1,60 @@
|
||||
#include "../Tests.h" |
||||
#include "../NamespacesBase/NamespacesBase.h" |
||||
|
||||
// Namespace clashes with NamespacesBase.OverlappingNamespace
|
||||
// Test whether qualified names turn out right.
|
||||
namespace OverlappingNamespace |
||||
{ |
||||
|
||||
class InDerivedLib |
||||
{ |
||||
public: |
||||
InDerivedLib(); |
||||
Base parentNSComponent; |
||||
ColorsEnum color; |
||||
}; |
||||
} |
||||
|
||||
|
||||
// Using a type imported from a different library.
|
||||
class DLL_API Derived : public Base |
||||
{ |
||||
public: |
||||
Derived(); |
||||
|
||||
Base component; |
||||
Base baseComponent; |
||||
Base getBase(); |
||||
void setBase(Base); |
||||
|
||||
OverlappingNamespace::InBaseLib nestedNSComponent; |
||||
OverlappingNamespace::InBaseLib getNestedNSComponent(); |
||||
void setNestedNSComponent(OverlappingNamespace::InBaseLib); |
||||
|
||||
OverlappingNamespace::ColorsEnum color; |
||||
|
||||
private: |
||||
int d; |
||||
}; |
||||
|
||||
|
||||
// For reference: using a type derived in the same library
|
||||
class Base2 |
||||
{ |
||||
public: |
||||
Base2(); |
||||
}; |
||||
|
||||
class Derived2 : public Base2 |
||||
{ |
||||
public: |
||||
Derived2(); |
||||
|
||||
Base2 baseComponent; |
||||
Base2 getBase(); |
||||
void setBase(Base2); |
||||
|
||||
OverlappingNamespace::InDerivedLib nestedNSComponent; |
||||
OverlappingNamespace::InDerivedLib getNestedNSComponent(); |
||||
void setNestedNSComponent(OverlappingNamespace::InDerivedLib); |
||||
|
||||
}; |
||||
|
||||
@ -1,4 +1,4 @@
@@ -1,4 +1,4 @@
|
||||
group "Tests/Namespaces" |
||||
SetupTestGeneratorProject("NamespacesDerived") |
||||
SetupTestNativeProject("NamespacesDerived", "NamespacesBase.Native") |
||||
SetupTestProjectsCSharp("NamespacesDerived", "NamespacesBase.CSharp") |
||||
SetupTestGeneratorProject("NamespacesDerived", "NamespacesBase") |
||||
SetupTestNativeProject("NamespacesDerived", "NamespacesBase") |
||||
SetupTestProjectsCSharp("NamespacesDerived", "NamespacesBase") |
||||
Loading…
Reference in new issue