diff --git a/src/Generator/Generators/CLI/CLIHeadersTemplate.cs b/src/Generator/Generators/CLI/CLIHeadersTemplate.cs index 90d4b0b6..10200a87 100644 --- a/src/Generator/Generators/CLI/CLIHeadersTemplate.cs +++ b/src/Generator/Generators/CLI/CLIHeadersTemplate.cs @@ -394,7 +394,7 @@ namespace Cxxi.Generators.CLI if (typedef.Type.IsPointerTo(out function)) { WriteLine("public {0};", - string.Format(TypePrinter.ToDelegateString(function), + string.Format(TypePrinter.VisitDelegate(function), SafeIdentifier(typedef.Name))); return true; } @@ -421,7 +421,7 @@ namespace Cxxi.Generators.CLI for (int i = 0; i < function.Parameters.Count; ++i) { var param = function.Parameters[i]; - Write("{0}", TypePrinter.GetArgumentString(param)); + Write("{0}", TypePrinter.VisitParameter(param)); if (i < function.Parameters.Count - 1) Write(", "); } diff --git a/src/Generator/Generators/CLI/CLISourcesTemplate.cs b/src/Generator/Generators/CLI/CLISourcesTemplate.cs index d71ac24e..e4ee8f2e 100644 --- a/src/Generator/Generators/CLI/CLISourcesTemplate.cs +++ b/src/Generator/Generators/CLI/CLISourcesTemplate.cs @@ -268,7 +268,7 @@ namespace Cxxi.Generators.CLI for (var i = 0; i < function.Parameters.Count; ++i) { var param = function.Parameters[i]; - Write("{0}", TypePrinter.GetArgumentString(param)); + Write("{0}", TypePrinter.VisitParameter(param)); if (i < function.Parameters.Count - 1) Write(", "); } diff --git a/src/Generator/Generators/CLI/CLITextTemplate.cs b/src/Generator/Generators/CLI/CLITextTemplate.cs index 9e3a6044..e75b5edb 100644 --- a/src/Generator/Generators/CLI/CLITextTemplate.cs +++ b/src/Generator/Generators/CLI/CLITextTemplate.cs @@ -81,7 +81,7 @@ namespace Cxxi.Generators.CLI continue; var param = method.Parameters[i]; - Write("{0}", TypePrinter.GetArgumentString(param)); + Write("{0}", TypePrinter.VisitParameter(param)); if (i < method.Parameters.Count - 1) Write(", "); } diff --git a/src/Generator/Generators/CLI/CLITypePrinter.cs b/src/Generator/Generators/CLI/CLITypePrinter.cs index d6ac8b8d..5d78b64e 100644 --- a/src/Generator/Generators/CLI/CLITypePrinter.cs +++ b/src/Generator/Generators/CLI/CLITypePrinter.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using Cxxi.Types; namespace Cxxi.Generators.CLI @@ -36,7 +37,7 @@ namespace Cxxi.Generators.CLI var args = string.Empty; if (arguments.Count > 0) - args = GetArgumentsString(function, hasNames: false); + args = VisitParameters(function.Arguments, hasNames: false); if (returnType.IsPrimitiveType(PrimitiveType.Void)) { @@ -51,22 +52,18 @@ namespace Cxxi.Generators.CLI return string.Format("System::Func<{0}{1}>", returnType.Visit(this), args); } - public string GetArgumentsString(FunctionType function, bool hasNames) + public string VisitParameters(IEnumerable @params, + bool hasNames) { - var arguments = function.Arguments; - var s = string.Empty; + var args = new List(); - for (var i = 0; i < arguments.Count; ++i) - { - s += GetArgumentString(arguments[i], hasNames); - if (i < arguments.Count - 1) - s += ", "; - } + foreach (var param in @params) + args.Add(VisitParameter(param, hasNames)); - return s; + return string.Join(" ,", args); } - public string GetArgumentString(Parameter param, bool hasName = true) + public string VisitParameter(Parameter param, bool hasName = true) { var type = param.Type.Visit(this, param.QualifiedType.Qualifiers); var name = param.Name; @@ -77,11 +74,11 @@ namespace Cxxi.Generators.CLI return type; } - public string ToDelegateString(FunctionType function) + public string VisitDelegate(FunctionType function) { return string.Format("delegate {0} {{0}}({1})", function.ReturnType.Visit(this), - GetArgumentsString(function, hasNames: true)); + VisitParameters(function.Arguments, hasNames: true)); } public string VisitPointerType(PointerType pointer, TypeQualifiers quals) diff --git a/src/Generator/Generators/CSharp/CSharpTypePrinter.cs b/src/Generator/Generators/CSharp/CSharpTypePrinter.cs index 3385d2f9..e8494095 100644 --- a/src/Generator/Generators/CSharp/CSharpTypePrinter.cs +++ b/src/Generator/Generators/CSharp/CSharpTypePrinter.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using Cxxi.Types; namespace Cxxi.Generators.CSharp @@ -37,7 +38,7 @@ namespace Cxxi.Generators.CSharp var args = string.Empty; if (arguments.Count > 0) - args = GetArgumentsString(function, hasNames: false); + args = VisitParameters(function.Arguments, hasNames: false); if (returnType.IsPrimitiveType(PrimitiveType.Void)) { @@ -210,22 +211,18 @@ namespace Cxxi.Generators.CSharp throw new NotImplementedException(); } - public string GetArgumentsString(FunctionType function, bool hasNames) + public string VisitParameters(IEnumerable @params, + bool hasNames) { - var arguments = function.Arguments; - var s = string.Empty; + var args = new List(); - for (var i = 0; i < arguments.Count; ++i) - { - s += GetArgumentString(arguments[i], hasNames); - if (i < arguments.Count - 1) - s += ", "; - } + foreach (var param in @params) + args.Add(VisitParameter(param, hasNames)); - return s; + return string.Join(" ,", args); } - public string GetArgumentString(Parameter arg, bool hasName) + public string VisitParameter(Parameter arg, bool hasName) { var type = arg.Type.Visit(this, arg.QualifiedType.Qualifiers); var name = arg.Name; @@ -236,11 +233,11 @@ namespace Cxxi.Generators.CSharp return type; } - public string ToDelegateString(FunctionType function) + public string VisitDelegate(FunctionType function) { return string.Format("delegate {0} {{0}}({1})", function.ReturnType.Visit(this), - GetArgumentsString(function, hasNames: true)); + VisitParameters(function.Arguments, hasNames: true)); } } } \ No newline at end of file diff --git a/src/Generator/Types/ITypePrinter.cs b/src/Generator/Types/ITypePrinter.cs index 8fae8a9e..e95a9b1d 100644 --- a/src/Generator/Types/ITypePrinter.cs +++ b/src/Generator/Types/ITypePrinter.cs @@ -1,11 +1,14 @@ -namespace Cxxi.Types +using System.Collections.Generic; + +namespace Cxxi.Types { public interface ITypePrinter : ITypeVisitor { Library Library { get; set; } - string GetArgumentsString(FunctionType function, bool hasNames); - string GetArgumentString(Parameter arg, bool hasName = true); - string ToDelegateString(FunctionType function); + string VisitParameters(IEnumerable @params, bool hasNames); + string VisitParameter(Parameter param, bool hasName = true); + + string VisitDelegate(FunctionType function); } }