mirror of https://github.com/mono/CppSharp.git
2 changed files with 123 additions and 120 deletions
@ -0,0 +1,123 @@
@@ -0,0 +1,123 @@
|
||||
using System; |
||||
using Cxxi.Types; |
||||
|
||||
namespace Cxxi.Generators.CLI |
||||
{ |
||||
public abstract class CLITextTemplate : TextTemplate |
||||
{ |
||||
protected const string DefaultIndent = " "; |
||||
protected const uint MaxIndent = 80; |
||||
|
||||
public ITypePrinter TypePrinter { get; set; } |
||||
|
||||
public static string SafeIdentifier(string proposedName) |
||||
{ |
||||
return proposedName; |
||||
} |
||||
|
||||
public string QualifiedIdentifier(Declaration decl) |
||||
{ |
||||
return string.Format("{0}::{1}", Library.Name, decl.Name); |
||||
} |
||||
|
||||
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) |
||||
{ |
||||
if (String.IsNullOrWhiteSpace(comment)) |
||||
return; |
||||
|
||||
// Wrap the comment to the line width.
|
||||
var maxSize = (int)(MaxIndent - CurrentIndent.Count - "/// ".Length); |
||||
var lines = StringHelpers.WordWrapLines(comment, maxSize); |
||||
|
||||
WriteLine("/// <summary>"); |
||||
foreach (string line in lines) |
||||
WriteLine(string.Format("/// {0}", line.TrimEnd())); |
||||
WriteLine("/// </summary>"); |
||||
} |
||||
|
||||
public void GenerateInlineSummary(string comment) |
||||
{ |
||||
if (String.IsNullOrWhiteSpace(comment)) |
||||
return; |
||||
WriteLine("/// <summary> {0} </summary>", comment); |
||||
} |
||||
|
||||
public void GenerateMethodParameters(Method method) |
||||
{ |
||||
for (var i = 0; i < method.Parameters.Count; ++i) |
||||
{ |
||||
if (method.Conversion == MethodConversionKind.FunctionToInstanceMethod |
||||
&& i == 0) |
||||
continue; |
||||
|
||||
var param = method.Parameters[i]; |
||||
Write("{0}", TypePrinter.GetArgumentString(param)); |
||||
if (i < method.Parameters.Count - 1) |
||||
Write(", "); |
||||
} |
||||
} |
||||
|
||||
public static bool CheckIgnoreMethod(Class @class, Method method) |
||||
{ |
||||
if (method.Ignore) return true; |
||||
|
||||
if (@class.IsAbstract && method.IsConstructor) |
||||
return true; |
||||
|
||||
if (@class.IsValueType && method.IsDefaultConstructor) |
||||
return true; |
||||
|
||||
if (method.IsCopyConstructor || method.IsMoveConstructor) |
||||
return true; |
||||
|
||||
if (method.IsDestructor) |
||||
return true; |
||||
|
||||
if (method.OperatorKind == CXXOperatorKind.Equal) |
||||
return true; |
||||
|
||||
if (method.Kind == CXXMethodKind.Conversion) |
||||
return true; |
||||
|
||||
if (method.Access != AccessSpecifier.Public) |
||||
return true; |
||||
|
||||
return false; |
||||
} |
||||
|
||||
public static bool CheckIgnoreField(Class @class, Field field) |
||||
{ |
||||
if (field.Ignore) return true; |
||||
|
||||
return false; |
||||
} |
||||
|
||||
public abstract override string FileExtension { get; } |
||||
|
||||
protected abstract override void Generate(); |
||||
} |
||||
} |
Loading…
Reference in new issue