|
|
|
@ -1,6 +1,4 @@
@@ -1,6 +1,4 @@
|
|
|
|
|
using Cxxi.Generators.CLI; |
|
|
|
|
using Cxxi.Types; |
|
|
|
|
using System.IO; |
|
|
|
|
using Cxxi.Types; |
|
|
|
|
|
|
|
|
|
namespace Cxxi.Generators |
|
|
|
|
{ |
|
|
|
@ -10,86 +8,20 @@ namespace Cxxi.Generators
@@ -10,86 +8,20 @@ namespace Cxxi.Generators
|
|
|
|
|
CSharp |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public interface ILanguageGenerator |
|
|
|
|
public interface IGenerator |
|
|
|
|
{ |
|
|
|
|
DriverOptions Options { get; set; } |
|
|
|
|
Library Library { get; set; } |
|
|
|
|
ILibrary Transform { get; set; } |
|
|
|
|
ITypeMapDatabase TypeMapDatabase { get; set; } |
|
|
|
|
Generator Generator { get; set; } |
|
|
|
|
|
|
|
|
|
bool Generate(TranslationUnit unit); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public partial class Generator |
|
|
|
|
{ |
|
|
|
|
public DriverOptions Options; |
|
|
|
|
public Library Library; |
|
|
|
|
public ILibrary LibraryTransform; |
|
|
|
|
public ITypeMapDatabase TypeMapDatabase; |
|
|
|
|
|
|
|
|
|
public Generator(DriverOptions options, Library library, ILibrary libraryTransform, |
|
|
|
|
ITypeMapDatabase typeMapDatabase) |
|
|
|
|
{ |
|
|
|
|
this.Options = options; |
|
|
|
|
this.Library = library; |
|
|
|
|
this.LibraryTransform = libraryTransform; |
|
|
|
|
this.TypeMapDatabase = typeMapDatabase; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void Generate() |
|
|
|
|
{ |
|
|
|
|
var generator = CreateLanguageGenerator(Options.Template); |
|
|
|
|
|
|
|
|
|
if (!Directory.Exists(Options.OutputDir)) |
|
|
|
|
Directory.CreateDirectory(Options.OutputDir); |
|
|
|
|
|
|
|
|
|
// Process everything in the global namespace for now.
|
|
|
|
|
foreach (var module in Library.TranslationUnits) |
|
|
|
|
{ |
|
|
|
|
if (module.ExplicityIgnored || !module.HasDeclarations) |
|
|
|
|
continue; |
|
|
|
|
|
|
|
|
|
if (module.IsSystemHeader) |
|
|
|
|
continue; |
|
|
|
|
|
|
|
|
|
// Generate the target code.
|
|
|
|
|
generator.Generate(module); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ILanguageGenerator CreateLanguageGenerator(LanguageGeneratorKind kind) |
|
|
|
|
public abstract class Generator : IGenerator |
|
|
|
|
{ |
|
|
|
|
ILanguageGenerator generator = null; |
|
|
|
|
public Driver Driver { get; private set; } |
|
|
|
|
|
|
|
|
|
switch (kind) |
|
|
|
|
protected Generator(Driver driver) |
|
|
|
|
{ |
|
|
|
|
case LanguageGeneratorKind.CPlusPlusCLI: |
|
|
|
|
generator = new CLIGenerator(this); |
|
|
|
|
break; |
|
|
|
|
case LanguageGeneratorKind.CSharp: |
|
|
|
|
//generator = new CSharpGenerator();
|
|
|
|
|
break; |
|
|
|
|
Driver = driver; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
generator.Options = Options; |
|
|
|
|
generator.Library = Library; |
|
|
|
|
generator.Transform = LibraryTransform; |
|
|
|
|
generator.TypeMapDatabase = TypeMapDatabase; |
|
|
|
|
|
|
|
|
|
return generator; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ILanguageGenerator CreateLanguageGenerator(string kind) |
|
|
|
|
{ |
|
|
|
|
switch (kind) |
|
|
|
|
{ |
|
|
|
|
default: |
|
|
|
|
case "cli": |
|
|
|
|
return CreateLanguageGenerator(LanguageGeneratorKind.CPlusPlusCLI); |
|
|
|
|
case "cs": |
|
|
|
|
return CreateLanguageGenerator(LanguageGeneratorKind.CSharp); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
public abstract bool Generate(TranslationUnit unit); |
|
|
|
|
} |
|
|
|
|
} |