From b9e57dba78e4dfc976a354a7ed837167ad3e400e Mon Sep 17 00:00:00 2001 From: triton Date: Wed, 17 Jul 2013 21:04:22 +0100 Subject: [PATCH] Re-write the blocks generator again (thanks to esdrubal for helping me with the new design). Now the whitespace/new line handling is done by the output generator per block, instead of having to be managed manually which could lead to all sorts of messy output without being extra careful. Also the new system limits the usage of generics since C# was too limited to design it properly, and it ended up being more trouble than it was worth. The blocks kinds were also changed to be const int, since enums are very hard to extend and made it hard to provide a common interface for dealing with blocks. --- src/Generator/Driver.cs | 9 +- src/Generator/Generators/CLI/CLIGenerator.cs | 4 +- .../Generators/CLI/CLIHeadersTemplate.cs | 81 ++-- .../Generators/CLI/CLISourcesTemplate.cs | 16 +- .../Generators/CLI/CLITextTemplate.cs | 64 ++-- .../Generators/CSharp/CSharpGenerator.cs | 4 +- .../Generators/CSharp/CSharpTextTemplate.cs | 13 +- src/Generator/Generators/Generator.cs | 6 +- src/Generator/Generators/Template.cs | 358 ++++++++++++++---- src/Generator/Utils/TextGenerator.cs | 25 +- 10 files changed, 401 insertions(+), 179 deletions(-) diff --git a/src/Generator/Driver.cs b/src/Generator/Driver.cs index ff3b4368..edb88042 100644 --- a/src/Generator/Driver.cs +++ b/src/Generator/Driver.cs @@ -122,8 +122,7 @@ namespace CppSharp public List GenerateCode() { - var outputs = Generator.Generate(); - return outputs; + return Generator.Generate(); } public void WriteCode(List outputs) @@ -146,9 +145,7 @@ namespace CppSharp Diagnostics.EmitMessage(DiagnosticId.FileGenerated, "Generated '{0}'", fileName); var filePath = Path.Combine(outputPath, fileName); - - var text = template.GenerateText(); - File.WriteAllText(Path.GetFullPath(filePath), text); + File.WriteAllText(Path.GetFullPath(filePath), template.Generate()); } } } @@ -177,6 +174,7 @@ namespace CppSharp GeneratePartialClasses = true; OutputInteropIncludes = true; MaxIndent = 80; + CommentPrefix = "///"; } // General options @@ -218,6 +216,7 @@ namespace CppSharp public bool WriteOnlyWhenChanged; public Func GenerateName; public int MaxIndent; + public string CommentPrefix; } public class InvalidOptionException : Exception diff --git a/src/Generator/Generators/CLI/CLIGenerator.cs b/src/Generator/Generators/CLI/CLIGenerator.cs index 5bf9735b..2f79c4aa 100644 --- a/src/Generator/Generators/CLI/CLIGenerator.cs +++ b/src/Generator/Generators/CLI/CLIGenerator.cs @@ -17,9 +17,9 @@ namespace CppSharp.Generators.CLI Type.TypePrinterDelegate += type => type.Visit(typePrinter); } - public override List Generate(TranslationUnit unit) + public override List