Browse Source

Reworked the way we generate constructors and destructors to always use the actual class name.

Fixes some problems that might happen with method declarations with names that don't match the their containing class.
pull/144/merge
triton 12 years ago
parent
commit
a5ebd151cf
  1. 6
      src/Generator/Generators/CLI/CLITextTemplate.cs
  2. 21
      src/Generator/Generators/CSharp/CSharpTextTemplate.cs

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

@ -86,6 +86,12 @@ namespace CppSharp.Generators.CLI
if (method.OperatorKind == CXXOperatorKind.Conversion) if (method.OperatorKind == CXXOperatorKind.Conversion)
return SafeIdentifier("operator " + method.ConversionType); return SafeIdentifier("operator " + method.ConversionType);
if (method.IsConstructor || method.IsDestructor)
{
var @class = (Class) method.Namespace;
return SafeIdentifier(@class.Name);
}
return SafeIdentifier(method.Name); return SafeIdentifier(method.Name);
} }

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

@ -418,7 +418,7 @@ namespace CppSharp.Generators.CSharp
PushBlock(CSharpBlockKind.Method); PushBlock(CSharpBlockKind.Method);
GenerateDeclarationCommon(method); GenerateDeclarationCommon(method);
var functionName = GetFunctionIdentifier(method); var functionName = GetMethodIdentifier(method);
Write("{0} {1}(", method.OriginalReturnType, functionName); Write("{0} {1}(", method.OriginalReturnType, functionName);
@ -1778,7 +1778,7 @@ namespace CppSharp.Generators.CSharp
if (Driver.Options.GenerateAbstractImpls && method.IsPure) if (Driver.Options.GenerateAbstractImpls && method.IsPure)
Write("abstract "); Write("abstract ");
var functionName = GetFunctionIdentifier(method); var functionName = GetMethodIdentifier(method);
if (method.IsConstructor || method.IsDestructor) if (method.IsConstructor || method.IsDestructor)
Write("{0}(", functionName); Write("{0}(", functionName);
@ -2330,17 +2330,20 @@ namespace CppSharp.Generators.CSharp
PopBlock(NewLineKind.BeforeNextBlock); PopBlock(NewLineKind.BeforeNextBlock);
} }
public static string GetFunctionIdentifier(Function function) public static string GetMethodIdentifier(Method method)
{ {
var identifier = SafeIdentifier(function.Name); if (method.IsConstructor || method.IsDestructor)
return method.Namespace.Name;
var method = function as Method; return GetFunctionIdentifier(method);
if (method == null || !method.IsOperator) }
return identifier;
identifier = Operators.GetOperatorIdentifier(method.OperatorKind); public static string GetFunctionIdentifier(Function function)
{
if (function.IsOperator)
return Operators.GetOperatorIdentifier(function.OperatorKind);
return identifier; return SafeIdentifier(function.Name);
} }
public static string GetFunctionNativeIdentifier(Function function) public static string GetFunctionNativeIdentifier(Function function)

Loading…
Cancel
Save