Browse Source

Fixed the option for output name-spaces to allow eliminating them.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/661/head
Dimitar Dobrev 10 years ago
parent
commit
9b51e30643
  1. 2
      src/CppParser/Bindings/ParserGen.cs
  2. 1
      src/Generator.Tests/GeneratorTest.cs
  3. 2
      src/Generator/Driver.cs
  4. 2
      src/Generator/Generator.cs
  5. 3
      src/Generator/Generators/CLI/CLIHeadersTemplate.cs
  6. 2
      src/Generator/Generators/CLI/CLIMarshal.cs
  7. 2
      src/Generator/Generators/CLI/CLITextTemplate.cs
  8. 2
      src/Generator/Generators/CLI/CLITypePrinter.cs
  9. 4
      src/Generator/Generators/CSharp/CSharpTextTemplate.cs
  10. 2
      src/Generator/Options.cs

2
src/CppParser/Bindings/ParserGen.cs

@ -83,7 +83,7 @@ namespace CppSharp
if (Kind == GeneratorKind.CSharp) if (Kind == GeneratorKind.CSharp)
options.OutputDir = Path.Combine(options.OutputDir, options.TargetTriple + extraTriple); options.OutputDir = Path.Combine(options.OutputDir, options.TargetTriple + extraTriple);
options.GenerateLibraryNamespace = false; options.OutputNamespace = string.Empty;
options.CheckSymbols = false; options.CheckSymbols = false;
} }

1
src/Generator.Tests/GeneratorTest.cs

@ -29,7 +29,6 @@ namespace CppSharp.Utils
options.GeneratorKind = kind; options.GeneratorKind = kind;
options.OutputDir = Path.Combine(GetOutputDirectory(), "gen", name); options.OutputDir = Path.Combine(GetOutputDirectory(), "gen", name);
options.SharedLibraryName = name + ".Native"; options.SharedLibraryName = name + ".Native";
options.GenerateLibraryNamespace = true;
options.Quiet = true; options.Quiet = true;
options.IgnoreParseWarnings = true; options.IgnoreParseWarnings = true;

2
src/Generator/Driver.cs

@ -72,7 +72,7 @@ namespace CppSharp
if (string.IsNullOrWhiteSpace(module.LibraryName)) if (string.IsNullOrWhiteSpace(module.LibraryName))
throw new InvalidOptionException("One of your modules has no library name."); throw new InvalidOptionException("One of your modules has no library name.");
if (string.IsNullOrWhiteSpace(module.OutputNamespace)) if (module.OutputNamespace == null)
module.OutputNamespace = module.LibraryName; module.OutputNamespace = module.LibraryName;
} }

2
src/Generator/Generator.cs

@ -115,7 +115,7 @@ namespace CppSharp.Generators
{ {
TranslationUnit = new TranslationUnit TranslationUnit = new TranslationUnit
{ {
FilePath = string.Format("{0}.cs", module.OutputNamespace ?? module.LibraryName), FilePath = string.Format("{0}.cs", module.LibraryName),
Module = module Module = module
}, },
Templates = Generate(module.Units) Templates = Generate(module.Units)

3
src/Generator/Generators/CLI/CLIHeadersTemplate.cs

@ -187,7 +187,8 @@ 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 || Options.GenerateLibraryNamespace; var generateNamespace = !isTopLevel ||
!string.IsNullOrEmpty(@namespace.TranslationUnit.Module.OutputNamespace);
if (generateNamespace) if (generateNamespace)
{ {

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

@ -313,7 +313,7 @@ namespace CppSharp.Generators.CLI
public string QualifiedIdentifier(Declaration decl) public string QualifiedIdentifier(Declaration decl)
{ {
if (Context.Driver.Options.GenerateLibraryNamespace) if (!string.IsNullOrEmpty(decl.TranslationUnit.Module.OutputNamespace))
return string.Format("{0}::{1}", decl.TranslationUnit.Module.OutputNamespace, return string.Format("{0}::{1}", decl.TranslationUnit.Module.OutputNamespace,
decl.QualifiedName); decl.QualifiedName);
return string.Format("{0}", decl.QualifiedName); return string.Format("{0}", decl.QualifiedName);

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

@ -81,7 +81,7 @@ namespace CppSharp.Generators.CLI
public string QualifiedIdentifier(Declaration decl) public string QualifiedIdentifier(Declaration decl)
{ {
if (Options.GenerateLibraryNamespace) if (!string.IsNullOrEmpty(TranslationUnit.Module.OutputNamespace))
{ {
if (string.IsNullOrEmpty(decl.QualifiedName)) if (string.IsNullOrEmpty(decl.QualifiedName))
return string.Format("{0}", decl.TranslationUnit.Module.OutputNamespace); return string.Format("{0}", decl.TranslationUnit.Module.OutputNamespace);

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

@ -327,7 +327,7 @@ namespace CppSharp.Generators.CLI
var names = new List<string>(); var names = new List<string>();
string rootNamespace = null; string rootNamespace = null;
if (Options.GenerateLibraryNamespace) if (!string.IsNullOrEmpty(decl.TranslationUnit.Module.OutputNamespace))
names.Add(rootNamespace = decl.TranslationUnit.Module.OutputNamespace); names.Add(rootNamespace = decl.TranslationUnit.Module.OutputNamespace);
if (!string.IsNullOrEmpty(decl.Namespace.QualifiedName)) if (!string.IsNullOrEmpty(decl.Namespace.QualifiedName))

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

@ -198,7 +198,7 @@ namespace CppSharp.Generators.CSharp
} }
PopBlock(NewLineKind.BeforeNextBlock); PopBlock(NewLineKind.BeforeNextBlock);
if (Options.GenerateLibraryNamespace) if (!string.IsNullOrEmpty(TranslationUnit.Module.OutputNamespace))
{ {
PushBlock(CSharpBlockKind.Namespace); PushBlock(CSharpBlockKind.Namespace);
WriteLine("namespace {0}", TranslationUnit.Module.OutputNamespace); WriteLine("namespace {0}", TranslationUnit.Module.OutputNamespace);
@ -210,7 +210,7 @@ namespace CppSharp.Generators.CSharp
GenerateDeclContext(unit); GenerateDeclContext(unit);
} }
if (Options.GenerateLibraryNamespace) if (!string.IsNullOrEmpty(TranslationUnit.Module.OutputNamespace))
{ {
WriteCloseBraceIndent(); WriteCloseBraceIndent();
PopBlock(NewLineKind.BeforeNextBlock); PopBlock(NewLineKind.BeforeNextBlock);

2
src/Generator/Options.cs

@ -30,7 +30,6 @@ namespace CppSharp
Modules = new List<Module>(); Modules = new List<Module>();
GeneratorKind = GeneratorKind.CSharp; GeneratorKind = GeneratorKind.CSharp;
GenerateLibraryNamespace = true;
GeneratePartialClasses = true; GeneratePartialClasses = true;
GenerateClassMarshals = false; GenerateClassMarshals = false;
OutputInteropIncludes = true; OutputInteropIncludes = true;
@ -105,7 +104,6 @@ namespace CppSharp
} }
public bool OutputInteropIncludes; public bool OutputInteropIncludes;
public bool GenerateLibraryNamespace;
public bool GenerateFunctionTemplates; public bool GenerateFunctionTemplates;
public bool GeneratePartialClasses; public bool GeneratePartialClasses;
public bool GenerateInterfacesForMultipleInheritance; public bool GenerateInterfacesForMultipleInheritance;

Loading…
Cancel
Save