From 2cd35daa5e9adb2ae0f36f5bb17c696d01fd140d Mon Sep 17 00:00:00 2001 From: triton Date: Wed, 20 Feb 2013 14:25:40 +0000 Subject: [PATCH] Update the C++/CLI templates to the new driver. --- .../Generators/CLI/CLIHeadersTemplate.cs | 37 ++++++++---------- .../Generators/CLI/CLISourcesTemplate.cs | 39 ++++++++++--------- 2 files changed, 38 insertions(+), 38 deletions(-) diff --git a/src/Generator/Generators/CLI/CLIHeadersTemplate.cs b/src/Generator/Generators/CLI/CLIHeadersTemplate.cs index c7114c7e..0383ebd8 100644 --- a/src/Generator/Generators/CLI/CLIHeadersTemplate.cs +++ b/src/Generator/Generators/CLI/CLIHeadersTemplate.cs @@ -23,7 +23,7 @@ namespace Cxxi.Generators.CLI WriteLine("#pragma once"); NewLine(); - WriteLine("#include <{0}>", Module.IncludePath); + WriteLine("#include <{0}>", unit.IncludePath); GenerateIncludeForwardRefs(); NewLine(); @@ -38,7 +38,7 @@ namespace Cxxi.Generators.CLI { forwardRefsPrinter = new CLIForwardRefeferencePrinter(); - foreach (var forwardRef in Module.ForwardReferences) + foreach (var forwardRef in unit.ForwardReferences) forwardRef.Visit(forwardRefsPrinter); var includes = new HashSet(); @@ -48,7 +48,7 @@ namespace Cxxi.Generators.CLI if (string.IsNullOrWhiteSpace(include)) continue; - if (include == Path.GetFileNameWithoutExtension(Module.FileName)) + if (include == Path.GetFileNameWithoutExtension(unit.FileName)) continue; includes.Add(string.Format("#include \"{0}.h\"", include)); @@ -87,23 +87,20 @@ namespace Cxxi.Generators.CLI bool needsNewline = false; // Generate all the enum declarations for the module. - for (var i = 0; i < Module.Enums.Count; ++i) + for (var i = 0; i < unit.Enums.Count; ++i) { - var @enum = Module.Enums[i]; + var @enum = unit.Enums[i]; if (@enum.Ignore || @enum.IsIncomplete) continue; GenerateEnum(@enum); - needsNewline = true; - if (i < Module.Enums.Count - 1) + NeedNewLine(); + if (i < unit.Enums.Count - 1) NewLine(); } - if (needsNewline) - NewLine(); - - needsNewline = false; + NewLineIfNeeded(); // Generate all the typedef declarations for the module. GenerateTypedefs(); @@ -111,9 +108,9 @@ namespace Cxxi.Generators.CLI needsNewline = false; // Generate all the struct/class declarations for the module. - for (var i = 0; i < Module.Classes.Count; ++i) + for (var i = 0; i < unit.Classes.Count; ++i) { - var @class = Module.Classes[i]; + var @class = unit.Classes[i]; if (@class.Ignore || @class.IsIncomplete) continue; @@ -124,11 +121,11 @@ namespace Cxxi.Generators.CLI GenerateClass(@class); needsNewline = true; - if (i < Module.Classes.Count - 1) + if (i < unit.Classes.Count - 1) NewLine(); } - if (Module.HasFunctions) + if (unit.HasFunctions) { if (needsNewline) NewLine(); @@ -141,7 +138,7 @@ namespace Cxxi.Generators.CLI public void GenerateTypedefs() { - foreach (var typedef in Module.Typedefs) + foreach (var typedef in unit.Typedefs) { if (typedef.Ignore) continue; @@ -156,13 +153,13 @@ namespace Cxxi.Generators.CLI public void GenerateFunctions() { WriteLine("public ref class {0}{1}", SafeIdentifier(Library.Name), - Module.FileNameWithoutExtension); + unit.FileNameWithoutExtension); WriteLine("{"); WriteLine("public:"); PushIndent(); // Generate all the function declarations for the module. - foreach (var function in Module.Functions) + foreach (var function in unit.Functions) { GenerateFunction(function); } @@ -190,7 +187,7 @@ namespace Cxxi.Generators.CLI //const string @namespace = "System::Runtime::InteropServices"; //WriteLine("[{0}::StructLayout({0}::LayoutKind::Explicit)]", // @namespace); - Console.WriteLine("Unions are not yet implemented"); + //throw new NotImplementedException("Unions are not supported yet"); } if (GenerateClassProlog(@class)) @@ -387,7 +384,7 @@ namespace Cxxi.Generators.CLI public void GenerateDebug(Declaration decl) { - if (DriverOptions.OutputDebug && !String.IsNullOrWhiteSpace(decl.DebugText)) + if (Options.OutputDebug && !String.IsNullOrWhiteSpace(decl.DebugText)) WriteLine("// DEBUG: " + decl.DebugText); } diff --git a/src/Generator/Generators/CLI/CLISourcesTemplate.cs b/src/Generator/Generators/CLI/CLISourcesTemplate.cs index 448265a9..569678d2 100644 --- a/src/Generator/Generators/CLI/CLISourcesTemplate.cs +++ b/src/Generator/Generators/CLI/CLISourcesTemplate.cs @@ -19,8 +19,8 @@ namespace Cxxi.Generators.CLI GenerateStart(); WriteLine("#include \"{0}{1}.h\"", - Path.GetFileNameWithoutExtension(Module.FileName), - CLIGenerator.WrapperSuffix ); + Path.GetFileNameWithoutExtension(unit.FileName), + Options.WrapperSuffix); GenerateForwardReferenceHeaders(); NewLine(); @@ -38,7 +38,7 @@ namespace Cxxi.Generators.CLI var includes = new HashSet(); // Generate the forward references. - foreach (var forwardRef in Module.ForwardReferences) + foreach (var forwardRef in unit.ForwardReferences) { var decl = forwardRef; @@ -46,17 +46,17 @@ namespace Cxxi.Generators.CLI decl = decl.CompleteDeclaration; var @namespace = decl.Namespace; - var unit = @namespace.TranslationUnit; + var translationUnit = @namespace.TranslationUnit; - if (unit.Ignore) + if (translationUnit.Ignore) continue; - if (unit.IsSystemHeader) + if (translationUnit.IsSystemHeader) continue; - var includeName = Path.GetFileNameWithoutExtension(unit.FileName); + var includeName = Path.GetFileNameWithoutExtension(translationUnit.FileName); - if (includeName == Path.GetFileNameWithoutExtension(Module.FileName)) + if (includeName == Path.GetFileNameWithoutExtension(((TextTemplate) this).unit.FileName)) continue; includes.Add(includeName); @@ -71,9 +71,9 @@ namespace Cxxi.Generators.CLI public void GenerateDeclarations() { // Generate all the struct/class definitions for the module. - for (var i = 0; i < Module.Classes.Count; ++i) + for (var i = 0; i < unit.Classes.Count; ++i) { - var @class = Module.Classes[i]; + var @class = unit.Classes[i]; if (@class.Ignore) continue; @@ -84,14 +84,14 @@ namespace Cxxi.Generators.CLI GenerateClass(@class); } - if (Module.HasFunctions) + if (unit.HasFunctions) { - var staticClassName = Library.Name + Module.FileNameWithoutExtension; + var staticClassName = Library.Name + unit.FileNameWithoutExtension; // Generate all the function declarations for the module. - for (var i = 0; i < Module.Functions.Count; ++i) + for (var i = 0; i < unit.Functions.Count; ++i) { - var function = Module.Functions[i]; + var function = unit.Functions[i]; if (function.Ignore) continue; @@ -104,11 +104,13 @@ namespace Cxxi.Generators.CLI public void GenerateDeclarationCommon(Declaration decl) { + if (!string.IsNullOrWhiteSpace(decl.BriefComment)) + WriteLine("// {0}", decl.BriefComment); } public void GenerateClass(Class @class) { - GenerateDeclarationCommon(@class); + //GenerateDeclarationCommon(@class); // Output a default constructor that takes the native pointer. GenerateClassConstructor(@class, isIntPtr: false); @@ -270,7 +272,8 @@ namespace Cxxi.Generators.CLI ReturnType = retType }; - var marshal = new CLIMarshalNativeToManagedPrinter(Generator, ctx); + var marshal = new CLIMarshalNativeToManagedPrinter(Driver.TypeDatabase, + Library, ctx); function.ReturnType.Visit(marshal); WriteLine("{0};", marshal.Return); @@ -320,7 +323,7 @@ namespace Cxxi.Generators.CLI Function = function }; - var marshal = new CLIMarshalManagedToNativePrinter(Generator.TypeMapDatabase, + var marshal = new CLIMarshalManagedToNativePrinter(Driver.TypeDatabase, ctx); param.Visit(marshal); @@ -359,7 +362,7 @@ namespace Cxxi.Generators.CLI public void GenerateDebug(Declaration decl) { - if (DriverOptions.OutputDebug && !String.IsNullOrWhiteSpace(decl.DebugText)) + if (Options.OutputDebug && !String.IsNullOrWhiteSpace(decl.DebugText)) WriteLine("// DEBUG: " + decl.DebugText); }