diff --git a/src/Generator/Generators/Registrable/Lua/Sol/LuaSolGenerator.cs b/src/Generator/Generators/Registrable/Lua/Sol/LuaSolGenerator.cs index ff55e533..ddb2faee 100644 --- a/src/Generator/Generators/Registrable/Lua/Sol/LuaSolGenerator.cs +++ b/src/Generator/Generators/Registrable/Lua/Sol/LuaSolGenerator.cs @@ -12,21 +12,19 @@ namespace CppSharp.Generators.Registrable.Lua.Sol { } - protected override LuaSolGeneratorOptions CreateOptions(RegistrableGenerator generator) + protected override LuaSolGeneratorOptions CreateOptions() { return new LuaSolGeneratorOptions(this); } - protected override LuaSolHeaders CreateHeader(RegistrableGenerator generator, IEnumerable units) + protected override LuaSolHeaders CreateHeader(IEnumerable units) { return new LuaSolHeaders(this, units); } - protected override LuaSolSources CreateSource(RegistrableGenerator generator, IEnumerable units) + protected override LuaSolSources CreateSource(IEnumerable units) { return new LuaSolSources(this, units); } - - public override bool SetupPasses() => true; } } diff --git a/src/Generator/Generators/Registrable/Lua/Sol/LuaSolGeneratorOptions.cs b/src/Generator/Generators/Registrable/Lua/Sol/LuaSolGeneratorOptions.cs index 1948b7d1..32531c21 100644 --- a/src/Generator/Generators/Registrable/Lua/Sol/LuaSolGeneratorOptions.cs +++ b/src/Generator/Generators/Registrable/Lua/Sol/LuaSolGeneratorOptions.cs @@ -1,6 +1,6 @@ namespace CppSharp.Generators.Registrable.Lua.Sol { - public class LuaSolGeneratorOptions : RegistrableGeneratorOptions + public class LuaSolGeneratorOptions : TRegistrableGeneratorOptions { public LuaSolNamingStrategy NamingStrategy; diff --git a/src/Generator/Generators/Registrable/RegistrableGenerator.cs b/src/Generator/Generators/Registrable/RegistrableGenerator.cs index 670e111c..00017d80 100644 --- a/src/Generator/Generators/Registrable/RegistrableGenerator.cs +++ b/src/Generator/Generators/Registrable/RegistrableGenerator.cs @@ -1,34 +1,64 @@ using CppSharp.AST; using System.Collections.Generic; +using System.IO; namespace CppSharp.Generators.Registrable { public abstract class RegistrableGenerator : 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 generator); + protected abstract TOptions CreateOptions(); - protected abstract THeader CreateHeader(RegistrableGenerator generator, IEnumerable units); + protected abstract THeader CreateHeader(IEnumerable units); - protected abstract TSource CreateSource(RegistrableGenerator generator, IEnumerable units); + protected abstract TSource CreateSource(IEnumerable units); public override List Generate(IEnumerable units) { return new List { - 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; + } } } diff --git a/src/Generator/Generators/Registrable/RegistrableGeneratorOptions.cs b/src/Generator/Generators/Registrable/RegistrableGeneratorOptions.cs index 04dfb892..d8b1b737 100644 --- a/src/Generator/Generators/Registrable/RegistrableGeneratorOptions.cs +++ b/src/Generator/Generators/Registrable/RegistrableGeneratorOptions.cs @@ -9,12 +9,11 @@ namespace CppSharp.Generators.Registrable Import } - public abstract class RegistrableGeneratorOptions - where TGenerator : Generator + public abstract class RegistrableGeneratorOptions { public delegate string Delegate(string name); - public TGenerator Generator { get; set; } + public virtual Generator Generator { get; set; } public virtual string OutputSubDir { get; } public virtual string RootContextType { get; } @@ -60,7 +59,7 @@ namespace CppSharp.Generators.Registrable public virtual string DefaultStaticCastFunctionTemplateFullyQualifiedName => null; public virtual string DefaultDynamicCastFunctionTemplateFullyQualifiedName => null; - public RegistrableGeneratorOptions(TGenerator generator) + public RegistrableGeneratorOptions(Generator generator) { Generator = generator; OutputSubDir = DefaultOutputSubdir; @@ -86,4 +85,14 @@ namespace CppSharp.Generators.Registrable DynamicCastFunctionTemplateFullyQualifiedName = DefaultDynamicCastFunctionTemplateFullyQualifiedName; } } + + public abstract class TRegistrableGeneratorOptions : RegistrableGeneratorOptions + where TGenerator : Generator + { + public override TGenerator Generator => (TGenerator)base.Generator; + + public TRegistrableGeneratorOptions(TGenerator generator) : base(generator) + { + } + } } diff --git a/src/Generator/Generators/Registrable/RegistrableModuleHeader.cs b/src/Generator/Generators/Registrable/RegistrableModuleHeader.cs new file mode 100644 index 00000000..b9b7ac55 --- /dev/null +++ b/src/Generator/Generators/Registrable/RegistrableModuleHeader.cs @@ -0,0 +1,19 @@ +using CppSharp.AST; +using System.Collections.Generic; + +namespace CppSharp.Generators.Registrable +{ + public class RegistrableModuleHeader : RegistrableCodeGenerator + where TGenerator : Generator + { + public RegistrableModuleHeader(TGenerator generator, IEnumerable units) : base(generator, units) + { + } + + public override string FileExtension { get; } = "h"; + + public override void Process() + { + } + } +} diff --git a/src/Generator/Generators/Registrable/RegistrableModuleSource.cs b/src/Generator/Generators/Registrable/RegistrableModuleSource.cs new file mode 100644 index 00000000..2546fd21 --- /dev/null +++ b/src/Generator/Generators/Registrable/RegistrableModuleSource.cs @@ -0,0 +1,19 @@ +using CppSharp.AST; +using System.Collections.Generic; + +namespace CppSharp.Generators.Registrable +{ + public class RegistrableModuleSource : RegistrableCodeGenerator + where TGenerator : Generator + { + public RegistrableModuleSource(TGenerator generator, IEnumerable units) : base(generator, units) + { + } + + public override string FileExtension { get; } = "cpp"; + + public override void Process() + { + } + } +}