Browse Source

Update the C++/CLI templates to the new driver.

pull/1/head
triton 13 years ago
parent
commit
2cd35daa5e
  1. 37
      src/Generator/Generators/CLI/CLIHeadersTemplate.cs
  2. 39
      src/Generator/Generators/CLI/CLISourcesTemplate.cs

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

@ -23,7 +23,7 @@ namespace Cxxi.Generators.CLI
WriteLine("#pragma once"); WriteLine("#pragma once");
NewLine(); NewLine();
WriteLine("#include <{0}>", Module.IncludePath); WriteLine("#include <{0}>", unit.IncludePath);
GenerateIncludeForwardRefs(); GenerateIncludeForwardRefs();
NewLine(); NewLine();
@ -38,7 +38,7 @@ namespace Cxxi.Generators.CLI
{ {
forwardRefsPrinter = new CLIForwardRefeferencePrinter(); forwardRefsPrinter = new CLIForwardRefeferencePrinter();
foreach (var forwardRef in Module.ForwardReferences) foreach (var forwardRef in unit.ForwardReferences)
forwardRef.Visit(forwardRefsPrinter); forwardRef.Visit(forwardRefsPrinter);
var includes = new HashSet<string>(); var includes = new HashSet<string>();
@ -48,7 +48,7 @@ namespace Cxxi.Generators.CLI
if (string.IsNullOrWhiteSpace(include)) if (string.IsNullOrWhiteSpace(include))
continue; continue;
if (include == Path.GetFileNameWithoutExtension(Module.FileName)) if (include == Path.GetFileNameWithoutExtension(unit.FileName))
continue; continue;
includes.Add(string.Format("#include \"{0}.h\"", include)); includes.Add(string.Format("#include \"{0}.h\"", include));
@ -87,23 +87,20 @@ namespace Cxxi.Generators.CLI
bool needsNewline = false; bool needsNewline = false;
// Generate all the enum declarations for the module. // 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) if (@enum.Ignore || @enum.IsIncomplete)
continue; continue;
GenerateEnum(@enum); GenerateEnum(@enum);
needsNewline = true; NeedNewLine();
if (i < Module.Enums.Count - 1) if (i < unit.Enums.Count - 1)
NewLine(); NewLine();
} }
if (needsNewline) NewLineIfNeeded();
NewLine();
needsNewline = false;
// Generate all the typedef declarations for the module. // Generate all the typedef declarations for the module.
GenerateTypedefs(); GenerateTypedefs();
@ -111,9 +108,9 @@ namespace Cxxi.Generators.CLI
needsNewline = false; needsNewline = false;
// Generate all the struct/class declarations for the module. // 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) if (@class.Ignore || @class.IsIncomplete)
continue; continue;
@ -124,11 +121,11 @@ namespace Cxxi.Generators.CLI
GenerateClass(@class); GenerateClass(@class);
needsNewline = true; needsNewline = true;
if (i < Module.Classes.Count - 1) if (i < unit.Classes.Count - 1)
NewLine(); NewLine();
} }
if (Module.HasFunctions) if (unit.HasFunctions)
{ {
if (needsNewline) if (needsNewline)
NewLine(); NewLine();
@ -141,7 +138,7 @@ namespace Cxxi.Generators.CLI
public void GenerateTypedefs() public void GenerateTypedefs()
{ {
foreach (var typedef in Module.Typedefs) foreach (var typedef in unit.Typedefs)
{ {
if (typedef.Ignore) if (typedef.Ignore)
continue; continue;
@ -156,13 +153,13 @@ namespace Cxxi.Generators.CLI
public void GenerateFunctions() public void GenerateFunctions()
{ {
WriteLine("public ref class {0}{1}", SafeIdentifier(Library.Name), WriteLine("public ref class {0}{1}", SafeIdentifier(Library.Name),
Module.FileNameWithoutExtension); unit.FileNameWithoutExtension);
WriteLine("{"); WriteLine("{");
WriteLine("public:"); WriteLine("public:");
PushIndent(); PushIndent();
// Generate all the function declarations for the module. // Generate all the function declarations for the module.
foreach (var function in Module.Functions) foreach (var function in unit.Functions)
{ {
GenerateFunction(function); GenerateFunction(function);
} }
@ -190,7 +187,7 @@ namespace Cxxi.Generators.CLI
//const string @namespace = "System::Runtime::InteropServices"; //const string @namespace = "System::Runtime::InteropServices";
//WriteLine("[{0}::StructLayout({0}::LayoutKind::Explicit)]", //WriteLine("[{0}::StructLayout({0}::LayoutKind::Explicit)]",
// @namespace); // @namespace);
Console.WriteLine("Unions are not yet implemented"); //throw new NotImplementedException("Unions are not supported yet");
} }
if (GenerateClassProlog(@class)) if (GenerateClassProlog(@class))
@ -387,7 +384,7 @@ namespace Cxxi.Generators.CLI
public void GenerateDebug(Declaration decl) public void GenerateDebug(Declaration decl)
{ {
if (DriverOptions.OutputDebug && !String.IsNullOrWhiteSpace(decl.DebugText)) if (Options.OutputDebug && !String.IsNullOrWhiteSpace(decl.DebugText))
WriteLine("// DEBUG: " + decl.DebugText); WriteLine("// DEBUG: " + decl.DebugText);
} }

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

@ -19,8 +19,8 @@ namespace Cxxi.Generators.CLI
GenerateStart(); GenerateStart();
WriteLine("#include \"{0}{1}.h\"", WriteLine("#include \"{0}{1}.h\"",
Path.GetFileNameWithoutExtension(Module.FileName), Path.GetFileNameWithoutExtension(unit.FileName),
CLIGenerator.WrapperSuffix ); Options.WrapperSuffix);
GenerateForwardReferenceHeaders(); GenerateForwardReferenceHeaders();
NewLine(); NewLine();
@ -38,7 +38,7 @@ namespace Cxxi.Generators.CLI
var includes = new HashSet<string>(); var includes = new HashSet<string>();
// Generate the forward references. // Generate the forward references.
foreach (var forwardRef in Module.ForwardReferences) foreach (var forwardRef in unit.ForwardReferences)
{ {
var decl = forwardRef; var decl = forwardRef;
@ -46,17 +46,17 @@ namespace Cxxi.Generators.CLI
decl = decl.CompleteDeclaration; decl = decl.CompleteDeclaration;
var @namespace = decl.Namespace; var @namespace = decl.Namespace;
var unit = @namespace.TranslationUnit; var translationUnit = @namespace.TranslationUnit;
if (unit.Ignore) if (translationUnit.Ignore)
continue; continue;
if (unit.IsSystemHeader) if (translationUnit.IsSystemHeader)
continue; 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; continue;
includes.Add(includeName); includes.Add(includeName);
@ -71,9 +71,9 @@ namespace Cxxi.Generators.CLI
public void GenerateDeclarations() public void GenerateDeclarations()
{ {
// Generate all the struct/class definitions for the module. // 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) if (@class.Ignore)
continue; continue;
@ -84,14 +84,14 @@ namespace Cxxi.Generators.CLI
GenerateClass(@class); 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. // 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) if (function.Ignore)
continue; continue;
@ -104,11 +104,13 @@ namespace Cxxi.Generators.CLI
public void GenerateDeclarationCommon(Declaration decl) public void GenerateDeclarationCommon(Declaration decl)
{ {
if (!string.IsNullOrWhiteSpace(decl.BriefComment))
WriteLine("// {0}", decl.BriefComment);
} }
public void GenerateClass(Class @class) public void GenerateClass(Class @class)
{ {
GenerateDeclarationCommon(@class); //GenerateDeclarationCommon(@class);
// Output a default constructor that takes the native pointer. // Output a default constructor that takes the native pointer.
GenerateClassConstructor(@class, isIntPtr: false); GenerateClassConstructor(@class, isIntPtr: false);
@ -270,7 +272,8 @@ namespace Cxxi.Generators.CLI
ReturnType = retType ReturnType = retType
}; };
var marshal = new CLIMarshalNativeToManagedPrinter(Generator, ctx); var marshal = new CLIMarshalNativeToManagedPrinter(Driver.TypeDatabase,
Library, ctx);
function.ReturnType.Visit(marshal); function.ReturnType.Visit(marshal);
WriteLine("{0};", marshal.Return); WriteLine("{0};", marshal.Return);
@ -320,7 +323,7 @@ namespace Cxxi.Generators.CLI
Function = function Function = function
}; };
var marshal = new CLIMarshalManagedToNativePrinter(Generator.TypeMapDatabase, var marshal = new CLIMarshalManagedToNativePrinter(Driver.TypeDatabase,
ctx); ctx);
param.Visit(marshal); param.Visit(marshal);
@ -359,7 +362,7 @@ namespace Cxxi.Generators.CLI
public void GenerateDebug(Declaration decl) public void GenerateDebug(Declaration decl)
{ {
if (DriverOptions.OutputDebug && !String.IsNullOrWhiteSpace(decl.DebugText)) if (Options.OutputDebug && !String.IsNullOrWhiteSpace(decl.DebugText))
WriteLine("// DEBUG: " + decl.DebugText); WriteLine("// DEBUG: " + decl.DebugText);
} }

Loading…
Cancel
Save