mirror of https://github.com/mono/CppSharp.git
6 changed files with 92 additions and 17 deletions
@ -1,34 +1,64 @@
@@ -1,34 +1,64 @@
|
||||
using CppSharp.AST; |
||||
using System.Collections.Generic; |
||||
using System.IO; |
||||
|
||||
namespace CppSharp.Generators.Registrable |
||||
{ |
||||
public abstract class RegistrableGenerator<TOptions, THeader, TSource> : Generator |
||||
where TOptions : RegistrableGeneratorOptions |
||||
where THeader : CodeGenerator |
||||
where TSource : CodeGenerator |
||||
{ |
||||
public TOptions GeneratorOptions { get; } |
||||
|
||||
public TranslationUnit GlobalTranslationUnit { get; private set; } |
||||
|
||||
public TranslationUnit InheritanceTranslationUnit { get; private set; } |
||||
|
||||
// TODO: Implement when Generator interface is cleaner
|
||||
// public CodeGenerator ModuleHeaderCodeGenerator { get; private set; }
|
||||
|
||||
// TODO: Implement when Generator interface is cleaner
|
||||
//public CodeGenerator ModuleSourceCodeGenerator { get; private set; }
|
||||
|
||||
public RegistrableGenerator(BindingContext context) : base(context) |
||||
{ |
||||
GeneratorOptions = CreateOptions(this); |
||||
GeneratorOptions = CreateOptions(); |
||||
} |
||||
|
||||
protected abstract TOptions CreateOptions(RegistrableGenerator<TOptions, THeader, TSource> generator); |
||||
protected abstract TOptions CreateOptions(); |
||||
|
||||
protected abstract THeader CreateHeader(RegistrableGenerator<TOptions, THeader, TSource> generator, IEnumerable<TranslationUnit> units); |
||||
protected abstract THeader CreateHeader(IEnumerable<TranslationUnit> units); |
||||
|
||||
protected abstract TSource CreateSource(RegistrableGenerator<TOptions, THeader, TSource> generator, IEnumerable<TranslationUnit> units); |
||||
protected abstract TSource CreateSource(IEnumerable<TranslationUnit> units); |
||||
|
||||
public override List<CodeGenerator> Generate(IEnumerable<TranslationUnit> units) |
||||
{ |
||||
return new List<CodeGenerator> |
||||
{ |
||||
CreateHeader(this, units), |
||||
CreateSource(this, units) |
||||
CreateHeader(units), |
||||
CreateSource(units) |
||||
}; |
||||
} |
||||
|
||||
public override bool SetupPasses() => true; |
||||
// TODO: Should be a better method for this maybe Configure.
|
||||
public override bool SetupPasses() |
||||
{ |
||||
{ |
||||
var module = Context.Options.Modules[1]; |
||||
GlobalTranslationUnit = Context.ASTContext.FindOrCreateTranslationUnit( |
||||
Path.Combine(Context.Options.OutputDir, GeneratorOptions.OutputSubDir, "@package", "global.h") |
||||
); |
||||
GlobalTranslationUnit.Module = module; |
||||
} |
||||
{ |
||||
var module = Context.Options.Modules[1]; |
||||
InheritanceTranslationUnit = Context.ASTContext.FindOrCreateTranslationUnit( |
||||
Path.Combine(Context.Options.OutputDir, GeneratorOptions.OutputSubDir, "@package", "inheritance.h") |
||||
); |
||||
InheritanceTranslationUnit.Module = module; |
||||
} |
||||
return true; |
||||
} |
||||
} |
||||
} |
||||
|
@ -0,0 +1,19 @@
@@ -0,0 +1,19 @@
|
||||
using CppSharp.AST; |
||||
using System.Collections.Generic; |
||||
|
||||
namespace CppSharp.Generators.Registrable |
||||
{ |
||||
public class RegistrableModuleHeader<TGenerator> : RegistrableCodeGenerator<TGenerator> |
||||
where TGenerator : Generator |
||||
{ |
||||
public RegistrableModuleHeader(TGenerator generator, IEnumerable<TranslationUnit> units) : base(generator, units) |
||||
{ |
||||
} |
||||
|
||||
public override string FileExtension { get; } = "h"; |
||||
|
||||
public override void Process() |
||||
{ |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,19 @@
@@ -0,0 +1,19 @@
|
||||
using CppSharp.AST; |
||||
using System.Collections.Generic; |
||||
|
||||
namespace CppSharp.Generators.Registrable |
||||
{ |
||||
public class RegistrableModuleSource<TGenerator> : RegistrableCodeGenerator<TGenerator> |
||||
where TGenerator : Generator |
||||
{ |
||||
public RegistrableModuleSource(TGenerator generator, IEnumerable<TranslationUnit> units) : base(generator, units) |
||||
{ |
||||
} |
||||
|
||||
public override string FileExtension { get; } = "cpp"; |
||||
|
||||
public override void Process() |
||||
{ |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue