diff --git a/src/Generator/Generators/CLI/CLIHelpers.cs b/src/Generator/Generators/CLI/CLIHelpers.cs index f9f92136..bdbf694a 100644 --- a/src/Generator/Generators/CLI/CLIHelpers.cs +++ b/src/Generator/Generators/CLI/CLIHelpers.cs @@ -4,126 +4,6 @@ using Cxxi.Types; namespace Cxxi.Generators.CLI { - #region CLI Text Templates - public abstract class CLITextTemplate : TextTemplate - { - protected const string DefaultIndent = " "; - protected const uint MaxIndent = 80; - - public CLITypePrinter TypeSig { 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("/// "); - foreach (string line in lines) - WriteLine(string.Format("/// {0}", line.TrimEnd())); - WriteLine("/// "); - } - - public void GenerateInlineSummary(string comment) - { - if (String.IsNullOrWhiteSpace(comment)) - return; - WriteLine("/// {0} ", 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}", TypeSig.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(); - } - #endregion - public class CLIGenerator : ILanguageGenerator { public Options Options { get; set; } diff --git a/src/Generator/Generators/CLI/CLITextTemplate.cs b/src/Generator/Generators/CLI/CLITextTemplate.cs new file mode 100644 index 00000000..2d539e61 --- /dev/null +++ b/src/Generator/Generators/CLI/CLITextTemplate.cs @@ -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("/// "); + foreach (string line in lines) + WriteLine(string.Format("/// {0}", line.TrimEnd())); + WriteLine("/// "); + } + + public void GenerateInlineSummary(string comment) + { + if (String.IsNullOrWhiteSpace(comment)) + return; + WriteLine("/// {0} ", 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(); + } +} \ No newline at end of file