mirror of https://github.com/mono/CppSharp.git
16 changed files with 1574 additions and 472 deletions
@ -0,0 +1,181 @@ |
|||||||
|
// ------------------------------------------------------------------------------
|
||||||
|
// <autogenerated>
|
||||||
|
// This code was generated by a tool.
|
||||||
|
// Mono Runtime Version: 4.0.30319.1
|
||||||
|
//
|
||||||
|
// Changes to this file may cause incorrect behavior and will be lost if
|
||||||
|
// the code is regenerated.
|
||||||
|
// </autogenerated>
|
||||||
|
// ------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace Templates { |
||||||
|
using System; |
||||||
|
|
||||||
|
|
||||||
|
public partial class Base : BaseBase { |
||||||
|
|
||||||
|
public virtual string TransformText() { |
||||||
|
this.GenerationEnvironment = null; |
||||||
|
|
||||||
|
#line 2 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/Base.tt"
|
||||||
|
/* This is a dummy template that language-specific templates may inherit from */ |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
return this.GenerationEnvironment.ToString(); |
||||||
|
} |
||||||
|
|
||||||
|
protected virtual void Initialize() { |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public class BaseBase { |
||||||
|
|
||||||
|
private global::System.Text.StringBuilder builder; |
||||||
|
|
||||||
|
private global::System.Collections.Generic.IDictionary<string, object> session; |
||||||
|
|
||||||
|
private global::System.CodeDom.Compiler.CompilerErrorCollection errors; |
||||||
|
|
||||||
|
private string currentIndent = string.Empty; |
||||||
|
|
||||||
|
private global::System.Collections.Generic.Stack<int> indents; |
||||||
|
|
||||||
|
private ToStringInstanceHelper _toStringHelper = new ToStringInstanceHelper(); |
||||||
|
|
||||||
|
public virtual global::System.Collections.Generic.IDictionary<string, object> Session { |
||||||
|
get { |
||||||
|
return this.session; |
||||||
|
} |
||||||
|
set { |
||||||
|
this.session = value; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public global::System.Text.StringBuilder GenerationEnvironment { |
||||||
|
get { |
||||||
|
if ((this.builder == null)) { |
||||||
|
this.builder = new global::System.Text.StringBuilder(); |
||||||
|
} |
||||||
|
return this.builder; |
||||||
|
} |
||||||
|
set { |
||||||
|
this.builder = value; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
protected global::System.CodeDom.Compiler.CompilerErrorCollection Errors { |
||||||
|
get { |
||||||
|
if ((this.errors == null)) { |
||||||
|
this.errors = new global::System.CodeDom.Compiler.CompilerErrorCollection(); |
||||||
|
} |
||||||
|
return this.errors; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public string CurrentIndent { |
||||||
|
get { |
||||||
|
return this.currentIndent; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private global::System.Collections.Generic.Stack<int> Indents { |
||||||
|
get { |
||||||
|
if ((this.indents == null)) { |
||||||
|
this.indents = new global::System.Collections.Generic.Stack<int>(); |
||||||
|
} |
||||||
|
return this.indents; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public ToStringInstanceHelper ToStringHelper { |
||||||
|
get { |
||||||
|
return this._toStringHelper; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public void Error(string message) { |
||||||
|
this.Errors.Add(new global::System.CodeDom.Compiler.CompilerError(null, -1, -1, null, message)); |
||||||
|
} |
||||||
|
|
||||||
|
public void Warning(string message) { |
||||||
|
global::System.CodeDom.Compiler.CompilerError val = new global::System.CodeDom.Compiler.CompilerError(null, -1, -1, null, message); |
||||||
|
val.IsWarning = true; |
||||||
|
this.Errors.Add(val); |
||||||
|
} |
||||||
|
|
||||||
|
public string PopIndent() { |
||||||
|
if ((this.Indents.Count == 0)) { |
||||||
|
return string.Empty; |
||||||
|
} |
||||||
|
int lastPos = (this.currentIndent.Length - this.Indents.Pop()); |
||||||
|
string last = this.currentIndent.Substring(lastPos); |
||||||
|
this.currentIndent = this.currentIndent.Substring(0, lastPos); |
||||||
|
return last; |
||||||
|
} |
||||||
|
|
||||||
|
public void PushIndent(string indent) { |
||||||
|
this.Indents.Push(indent.Length); |
||||||
|
this.currentIndent = (this.currentIndent + indent); |
||||||
|
} |
||||||
|
|
||||||
|
public void ClearIndent() { |
||||||
|
this.currentIndent = string.Empty; |
||||||
|
this.Indents.Clear(); |
||||||
|
} |
||||||
|
|
||||||
|
public void Write(string textToAppend) { |
||||||
|
this.GenerationEnvironment.Append(textToAppend); |
||||||
|
} |
||||||
|
|
||||||
|
public void Write(string format, params object[] args) { |
||||||
|
this.GenerationEnvironment.AppendFormat(format, args); |
||||||
|
} |
||||||
|
|
||||||
|
public void WriteLine(string textToAppend) { |
||||||
|
this.GenerationEnvironment.Append(this.currentIndent); |
||||||
|
this.GenerationEnvironment.AppendLine(textToAppend); |
||||||
|
} |
||||||
|
|
||||||
|
public void WriteLine(string format, params object[] args) { |
||||||
|
this.GenerationEnvironment.Append(this.currentIndent); |
||||||
|
this.GenerationEnvironment.AppendFormat(format, args); |
||||||
|
this.GenerationEnvironment.AppendLine(); |
||||||
|
} |
||||||
|
|
||||||
|
public class ToStringInstanceHelper { |
||||||
|
|
||||||
|
private global::System.IFormatProvider formatProvider = global::System.Globalization.CultureInfo.InvariantCulture; |
||||||
|
|
||||||
|
public global::System.IFormatProvider FormatProvider { |
||||||
|
get { |
||||||
|
return this.formatProvider; |
||||||
|
} |
||||||
|
set { |
||||||
|
if ((this.formatProvider == null)) { |
||||||
|
throw new global::System.ArgumentNullException("formatProvider"); |
||||||
|
} |
||||||
|
this.formatProvider = value; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public string ToStringWithCulture(object objectToConvert) { |
||||||
|
if ((objectToConvert == null)) { |
||||||
|
throw new global::System.ArgumentNullException("objectToConvert"); |
||||||
|
} |
||||||
|
global::System.Type type = objectToConvert.GetType(); |
||||||
|
global::System.Type iConvertibleType = typeof(global::System.IConvertible); |
||||||
|
if (iConvertibleType.IsAssignableFrom(type)) { |
||||||
|
return ((global::System.IConvertible)(objectToConvert)).ToString(this.formatProvider); |
||||||
|
} |
||||||
|
global::System.Reflection.MethodInfo methInfo = type.GetMethod("ToString", new global::System.Type[] { |
||||||
|
iConvertibleType}); |
||||||
|
if ((methInfo != null)) { |
||||||
|
return ((string)(methInfo.Invoke(objectToConvert, new object[] { |
||||||
|
this.formatProvider}))); |
||||||
|
} |
||||||
|
return objectToConvert.ToString(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,2 @@ |
|||||||
|
<#@ template language="C#" #> |
||||||
|
<# /* This is a dummy template that language-specific templates may inherit from */ #> |
@ -0,0 +1,16 @@ |
|||||||
|
using System; |
||||||
|
|
||||||
|
namespace Templates { |
||||||
|
|
||||||
|
public interface ITemplate { |
||||||
|
Generator Generator { get; set; } |
||||||
|
Class Class { get; set; } |
||||||
|
string TransformText (); |
||||||
|
} |
||||||
|
|
||||||
|
public partial class Base : ITemplate { |
||||||
|
|
||||||
|
public Generator Generator { get; set; } |
||||||
|
public Class Class { get; set; } |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,828 @@ |
|||||||
|
// ------------------------------------------------------------------------------
|
||||||
|
// <autogenerated>
|
||||||
|
// This code was generated by a tool.
|
||||||
|
// Mono Runtime Version: 4.0.30319.1
|
||||||
|
//
|
||||||
|
// Changes to this file may cause incorrect behavior and will be lost if
|
||||||
|
// the code is regenerated.
|
||||||
|
// </autogenerated>
|
||||||
|
// ------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace Templates { |
||||||
|
using System.IO; |
||||||
|
using System.Linq; |
||||||
|
using System.Collections.Generic; |
||||||
|
using Mono.VisualC.Interop; |
||||||
|
using System; |
||||||
|
|
||||||
|
|
||||||
|
public partial class CSharpClass : Base { |
||||||
|
|
||||||
|
|
||||||
|
#line 204 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt"
|
||||||
|
|
||||||
|
private void WriteMethodHeader (Method method, string initBases) |
||||||
|
{ |
||||||
|
var returnType = GetCSharpType (Generator.CppTypeToManaged (method.ReturnType)); |
||||||
|
|
||||||
|
if (method.IsVirtual) |
||||||
|
WriteLine (string.Format ("[OverrideNative (\"{0}\")]", method.Name)); |
||||||
|
|
||||||
|
Write (CurrentIndent + "public "); |
||||||
|
if (method.IsConstructor) { |
||||||
|
Write (method.FormattedName); |
||||||
|
} else { |
||||||
|
if (method.IsStatic) Write ("static "); |
||||||
|
if (method.IsVirtual) Write ("virtual "); |
||||||
|
// ...?
|
||||||
|
Write (returnType); |
||||||
|
Write (" "); |
||||||
|
Write (method.FormattedName); |
||||||
|
} |
||||||
|
|
||||||
|
Write (" ("); |
||||||
|
WriteParameters (method.Parameters, true, false); |
||||||
|
Write (")\n"); |
||||||
|
|
||||||
|
if (method.IsConstructor) |
||||||
|
WriteLine (initBases); |
||||||
|
else |
||||||
|
WriteLine ("{"); |
||||||
|
|
||||||
|
PushIndent ("\t"); |
||||||
|
Write (CurrentIndent); |
||||||
|
|
||||||
|
if (returnType != "void") |
||||||
|
Write ("return "); |
||||||
|
} |
||||||
|
|
||||||
|
private void WriteParameters (IList<Parameter> parameters, bool writeType, bool writeAttributes) |
||||||
|
{ |
||||||
|
for (var i = 0; i < parameters.Count; i++) { |
||||||
|
if (i != 0) |
||||||
|
Write (", "); |
||||||
|
|
||||||
|
var type = GetCSharpType (Generator.CppTypeToManaged (parameters [i].Type)); |
||||||
|
|
||||||
|
if (writeAttributes) { |
||||||
|
var mangleAs = parameters [i].Type.ToString (); |
||||||
|
if (mangleAs != "" && mangleAs != type) |
||||||
|
Write (string.Format ("[MangleAs (\"{0}\")] ", mangleAs)); |
||||||
|
if (IsByVal (parameters [i].Type)) |
||||||
|
Write ("[ByVal] "); |
||||||
|
} |
||||||
|
|
||||||
|
if (type.EndsWith ("&")) { |
||||||
|
Write ("ref "); |
||||||
|
type = GetCSharpType (type.TrimEnd ('&')); |
||||||
|
} |
||||||
|
|
||||||
|
if (writeType) { |
||||||
|
Write (type); |
||||||
|
Write (" "); |
||||||
|
} |
||||||
|
|
||||||
|
Write (parameters [i].Name); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private string GetCSharpType (string str) |
||||||
|
{ |
||||||
|
switch (str) { |
||||||
|
case "System.Void": return "void"; |
||||||
|
case "System.Boolean": return "bool"; |
||||||
|
case "System.Byte": return "byte"; |
||||||
|
case "System.SByte": return "sbyte"; |
||||||
|
case "System.Char": return "char"; |
||||||
|
case "System.Int16": return "short"; |
||||||
|
case "System.UInt16": return "ushort"; |
||||||
|
case "System.Decimal": return "decimal"; |
||||||
|
case "System.Single": return "float"; |
||||||
|
case "System.Double": return "double"; |
||||||
|
case "System.Int32": return "int"; |
||||||
|
case "System.UInt32": return "uint"; |
||||||
|
case "System.Int64": return "long"; |
||||||
|
case "System.UInt64": return "ulong"; |
||||||
|
case "System.Object": return "object"; |
||||||
|
case "System.String": return "string"; |
||||||
|
} |
||||||
|
|
||||||
|
var lastDot = str.LastIndexOf ('.'); |
||||||
|
if (str.StartsWith ("System") && lastDot == "System".Length) |
||||||
|
return str.Substring (lastDot + 1); |
||||||
|
|
||||||
|
return str; |
||||||
|
} |
||||||
|
|
||||||
|
private string GetBaseString () |
||||||
|
{ |
||||||
|
if (Class.BaseClasses.Count == 0) |
||||||
|
return "ICppObject"; |
||||||
|
|
||||||
|
var str = Class.BaseClasses [0].Name; |
||||||
|
if (Class.BaseClasses.Count > 1) { |
||||||
|
str = string.Format ("{0} /*, {1} */", str, string.Join (", ", Class.BaseClasses.Skip (1).Select (bc => bc.Name).ToArray ())); |
||||||
|
} |
||||||
|
|
||||||
|
return str; |
||||||
|
} |
||||||
|
|
||||||
|
private bool IsByVal (CppType t) |
||||||
|
{ |
||||||
|
return ((t.ElementType == CppTypes.Class || t.ElementType == CppTypes.Struct) && |
||||||
|
!t.Modifiers.Contains (CppModifiers.Pointer) && |
||||||
|
!t.Modifiers.Contains (CppModifiers.Reference) && |
||||||
|
!t.Modifiers.Contains (CppModifiers.Array)); |
||||||
|
} |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
public override string TransformText() { |
||||||
|
this.GenerationEnvironment = null; |
||||||
|
|
||||||
|
#line 6 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt"
|
||||||
|
|
||||||
|
var hasBase = Class.BaseClasses.Count > 0; |
||||||
|
var wrapper = Class.Name; |
||||||
|
var iface = "I" + Class.Name; |
||||||
|
var layout = "_" + Class.Name; |
||||||
|
|
||||||
|
var initBases = "{"; |
||||||
|
if (hasBase) { |
||||||
|
initBases = "\t: base (impl.TypeInfo) {"; |
||||||
|
foreach (var nonPrimaryBase in Class.BaseClasses.Skip (1)) { |
||||||
|
initBases = string.Format ("{0}\n\t\t\tnew {1} (impl.TypeInfo);", initBases, nonPrimaryBase.Name); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 20 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt"
|
||||||
|
this.Write("// -------------------------------------------------------------------------\n// Managed wrapper for "); |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 21 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt"
|
||||||
|
this.Write(this.ToStringHelper.ToStringWithCulture( Class.Name )); |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 21 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt"
|
||||||
|
this.Write("\n// Generated from "); |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 22 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt"
|
||||||
|
this.Write(this.ToStringHelper.ToStringWithCulture( Path.GetFileName (Generator.InputFileName) )); |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 22 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt"
|
||||||
|
this.Write(" on "); |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 22 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt"
|
||||||
|
this.Write(this.ToStringHelper.ToStringWithCulture( DateTime.Now )); |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 22 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt"
|
||||||
|
this.Write("\n//\n// This file was auto generated. Do not edit.\n// -------------------------------------------------------------------------\n\nusing System;\nusing Mono.VisualC.Interop;\n\nnamespace "); |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 30 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt"
|
||||||
|
this.Write(this.ToStringHelper.ToStringWithCulture( Generator.Namespace )); |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 30 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt"
|
||||||
|
this.Write(" {\n\n\tpublic partial class "); |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 32 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt"
|
||||||
|
this.Write(this.ToStringHelper.ToStringWithCulture( wrapper )); |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 32 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt"
|
||||||
|
this.Write(" : "); |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 32 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt"
|
||||||
|
this.Write(this.ToStringHelper.ToStringWithCulture( GetBaseString () )); |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 32 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt"
|
||||||
|
this.Write(" {\n\n\t\tprivate static readonly "); |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 34 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt"
|
||||||
|
this.Write(this.ToStringHelper.ToStringWithCulture( iface )); |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 34 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt"
|
||||||
|
this.Write(" impl = Libs."); |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 34 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt"
|
||||||
|
this.Write(this.ToStringHelper.ToStringWithCulture( Generator.LibBaseName )); |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 34 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt"
|
||||||
|
this.Write(".GetClass<"); |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 34 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt"
|
||||||
|
this.Write(this.ToStringHelper.ToStringWithCulture( iface + "," + layout + "," + wrapper )); |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 34 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt"
|
||||||
|
this.Write("> (\""); |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 34 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt"
|
||||||
|
this.Write(this.ToStringHelper.ToStringWithCulture( Class.Name )); |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 34 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt"
|
||||||
|
this.Write("\");\n"); |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 35 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt"
|
||||||
|
if (!hasBase) { |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 36 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt"
|
||||||
|
this.Write("\t\tpublic CppInstancePtr Native { get; protected set; }\n"); |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 37 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt"
|
||||||
|
} |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 38 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt"
|
||||||
|
this.Write("\n"); |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 39 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt"
|
||||||
|
/* Interface */ |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 40 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt"
|
||||||
|
this.Write("\t\tpublic interface "); |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 40 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt"
|
||||||
|
this.Write(this.ToStringHelper.ToStringWithCulture( iface )); |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 40 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt"
|
||||||
|
this.Write(" : ICppClassOverridable<"); |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 40 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt"
|
||||||
|
this.Write(this.ToStringHelper.ToStringWithCulture( wrapper )); |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 40 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt"
|
||||||
|
this.Write("> {\n"); |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 41 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt"
|
||||||
|
PushIndent ("\t\t\t"); |
||||||
|
foreach (var method in Class.Methods) { |
||||||
|
Write (CurrentIndent); |
||||||
|
|
||||||
|
if (method.IsVirtual) Write ("[Virtual] "); |
||||||
|
if (method.IsStatic) Write ("[Static] "); |
||||||
|
if (method.IsArtificial) Write ("[Artificial] "); |
||||||
|
if (method.IsInline) Write ("[Inline] "); |
||||||
|
if (method.IsConst) Write ("[Const] "); |
||||||
|
if (method.IsConstructor) Write ("[Constructor] "); |
||||||
|
if (method.IsDestructor) Write ("[Destructor] "); |
||||||
|
if (method.IsCopyCtor) Write ("[CopyConstructor] "); |
||||||
|
|
||||||
|
if (IsByVal (method.ReturnType)) { |
||||||
|
Write ("[return: ByVal] "); |
||||||
|
} |
||||||
|
Write (GetCSharpType (Generator.CppTypeToManaged (method.ReturnType))); |
||||||
|
Write (" "); |
||||||
|
Write (method.Name); |
||||||
|
|
||||||
|
Write (" ("); |
||||||
|
if (!method.IsStatic) { |
||||||
|
Write ("CppInstancePtr @this"); |
||||||
|
if (method.Parameters.Count != 0) |
||||||
|
Write (", "); |
||||||
|
} |
||||||
|
|
||||||
|
WriteParameters (method.Parameters, true, !method.IsVirtual); |
||||||
|
Write (");\n"); |
||||||
|
} |
||||||
|
ClearIndent (); |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 72 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt"
|
||||||
|
this.Write("\t\t}\n"); |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 73 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt"
|
||||||
|
/* Native layout */ |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 74 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt"
|
||||||
|
this.Write("\t\tprivate struct "); |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 74 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt"
|
||||||
|
this.Write(this.ToStringHelper.ToStringWithCulture( layout )); |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 74 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt"
|
||||||
|
this.Write(" {\n"); |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 75 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt"
|
||||||
|
foreach (var field in Class.Fields) { |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 76 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt"
|
||||||
|
this.Write("\t\t\tpublic "); |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 76 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt"
|
||||||
|
this.Write(this.ToStringHelper.ToStringWithCulture( GetCSharpType (Generator.CppTypeToManaged (field.Type)) )); |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 76 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt"
|
||||||
|
this.Write(" "); |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 76 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt"
|
||||||
|
this.Write(this.ToStringHelper.ToStringWithCulture( field.Name )); |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 76 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt"
|
||||||
|
this.Write(";\n"); |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 77 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt"
|
||||||
|
} |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 78 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt"
|
||||||
|
this.Write("\t\t}\n\n"); |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 80 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt"
|
||||||
|
/* Native constructor */ |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 81 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt"
|
||||||
|
this.Write("\t\tpublic "); |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 81 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt"
|
||||||
|
this.Write(this.ToStringHelper.ToStringWithCulture( wrapper )); |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 81 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt"
|
||||||
|
this.Write(" (CppInstancePtr native)\n\t\t"); |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 82 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt"
|
||||||
|
this.Write(this.ToStringHelper.ToStringWithCulture( initBases )); |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 82 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt"
|
||||||
|
this.Write("\n\t\t\tNative = native;\n\t\t}\n\n"); |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 86 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt"
|
||||||
|
/* Subclass constructor */ |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 87 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt"
|
||||||
|
this.Write("\t\tpublic "); |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 87 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt"
|
||||||
|
this.Write(this.ToStringHelper.ToStringWithCulture( wrapper )); |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 87 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt"
|
||||||
|
this.Write(" (CppTypeInfo subClass)\n\t\t"); |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 88 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt"
|
||||||
|
this.Write(this.ToStringHelper.ToStringWithCulture( initBases )); |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 88 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt"
|
||||||
|
this.Write("\n\t\t\tsubClass.AddBase (impl.TypeInfo);\n\t\t}\n\n"); |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 92 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt"
|
||||||
|
/* Wrapper methods */ |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 93 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt"
|
||||||
|
PushIndent ("\t\t"); |
||||||
|
foreach (var method in Class.Methods.Where (m => m.GenWrapperMethod)) { |
||||||
|
|
||||||
|
WriteMethodHeader (method, initBases); |
||||||
|
|
||||||
|
if (method.IsConstructor) { |
||||||
|
Write ("Native = impl.Alloc (this);\n"); |
||||||
|
Write (CurrentIndent); |
||||||
|
} |
||||||
|
|
||||||
|
Write (string.Format ("impl.{0} (", method.Name)); |
||||||
|
if (!method.IsStatic) { |
||||||
|
Write ("Native"); |
||||||
|
if (method.Parameters.Count != 0) |
||||||
|
Write (", "); |
||||||
|
} |
||||||
|
|
||||||
|
WriteParameters (method.Parameters, false, false); |
||||||
|
PopIndent (); |
||||||
|
Write (string.Format (");\n{0}}}\n\n", CurrentIndent)); |
||||||
|
} |
||||||
|
ClearIndent (); |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 115 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt"
|
||||||
|
this.Write("\n"); |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 116 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt"
|
||||||
|
/* Wrapper properties */ |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 117 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt"
|
||||||
|
PushIndent ("\t\t"); |
||||||
|
foreach (var prop in Class.Properties) { |
||||||
|
var type = GetCSharpType (Generator.CppTypeToManaged (prop.Type)); |
||||||
|
|
||||||
|
Write (CurrentIndent + "public "); |
||||||
|
|
||||||
|
if ((prop.GetMethod == null || prop.GetMethod.IsVirtual) && |
||||||
|
(prop.SetMethod == null || prop.SetMethod.IsVirtual)) |
||||||
|
Write ("virtual "); |
||||||
|
|
||||||
|
Write (type); |
||||||
|
Write (" "); |
||||||
|
Write (prop.Name); |
||||||
|
Write (" {\n"); |
||||||
|
|
||||||
|
PushIndent ("\t"); |
||||||
|
Write (CurrentIndent); |
||||||
|
|
||||||
|
if (prop.GetMethod != null) { |
||||||
|
if (prop.GetMethod.IsVirtual) |
||||||
|
Write (string.Format ("[OverrideNative (\"{0}\")] ", prop.GetMethod.Name)); |
||||||
|
|
||||||
|
Write ("get {\n"); |
||||||
|
PushIndent ("\t"); |
||||||
|
WriteLine (string.Format ("return impl.{0} (Native);", prop.GetMethod.Name)); |
||||||
|
PopIndent (); |
||||||
|
WriteLine ("}"); |
||||||
|
} |
||||||
|
if (prop.SetMethod != null) { |
||||||
|
if (prop.SetMethod.IsVirtual) |
||||||
|
Write (string.Format ("[OverrideNative (\"{0}\")] ", prop.SetMethod.Name)); |
||||||
|
|
||||||
|
Write ("set {\n"); |
||||||
|
PushIndent ("\t"); |
||||||
|
WriteLine (string.Format ("impl.{0} (Native, value);", prop.SetMethod.Name)); |
||||||
|
PopIndent (); |
||||||
|
WriteLine ("}"); |
||||||
|
} |
||||||
|
|
||||||
|
PopIndent (); |
||||||
|
WriteLine ("}\n"); |
||||||
|
} |
||||||
|
ClearIndent (); |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 160 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt"
|
||||||
|
this.Write("\n"); |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 161 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt"
|
||||||
|
/* Make this wrapper castable to non-primary bases */ |
||||||
|
foreach (var npBase in Class.BaseClasses.Skip (1)) { |
||||||
|
var npImpl = npBase.Name + "_impl"; |
||||||
|
|
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 165 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt"
|
||||||
|
this.Write("\t\t// Non-primary base class implementation for "); |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 165 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt"
|
||||||
|
this.Write(this.ToStringHelper.ToStringWithCulture( npBase.Name )); |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 165 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt"
|
||||||
|
this.Write(":\n\t\tprivate "); |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 166 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt"
|
||||||
|
this.Write(this.ToStringHelper.ToStringWithCulture( npBase.Name )); |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 166 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt"
|
||||||
|
this.Write(" "); |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 166 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt"
|
||||||
|
this.Write(this.ToStringHelper.ToStringWithCulture( npImpl )); |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 166 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt"
|
||||||
|
this.Write(";\n\t\tpublic static implicit operator "); |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 167 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt"
|
||||||
|
this.Write(this.ToStringHelper.ToStringWithCulture( npBase.Name )); |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 167 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt"
|
||||||
|
this.Write("("); |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 167 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt"
|
||||||
|
this.Write(this.ToStringHelper.ToStringWithCulture( wrapper )); |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 167 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt"
|
||||||
|
this.Write(" subClass)\n\t\t{\n\t\t\tif (subClass."); |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 169 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt"
|
||||||
|
this.Write(this.ToStringHelper.ToStringWithCulture( npImpl )); |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 169 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt"
|
||||||
|
this.Write(" == null)\n\t\t\t\tsubClass."); |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 170 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt"
|
||||||
|
this.Write(this.ToStringHelper.ToStringWithCulture( npImpl )); |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 170 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt"
|
||||||
|
this.Write(" = impl.TypeInfo.Cast<"); |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 170 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt"
|
||||||
|
this.Write(this.ToStringHelper.ToStringWithCulture( npBase.Name )); |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 170 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt"
|
||||||
|
this.Write("> (subClass);\n\t\t\treturn subClass."); |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 171 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt"
|
||||||
|
this.Write(this.ToStringHelper.ToStringWithCulture( npImpl )); |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 171 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt"
|
||||||
|
this.Write(";\n\t\t}\n\n"); |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 174 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt"
|
||||||
|
PushIndent ("\t\t"); |
||||||
|
foreach (var method in npBase.Methods) { |
||||||
|
// With the exception of virtual methods that have been overridden, these methods must be called
|
||||||
|
// thru a cast to the base class that performs a this ptr adjustment
|
||||||
|
if (!method.GenWrapperMethod || method.IsConstructor || method.IsStatic || |
||||||
|
(method.IsVirtual && Class.Methods.Any (m => m.Node.CheckValue ("overrides", method.Node.Id)))) |
||||||
|
continue; |
||||||
|
|
||||||
|
WriteMethodHeader (method, initBases); |
||||||
|
|
||||||
|
Write (string.Format ("(({0})this).{1} (", npBase.Name, method.FormattedName)); |
||||||
|
|
||||||
|
WriteParameters (method.Parameters, false, false); |
||||||
|
PopIndent (); |
||||||
|
Write (string.Format (");\n{0}}}\n\n", CurrentIndent)); |
||||||
|
} |
||||||
|
ClearIndent (); |
||||||
|
} |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 192 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt"
|
||||||
|
this.Write("\n\t\tpublic "); |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 193 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt"
|
||||||
|
this.Write(this.ToStringHelper.ToStringWithCulture( hasBase? "override" : "virtual" )); |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 193 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt"
|
||||||
|
this.Write(" void Dispose ()\n\t\t{\n"); |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 195 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt"
|
||||||
|
if (Class.Methods.Any (m => m.IsDestructor && !m.IsArtificial)) { |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 196 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt"
|
||||||
|
this.Write("\t\t\timpl.Destruct (Native);\n"); |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 197 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt"
|
||||||
|
} |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 198 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpClass.tt"
|
||||||
|
this.Write("\t\t\tNative.Dispose ();\n\t\t}\n\n\t}\n}\n\n"); |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
return this.GenerationEnvironment.ToString(); |
||||||
|
} |
||||||
|
|
||||||
|
protected override void Initialize() { |
||||||
|
base.Initialize(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,318 @@ |
|||||||
|
<#@ template language="C#" inherits="Base" #> |
||||||
|
<#@ import namespace="System.IO" #> |
||||||
|
<#@ import namespace="System.Linq" #> |
||||||
|
<#@ import namespace="System.Collections.Generic" #> |
||||||
|
<#@ import namespace="Mono.VisualC.Interop" #> |
||||||
|
<# |
||||||
|
var hasBase = Class.BaseClasses.Count > 0; |
||||||
|
var wrapper = Class.Name; |
||||||
|
var iface = "I" + Class.Name; |
||||||
|
var layout = "_" + Class.Name; |
||||||
|
|
||||||
|
var initBases = "{"; |
||||||
|
if (hasBase) { |
||||||
|
initBases = "\t: base (impl.TypeInfo) {"; |
||||||
|
foreach (var nonPrimaryBase in Class.BaseClasses.Skip (1)) { |
||||||
|
initBases = string.Format ("{0}\n\t\t\tnew {1} (impl.TypeInfo);", initBases, nonPrimaryBase.Name); |
||||||
|
} |
||||||
|
} |
||||||
|
#> |
||||||
|
// ------------------------------------------------------------------------- |
||||||
|
// Managed wrapper for <#= Class.Name #> |
||||||
|
// Generated from <#= Path.GetFileName (Generator.InputFileName) #> on <#= DateTime.Now #> |
||||||
|
// |
||||||
|
// This file was auto generated. Do not edit. |
||||||
|
// ------------------------------------------------------------------------- |
||||||
|
|
||||||
|
using System; |
||||||
|
using Mono.VisualC.Interop; |
||||||
|
|
||||||
|
namespace <#= Generator.Namespace #> { |
||||||
|
|
||||||
|
public partial class <#= wrapper #> : <#= GetBaseString () #> { |
||||||
|
|
||||||
|
private static readonly <#= iface #> impl = Libs.<#= Generator.LibBaseName #>.GetClass<<#= iface + "," + layout + "," + wrapper #>> ("<#= Class.Name #>"); |
||||||
|
<# if (!hasBase) { #> |
||||||
|
public CppInstancePtr Native { get; protected set; } |
||||||
|
<# } #> |
||||||
|
|
||||||
|
<# /* Interface */ #> |
||||||
|
public interface <#= iface #> : ICppClassOverridable<<#= wrapper #>> { |
||||||
|
<# PushIndent ("\t\t\t"); |
||||||
|
foreach (var method in Class.Methods) { |
||||||
|
Write (CurrentIndent); |
||||||
|
|
||||||
|
if (method.IsVirtual) Write ("[Virtual] "); |
||||||
|
if (method.IsStatic) Write ("[Static] "); |
||||||
|
if (method.IsArtificial) Write ("[Artificial] "); |
||||||
|
if (method.IsInline) Write ("[Inline] "); |
||||||
|
if (method.IsConst) Write ("[Const] "); |
||||||
|
if (method.IsConstructor) Write ("[Constructor] "); |
||||||
|
if (method.IsDestructor) Write ("[Destructor] "); |
||||||
|
if (method.IsCopyCtor) Write ("[CopyConstructor] "); |
||||||
|
|
||||||
|
if (IsByVal (method.ReturnType)) { |
||||||
|
Write ("[return: ByVal] "); |
||||||
|
} |
||||||
|
Write (GetCSharpType (Generator.CppTypeToManaged (method.ReturnType))); |
||||||
|
Write (" "); |
||||||
|
Write (method.Name); |
||||||
|
|
||||||
|
Write (" ("); |
||||||
|
if (!method.IsStatic) { |
||||||
|
Write ("CppInstancePtr @this"); |
||||||
|
if (method.Parameters.Count != 0) |
||||||
|
Write (", "); |
||||||
|
} |
||||||
|
|
||||||
|
WriteParameters (method.Parameters, true, !method.IsVirtual); |
||||||
|
Write (");\n"); |
||||||
|
} |
||||||
|
ClearIndent (); #> |
||||||
|
} |
||||||
|
<# /* Native layout */ #> |
||||||
|
private struct <#= layout #> { |
||||||
|
<# foreach (var field in Class.Fields) { #> |
||||||
|
public <#= GetCSharpType (Generator.CppTypeToManaged (field.Type)) #> <#= field.Name #>; |
||||||
|
<# } #> |
||||||
|
} |
||||||
|
|
||||||
|
<# /* Native constructor */ #> |
||||||
|
public <#= wrapper #> (CppInstancePtr native) |
||||||
|
<#= initBases #> |
||||||
|
Native = native; |
||||||
|
} |
||||||
|
|
||||||
|
<# /* Subclass constructor */ #> |
||||||
|
public <#= wrapper #> (CppTypeInfo subClass) |
||||||
|
<#= initBases #> |
||||||
|
subClass.AddBase (impl.TypeInfo); |
||||||
|
} |
||||||
|
|
||||||
|
<# /* Wrapper methods */ #> |
||||||
|
<# PushIndent ("\t\t"); |
||||||
|
foreach (var method in Class.Methods.Where (m => m.GenWrapperMethod)) { |
||||||
|
|
||||||
|
WriteMethodHeader (method, initBases); |
||||||
|
|
||||||
|
if (method.IsConstructor) { |
||||||
|
Write ("Native = impl.Alloc (this);\n"); |
||||||
|
Write (CurrentIndent); |
||||||
|
} |
||||||
|
|
||||||
|
Write (string.Format ("impl.{0} (", method.Name)); |
||||||
|
if (!method.IsStatic) { |
||||||
|
Write ("Native"); |
||||||
|
if (method.Parameters.Count != 0) |
||||||
|
Write (", "); |
||||||
|
} |
||||||
|
|
||||||
|
WriteParameters (method.Parameters, false, false); |
||||||
|
PopIndent (); |
||||||
|
Write (string.Format (");\n{0}}}\n\n", CurrentIndent)); |
||||||
|
} |
||||||
|
ClearIndent (); #> |
||||||
|
|
||||||
|
<# /* Wrapper properties */ #> |
||||||
|
<# PushIndent ("\t\t"); |
||||||
|
foreach (var prop in Class.Properties) { |
||||||
|
var type = GetCSharpType (Generator.CppTypeToManaged (prop.Type)); |
||||||
|
|
||||||
|
Write (CurrentIndent + "public "); |
||||||
|
|
||||||
|
if ((prop.GetMethod == null || prop.GetMethod.IsVirtual) && |
||||||
|
(prop.SetMethod == null || prop.SetMethod.IsVirtual)) |
||||||
|
Write ("virtual "); |
||||||
|
|
||||||
|
Write (type); |
||||||
|
Write (" "); |
||||||
|
Write (prop.Name); |
||||||
|
Write (" {\n"); |
||||||
|
|
||||||
|
PushIndent ("\t"); |
||||||
|
Write (CurrentIndent); |
||||||
|
|
||||||
|
if (prop.GetMethod != null) { |
||||||
|
if (prop.GetMethod.IsVirtual) |
||||||
|
Write (string.Format ("[OverrideNative (\"{0}\")] ", prop.GetMethod.Name)); |
||||||
|
|
||||||
|
Write ("get {\n"); |
||||||
|
PushIndent ("\t"); |
||||||
|
WriteLine (string.Format ("return impl.{0} (Native);", prop.GetMethod.Name)); |
||||||
|
PopIndent (); |
||||||
|
WriteLine ("}"); |
||||||
|
} |
||||||
|
if (prop.SetMethod != null) { |
||||||
|
if (prop.SetMethod.IsVirtual) |
||||||
|
Write (string.Format ("[OverrideNative (\"{0}\")] ", prop.SetMethod.Name)); |
||||||
|
|
||||||
|
Write ("set {\n"); |
||||||
|
PushIndent ("\t"); |
||||||
|
WriteLine (string.Format ("impl.{0} (Native, value);", prop.SetMethod.Name)); |
||||||
|
PopIndent (); |
||||||
|
WriteLine ("}"); |
||||||
|
} |
||||||
|
|
||||||
|
PopIndent (); |
||||||
|
WriteLine ("}\n"); |
||||||
|
} |
||||||
|
ClearIndent (); #> |
||||||
|
|
||||||
|
<# /* Make this wrapper castable to non-primary bases */ |
||||||
|
foreach (var npBase in Class.BaseClasses.Skip (1)) { |
||||||
|
var npImpl = npBase.Name + "_impl"; |
||||||
|
#> |
||||||
|
// Non-primary base class implementation for <#= npBase.Name #>: |
||||||
|
private <#= npBase.Name #> <#= npImpl #>; |
||||||
|
public static implicit operator <#= npBase.Name #>(<#= wrapper #> subClass) |
||||||
|
{ |
||||||
|
if (subClass.<#= npImpl #> == null) |
||||||
|
subClass.<#= npImpl #> = impl.TypeInfo.Cast<<#= npBase.Name #>> (subClass); |
||||||
|
return subClass.<#= npImpl #>; |
||||||
|
} |
||||||
|
|
||||||
|
<# PushIndent ("\t\t"); |
||||||
|
foreach (var method in npBase.Methods) { |
||||||
|
// With the exception of virtual methods that have been overridden, these methods must be called |
||||||
|
// thru a cast to the base class that performs a this ptr adjustment |
||||||
|
if (!method.GenWrapperMethod || method.IsConstructor || method.IsStatic || |
||||||
|
(method.IsVirtual && Class.Methods.Any (m => m.Node.CheckValue ("overrides", method.Node.Id)))) |
||||||
|
continue; |
||||||
|
|
||||||
|
WriteMethodHeader (method, initBases); |
||||||
|
|
||||||
|
Write (string.Format ("(({0})this).{1} (", npBase.Name, method.FormattedName)); |
||||||
|
|
||||||
|
WriteParameters (method.Parameters, false, false); |
||||||
|
PopIndent (); |
||||||
|
Write (string.Format (");\n{0}}}\n\n", CurrentIndent)); |
||||||
|
} |
||||||
|
ClearIndent (); |
||||||
|
} #> |
||||||
|
|
||||||
|
public <#= hasBase? "override" : "virtual" #> void Dispose () |
||||||
|
{ |
||||||
|
<# if (Class.Methods.Any (m => m.IsDestructor && !m.IsArtificial)) { #> |
||||||
|
impl.Destruct (Native); |
||||||
|
<# } #> |
||||||
|
Native.Dispose (); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
<#+ |
||||||
|
private void WriteMethodHeader (Method method, string initBases) |
||||||
|
{ |
||||||
|
var returnType = GetCSharpType (Generator.CppTypeToManaged (method.ReturnType)); |
||||||
|
|
||||||
|
if (method.IsVirtual) |
||||||
|
WriteLine (string.Format ("[OverrideNative (\"{0}\")]", method.Name)); |
||||||
|
|
||||||
|
Write (CurrentIndent + "public "); |
||||||
|
if (method.IsConstructor) { |
||||||
|
Write (method.FormattedName); |
||||||
|
} else { |
||||||
|
if (method.IsStatic) Write ("static "); |
||||||
|
if (method.IsVirtual) Write ("virtual "); |
||||||
|
// ...? |
||||||
|
Write (returnType); |
||||||
|
Write (" "); |
||||||
|
Write (method.FormattedName); |
||||||
|
} |
||||||
|
|
||||||
|
Write (" ("); |
||||||
|
WriteParameters (method.Parameters, true, false); |
||||||
|
Write (")\n"); |
||||||
|
|
||||||
|
if (method.IsConstructor) |
||||||
|
WriteLine (initBases); |
||||||
|
else |
||||||
|
WriteLine ("{"); |
||||||
|
|
||||||
|
PushIndent ("\t"); |
||||||
|
Write (CurrentIndent); |
||||||
|
|
||||||
|
if (returnType != "void") |
||||||
|
Write ("return "); |
||||||
|
} |
||||||
|
|
||||||
|
private void WriteParameters (IList<Parameter> parameters, bool writeType, bool writeAttributes) |
||||||
|
{ |
||||||
|
for (var i = 0; i < parameters.Count; i++) { |
||||||
|
if (i != 0) |
||||||
|
Write (", "); |
||||||
|
|
||||||
|
var type = GetCSharpType (Generator.CppTypeToManaged (parameters [i].Type)); |
||||||
|
|
||||||
|
if (writeAttributes) { |
||||||
|
var mangleAs = parameters [i].Type.ToString (); |
||||||
|
if (mangleAs != "" && mangleAs != type) |
||||||
|
Write (string.Format ("[MangleAs (\"{0}\")] ", mangleAs)); |
||||||
|
if (IsByVal (parameters [i].Type)) |
||||||
|
Write ("[ByVal] "); |
||||||
|
} |
||||||
|
|
||||||
|
if (type.EndsWith ("&")) { |
||||||
|
Write ("ref "); |
||||||
|
type = GetCSharpType (type.TrimEnd ('&')); |
||||||
|
} |
||||||
|
|
||||||
|
if (writeType) { |
||||||
|
Write (type); |
||||||
|
Write (" "); |
||||||
|
} |
||||||
|
|
||||||
|
Write (parameters [i].Name); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private string GetCSharpType (string str) |
||||||
|
{ |
||||||
|
switch (str) { |
||||||
|
case "System.Void": return "void"; |
||||||
|
case "System.Boolean": return "bool"; |
||||||
|
case "System.Byte": return "byte"; |
||||||
|
case "System.SByte": return "sbyte"; |
||||||
|
case "System.Char": return "char"; |
||||||
|
case "System.Int16": return "short"; |
||||||
|
case "System.UInt16": return "ushort"; |
||||||
|
case "System.Decimal": return "decimal"; |
||||||
|
case "System.Single": return "float"; |
||||||
|
case "System.Double": return "double"; |
||||||
|
case "System.Int32": return "int"; |
||||||
|
case "System.UInt32": return "uint"; |
||||||
|
case "System.Int64": return "long"; |
||||||
|
case "System.UInt64": return "ulong"; |
||||||
|
case "System.Object": return "object"; |
||||||
|
case "System.String": return "string"; |
||||||
|
} |
||||||
|
|
||||||
|
var lastDot = str.LastIndexOf ('.'); |
||||||
|
if (str.StartsWith ("System") && lastDot == "System".Length) |
||||||
|
return str.Substring (lastDot + 1); |
||||||
|
|
||||||
|
return str; |
||||||
|
} |
||||||
|
|
||||||
|
private string GetBaseString () |
||||||
|
{ |
||||||
|
if (Class.BaseClasses.Count == 0) |
||||||
|
return "ICppObject"; |
||||||
|
|
||||||
|
var str = Class.BaseClasses [0].Name; |
||||||
|
if (Class.BaseClasses.Count > 1) { |
||||||
|
str = string.Format ("{0} /*, {1} */", str, string.Join (", ", Class.BaseClasses.Skip (1).Select (bc => bc.Name).ToArray ())); |
||||||
|
} |
||||||
|
|
||||||
|
return str; |
||||||
|
} |
||||||
|
|
||||||
|
private bool IsByVal (CppType t) |
||||||
|
{ |
||||||
|
return ((t.ElementType == CppTypes.Class || t.ElementType == CppTypes.Struct) && |
||||||
|
!t.Modifiers.Contains (CppModifiers.Pointer) && |
||||||
|
!t.Modifiers.Contains (CppModifiers.Reference) && |
||||||
|
!t.Modifiers.Contains (CppModifiers.Array)); |
||||||
|
} |
||||||
|
#> |
@ -0,0 +1,92 @@ |
|||||||
|
// ------------------------------------------------------------------------------
|
||||||
|
// <autogenerated>
|
||||||
|
// This code was generated by a tool.
|
||||||
|
// Mono Runtime Version: 4.0.30319.1
|
||||||
|
//
|
||||||
|
// Changes to this file may cause incorrect behavior and will be lost if
|
||||||
|
// the code is regenerated.
|
||||||
|
// </autogenerated>
|
||||||
|
// ------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace Templates { |
||||||
|
using System; |
||||||
|
|
||||||
|
|
||||||
|
public partial class CSharpLibs : Base { |
||||||
|
|
||||||
|
public override string TransformText() { |
||||||
|
this.GenerationEnvironment = null; |
||||||
|
|
||||||
|
#line 2 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpLibs.tt"
|
||||||
|
this.Write("// -------------------------------------------------------------------------\n// C++ libarary declarations\n// Generated on "); |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 4 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpLibs.tt"
|
||||||
|
this.Write(this.ToStringHelper.ToStringWithCulture( DateTime.Now )); |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 4 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpLibs.tt"
|
||||||
|
this.Write("\n//\n// This file was auto generated. Do not edit.\n// -------------------------------------------------------------------------\n\nusing System;\nusing Mono.VisualC.Interop;\n\nnamespace "); |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 12 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpLibs.tt"
|
||||||
|
this.Write(this.ToStringHelper.ToStringWithCulture( Generator.Namespace )); |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 12 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpLibs.tt"
|
||||||
|
this.Write(" {\n\n\tpublic static partial class Libs {\n\n\t\tpublic static readonly CppLibrary "); |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 16 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpLibs.tt"
|
||||||
|
this.Write(this.ToStringHelper.ToStringWithCulture( Generator.LibBaseName )); |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 16 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpLibs.tt"
|
||||||
|
this.Write(" = new CppLibrary (\""); |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 16 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpLibs.tt"
|
||||||
|
this.Write(this.ToStringHelper.ToStringWithCulture( Generator.LibBaseName )); |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 16 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpLibs.tt"
|
||||||
|
this.Write("\", InlineMethods."); |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 16 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpLibs.tt"
|
||||||
|
this.Write(this.ToStringHelper.ToStringWithCulture( Generator.InlinePolicy.ToString () )); |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
|
||||||
|
#line 16 "/Users/alex/OpenSource/cppinterop/src/generator/Templates/CSharp/CSharpLibs.tt"
|
||||||
|
this.Write(");\n\n\t}\n}\n"); |
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
return this.GenerationEnvironment.ToString(); |
||||||
|
} |
||||||
|
|
||||||
|
protected override void Initialize() { |
||||||
|
base.Initialize(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,19 @@ |
|||||||
|
<#@ template language="C#" inherits="Base" #> |
||||||
|
// ------------------------------------------------------------------------- |
||||||
|
// C++ libarary declarations |
||||||
|
// Generated on <#= DateTime.Now #> |
||||||
|
// |
||||||
|
// This file was auto generated. Do not edit. |
||||||
|
// ------------------------------------------------------------------------- |
||||||
|
|
||||||
|
using System; |
||||||
|
using Mono.VisualC.Interop; |
||||||
|
|
||||||
|
namespace <#= Generator.Namespace #> { |
||||||
|
|
||||||
|
public static partial class Libs { |
||||||
|
|
||||||
|
public static readonly CppLibrary <#= Generator.LibBaseName #> = new CppLibrary ("<#= Generator.LibBaseName #>", InlineMethods.<#= Generator.InlinePolicy.ToString () #>); |
||||||
|
|
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue