forked from qt-creator/qt-creator
CPlusPlus: Do not ignore namespaces
... when comparing type names. For instance, this is relevant when deciding whether to offer the "Apply signature changes" refactoring action. Add fallback code for function lookups, which was relying on the relaxed semantics for parameter types. Fixes: QTCREATORBUG-9856 Change-Id: I2001b77034ff15e96a23e3359d19654d0f43f60b Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
14
src/libs/3rdparty/cplusplus/Matcher.cpp
vendored
14
src/libs/3rdparty/cplusplus/Matcher.cpp
vendored
@@ -154,19 +154,7 @@ bool Matcher::match(const NamedType *type, const NamedType *otherType)
|
|||||||
{
|
{
|
||||||
if (type == otherType)
|
if (type == otherType)
|
||||||
return true;
|
return true;
|
||||||
|
return Matcher::match(type->name(), otherType->name(), this);
|
||||||
const Name *name = type->name();
|
|
||||||
if (const QualifiedNameId *q = name->asQualifiedNameId())
|
|
||||||
name = q->name();
|
|
||||||
|
|
||||||
const Name *otherName = otherType->name();
|
|
||||||
if (const QualifiedNameId *q = otherName->asQualifiedNameId())
|
|
||||||
otherName = q->name();
|
|
||||||
|
|
||||||
if (! Matcher::match(name, otherName, this))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Matcher::match(const Function *type, const Function *otherType)
|
bool Matcher::match(const Function *type, const Function *otherType)
|
||||||
|
|||||||
24
src/libs/3rdparty/cplusplus/Symbols.cpp
vendored
24
src/libs/3rdparty/cplusplus/Symbols.cpp
vendored
@@ -339,6 +339,28 @@ bool Function::isSignatureEqualTo(const Function *other, Matcher *matcher) const
|
|||||||
else if (! Matcher::match(unqualifiedName(), other->unqualifiedName(), matcher))
|
else if (! Matcher::match(unqualifiedName(), other->unqualifiedName(), matcher))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
class FallbackMatcher : public Matcher
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit FallbackMatcher(Matcher *baseMatcher) : m_baseMatcher(baseMatcher) {}
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool match(const NamedType *type, const NamedType *otherType) override
|
||||||
|
{
|
||||||
|
if (type == otherType)
|
||||||
|
return true;
|
||||||
|
const Name *name = type->name();
|
||||||
|
if (const QualifiedNameId *q = name->asQualifiedNameId())
|
||||||
|
name = q->name();
|
||||||
|
const Name *otherName = otherType->name();
|
||||||
|
if (const QualifiedNameId *q = otherName->asQualifiedNameId())
|
||||||
|
otherName = q->name();
|
||||||
|
return Matcher::match(name, otherName, m_baseMatcher);
|
||||||
|
}
|
||||||
|
|
||||||
|
Matcher * const m_baseMatcher;
|
||||||
|
} fallbackMatcher(matcher);
|
||||||
|
|
||||||
const int argc = argumentCount();
|
const int argc = argumentCount();
|
||||||
if (argc != other->argumentCount())
|
if (argc != other->argumentCount())
|
||||||
return false;
|
return false;
|
||||||
@@ -359,6 +381,8 @@ bool Function::isSignatureEqualTo(const Function *other, Matcher *matcher) const
|
|||||||
if (lType.match(rType))
|
if (lType.match(rType))
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (l->type().match(r->type(), &fallbackMatcher))
|
||||||
|
continue;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -794,8 +794,9 @@ ChangeSet FunctionDeclDefLink::changes(const Snapshot &snapshot, int targetOffse
|
|||||||
renamedTargetParameters[targetParam] = overview.prettyName(replacementName);
|
renamedTargetParameters[targetParam] = overview.prettyName(replacementName);
|
||||||
|
|
||||||
// need to change the type (and name)?
|
// need to change the type (and name)?
|
||||||
|
FullySpecifiedType replacementType = rewriteType(newParam->type(), &env, control);
|
||||||
if (!newParam->type().match(sourceParam->type())
|
if (!newParam->type().match(sourceParam->type())
|
||||||
&& !newParam->type().match(targetParam->type())) {
|
&& !replacementType.match(targetParam->type())) {
|
||||||
const int parameterTypeStart = targetFile->startOf(targetParamAst);
|
const int parameterTypeStart = targetFile->startOf(targetParamAst);
|
||||||
int parameterTypeEnd = 0;
|
int parameterTypeEnd = 0;
|
||||||
if (targetParamAst->declarator)
|
if (targetParamAst->declarator)
|
||||||
@@ -805,7 +806,6 @@ ChangeSet FunctionDeclDefLink::changes(const Snapshot &snapshot, int targetOffse
|
|||||||
else
|
else
|
||||||
parameterTypeEnd = targetFile->startOf(targetParamAst);
|
parameterTypeEnd = targetFile->startOf(targetParamAst);
|
||||||
|
|
||||||
FullySpecifiedType replacementType = rewriteType(newParam->type(), &env, control);
|
|
||||||
newTargetParam = targetFile->textOf(parameterStart, parameterTypeStart);
|
newTargetParam = targetFile->textOf(parameterStart, parameterTypeStart);
|
||||||
newTargetParam += overview.prettyType(replacementType, replacementName);
|
newTargetParam += overview.prettyType(replacementType, replacementName);
|
||||||
newTargetParam += targetFile->textOf(parameterTypeEnd, parameterEnd);
|
newTargetParam += targetFile->textOf(parameterTypeEnd, parameterEnd);
|
||||||
|
|||||||
Reference in New Issue
Block a user