Re-use generator base class from CppSharp.
This commit is contained in:
Родитель
06a05c3525
Коммит
070a2b04ff
|
@ -135,7 +135,7 @@ namespace MonoEmbeddinator4000
|
|||
{
|
||||
Output = new ProjectOutput();
|
||||
|
||||
Generators.Generator generator = null;
|
||||
Generator generator = null;
|
||||
switch (Options.GeneratorKind)
|
||||
{
|
||||
case GeneratorKind.C:
|
||||
|
@ -153,7 +153,7 @@ namespace MonoEmbeddinator4000
|
|||
|
||||
foreach (var unit in Context.ASTContext.TranslationUnits)
|
||||
{
|
||||
var outputs = generator.Generate(unit);
|
||||
var outputs = generator.Generate(new[] { unit });
|
||||
|
||||
foreach (var output in outputs)
|
||||
{
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using CppSharp;
|
||||
using CppSharp.AST;
|
||||
using CppSharp.Generators;
|
||||
|
@ -12,8 +13,9 @@ namespace MonoEmbeddinator4000.Generators
|
|||
{
|
||||
}
|
||||
|
||||
public override List<CodeGenerator> Generate(TranslationUnit unit)
|
||||
public override List<CodeGenerator> Generate(IEnumerable<TranslationUnit> units)
|
||||
{
|
||||
var unit = units.First();
|
||||
var headers = new CHeaders(Context, unit);
|
||||
var sources = new CSources(Context, unit);
|
||||
|
||||
|
@ -55,7 +57,17 @@ namespace MonoEmbeddinator4000.Generators
|
|||
};
|
||||
|
||||
return typePrinter;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool SetupPasses()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override string TypePrinterDelegate(CppSharp.AST.Type type)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
public abstract class CCodeGenerator : CodeGenerator
|
||||
|
@ -81,13 +93,8 @@ namespace MonoEmbeddinator4000.Generators
|
|||
return decl.QualifiedName;
|
||||
}
|
||||
|
||||
public CManagedToNativeTypePrinter CTypePrinter
|
||||
{
|
||||
get
|
||||
{
|
||||
return CGenerator.GetCTypePrinter(Options.GeneratorKind);
|
||||
}
|
||||
}
|
||||
public CManagedToNativeTypePrinter CTypePrinter =>
|
||||
CGenerator.GetCTypePrinter(Options.GeneratorKind);
|
||||
|
||||
public virtual void WriteHeaders() { }
|
||||
|
||||
|
|
|
@ -1,24 +0,0 @@
|
|||
using CppSharp.AST;
|
||||
using CppSharp.Generators;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace MonoEmbeddinator4000.Generators
|
||||
{
|
||||
/// <summary>
|
||||
/// Generators are the base class for each language backend.
|
||||
/// </summary>
|
||||
public abstract class Generator
|
||||
{
|
||||
public BindingContext Context { get; private set; }
|
||||
|
||||
protected Generator(BindingContext context)
|
||||
{
|
||||
Context = context;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generates the outputs for a given translation unit.
|
||||
/// </summary>
|
||||
public abstract List<CodeGenerator> Generate(TranslationUnit unit);
|
||||
}
|
||||
}
|
|
@ -1,4 +1,6 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using CppSharp;
|
||||
using CppSharp.AST;
|
||||
using CppSharp.Generators;
|
||||
|
@ -11,8 +13,9 @@ namespace MonoEmbeddinator4000.Generators
|
|||
{
|
||||
}
|
||||
|
||||
public override List<CodeGenerator> Generate(TranslationUnit unit)
|
||||
public override List<CodeGenerator> Generate(IEnumerable<TranslationUnit> units)
|
||||
{
|
||||
var unit = units.First();
|
||||
var sources = new JavaSources(Context, unit);
|
||||
|
||||
return new List<CodeGenerator> { sources };
|
||||
|
@ -36,6 +39,16 @@ namespace MonoEmbeddinator4000.Generators
|
|||
PrintVariableArrayAsPointers = true
|
||||
};
|
||||
}
|
||||
|
||||
public override bool SetupPasses()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override string TypePrinterDelegate(CppSharp.AST.Type type)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
public abstract class JavaCodeGenerator : CodeGenerator
|
||||
|
@ -61,13 +74,8 @@ namespace MonoEmbeddinator4000.Generators
|
|||
return decl.QualifiedName;
|
||||
}
|
||||
|
||||
public CManagedToNativeTypePrinter CTypePrinter
|
||||
{
|
||||
get
|
||||
{
|
||||
return CGenerator.GetCTypePrinter(Options.GeneratorKind);
|
||||
}
|
||||
}
|
||||
public CManagedToNativeTypePrinter CTypePrinter =>
|
||||
CGenerator.GetCTypePrinter(Options.GeneratorKind);
|
||||
|
||||
public override void GenerateFilePreamble()
|
||||
{
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using CppSharp.AST;
|
||||
using CppSharp.Generators;
|
||||
|
||||
|
@ -12,8 +13,9 @@ namespace MonoEmbeddinator4000.Generators
|
|||
{
|
||||
}
|
||||
|
||||
public override List<CodeGenerator> Generate(TranslationUnit unit)
|
||||
{
|
||||
public override List<CodeGenerator> Generate(IEnumerable<TranslationUnit> units)
|
||||
{
|
||||
var unit = units.First();
|
||||
var headers = new ObjCHeaders(Context, unit);
|
||||
var sources = new ObjCSources(Context, unit);
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
<AssemblyName>MonoEmbeddinator4000</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<BaseIntermediateOutputPath>..\obj\Debug\MonoEmbeddinator4000</BaseIntermediateOutputPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
|
@ -68,9 +69,6 @@
|
|||
<Compile Include="../../binder/Generators/C/CTypes.cs">
|
||||
<Link>binder/Generators/C/CTypes.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="../../binder/Generators/Generator.cs">
|
||||
<Link>binder/Generators/Generator.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="../../binder/Generators/Java/JavaGenerator.cs">
|
||||
<Link>binder/Generators/Java/JavaGenerator.cs</Link>
|
||||
</Compile>
|
||||
|
|
Загрузка…
Ссылка в новой задаче