Browse Source

Merge pull request #187 from ddobrev/master

Applied Helpers.SafeIdentifier in the name-cleaning pass in order to get correct names in type maps
pull/188/merge
João Matos 12 years ago
parent
commit
bcdd83de5d
  1. 1
      src/Generator/Driver.cs
  2. 26
      src/Generator/Generators/CLI/CLIHeadersTemplate.cs
  3. 8
      src/Generator/Generators/CLI/CLISourcesTemplate.cs
  4. 6
      src/Generator/Generators/CLI/CLITextTemplate.cs
  5. 19
      src/Generator/Generators/CSharp/CSharpMarshal.cs
  6. 80
      src/Generator/Generators/CSharp/CSharpTextTemplate.cs
  7. 2
      src/Generator/Generators/CSharp/CSharpTypePrinter.cs
  8. 15
      src/Generator/Passes/CleanInvalidDeclNamesPass.cs

1
src/Generator/Driver.cs

@ -248,7 +248,6 @@ namespace CppSharp @@ -248,7 +248,6 @@ namespace CppSharp
TranslationUnitPasses.AddPass(new CleanUnitPass(Options));
TranslationUnitPasses.AddPass(new SortDeclarationsPass());
TranslationUnitPasses.AddPass(new ResolveIncompleteDeclsPass());
TranslationUnitPasses.AddPass(new CleanInvalidDeclNamesPass());
TranslationUnitPasses.AddPass(new CheckIgnoredDeclsPass());
if (Options.IsCSharpGenerator)

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

@ -190,7 +190,7 @@ namespace CppSharp.Generators.CLI @@ -190,7 +190,7 @@ namespace CppSharp.Generators.CLI
PushBlock(CLIBlockKind.Namespace, @namespace);
WriteLine("namespace {0}", isTopLevel
? Options.OutputNamespace
: SafeIdentifier(@namespace.Name));
: @namespace.Name);
WriteStartBraceIndent();
}
@ -218,7 +218,7 @@ namespace CppSharp.Generators.CLI @@ -218,7 +218,7 @@ namespace CppSharp.Generators.CLI
{
PushBlock(CLIBlockKind.FunctionsClass);
WriteLine("public ref class {0}{1}", SafeIdentifier(Options.OutputNamespace),
WriteLine("public ref class {0}{1}", Options.OutputNamespace,
TranslationUnit.FileNameWithoutExtension);
WriteLine("{");
WriteLine("public:");
@ -348,7 +348,7 @@ namespace CppSharp.Generators.CLI @@ -348,7 +348,7 @@ namespace CppSharp.Generators.CLI
NewLine();
WriteLine("{0} {1}({2});", retType, SafeIdentifier(function.Name),
WriteLine("{0} {1}({2});", retType, function.Name,
GenerateParametersList(function.Parameters));
PopBlock(NewLineKind.BeforeNextBlock);
@ -363,8 +363,8 @@ namespace CppSharp.Generators.CLI @@ -363,8 +363,8 @@ namespace CppSharp.Generators.CLI
PushIndent();
// Output a default constructor that takes the native pointer.
WriteLine("{0}({1} native);", SafeIdentifier(@class.Name), nativeType);
WriteLine("{0}({1} native);", SafeIdentifier(@class.Name), "System::IntPtr");
WriteLine("{0}({1} native);", @class.Name, nativeType);
WriteLine("{0}({1} native);", @class.Name, "System::IntPtr");
foreach (var ctor in @class.Constructors)
{
@ -441,7 +441,7 @@ namespace CppSharp.Generators.CLI @@ -441,7 +441,7 @@ namespace CppSharp.Generators.CLI
if (@class.IsUnion)
WriteLine("[System::Runtime::InteropServices::FieldOffset({0})]",
field.Offset);
WriteLine("{0} {1};", field.Type, SafeIdentifier(field.Name));
WriteLine("{0} {1};", field.Type, field.Name);
PopBlock(NewLineKind.Never);
}
@ -558,7 +558,7 @@ namespace CppSharp.Generators.CLI @@ -558,7 +558,7 @@ namespace CppSharp.Generators.CLI
Write(@class.IsValueType ? "value struct " : "ref class ");
Write("{0}", SafeIdentifier(@class.Name));
Write("{0}", @class.Name);
if (@class.IsOpaque)
{
@ -652,7 +652,7 @@ namespace CppSharp.Generators.CLI @@ -652,7 +652,7 @@ namespace CppSharp.Generators.CLI
method.OperatorKind == CXXOperatorKind.Conversion)
Write("{0}(", GetMethodName(method));
else
Write("{0} {1}(", method.ReturnType, SafeIdentifier(method.Name));
Write("{0} {1}(", method.ReturnType, method.Name);
GenerateMethodParameters(method);
@ -682,7 +682,7 @@ namespace CppSharp.Generators.CLI @@ -682,7 +682,7 @@ namespace CppSharp.Generators.CLI
WriteLine("{0}{1};",
!insideClass ? "public " : "",
string.Format(TypePrinter.VisitDelegate(function),
SafeIdentifier(typedef.Name)));
typedef.Name));
PopBlock(NewLineKind.BeforeNextBlock);
return true;
@ -701,7 +701,7 @@ namespace CppSharp.Generators.CLI @@ -701,7 +701,7 @@ namespace CppSharp.Generators.CLI
GenerateDeclarationCommon(function);
var retType = function.ReturnType.ToString();
Write("static {0} {1}(", retType, SafeIdentifier(function.Name));
Write("static {0} {1}(", retType, function.Name);
Write(GenerateParametersList(function.Parameters));
@ -727,7 +727,7 @@ namespace CppSharp.Generators.CLI @@ -727,7 +727,7 @@ namespace CppSharp.Generators.CLI
if (@enum.Namespace is Namespace)
Write("public ");
Write("enum struct {0}", SafeIdentifier(@enum.Name));
Write("enum struct {0}", @enum.Name);
var typeName = TypePrinter.VisitPrimitiveType(@enum.BuiltinType.Type,
new TypeQualifiers());
@ -746,10 +746,10 @@ namespace CppSharp.Generators.CLI @@ -746,10 +746,10 @@ namespace CppSharp.Generators.CLI
GenerateInlineSummary(item.Comment);
if (item.ExplicitValue)
Write(String.Format("{0} = {1}", SafeIdentifier(item.Name),
Write(String.Format("{0} = {1}", item.Name,
@enum.GetItemValueAsString(item)));
else
Write(String.Format("{0}", SafeIdentifier(item.Name)));
Write(String.Format("{0}", item.Name));
if (item != @enum.Items.Last())
WriteLine(",");

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

@ -278,7 +278,7 @@ namespace CppSharp.Generators.CLI @@ -278,7 +278,7 @@ namespace CppSharp.Generators.CLI
WriteLine("generic<{0}>", typeNames);
WriteLine("{0} {1}::{2}({3})", retType,
QualifiedIdentifier(function.Namespace), SafeIdentifier(function.Name),
QualifiedIdentifier(function.Namespace), function.Name,
GenerateParametersList(function.Parameters));
WriteStartBraceIndent();
@ -553,7 +553,7 @@ namespace CppSharp.Generators.CLI @@ -553,7 +553,7 @@ namespace CppSharp.Generators.CLI
private void GenerateClassConstructor(Class @class, bool isIntPtr)
{
Write("{0}::{1}(", QualifiedIdentifier(@class), SafeIdentifier(@class.Name));
Write("{0}::{1}(", QualifiedIdentifier(@class), @class.Name);
var nativeType = string.Format("::{0}*", @class.QualifiedOriginalName);
WriteLine("{0} native)", isIntPtr ? "System::IntPtr" : nativeType);
@ -661,7 +661,7 @@ namespace CppSharp.Generators.CLI @@ -661,7 +661,7 @@ namespace CppSharp.Generators.CLI
Write("{0}::{1}(", QualifiedIdentifier(@class), GetMethodName(method));
else
Write("{0} {1}::{2}(", method.ReturnType, QualifiedIdentifier(@class),
SafeIdentifier(method.Name));
method.Name);
GenerateMethodParameters(method);
@ -784,7 +784,7 @@ namespace CppSharp.Generators.CLI @@ -784,7 +784,7 @@ namespace CppSharp.Generators.CLI
Options.OutputNamespace, TranslationUnit.FileNameWithoutExtension);
Write("{0} {1}::{2}(", function.ReturnType, classSig,
SafeIdentifier(function.Name));
function.Name);
for (var i = 0; i < function.Parameters.Count; ++i)
{

6
src/Generator/Generators/CLI/CLITextTemplate.cs

@ -89,15 +89,15 @@ namespace CppSharp.Generators.CLI @@ -89,15 +89,15 @@ namespace CppSharp.Generators.CLI
public string GetMethodName(Method method)
{
if (method.OperatorKind == CXXOperatorKind.Conversion)
return SafeIdentifier("operator " + method.ConversionType);
return "operator " + method.ConversionType;
if (method.IsConstructor || method.IsDestructor)
{
var @class = (Class) method.Namespace;
return SafeIdentifier(@class.Name);
return @class.Name;
}
return SafeIdentifier(method.Name);
return method.Name;
}
public void GenerateDeclarationCommon(Declaration decl)

19
src/Generator/Generators/CSharp/CSharpMarshal.cs

@ -418,10 +418,8 @@ namespace CppSharp.Generators.CSharp @@ -418,10 +418,8 @@ namespace CppSharp.Generators.CSharp
pointee.IsPrimitiveType(PrimitiveType.WideChar)) &&
pointer.QualifiedPointee.Qualifiers.IsConst)
{
Context.Return.Write(MarshalStringToUnmanaged(
Helpers.SafeIdentifier(Context.Parameter.Name)));
CSharpContext.Cleanup.WriteLine("Marshal.FreeHGlobal({0});",
Helpers.SafeIdentifier(Context.ArgName));
Context.Return.Write(MarshalStringToUnmanaged(Context.Parameter.Name));
CSharpContext.Cleanup.WriteLine("Marshal.FreeHGlobal({0});", Context.ArgName);
return true;
}
@ -443,7 +441,7 @@ namespace CppSharp.Generators.CSharp @@ -443,7 +441,7 @@ namespace CppSharp.Generators.CSharp
{
Context.SupportBefore.WriteLine("var {0} = {1}.ToInternal();",
Generator.GeneratedIdentifier(Context.ArgName),
Helpers.SafeIdentifier(Context.Parameter.Name));
Context.Parameter.Name);
}
Context.Return.Write("new global::System.IntPtr(&{0})",
@ -464,8 +462,7 @@ namespace CppSharp.Generators.CSharp @@ -464,8 +462,7 @@ namespace CppSharp.Generators.CSharp
{
var typeName = Type.TypePrinterDelegate(pointee);
Context.SupportBefore.WriteLine("{0} _{1};", typeName,
Helpers.SafeIdentifier(param.Name));
Context.SupportBefore.WriteLine("{0} _{1};", typeName, param.Name);
Context.Return.Write("&_{0}", param.Name);
}
@ -549,7 +546,7 @@ namespace CppSharp.Generators.CSharp @@ -549,7 +546,7 @@ namespace CppSharp.Generators.CSharp
if (@class.IsValueType)
{
MarshalValueClass(@class);
MarshalValueClass();
}
else
{
@ -570,7 +567,7 @@ namespace CppSharp.Generators.CSharp @@ -570,7 +567,7 @@ namespace CppSharp.Generators.CSharp
return;
}
string param = Helpers.SafeIdentifier(Context.Parameter.Name);
string param = Context.Parameter.Name;
Type type = Context.Parameter.Type.Desugar();
if (type.IsAddress())
{
@ -590,9 +587,9 @@ namespace CppSharp.Generators.CSharp @@ -590,9 +587,9 @@ namespace CppSharp.Generators.CSharp
qualifiedIdentifier, Helpers.InstanceIdentifier);
}
private void MarshalValueClass(Class @class)
private void MarshalValueClass()
{
Context.Return.Write("{0}.ToInternal()", Helpers.SafeIdentifier(Context.Parameter.Name));
Context.Return.Write("{0}.ToInternal()", Context.Parameter.Name);
}
public override bool VisitFieldDecl(Field field)

80
src/Generator/Generators/CSharp/CSharpTextTemplate.cs

@ -37,8 +37,9 @@ namespace CppSharp.Generators.CSharp @@ -37,8 +37,9 @@ namespace CppSharp.Generators.CSharp
public static string SafeIdentifier(string id)
{
id = new string(id.Select(c => char.IsLetterOrDigit(c) ? c : '_').ToArray());
return Keywords.Contains(id) ? "@" + id : id;
if (id.All(char.IsLetterOrDigit))
return Keywords.Contains(id) ? "@" + id : id;
return new string(id.Select(c => char.IsLetterOrDigit(c) ? c : '_').ToArray());
}
public static string ToCSharpCallConv(CallingConvention convention)
@ -146,11 +147,6 @@ namespace CppSharp.Generators.CSharp @@ -146,11 +147,6 @@ namespace CppSharp.Generators.CSharp
return Generator.GeneratedIdentifier(id);
}
public static string SafeIdentifier(string id)
{
return Helpers.SafeIdentifier(id);
}
#endregion
public override void Process()
@ -170,7 +166,7 @@ namespace CppSharp.Generators.CSharp @@ -170,7 +166,7 @@ namespace CppSharp.Generators.CSharp
if (Options.GenerateLibraryNamespace)
{
PushBlock(CSharpBlockKind.Namespace);
WriteLine("namespace {0}", SafeIdentifier(Driver.Options.OutputNamespace));
WriteLine("namespace {0}", Driver.Options.OutputNamespace);
WriteStartBraceIndent();
}
@ -242,7 +238,7 @@ namespace CppSharp.Generators.CSharp @@ -242,7 +238,7 @@ namespace CppSharp.Generators.CSharp
if (context.HasFunctions)
{
PushBlock(CSharpBlockKind.Functions);
WriteLine("public unsafe partial class {0}{1}", SafeIdentifier(Options.OutputNamespace),
WriteLine("public unsafe partial class {0}{1}", Options.OutputNamespace,
TranslationUnit.FileNameWithoutExtension);
WriteStartBraceIndent();
@ -497,7 +493,7 @@ namespace CppSharp.Generators.CSharp @@ -497,7 +493,7 @@ namespace CppSharp.Generators.CSharp
GenerateClassInternalHead(@class);
WriteStartBraceIndent();
var typePrinter = TypePrinter as CSharpTypePrinter;
var typePrinter = TypePrinter;
typePrinter.PushContext(CSharpTypePrinterContextKind.Native);
GenerateClassInternalsFields(@class);
@ -593,9 +589,7 @@ namespace CppSharp.Generators.CSharp @@ -593,9 +589,7 @@ namespace CppSharp.Generators.CSharp
continue;
var typeName = param.CSharpType(TypePrinter);
string paramName = param.IsSynthetized ?
GeneratedIdentifier(param.Name) : SafeIdentifier(param.Name);
@params.Add(string.Format("{0} {1}", typeName, paramName));
@params.Add(string.Format("{0} {1}", typeName, param.Name));
}
if (method != null && method.IsConstructor)
@ -636,7 +630,8 @@ namespace CppSharp.Generators.CSharp @@ -636,7 +630,8 @@ namespace CppSharp.Generators.CSharp
if (property.Ignore || property.Field == null) continue;
var nativeField = string.Format("{0}->{1}",
Generator.GeneratedIdentifier("ptr"), property.Field.OriginalName);
Generator.GeneratedIdentifier("ptr"),
Helpers.SafeIdentifier(property.Field.OriginalName));
var ctx = new CSharpMarshalContext(Driver)
{
@ -693,7 +688,8 @@ namespace CppSharp.Generators.CSharp @@ -693,7 +688,8 @@ namespace CppSharp.Generators.CSharp
private void GenerateStructInternalMarshalingProperty(Property property, string marshalVar)
{
var nativeField = string.Format("{0}->{1}",
Generator.GeneratedIdentifier("ptr"), property.Field.OriginalName);
Generator.GeneratedIdentifier("ptr"),
Helpers.SafeIdentifier(property.Field.OriginalName));
var marshalCtx = new CSharpMarshalContext(Driver)
{
ArgName = property.Name,
@ -721,7 +717,7 @@ namespace CppSharp.Generators.CSharp @@ -721,7 +717,7 @@ namespace CppSharp.Generators.CSharp
if (marshal.Context.Return.StringBuilder.Length > 0)
{
WriteLine("{0}.{1} = {2};", marshalVar,
property.OriginalName, marshal.Context.Return);
Helpers.SafeIdentifier(property.OriginalName), marshal.Context.Return);
}
if (isRef)
@ -761,7 +757,7 @@ namespace CppSharp.Generators.CSharp @@ -761,7 +757,7 @@ namespace CppSharp.Generators.CSharp
Write("partial ");
Write(@class.IsInterface ? "interface " : (@class.IsValueType ? "struct " : "class "));
Write("{0}", SafeIdentifier(@class.Name));
Write("{0}", @class.Name);
var bases = new List<string>();
@ -809,7 +805,7 @@ namespace CppSharp.Generators.CSharp @@ -809,7 +805,7 @@ namespace CppSharp.Generators.CSharp
private void GenerateClassInternalsField(Field field)
{
var safeIdentifier = SafeIdentifier(field.OriginalName);
var safeIdentifier = Helpers.SafeIdentifier(field.OriginalName);
PushBlock(CSharpBlockKind.Field);
@ -844,7 +840,7 @@ namespace CppSharp.Generators.CSharp @@ -844,7 +840,7 @@ namespace CppSharp.Generators.CSharp
WriteLine("[FieldOffset({0})]", field.Offset);
WriteLine("{0} {1} {2};", @public ? "public" : "private",
field.Type, SafeIdentifier(field.Name));
field.Type, field.Name);
PopBlock(NewLineKind.BeforeNextBlock);
}
@ -961,7 +957,8 @@ namespace CppSharp.Generators.CSharp @@ -961,7 +957,8 @@ namespace CppSharp.Generators.CSharp
var marshal = new CSharpMarshalManagedToNativePrinter(ctx);
ctx.ReturnVarName = string.Format("{0}->{1}",
Generator.GeneratedIdentifier("ptr"), Helpers.SafeIdentifier(field.OriginalName));
Generator.GeneratedIdentifier("ptr"),
Helpers.SafeIdentifier(field.OriginalName));
param.Visit(marshal);
if (!string.IsNullOrWhiteSpace(marshal.Context.SupportBefore))
@ -1282,14 +1279,14 @@ namespace CppSharp.Generators.CSharp @@ -1282,14 +1279,14 @@ namespace CppSharp.Generators.CSharp
private string GetPropertyName(Property prop)
{
return prop.Parameters.Count == 0 ? SafeIdentifier(prop.Name)
return prop.Parameters.Count == 0 ? prop.Name
: string.Format("this[{0}]", FormatMethodParameters(prop.Parameters));
}
private void GenerateVariable(Class @class, Type type, Variable variable)
{
PushBlock(CSharpBlockKind.Variable);
WriteLine("public static {0} {1}", type, SafeIdentifier(variable.Name));
WriteLine("public static {0} {1}", type, variable.Name);
WriteStartBraceIndent();
GeneratePropertyGetter(variable, @class);
@ -1535,7 +1532,7 @@ namespace CppSharp.Generators.CSharp @@ -1535,7 +1532,7 @@ namespace CppSharp.Generators.CSharp
var ctx = new CSharpMarshalContext(Driver)
{
ReturnType = param.QualifiedType,
ReturnVarName = SafeIdentifier(param.Name)
ReturnVarName = param.Name
};
var marshal = new CSharpMarshalNativeToManagedPrinter(ctx) { VarSuffix = i };
@ -1556,7 +1553,7 @@ namespace CppSharp.Generators.CSharp @@ -1556,7 +1553,7 @@ namespace CppSharp.Generators.CSharp
Method m = ((Class) method.Namespace).GetMethodByName(method.Name);
if (m.IsGenerated)
{
WriteLine("target.{0}({1});", SafeIdentifier(method.Name), string.Join(", ", marshals));
WriteLine("target.{0}({1});", method.Name, string.Join(", ", marshals));
}
else
{
@ -1597,12 +1594,12 @@ namespace CppSharp.Generators.CSharp @@ -1597,12 +1594,12 @@ namespace CppSharp.Generators.CSharp
{
property = ((Class) method.Namespace).Properties.First(
p => p.SetMethod == method);
WriteLine("target.{0} = {1};", SafeIdentifier(property.Name),
WriteLine("target.{0} = {1};", property.Name,
string.Join(", ", marshals));
}
else
{
WriteLine("target.{0};", SafeIdentifier(property.Name));
WriteLine("target.{0};", property.Name);
}
}
@ -1707,7 +1704,7 @@ namespace CppSharp.Generators.CSharp @@ -1707,7 +1704,7 @@ namespace CppSharp.Generators.CSharp
NewLine();
WriteLine("{0} {1};", @event.Type, delegateInstance);
WriteLine("public event {0} {1}", @event.Type, Helpers.SafeIdentifier(@event.Name));
WriteLine("public event {0} {1}", @event.Type, @event.Name);
WriteStartBraceIndent();
GenerateEventAdd(@event);
@ -1773,7 +1770,7 @@ namespace CppSharp.Generators.CSharp @@ -1773,7 +1770,7 @@ namespace CppSharp.Generators.CSharp
{
var ctx = new CSharpMarshalContext(Driver)
{
ReturnVarName = Helpers.SafeIdentifier(param.Name),
ReturnVarName = param.Name,
ReturnType = param.QualifiedType
};
@ -1884,7 +1881,7 @@ namespace CppSharp.Generators.CSharp @@ -1884,7 +1881,7 @@ namespace CppSharp.Generators.CSharp
{
PushBlock(CSharpBlockKind.Method);
string className = @class.Name;
string safeIdentifier = SafeIdentifier(className);
string safeIdentifier = className;
if (@class.Access == AccessSpecifier.Private && className.EndsWith("Internal"))
{
className = className.Substring(0,
@ -2230,7 +2227,7 @@ namespace CppSharp.Generators.CSharp @@ -2230,7 +2227,7 @@ namespace CppSharp.Generators.CSharp
&& !string.IsNullOrWhiteSpace(param.Context.ArgumentPrefix))
name += param.Context.ArgumentPrefix;
name += Helpers.SafeIdentifier(param.Name);
name += param.Name;
names.Add(name);
}
@ -2454,7 +2451,7 @@ namespace CppSharp.Generators.CSharp @@ -2454,7 +2451,7 @@ namespace CppSharp.Generators.CSharp
if (!string.IsNullOrWhiteSpace(marshal.Context.SupportBefore))
Write(marshal.Context.SupportBefore);
WriteLine("var {0} = {1};", SafeIdentifier(argName), marshal.Context.Return);
WriteLine("var {0} = {1};", argName, marshal.Context.Return);
return paramMarshal;
}
@ -2479,7 +2476,7 @@ namespace CppSharp.Generators.CSharp @@ -2479,7 +2476,7 @@ namespace CppSharp.Generators.CSharp
where param.Kind != ParameterKind.IndirectReturnType
let typeName = param.CSharpType(TypePrinter)
select string.Format("{0}{1} {2}", GetParameterUsage(param.Usage),
typeName, SafeIdentifier(param.Name)));
typeName, param.Name));
}
#endregion
@ -2498,7 +2495,7 @@ namespace CppSharp.Generators.CSharp @@ -2498,7 +2495,7 @@ namespace CppSharp.Generators.CSharp
|| typedef.Type.IsPointerTo(out tag))
{
PushBlock(CSharpBlockKind.Typedef);
WriteLine("public class " + SafeIdentifier(typedef.Name) + @" { }");
WriteLine("public class " + typedef.Name + @" { }");
PopBlock(NewLineKind.BeforeNextBlock);
}
else if (typedef.Type.IsPointerTo(out functionType))
@ -2510,7 +2507,7 @@ namespace CppSharp.Generators.CSharp @@ -2510,7 +2507,7 @@ namespace CppSharp.Generators.CSharp
WriteLine("{0}unsafe {1};",
Helpers.GetAccess(typedef.Access),
string.Format(TypePrinter.VisitDelegate(functionType).Type,
SafeIdentifier(typedef.Name)));
typedef.Name));
TypePrinter.PopContext();
PopBlock(NewLineKind.BeforeNextBlock);
}
@ -2528,7 +2525,7 @@ namespace CppSharp.Generators.CSharp @@ -2528,7 +2525,7 @@ namespace CppSharp.Generators.CSharp
if (@enum.IsFlags)
WriteLine("[Flags]");
Write("public enum {0}", SafeIdentifier(@enum.Name));
Write("public enum {0}", @enum.Name);
var typeName = TypePrinter.VisitPrimitiveType(@enum.BuiltinType.Type,
new TypeQualifiers());
@ -2546,8 +2543,8 @@ namespace CppSharp.Generators.CSharp @@ -2546,8 +2543,8 @@ namespace CppSharp.Generators.CSharp
var value = @enum.GetItemValueAsString(item);
Write(item.ExplicitValue
? string.Format("{0} = {1}", SafeIdentifier(item.Name), value)
: string.Format("{0}", SafeIdentifier(item.Name)));
? string.Format("{0} = {1}", item.Name, value)
: string.Format("{0}", item.Name));
if (i < @enum.Items.Count - 1)
Write(",");
@ -2572,7 +2569,7 @@ namespace CppSharp.Generators.CSharp @@ -2572,7 +2569,7 @@ namespace CppSharp.Generators.CSharp
if (function.IsOperator)
return Operators.GetOperatorIdentifier(function.OperatorKind);
return SafeIdentifier(function.Name);
return function.Name;
}
public static string GetFunctionNativeIdentifier(Function function)
@ -2592,7 +2589,7 @@ namespace CppSharp.Generators.CSharp @@ -2592,7 +2589,7 @@ namespace CppSharp.Generators.CSharp
functionName = GetMethodIdentifier(method);
}
var identifier = SafeIdentifier(functionName);
var identifier = functionName;
if (function.IsOperator)
identifier = "Operator" + function.OperatorKind;
@ -2672,10 +2669,7 @@ namespace CppSharp.Generators.CSharp @@ -2672,10 +2669,7 @@ namespace CppSharp.Generators.CSharp
var typeName = param.CSharpType(typePrinter);
var paramName = param.IsSynthetized ?
GeneratedIdentifier(param.Name) : SafeIdentifier(param.Name);
@params.Add(string.Format("{0} {1}", typeName, paramName));
@params.Add(string.Format("{0} {1}", typeName, param.Name));
}
if (method != null && method.IsConstructor)

