Browse Source

Removed redundant indexation from internal functions in C#.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/888/head
Dimitar Dobrev 8 years ago
parent
commit
351bae6bb6
  1. 2
      src/AST/FunctionExtensions.cs
  2. 43
      src/Generator/Generators/CSharp/CSharpSources.cs

2
src/AST/FunctionExtensions.cs

@ -6,7 +6,7 @@ namespace CppSharp.AST @@ -6,7 +6,7 @@ namespace CppSharp.AST
{
public static class FunctionExtensions
{
public static IEnumerable<Parameter> GatherInternalParams(this Function function,
public static IList<Parameter> GatherInternalParams(this Function function,
bool isItaniumLikeAbi, bool universalDelegate = false)
{
var @params = new List<Parameter>();

43
src/Generator/Generators/CSharp/CSharpSources.cs

@ -3008,8 +3008,8 @@ namespace CppSharp.Generators.CSharp @@ -3008,8 +3008,8 @@ namespace CppSharp.Generators.CSharp
return function.Name;
}
public static string GetFunctionNativeIdentifier(Function function,
bool ignoreSpecialization = false)
public string GetFunctionNativeIdentifier(Function function,
bool isForDelegate = false)
{
var identifier = new StringBuilder();
@ -3036,17 +3036,26 @@ namespace CppSharp.Generators.CSharp @@ -3036,17 +3036,26 @@ namespace CppSharp.Generators.CSharp
}
var specialization = function.Namespace as ClassTemplateSpecialization;
if (specialization != null && !ignoreSpecialization)
if (specialization != null && !isForDelegate)
identifier.Append(Helpers.GetSuffixFor(specialization));
var internalParams = function.GatherInternalParams(
Context.ParserOptions.IsItaniumLikeAbi);
var overloads = function.Namespace.GetOverloads(function)
.Where(f => f.IsGenerated || f.OperatorKind == CXXOperatorKind.Subscript).ToList();
var index = overloads.IndexOf(function);
.Where(f => !f.Ignore && (isForDelegate || internalParams.SequenceEqual(
f.GatherInternalParams(Context.ParserOptions.IsItaniumLikeAbi),
new MarshallingParamComparer()))).ToList();
var index = -1;
if (overloads.Count > 1)
index = overloads.IndexOf(function);
if (index >= 0)
{
identifier.Append('_');
identifier.Append(index.ToString(CultureInfo.InvariantCulture));
if (index > 0)
{
identifier.Append('_');
identifier.Append(index.ToString(CultureInfo.InvariantCulture));
}
}
else if (function.Index.HasValue)
{
@ -3133,6 +3142,26 @@ namespace CppSharp.Generators.CSharp @@ -3133,6 +3142,26 @@ namespace CppSharp.Generators.CSharp
return libName;
}
private class MarshallingParamComparer : IEqualityComparer<Parameter>
{
public bool Equals(Parameter x, Parameter y) =>
IsIntPtr(x) == IsIntPtr(y) || x.Type.Equals(y.Type);
private static bool IsIntPtr(Parameter p)
{
var type = p.Type.Desugar();
return p.Kind == ParameterKind.IndirectReturnType
|| (type.IsAddress()
&& (!type.GetPointee().Desugar().IsPrimitiveType()
|| type.GetPointee().Desugar().IsPrimitiveType(PrimitiveType.Void)));
}
public int GetHashCode(Parameter obj)
{
return obj.Type.Desugar().GetHashCode();
}
}
}
internal class SymbolNotFoundException : Exception

Loading…
Cancel
Save