Browse Source

Simplified the way generators are created in the driver.

pull/86/head
triton 12 years ago
parent
commit
b409d75bb6
  1. 32
      src/Generator/Driver.cs

32
src/Generator/Driver.cs

@ -17,20 +17,6 @@ namespace CppSharp @@ -17,20 +17,6 @@ namespace CppSharp
{
public class Driver
{
public delegate Generator CreateGeneratorDelegate(Driver driver);
public static Dictionary<LanguageGeneratorKind, CreateGeneratorDelegate>
Generators;
static Driver()
{
Generators = new Dictionary<LanguageGeneratorKind,
CreateGeneratorDelegate>();
Generators[LanguageGeneratorKind.CSharp] = driver =>
new CSharpGenerator(driver);
Generators[LanguageGeneratorKind.CLI] = driver =>
new CLIGenerator(driver);
}
public DriverOptions Options { get; private set; }
public IDiagnosticConsumer Diagnostics { get; private set; }
public Project Project { get; private set; }
@ -54,11 +40,21 @@ namespace CppSharp @@ -54,11 +40,21 @@ namespace CppSharp
GeneratorOutputPasses = new PassBuilder<GeneratorOutputPass>(this);
}
static void ValidateOptions(DriverOptions options)
Generator CreateGeneratorFromKind(GeneratorKind kind)
{
if (!Generators.ContainsKey(options.GeneratorKind))
throw new InvalidOptionException();
switch (kind)
{
case GeneratorKind.CLI:
return new CLIGenerator(this);
case GeneratorKind.CSharp:
return new CSharpGenerator(this);
}
return null;
}
static void ValidateOptions(DriverOptions options)
{
if (string.IsNullOrWhiteSpace(options.LibraryName))
throw new InvalidOptionException();
@ -75,8 +71,6 @@ namespace CppSharp @@ -75,8 +71,6 @@ namespace CppSharp
public void Setup()
{
ValidateOptions(Options);
Generator = Generators[Options.GeneratorKind](this);
TypeDatabase.SetupTypeMaps();
Generator = CreateGeneratorFromKind(Options.GeneratorKind);
}

Loading…
Cancel
Save