Skip to content

Commit

Permalink
Fixed the renaming of overrides in a certain situation.
Browse files Browse the repository at this point in the history
Signed-off-by: Dimitar Dobrev <dpldobrev@yahoo.com>
  • Loading branch information
ddobrev committed Aug 4, 2015
1 parent cd3e729 commit c8da628
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 22 deletions.
5 changes: 4 additions & 1 deletion src/AST/ASTVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,10 @@ public virtual bool VisitProperty(Property property)
if (!VisitDeclaration(property))
return false;

return property.Type.Visit(this);
if (Options.VisitFunctionReturnType)
return property.Type.Visit(this);

return true;
}

public bool VisitFriend(Friend friend)
Expand Down
6 changes: 3 additions & 3 deletions src/AST/ClassExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public static Class GetNonIgnoredRootBase(this Class @class)
public static Method GetRootBaseMethod(this Class c, Method @override, bool onlyFirstBase = false)
{
return (from @base in c.Bases
where @base.IsClass && (!onlyFirstBase || !@base.Class.IsInterface)
where @base.IsClass && @base.Class.OriginalClass != c && (!onlyFirstBase || !@base.Class.IsInterface)
let baseMethod = (
from method in @base.Class.Methods
where
Expand All @@ -74,15 +74,15 @@ public static Method GetRootBaseMethod(this Class c, Method @override, bool only
public static Property GetRootBaseProperty(this Class c, Property @override, bool onlyFirstBase = false)
{
return (from @base in c.Bases
where (!onlyFirstBase || !@base.Class.IsInterface) && @base.IsClass
where @base.IsClass && @base.Class.OriginalClass != c && (!onlyFirstBase || !@base.Class.IsInterface)
let baseProperty = (
from property in @base.Class.Properties
where
property.OriginalName == @override.OriginalName &&
property.Parameters.SequenceEqual(@override.Parameters,
new ParameterTypeComparer())
select property).FirstOrDefault()
let rootBaseProperty = @base.Class.GetRootBaseProperty(@override) ?? baseProperty
let rootBaseProperty = @base.Class.GetRootBaseProperty(@override, onlyFirstBase) ?? baseProperty
where rootBaseProperty != null || onlyFirstBase
select rootBaseProperty).FirstOrDefault();
}
Expand Down
21 changes: 4 additions & 17 deletions src/Generator/Passes/RenamePass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,13 @@ public int GetHashCode(Parameter obj)

protected RenamePass()
{
Options.VisitFunctionReturnType = false;
Options.VisitFunctionParameters = false;
Options.VisitTemplateArguments = false;
}

protected RenamePass(RenameTargets targets)
: this()
{
Targets = targets;
}
Expand Down Expand Up @@ -85,23 +89,6 @@ public bool IsRenameableDecl(Declaration decl)
return false;
}

public override bool VisitClassDecl(Class @class)
{
if (@class.IsDynamic)
{
// HACK: entries in v-tables are not shared (as objects) with the virtual methods they represent;
// this is why this pass has to rename entries in the v-table as well;
// this should be fixed in the parser: it should reuse method objects
foreach (var method in VTables.GatherVTableMethodEntries(@class).Where(
e => e.Method != null && IsRenameableDecl(e.Method)).Select(e => e.Method))
{
Rename(method);
}
}

return base.VisitClassDecl(@class);
}

public override bool VisitDeclaration(Declaration decl)
{
if (AlreadyVisited(decl))
Expand Down
3 changes: 2 additions & 1 deletion tests/CSharpTemp/CSharpTemp.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public void TestUncompilableCode()
var isNoParams = foo.IsNoParams;
foo.SetNoParams();
}
using (var hasOverride = new HasOverrideOfHasPropertyWithDerivedType())
hasOverride.CauseRenamingError();
// TODO: remove when the bug in question is fixed
if (Type.GetType("Mono.Runtime") != null)
{
Expand Down Expand Up @@ -343,5 +345,4 @@ public void TestNullAttributedFunctionPtr()
foo.AttributedFunctionPtr = null;
}
}

}
16 changes: 16 additions & 0 deletions tests/CSharpTemp/CSharpTemp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -672,3 +672,19 @@ int TypeMappedWithOperator::operator |(int i)
{
return 0;
}

HasPropertyWithDerivedType::HasPropertyWithDerivedType()
{
}

void HasPropertyWithDerivedType::causeRenamingError()
{
}

HasOverrideOfHasPropertyWithDerivedType::HasOverrideOfHasPropertyWithDerivedType()
{
}

void HasOverrideOfHasPropertyWithDerivedType::causeRenamingError()
{
}
17 changes: 17 additions & 0 deletions tests/CSharpTemp/CSharpTemp.h
Original file line number Diff line number Diff line change
Expand Up @@ -600,3 +600,20 @@ class DLL_API TypeMappedWithOperator
TypeMappedWithOperator();
int operator |(int i);
};

class HasOverrideOfHasPropertyWithDerivedType;

class DLL_API HasPropertyWithDerivedType
{
public:
HasPropertyWithDerivedType();
HasOverrideOfHasPropertyWithDerivedType* hasPropertyWithDerivedTypeSubclass;
virtual void causeRenamingError();
};

class DLL_API HasOverrideOfHasPropertyWithDerivedType : public HasPropertyWithDerivedType
{
public:
HasOverrideOfHasPropertyWithDerivedType();
virtual void causeRenamingError();
};

0 comments on commit c8da628

Please sign in to comment.