2
src/Generator/Generators/CSharp/CSharpTypePrinter.cs

@ -508,7 +508,7 @@ namespace CppSharp.Generators.CSharp @@ -508,7 +508,7 @@ namespace CppSharp.Generators.CSharp
public CSharpTypePrinterResult VisitParameter(Parameter arg, bool hasName)
{
var type = arg.Type.Visit(this, arg.QualifiedType.Qualifiers);
var name = Helpers.SafeIdentifier(arg.Name);
var name = arg.Name;
if (hasName && !string.IsNullOrEmpty(name))
return string.Format("{0} {1}", type, name);

15
src/Generator/Passes/CleanInvalidDeclNamesPass.cs

@ -1,6 +1,8 @@ @@ -1,6 +1,8 @@
using System;
using System.Linq;
using CppSharp.AST;
using CppSharp.Generators.CLI;
using CppSharp.Generators.CSharp;
namespace CppSharp.Passes
{
@ -14,13 +16,13 @@ namespace CppSharp.Passes @@ -14,13 +16,13 @@ namespace CppSharp.Passes
if (string.IsNullOrWhiteSpace(name))
return string.Format("_{0}", uniqueName++);
var firstChar = name.FirstOrDefault();
// Clean up the item name if the first digit is not a valid name.
if (char.IsNumber(firstChar))
if (char.IsNumber(name[0]))
return '_' + name;
return name;
if (Driver.Options.IsCLIGenerator)
return CLITextTemplate.SafeIdentifier(name);
return Helpers.SafeIdentifier(name);
}
public override bool VisitDeclaration(Declaration decl)
@ -33,11 +35,14 @@ namespace CppSharp.Passes @@ -33,11 +35,14 @@ namespace CppSharp.Passes
// types with empty names are assumed to be private
if (decl is Class && string.IsNullOrWhiteSpace(decl.Name))
{
decl.Name = "_";
decl.ExplicityIgnored = true;
return false;
}
decl.Name = CheckName(decl.Name);
Function function = decl as Function;
if (function == null || !function.IsOperator)
decl.Name = CheckName(decl.Name);
StringHelpers.CleanupText(ref decl.DebugText);
return base.VisitDeclaration(decl);

Loading…
Cancel
Save