Permalink
Browse files

Removed redundant indexation from internal functions in C#.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
  • Loading branch information...
ddobrev committed Jul 15, 2017
1 parent f646647 commit 351bae6bb67abae032ff8a434c0b73665b616b15
Showing with 37 additions and 8 deletions.
  1. +1 −1 src/AST/FunctionExtensions.cs
  2. +36 −7 src/Generator/Generators/CSharp/CSharpSources.cs
@@ -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>();
@@ -3008,8 +3008,8 @@ public static string GetFunctionIdentifier(Function function)
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 @@ public static string GetFunctionIdentifier(Function function)
}
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 @@ private string GetLibraryOf(Declaration declaration)
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

0 comments on commit 351bae6

Please sign in to comment.