Browse Source

Fixed the renaming of overrides in a certain situation.

Signed-off-by: Dimitar Dobrev <dpldobrev@yahoo.com>
pull/503/merge
Dimitar Dobrev 10 years ago
parent
commit
c8da628782
  1. 5
      src/AST/ASTVisitor.cs
  2. 6
      src/AST/ClassExtensions.cs
  3. 21
      src/Generator/Passes/RenamePass.cs
  4. 3
      tests/CSharpTemp/CSharpTemp.Tests.cs
  5. 16
      tests/CSharpTemp/CSharpTemp.cpp
  6. 17
      tests/CSharpTemp/CSharpTemp.h

5
src/AST/ASTVisitor.cs

@ -291,7 +291,10 @@ namespace CppSharp.AST
if (!VisitDeclaration(property)) if (!VisitDeclaration(property))
return false; return false;
return property.Type.Visit(this); if (Options.VisitFunctionReturnType)
return property.Type.Visit(this);
return true;
} }
public bool VisitFriend(Friend friend) public bool VisitFriend(Friend friend)

6
src/AST/ClassExtensions.cs

@ -57,7 +57,7 @@ namespace CppSharp.AST
public static Method GetRootBaseMethod(this Class c, Method @override, bool onlyFirstBase = false) public static Method GetRootBaseMethod(this Class c, Method @override, bool onlyFirstBase = false)
{ {
return (from @base in c.Bases 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 = ( let baseMethod = (
from method in @base.Class.Methods from method in @base.Class.Methods
where where
@ -74,7 +74,7 @@ namespace CppSharp.AST
public static Property GetRootBaseProperty(this Class c, Property @override, bool onlyFirstBase = false) public static Property GetRootBaseProperty(this Class c, Property @override, bool onlyFirstBase = false)
{ {
return (from @base in c.Bases 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 = ( let baseProperty = (
from property in @base.Class.Properties from property in @base.Class.Properties
where where
@ -82,7 +82,7 @@ namespace CppSharp.AST
property.Parameters.SequenceEqual(@override.Parameters, property.Parameters.SequenceEqual(@override.Parameters,
new ParameterTypeComparer()) new ParameterTypeComparer())
select property).FirstOrDefault() select property).FirstOrDefault()
let rootBaseProperty = @base.Class.GetRootBaseProperty(@override) ?? baseProperty let rootBaseProperty = @base.Class.GetRootBaseProperty(@override, onlyFirstBase) ?? baseProperty
where rootBaseProperty != null || onlyFirstBase where rootBaseProperty != null || onlyFirstBase
select rootBaseProperty).FirstOrDefault(); select rootBaseProperty).FirstOrDefault();
} }

21
src/Generator/Passes/RenamePass.cs

@ -30,9 +30,13 @@ namespace CppSharp.Passes
protected RenamePass() protected RenamePass()
{ {
Options.VisitFunctionReturnType = false;
Options.VisitFunctionParameters = false;
Options.VisitTemplateArguments = false;
} }
protected RenamePass(RenameTargets targets) protected RenamePass(RenameTargets targets)
: this()
{ {
Targets = targets; Targets = targets;
} }
@ -85,23 +89,6 @@ namespace CppSharp.Passes
return false; 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) public override bool VisitDeclaration(Declaration decl)
{ {
if (AlreadyVisited(decl)) if (AlreadyVisited(decl))

3
tests/CSharpTemp/CSharpTemp.Tests.cs

@ -27,6 +27,8 @@ public class CSharpTempTests : GeneratorTestFixture
var isNoParams = foo.IsNoParams; var isNoParams = foo.IsNoParams;
foo.SetNoParams(); foo.SetNoParams();
} }
using (var hasOverride = new HasOverrideOfHasPropertyWithDerivedType())
hasOverride.CauseRenamingError();
// TODO: remove when the bug in question is fixed // TODO: remove when the bug in question is fixed
if (Type.GetType("Mono.Runtime") != null) if (Type.GetType("Mono.Runtime") != null)
{ {
@ -343,5 +345,4 @@ public class CSharpTempTests : GeneratorTestFixture
foo.AttributedFunctionPtr = null; foo.AttributedFunctionPtr = null;
} }
} }
} }

16
tests/CSharpTemp/CSharpTemp.cpp

@ -672,3 +672,19 @@ int TypeMappedWithOperator::operator |(int i)
{ {
return 0; return 0;
} }
HasPropertyWithDerivedType::HasPropertyWithDerivedType()
{
}
void HasPropertyWithDerivedType::causeRenamingError()
{
}
HasOverrideOfHasPropertyWithDerivedType::HasOverrideOfHasPropertyWithDerivedType()
{
}
void HasOverrideOfHasPropertyWithDerivedType::causeRenamingError()
{
}

17
tests/CSharpTemp/CSharpTemp.h

@ -600,3 +600,20 @@ public:
TypeMappedWithOperator(); TypeMappedWithOperator();
int operator |(int i); 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();
};

Loading…
Cancel
Save