Browse Source

Added a special system module to contain all system units.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/661/head
Dimitar Dobrev 9 years ago
parent
commit
af81834b38
  1. 2
      src/AST/Module.cs
  2. 6
      src/Generator/Options.cs
  3. 37
      src/Generator/Passes/CleanUnitPass.cs
  4. 4
      tests/NamespacesDerived/NamespacesDerived.cs

2
src/AST/Module.cs

@ -4,6 +4,8 @@ namespace CppSharp.AST @@ -4,6 +4,8 @@ namespace CppSharp.AST
{
public class Module
{
public static Module SystemModule = new Module { OutputNamespace = string.Empty, LibraryName = "Std" };
public Module()
{
IncludeDirs = new List<string>();

6
src/Generator/Options.cs

@ -27,7 +27,7 @@ namespace CppSharp @@ -27,7 +27,7 @@ namespace CppSharp
OutputDir = Directory.GetCurrentDirectory();
Modules = new List<Module>();
Modules = new List<Module> { Module.SystemModule };
GeneratorKind = GeneratorKind.CSharp;
GeneratePartialClasses = true;
@ -62,9 +62,9 @@ namespace CppSharp @@ -62,9 +62,9 @@ namespace CppSharp
{
get
{
if (Modules.Count == 0)
if (Modules.Count == 1)
Modules.Add(new Module());
return Modules[0];
return Modules[1];
}
}

37
src/Generator/Passes/CleanUnitPass.cs

@ -16,26 +16,24 @@ namespace CppSharp.Passes @@ -16,26 +16,24 @@ namespace CppSharp.Passes
public override bool VisitTranslationUnit(TranslationUnit unit)
{
if (!base.VisitTranslationUnit(unit))
if (!unit.IsValid)
return false;
if (unit.IsValid && !unit.IsSystemHeader)
if (unit.IsSystemHeader)
{
unit.Module = Module.SystemModule;
}
else
{
var includeDir = Path.GetFullPath(Path.GetDirectoryName(unit.FilePath));
unit.Module = DriverOptions.Modules.FirstOrDefault(
m => m.IncludeDirs.Any(i => Path.GetFullPath(i) == includeDir)) ??
DriverOptions.MainModule;
unit.Module.Units.Add(unit);
}
// Try to get an include path that works from the original include
// directories paths.
if (unit.IsValid)
{
unit.IncludePath = GetIncludePath(unit.FilePath);
return true;
}
return false;
unit.Module.Units.Add(unit);
// Try to get an include path that works from the original include directories paths
unit.IncludePath = GetIncludePath(unit.FilePath);
return true;
}
string GetIncludePath(string filePath)
@ -67,20 +65,5 @@ namespace CppSharp.Passes @@ -67,20 +65,5 @@ namespace CppSharp.Passes
return includePath.Replace('\\', '/');
}
bool IsExternalDeclaration(TranslationUnit translationUnit)
{
if (DriverOptions.NoGenIncludeDirs == null)
return false;
foreach (var path in DriverOptions.NoGenIncludeDirs)
{
if (translationUnit.FilePath.StartsWith(path, StringComparison.Ordinal))
return true;
}
return false;
}
}
}

4
tests/NamespacesDerived/NamespacesDerived.cs

@ -19,7 +19,7 @@ namespace CppSharp.Tests @@ -19,7 +19,7 @@ namespace CppSharp.Tests
driver.Options.GenerateDefaultValuesForArguments = true;
driver.Options.GeneratePropertiesAdvanced = true;
driver.Options.Modules[0].IncludeDirs.Add(GetTestsDirectory("NamespacesDerived"));
driver.Options.Modules[1].IncludeDirs.Add(GetTestsDirectory("NamespacesDerived"));
var @base = "NamespacesBase";
var module = new Module();
module.IncludeDirs.Add(Path.GetFullPath(GetTestsDirectory(@base)));
@ -30,7 +30,7 @@ namespace CppSharp.Tests @@ -30,7 +30,7 @@ namespace CppSharp.Tests
if (System.Type.GetType("Mono.Runtime") == null)
module.SharedLibraryName += ".dll";
module.LibraryName = string.Format("{0}.CSharp", @base);
driver.Options.Modules.Insert(0, module);
driver.Options.Modules.Insert(1, module);
}
public override void Postprocess(Driver driver, ASTContext ctx)

Loading…
Cancel
Save