Skip to content

Commit

Permalink
Simplified the getting of base methods from only the primary bases.
Browse files Browse the repository at this point in the history
Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
  • Loading branch information
ddobrev committed Jul 27, 2017
1 parent 0c22c4d commit e0367c5
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 19 deletions.
22 changes: 5 additions & 17 deletions src/AST/ClassExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,33 +41,21 @@ public static Class GetNonIgnoredRootBase(this Class @class)
}
}

public static Method GetBaseMethod(this Class @class, Method @override,
bool onlyPrimaryBase = false, bool getTopmost = false)
public static Method GetBaseMethod(this Class @class, Method @override)
{
foreach (var @base in @class.Bases.Where(
b => b.IsClass && b.Class.OriginalClass != @class && (!onlyPrimaryBase || !b.Class.IsInterface)))
b => b.IsClass && b.Class.OriginalClass != @class && !b.Class.IsInterface))
{
var baseClass = @base.Class.OriginalClass ?? @base.Class;
Method baseMethod;
if (!getTopmost)
{
baseMethod = baseClass.GetBaseMethod(@override, onlyPrimaryBase);
if (baseMethod != null)
return baseMethod;
}
Method baseMethod = baseClass.GetBaseMethod(@override);
if (baseMethod != null)
return baseMethod;

baseMethod = (from method in baseClass.Methods
where @override.CanOverride(method)
select method).FirstOrDefault();
if (baseMethod != null)
return baseMethod;

if (getTopmost)
{
baseMethod = (baseClass.GetBaseMethod(@override, onlyPrimaryBase, true));
if (baseMethod != null)
return baseMethod;
}
}
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion src/AST/FunctionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public static bool IsGeneratedOverride(this Method method)
var @class = method.Namespace as Class;
Method rootBaseMethod;
return method.IsOverride &&
(rootBaseMethod = @class.GetBaseMethod(method, true)) != null &&
(rootBaseMethod = @class.GetBaseMethod(method)) != null &&
rootBaseMethod.IsGenerated && rootBaseMethod.IsVirtual;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Generator/Passes/MultipleInheritancePass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ private void ImplementInterfaceMethods(Class @class, Class @interface)
OriginalNamespace = @interface,
OriginalFunction = method.OriginalFunction
};
var rootBaseMethod = @class.GetBaseMethod(method, true);
var rootBaseMethod = @class.GetBaseMethod(method);
if (rootBaseMethod != null && rootBaseMethod.IsDeclared)
impl.ExplicitInterfaceImpl = @interface;
@class.Methods.Add(impl);
Expand Down

0 comments on commit e0367c5

Please sign in to comment.