C++: Fix some Matcher::match() functions

...before using Matcher instead of {Type,Name}::isEqualTo().

Change-Id: Iba1c04064799fe9c81fe997dbd54fc02b15cdec7
Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
This commit is contained in:
Nikolai Kosjar
2014-05-15 15:15:02 -04:00
parent 194591da98
commit 558f62ec71
4 changed files with 79 additions and 31 deletions

View File

@@ -35,6 +35,12 @@
using namespace CPlusPlus; using namespace CPlusPlus;
static Matcher *defaultMatcher()
{
static Matcher matcher;
return &matcher;
}
Matcher::Matcher() Matcher::Matcher()
{ {
} }
@@ -50,7 +56,7 @@ bool Matcher::match(const Type *type, const Type *otherType, Matcher *matcher)
if (!type || !otherType) if (!type || !otherType)
return false; return false;
return type->match0(otherType, matcher); return type->match0(otherType, matcher ? matcher : defaultMatcher());
} }
bool Matcher::match(const Name *name, const Name *otherName, Matcher *matcher) bool Matcher::match(const Name *name, const Name *otherName, Matcher *matcher)
@@ -60,7 +66,7 @@ bool Matcher::match(const Name *name, const Name *otherName, Matcher *matcher)
if (!name || !otherName) if (!name || !otherName)
return false; return false;
return name->match0(otherName, matcher); return name->match0(otherName, matcher ? matcher : defaultMatcher());
} }
bool Matcher::match(const UndefinedType *, const UndefinedType *) bool Matcher::match(const UndefinedType *, const UndefinedType *)
@@ -161,7 +167,13 @@ bool Matcher::match(const NamedType *type, const NamedType *otherType)
bool Matcher::match(const Function *type, const Function *otherType) bool Matcher::match(const Function *type, const Function *otherType)
{ {
if (type != otherType) if (type == otherType)
return true;
else if (! type->isSignatureEqualTo(otherType, this))
return false;
else if (! type->returnType().match(otherType->returnType(), this))
return false; return false;
return true; return true;
@@ -169,7 +181,10 @@ bool Matcher::match(const Function *type, const Function *otherType)
bool Matcher::match(const Enum *type, const Enum *otherType) bool Matcher::match(const Enum *type, const Enum *otherType)
{ {
if (type != otherType) if (type == otherType)
return true;
else if (! Name::match(type->unqualifiedName(), otherType->unqualifiedName(), this))
return false; return false;
return true; return true;
@@ -177,7 +192,10 @@ bool Matcher::match(const Enum *type, const Enum *otherType)
bool Matcher::match(const Namespace *type, const Namespace *otherType) bool Matcher::match(const Namespace *type, const Namespace *otherType)
{ {
if (type != otherType) if (type == otherType)
return true;
else if (! Name::match(type->unqualifiedName(), otherType->unqualifiedName(), this))
return false; return false;
return true; return true;
@@ -193,7 +211,10 @@ bool Matcher::match(const Template *type, const Template *otherType)
bool Matcher::match(const ForwardClassDeclaration *type, const ForwardClassDeclaration *otherType) bool Matcher::match(const ForwardClassDeclaration *type, const ForwardClassDeclaration *otherType)
{ {
if (type != otherType) if (type == otherType)
return true;
else if (! Name::match(type->name(), otherType->name(), this))
return false; return false;
return true; return true;
@@ -201,7 +222,10 @@ bool Matcher::match(const ForwardClassDeclaration *type, const ForwardClassDecla
bool Matcher::match(const Class *type, const Class *otherType) bool Matcher::match(const Class *type, const Class *otherType)
{ {
if (type != otherType) if (type == otherType)
return true;
else if (! Name::match(type->unqualifiedName(), otherType->unqualifiedName(), this))
return false; return false;
return true; return true;
@@ -209,7 +233,10 @@ bool Matcher::match(const Class *type, const Class *otherType)
bool Matcher::match(const ObjCClass *type, const ObjCClass *otherType) bool Matcher::match(const ObjCClass *type, const ObjCClass *otherType)
{ {
if (type != otherType) if (type == otherType)
return true;
else if (! Name::match(type->unqualifiedName(), otherType->unqualifiedName(), this))
return false; return false;
return true; return true;
@@ -217,7 +244,10 @@ bool Matcher::match(const ObjCClass *type, const ObjCClass *otherType)
bool Matcher::match(const ObjCProtocol *type, const ObjCProtocol *otherType) bool Matcher::match(const ObjCProtocol *type, const ObjCProtocol *otherType)
{ {
if (type != otherType) if (type == otherType)
return true;
else if (! Name::match(type->unqualifiedName(), otherType->unqualifiedName(), this))
return false; return false;
return true; return true;
@@ -225,7 +255,10 @@ bool Matcher::match(const ObjCProtocol *type, const ObjCProtocol *otherType)
bool Matcher::match(const ObjCForwardClassDeclaration *type, const ObjCForwardClassDeclaration *otherType) bool Matcher::match(const ObjCForwardClassDeclaration *type, const ObjCForwardClassDeclaration *otherType)
{ {
if (type != otherType) if (type == otherType)
return true;
else if (! Name::match(type->name(), otherType->name(), this))
return false; return false;
return true; return true;
@@ -233,7 +266,10 @@ bool Matcher::match(const ObjCForwardClassDeclaration *type, const ObjCForwardCl
bool Matcher::match(const ObjCForwardProtocolDeclaration *type, const ObjCForwardProtocolDeclaration *otherType) bool Matcher::match(const ObjCForwardProtocolDeclaration *type, const ObjCForwardProtocolDeclaration *otherType)
{ {
if (type != otherType) if (type == otherType)
return true;
else if (! Name::match(type->name(), otherType->name(), this))
return false; return false;
return true; return true;
@@ -241,9 +277,25 @@ bool Matcher::match(const ObjCForwardProtocolDeclaration *type, const ObjCForwar
bool Matcher::match(const ObjCMethod *type, const ObjCMethod *otherType) bool Matcher::match(const ObjCMethod *type, const ObjCMethod *otherType)
{ {
if (type != otherType) if (type == otherType)
return true;
else if (! Name::match(type->unqualifiedName(), otherType->unqualifiedName(), this))
return false; return false;
else if (type->argumentCount() != otherType->argumentCount())
return false;
else if (! type->returnType().match(otherType->returnType(), this))
return false;
for (unsigned i = 0; i < type->argumentCount(); ++i) {
Symbol *l = type->argumentAt(i);
Symbol *r = otherType->argumentAt(i);
if (! l->type().match(r->type(), this))
return false;
}
return true; return true;
} }
@@ -301,8 +353,7 @@ bool Matcher::match(const QualifiedNameId *name, const QualifiedNameId *otherNam
bool Matcher::match(const SelectorNameId *name, const SelectorNameId *otherName) bool Matcher::match(const SelectorNameId *name, const SelectorNameId *otherName)
{ {
const unsigned nc = name->nameCount(); const unsigned nc = name->nameCount();
if (name->hasArguments() != otherName->hasArguments() || if (name->hasArguments() != otherName->hasArguments() || nc != otherName->nameCount())
nc != otherName->nameCount())
return false; return false;
for (unsigned i = 0; i < nc; ++i) for (unsigned i = 0; i < nc; ++i)
if (!Name::match(name->nameAt(i), otherName->nameAt(i), this)) if (!Name::match(name->nameAt(i), otherName->nameAt(i), this))

View File

@@ -43,8 +43,8 @@ public:
Matcher(); Matcher();
virtual ~Matcher(); virtual ~Matcher();
static bool match(const Type *type, const Type *otherType, Matcher *matcher); static bool match(const Type *type, const Type *otherType, Matcher *matcher = 0);
static bool match(const Name *name, const Name *otherName, Matcher *matcher); static bool match(const Name *name, const Name *otherName, Matcher *matcher = 0);
virtual bool match(const UndefinedType *type, const UndefinedType *otherType); virtual bool match(const UndefinedType *type, const UndefinedType *otherType);
virtual bool match(const VoidType *type, const VoidType *otherType); virtual bool match(const VoidType *type, const VoidType *otherType);

View File

@@ -222,7 +222,7 @@ int Function::methodKey() const
void Function::setMethodKey(int key) void Function::setMethodKey(int key)
{ f._methodKey = key; } { f._methodKey = key; }
bool Function::isSignatureEqualTo(const Function *other) const bool Function::isSignatureEqualTo(const Function *other, Matcher *matcher) const
{ {
if (! other) if (! other)
return false; return false;
@@ -230,22 +230,19 @@ bool Function::isSignatureEqualTo(const Function *other) const
return false; return false;
else if (isVolatile() != other->isVolatile()) else if (isVolatile() != other->isVolatile())
return false; return false;
else if (! Matcher::match(unqualifiedName(), other->unqualifiedName(), matcher))
return false;
const Name *l = unqualifiedName(); const unsigned argc = argumentCount();
const Name *r = other->unqualifiedName(); if (argc != other->argumentCount())
if (l == r || (l && l->isEqualTo(r))) { return false;
const unsigned argc = argumentCount(); for (unsigned i = 0; i < argc; ++i) {
if (argc != other->argumentCount()) Symbol *l = argumentAt(i);
Symbol *r = other->argumentAt(i);
if (! l->type().match(r->type(), matcher))
return false; return false;
for (unsigned i = 0; i < argc; ++i) {
Symbol *l = argumentAt(i);
Symbol *r = other->argumentAt(i);
if (! l->type().isEqualTo(r->type()))
return false;
}
return true;
} }
return false; return true;
} }
bool Function::isEqualTo(const Type *other) const bool Function::isEqualTo(const Type *other) const

View File

@@ -347,7 +347,7 @@ public:
bool isPureVirtual() const; bool isPureVirtual() const;
void setPureVirtual(bool isPureVirtual); void setPureVirtual(bool isPureVirtual);
bool isSignatureEqualTo(const Function *other) const; bool isSignatureEqualTo(const Function *other, Matcher *matcher = 0) const;
// Symbol's interface // Symbol's interface
virtual FullySpecifiedType type() const; virtual FullySpecifiedType type() const;