Browse Source

Ensured the system module only contains units from the current run.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/681/head
Dimitar Dobrev 9 years ago
parent
commit
b77d2ccdde
  1. 2
      src/AST/Module.cs
  2. 6
      src/Generator/Driver.cs
  3. 5
      src/Generator/Generators/CSharp/CSharpTextTemplate.cs
  4. 4
      src/Generator/Options.cs
  5. 2
      src/Generator/Passes/CleanUnitPass.cs
  6. 2
      src/Generator/Passes/GenerateTemplatesCodePass.cs

2
src/AST/Module.cs

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

6
src/Generator/Driver.cs

@ -434,9 +434,9 @@ namespace CppSharp @@ -434,9 +434,9 @@ namespace CppSharp
CompilerOptions = compilerOptions.ToString()
};
if (module != AST.Module.SystemModule)
if (module != Options.SystemModule)
compilerParameters.ReferencedAssemblies.Add(
string.Format("{0}.dll", AST.Module.SystemModule.LibraryName));
string.Format("{0}.dll", Options.SystemModule.LibraryName));
// add a reference to System.Core
compilerParameters.ReferencedAssemblies.Add(typeof(Enumerable).Assembly.Location);
@ -529,7 +529,7 @@ namespace CppSharp @@ -529,7 +529,7 @@ namespace CppSharp
}
new CleanUnitPass(options).VisitLibrary(driver.ASTContext);
options.Modules.RemoveAll(m => m != AST.Module.SystemModule && !m.Units.GetGenerated().Any());
options.Modules.RemoveAll(m => m != options.SystemModule && !m.Units.GetGenerated().Any());
if (!options.Quiet)
Log.Message("Processing code...");

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

@ -197,7 +197,8 @@ namespace CppSharp.Generators.CSharp @@ -197,7 +197,8 @@ namespace CppSharp.Generators.CSharp
}
PopBlock(NewLineKind.BeforeNextBlock);
var module = TranslationUnits.Count == 0 ? Module.SystemModule : TranslationUnit.Module;
var module = TranslationUnits.Count == 0 ?
Driver.Options.SystemModule : TranslationUnit.Module;
if (!string.IsNullOrEmpty(module.OutputNamespace))
{
PushBlock(CSharpBlockKind.Namespace);
@ -3131,7 +3132,7 @@ namespace CppSharp.Generators.CSharp @@ -3131,7 +3132,7 @@ namespace CppSharp.Generators.CSharp
private string GetLibraryOf(Declaration declaration)
{
if (declaration.TranslationUnit.IsSystemHeader)
return Module.SystemModule.TemplatesLibraryName;
return Driver.Options.SystemModule.TemplatesLibraryName;
string libName = declaration.TranslationUnit.Module.SharedLibraryName;

4
src/Generator/Options.cs

@ -27,7 +27,8 @@ namespace CppSharp @@ -27,7 +27,8 @@ namespace CppSharp
OutputDir = Directory.GetCurrentDirectory();
Modules = new List<Module> { Module.SystemModule };
SystemModule = new Module { OutputNamespace = string.Empty, LibraryName = "Std" };
Modules = new List<Module> { SystemModule };
GeneratorKind = GeneratorKind.CSharp;
GeneratePartialClasses = true;
@ -56,6 +57,7 @@ namespace CppSharp @@ -56,6 +57,7 @@ namespace CppSharp
/// </summary>
public bool DryRun;
public Module SystemModule { get; private set; }
public List<Module> Modules { get; private set; }
public Module MainModule

2
src/Generator/Passes/CleanUnitPass.cs

@ -20,7 +20,7 @@ namespace CppSharp.Passes @@ -20,7 +20,7 @@ namespace CppSharp.Passes
if (unit.IsSystemHeader)
{
unit.Module = Module.SystemModule;
unit.Module = DriverOptions.SystemModule;
}
else
{

2
src/Generator/Passes/GenerateTemplatesCodePass.cs

@ -43,7 +43,7 @@ namespace CppSharp.Passes @@ -43,7 +43,7 @@ namespace CppSharp.Passes
foreach (var module in Driver.Options.Modules.Where(m => templateInstantiations.ContainsKey(m)))
{
var cppBuilder = new StringBuilder();
if (module == Module.SystemModule)
if (module == Driver.Options.SystemModule)
cppBuilder.Append("#include <string>\n");
else
foreach (var header in module.Headers)

Loading…
Cancel
Save