Browse Source

Remove the GenerateStart and GenerateAfterNamespaces methods from the ILibrary interface and replace them with delegates on each generator.

pull/3/head
triton 12 years ago
parent
commit
20b0b76421
  1. 4
      src/Generator/Generators/CLI/CLIHeadersTemplate.cs
  2. 5
      src/Generator/Generators/CLI/CLISourcesTemplate.cs
  3. 36
      src/Generator/Generators/CLI/CLITextTemplate.cs
  4. 12
      src/Generator/Library.cs

4
src/Generator/Generators/CLI/CLIHeadersTemplate.cs

@ -18,7 +18,7 @@ namespace CppSharp.Generators.CLI
public override void Generate() public override void Generate()
{ {
GenerateStart(); OnStart(this);
WriteLine("#pragma once"); WriteLine("#pragma once");
NewLine(); NewLine();
@ -170,7 +170,7 @@ namespace CppSharp.Generators.CLI
public void GenerateFunctions(Namespace @namespace) public void GenerateFunctions(Namespace @namespace)
{ {
WriteLine("public ref class {0}{1}", SafeIdentifier(Library.Name), WriteLine("public ref class {0}{1}", SafeIdentifier(Options.OutputNamespace),
TranslationUnit.FileNameWithoutExtension); TranslationUnit.FileNameWithoutExtension);
WriteLine("{"); WriteLine("{");
WriteLine("public:"); WriteLine("public:");

5
src/Generator/Generators/CLI/CLISourcesTemplate.cs

@ -17,7 +17,7 @@ namespace CppSharp.Generators.CLI
public override void Generate() public override void Generate()
{ {
GenerateStart(); OnStart(this);
var file = Path.GetFileNameWithoutExtension(TranslationUnit.FileName).Replace('\\', '/'); var file = Path.GetFileNameWithoutExtension(TranslationUnit.FileName).Replace('\\', '/');
@ -35,7 +35,8 @@ namespace CppSharp.Generators.CLI
WriteLine("using namespace System;"); WriteLine("using namespace System;");
WriteLine("using namespace System::Runtime::InteropServices;"); WriteLine("using namespace System::Runtime::InteropServices;");
GenerateAfterNamespaces();
OnNamespaces(this);
NewLine(); NewLine();
GenerateDeclarations(); GenerateDeclarations();

36
src/Generator/Generators/CLI/CLITextTemplate.cs

@ -27,6 +27,18 @@ namespace CppSharp.Generators.CLI
protected const string DefaultIndent = " "; protected const string DefaultIndent = " ";
protected const uint MaxIndent = 80; protected const uint MaxIndent = 80;
public delegate void GenerateTextDelegate(CLITextTemplate gen);
/// <summary>
/// Called when the generation is starting.
/// </summary>
public GenerateTextDelegate OnStart = delegate { };
/// <summary>
/// Called when generating namespaces.
/// </summary>
public GenerateTextDelegate OnNamespaces = delegate { };
public CLITypePrinter TypePrinter { get; set; } public CLITypePrinter TypePrinter { get; set; }
public ISet<Include> Includes; public ISet<Include> Includes;
@ -50,30 +62,6 @@ namespace CppSharp.Generators.CLI
return string.Format("{0}", decl.QualifiedName); return string.Format("{0}", decl.QualifiedName);
} }
public void GenerateStart()
{
if (Transform == null)
{
WriteLine("//----------------------------------------------------------------------------");
WriteLine("// This is autogenerated code by cxxi-generator.");
WriteLine("// Do not edit this file or all your changes will be lost after re-generation.");
WriteLine("//----------------------------------------------------------------------------");
if (FileExtension == "cpp")
WriteLine(@"#include ""../interop.h"" // marshalString");
}
else
{
Transform.GenerateStart(this);
}
}
public void GenerateAfterNamespaces()
{
if (Transform != null)
Transform.GenerateAfterNamespaces(this);
}
public void GenerateSummary(string comment) public void GenerateSummary(string comment)
{ {
if (string.IsNullOrWhiteSpace(comment)) if (string.IsNullOrWhiteSpace(comment))

12
src/Generator/Library.cs

@ -38,18 +38,6 @@ namespace CppSharp
/// <param name="driver"></param> /// <param name="driver"></param>
/// <param name="passes"></param> /// <param name="passes"></param>
void SetupPasses(Driver driver, PassBuilder passes); void SetupPasses(Driver driver, PassBuilder passes);
/// <summary>
/// Called to generate text at the start of the text template.
/// </summary>
/// <param name="template"></param>
void GenerateStart(TextTemplate template);
/// <summary>
/// Called to generate text after the generation of namespaces.
/// </summary>
/// <param name="template"></param>
void GenerateAfterNamespaces(TextTemplate template);
} }
public static class LibraryHelpers public static class LibraryHelpers

Loading…
Cancel
Save