|
|
|
@ -7,38 +7,43 @@ namespace CppSharp.AST
@@ -7,38 +7,43 @@ namespace CppSharp.AST
|
|
|
|
|
{ |
|
|
|
|
public static class ClassExtensions |
|
|
|
|
{ |
|
|
|
|
public static IEnumerable<Method> FindOperator(this Class c, CXXOperatorKind kind) |
|
|
|
|
public static IEnumerable<Method> FindOperator(this Class @class, |
|
|
|
|
CXXOperatorKind kind) |
|
|
|
|
{ |
|
|
|
|
return c.Operators.Where(method => method.OperatorKind == kind); |
|
|
|
|
return @class.Operators.Where(method => method.OperatorKind == kind); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static IEnumerable<Method> FindMethodByOriginalName(this Class c, string name) |
|
|
|
|
public static IEnumerable<Method> FindMethodByOriginalName(this Class @class, |
|
|
|
|
string name) |
|
|
|
|
{ |
|
|
|
|
return c.Methods.Where(method => method.OriginalName == name); |
|
|
|
|
return @class.Methods.Where(method => method.OriginalName == name); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static IEnumerable<Variable> FindVariableByOriginalName(this Class c, string originalName) |
|
|
|
|
public static IEnumerable<Variable> FindVariableByOriginalName(this Class @class, |
|
|
|
|
string originalName) |
|
|
|
|
{ |
|
|
|
|
return c.Variables.Where(v => v.OriginalName == originalName); |
|
|
|
|
return @class.Variables.Where(v => v.OriginalName == originalName); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static IEnumerable<Function> GetFunctionOverloads(this Class c, Function function) |
|
|
|
|
public static IEnumerable<Function> GetFunctionOverloads(this Class @class, |
|
|
|
|
Function function) |
|
|
|
|
{ |
|
|
|
|
if (function.IsOperator) |
|
|
|
|
return c.FindOperator(function.OperatorKind); |
|
|
|
|
return c.Methods.Where(method => method.Name == function.Name); |
|
|
|
|
return @class.FindOperator(function.OperatorKind); |
|
|
|
|
return @class.Methods.Where(method => method.Name == function.Name); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static IEnumerable<T> FindHierarchy<T>(this Class c, Func<Class, IEnumerable<T>> func) |
|
|
|
|
public static IEnumerable<T> FindHierarchy<T>(this Class @class, |
|
|
|
|
Func<Class, IEnumerable<T>> func) |
|
|
|
|
where T : Declaration |
|
|
|
|
{ |
|
|
|
|
foreach (var elem in func(c)) |
|
|
|
|
foreach (var elem in func(@class)) |
|
|
|
|
yield return elem; |
|
|
|
|
|
|
|
|
|
foreach (var @base in c.Bases) |
|
|
|
|
foreach (var @base in @class.Bases) |
|
|
|
|
{ |
|
|
|
|
if (!@base.IsClass) continue; |
|
|
|
|
foreach(var elem in @base.Class.FindHierarchy<T>(func)) |
|
|
|
|
foreach(var elem in @base.Class.FindHierarchy(func)) |
|
|
|
|
yield return elem; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -54,25 +59,25 @@ namespace CppSharp.AST
@@ -54,25 +59,25 @@ namespace CppSharp.AST
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static Method GetBaseMethod(this Class c, Method @override, bool onlyPrimaryBase = false, bool getTopmost = false) |
|
|
|
|
public static Method GetBaseMethod(this Class @class, Method @override, |
|
|
|
|
bool onlyPrimaryBase = false, bool getTopmost = false) |
|
|
|
|
{ |
|
|
|
|
foreach (var @base in c.Bases) |
|
|
|
|
var parameterTypeComparer = new ParameterTypeComparer(); |
|
|
|
|
foreach (var @base in @class.Bases.Where( |
|
|
|
|
b => b.IsClass && b.Class.OriginalClass != @class && (!onlyPrimaryBase || !b.Class.IsInterface))) |
|
|
|
|
{ |
|
|
|
|
if (!@base.IsClass || @base.Class.OriginalClass == c || (onlyPrimaryBase && @base.Class.IsInterface)) |
|
|
|
|
continue; |
|
|
|
|
|
|
|
|
|
Method baseMethod; |
|
|
|
|
if (!getTopmost) |
|
|
|
|
{ |
|
|
|
|
baseMethod = (@base.Class.GetBaseMethod(@override, onlyPrimaryBase)); |
|
|
|
|
baseMethod = @base.Class.GetBaseMethod(@override, onlyPrimaryBase); |
|
|
|
|
if (baseMethod != null) |
|
|
|
|
return baseMethod; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
baseMethod = (from method in @base.Class.Methods |
|
|
|
|
where |
|
|
|
|
(method.OriginalName == @override.OriginalName && method.ReturnType == @override.ReturnType && |
|
|
|
|
method.Parameters.SequenceEqual(@override.Parameters, new ParameterTypeComparer())) || |
|
|
|
|
where (method.OriginalName == @override.OriginalName && |
|
|
|
|
method.ReturnType == @override.ReturnType && |
|
|
|
|
method.Parameters.SequenceEqual(@override.Parameters, parameterTypeComparer)) || |
|
|
|
|
(@override.IsDestructor && method.IsDestructor && method.IsVirtual) |
|
|
|
|
select method).FirstOrDefault(); |
|
|
|
|
if (baseMethod != null) |
|
|
|
@ -94,11 +99,14 @@ namespace CppSharp.AST
@@ -94,11 +99,14 @@ namespace CppSharp.AST
|
|
|
|
|
return baseMethod != null && !baseMethod.IsPure; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static Property GetBaseProperty(this Class c, Property @override, bool onlyFirstBase = false, bool getTopmost = false) |
|
|
|
|
public static Property GetBaseProperty(this Class @class, Property @override, |
|
|
|
|
bool onlyFirstBase = false, bool getTopmost = false) |
|
|
|
|
{ |
|
|
|
|
foreach (var @base in c.Bases) |
|
|
|
|
var parameterTypeComparer = new ParameterTypeComparer(); |
|
|
|
|
foreach (var @base in @class.Bases) |
|
|
|
|
{ |
|
|
|
|
if (!@base.IsClass || @base.Class.OriginalClass == c || (onlyFirstBase && @base.Class.IsInterface)) |
|
|
|
|
if (!@base.IsClass || @base.Class.OriginalClass == @class || |
|
|
|
|
(onlyFirstBase && @base.Class.IsInterface)) |
|
|
|
|
continue; |
|
|
|
|
|
|
|
|
|
Property baseProperty; |
|
|
|
@ -110,9 +118,8 @@ namespace CppSharp.AST
@@ -110,9 +118,8 @@ namespace CppSharp.AST
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
baseProperty = (from property in @base.Class.Properties |
|
|
|
|
where |
|
|
|
|
property.OriginalName == @override.OriginalName && |
|
|
|
|
property.Parameters.SequenceEqual(@override.Parameters, new ParameterTypeComparer()) |
|
|
|
|
where property.OriginalName == @override.OriginalName && |
|
|
|
|
property.Parameters.SequenceEqual(@override.Parameters, parameterTypeComparer) |
|
|
|
|
select property).FirstOrDefault(); |
|
|
|
|
if (baseProperty != null) |
|
|
|
|
return baseProperty; |
|
|
|
@ -133,13 +140,13 @@ namespace CppSharp.AST
@@ -133,13 +140,13 @@ namespace CppSharp.AST
|
|
|
|
|
return baseProperty != null && !baseProperty.IsPure; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static Property GetPropertyByName(this Class c, string propertyName) |
|
|
|
|
public static Property GetPropertyByName(this Class @class, string propertyName) |
|
|
|
|
{ |
|
|
|
|
Property property = c.Properties.FirstOrDefault(m => m.Name == propertyName); |
|
|
|
|
Property property = @class.Properties.FirstOrDefault(m => m.Name == propertyName); |
|
|
|
|
if (property != null) |
|
|
|
|
return property; |
|
|
|
|
|
|
|
|
|
foreach (var baseClassSpecifier in c.Bases.Where( |
|
|
|
|
foreach (var baseClassSpecifier in @class.Bases.Where( |
|
|
|
|
b => b.Type.IsClass() && b.Class.IsDeclared)) |
|
|
|
|
{ |
|
|
|
|
property = baseClassSpecifier.Class.GetPropertyByName(propertyName); |
|
|
|
@ -149,16 +156,16 @@ namespace CppSharp.AST
@@ -149,16 +156,16 @@ namespace CppSharp.AST
|
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static Property GetPropertyByConstituentMethod(this Class c, Method method) |
|
|
|
|
public static Property GetPropertyByConstituentMethod(this Class @class, Method method) |
|
|
|
|
{ |
|
|
|
|
var property = c.Properties.FirstOrDefault(p => p.GetMethod == method); |
|
|
|
|
var property = @class.Properties.FirstOrDefault(p => p.GetMethod == method); |
|
|
|
|
if (property != null) |
|
|
|
|
return property; |
|
|
|
|
property = c.Properties.FirstOrDefault(p => p.SetMethod == method); |
|
|
|
|
property = @class.Properties.FirstOrDefault(p => p.SetMethod == method); |
|
|
|
|
if (property != null) |
|
|
|
|
return property; |
|
|
|
|
|
|
|
|
|
foreach (BaseClassSpecifier @base in c.Bases.Where(b => b.Type.IsClass())) |
|
|
|
|
foreach (BaseClassSpecifier @base in @class.Bases.Where(b => b.Type.IsClass())) |
|
|
|
|
{ |
|
|
|
|
property = @base.Class.GetPropertyByConstituentMethod(method); |
|
|
|
|
if (property != null) |
|
|
|
@ -167,13 +174,13 @@ namespace CppSharp.AST
@@ -167,13 +174,13 @@ namespace CppSharp.AST
|
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static Method GetMethodByName(this Class c, string methodName) |
|
|
|
|
public static Method GetMethodByName(this Class @class, string methodName) |
|
|
|
|
{ |
|
|
|
|
var method = c.Methods.FirstOrDefault(m => m.Name == methodName); |
|
|
|
|
var method = @class.Methods.FirstOrDefault(m => m.Name == methodName); |
|
|
|
|
if (method != null) |
|
|
|
|
return method; |
|
|
|
|
|
|
|
|
|
foreach (BaseClassSpecifier @base in c.Bases.Where(b => b.Type.IsClass())) |
|
|
|
|
foreach (var @base in @class.Bases.Where(b => b.Type.IsClass())) |
|
|
|
|
{ |
|
|
|
|
method = @base.Class.GetMethodByName(methodName); |
|
|
|
|
if (method != null) |
|
|
|
@ -184,18 +191,18 @@ namespace CppSharp.AST
@@ -184,18 +191,18 @@ namespace CppSharp.AST
|
|
|
|
|
|
|
|
|
|
public static bool HasRefBase(this Class @class) |
|
|
|
|
{ |
|
|
|
|
Class baseClass = null; |
|
|
|
|
Class @base = null; |
|
|
|
|
|
|
|
|
|
if (@class.HasBaseClass) |
|
|
|
|
baseClass = @class.Bases[0].Class; |
|
|
|
|
@base = @class.Bases[0].Class; |
|
|
|
|
|
|
|
|
|
var hasRefBase = baseClass != null && baseClass.IsRefType |
|
|
|
|
&& baseClass.IsDeclared; |
|
|
|
|
var hasRefBase = @base != null && @base.IsRefType && @base.IsDeclared; |
|
|
|
|
|
|
|
|
|
return hasRefBase; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static bool ComputeClassPath(this Class current, Class target, IList<BaseClassSpecifier> path) |
|
|
|
|
private static bool ComputeClassPath(this Class current, Class target, |
|
|
|
|
IList<BaseClassSpecifier> path) |
|
|
|
|
{ |
|
|
|
|
if (target == current) |
|
|
|
|
return true; |
|
|
|
|