forked from qt-creator/qt-creator
C++ insert def: Fix bug when minimizing name.
Constructors would not get the correct name before. Now rewriting the function's name is not done by going through the 'rewrite type' func- tionality but rather by minimizing the symbol's name directly. Task-number: QTCREATORBUG-6223 Change-Id: I3c25e414337937f5dd0f54570c899ca2ca21d2ef Reviewed-by: Leandro T. C. Melo <leandro.melo@nokia.com>
This commit is contained in:
@@ -387,18 +387,6 @@ UseMinimalNames::~UseMinimalNames()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool symbolIdentical(Symbol *s1, Symbol *s2)
|
|
||||||
{
|
|
||||||
if (!s1 || !s2)
|
|
||||||
return false;
|
|
||||||
if (s1->line() != s2->line())
|
|
||||||
return false;
|
|
||||||
if (s1->column() != s2->column())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return QByteArray(s1->fileName()) == QByteArray(s2->fileName());
|
|
||||||
}
|
|
||||||
|
|
||||||
FullySpecifiedType UseMinimalNames::apply(const Name *name, Rewrite *rewrite) const
|
FullySpecifiedType UseMinimalNames::apply(const Name *name, Rewrite *rewrite) const
|
||||||
{
|
{
|
||||||
SubstitutionEnvironment *env = rewrite->env;
|
SubstitutionEnvironment *env = rewrite->env;
|
||||||
@@ -416,26 +404,7 @@ FullySpecifiedType UseMinimalNames::apply(const Name *name, Rewrite *rewrite) co
|
|||||||
const QList<LookupItem> results = context.lookup(name, scope);
|
const QList<LookupItem> results = context.lookup(name, scope);
|
||||||
foreach (const LookupItem &r, results) {
|
foreach (const LookupItem &r, results) {
|
||||||
if (Symbol *d = r.declaration()) {
|
if (Symbol *d = r.declaration()) {
|
||||||
const Name *n = 0;
|
return control->namedType(LookupContext::minimalName(d, _target, control));
|
||||||
QList<const Name *> names = LookupContext::fullyQualifiedName(d);
|
|
||||||
for (int i = names.size() - 1; i >= 0; --i) {
|
|
||||||
if (! n)
|
|
||||||
n = names.at(i);
|
|
||||||
else
|
|
||||||
n = control->qualifiedNameId(names.at(i), n);
|
|
||||||
if (_target) {
|
|
||||||
// minimize the qualifications
|
|
||||||
const QList<LookupItem> tresults = _target->lookup(n);
|
|
||||||
foreach (const LookupItem &tr, tresults) {
|
|
||||||
if (symbolIdentical(tr.declaration(), d)) {
|
|
||||||
i = 0; // break outer
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return control->namedType(n);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return r.type();
|
return r.type();
|
||||||
|
|||||||
@@ -157,50 +157,40 @@ QList<const Name *> LookupContext::path(Symbol *symbol)
|
|||||||
return names;
|
return names;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool symbolIdentical(Symbol *s1, Symbol *s2)
|
||||||
const Name *LookupContext::minimalName(const Name *name,
|
|
||||||
Scope *scope,
|
|
||||||
ClassOrNamespace *target) const
|
|
||||||
{
|
{
|
||||||
Q_UNUSED(name);
|
if (!s1 || !s2)
|
||||||
Q_UNUSED(scope);
|
return false;
|
||||||
Q_UNUSED(target);
|
if (s1->line() != s2->line())
|
||||||
|
return false;
|
||||||
|
if (s1->column() != s2->column())
|
||||||
|
return false;
|
||||||
|
|
||||||
qWarning() << "TODO:" << Q_FUNC_INFO;
|
return QByteArray(s1->fileName()) == QByteArray(s2->fileName());
|
||||||
return name;
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
Q_ASSERT(name);
|
|
||||||
Q_ASSERT(source);
|
|
||||||
Q_ASSERT(target);
|
|
||||||
|
|
||||||
QList<Symbol *> symbols = lookup(name, source);
|
|
||||||
if (symbols.isEmpty())
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
Symbol *canonicalSymbol = symbols.first();
|
|
||||||
std::vector<const Name *> fqNames = fullyQualifiedName(canonicalSymbol).toVector().toStdVector();
|
|
||||||
if (const QualifiedNameId *qId = name->asQualifiedNameId())
|
|
||||||
fqNames.push_back(qId->name());
|
|
||||||
else
|
|
||||||
fqNames.push_back(name);
|
|
||||||
|
|
||||||
const QualifiedNameId *lastWorking = 0;
|
|
||||||
for (unsigned i = 0; i < fqNames.size(); ++i) {
|
|
||||||
const QualifiedNameId *newName = control()->qualifiedNameId(&fqNames[i],
|
|
||||||
fqNames.size() - i);
|
|
||||||
QList<Symbol *> candidates = target->lookup(newName);
|
|
||||||
if (candidates.contains(canonicalSymbol))
|
|
||||||
lastWorking = newName;
|
|
||||||
else
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lastWorking && lastWorking->nameCount() == 1)
|
const Name *LookupContext::minimalName(Symbol *symbol, ClassOrNamespace *target, Control *control)
|
||||||
return lastWorking->nameAt(0);
|
{
|
||||||
|
const Name *n = 0;
|
||||||
|
QList<const Name *> names = LookupContext::fullyQualifiedName(symbol);
|
||||||
|
|
||||||
|
for (int i = names.size() - 1; i >= 0; --i) {
|
||||||
|
if (! n)
|
||||||
|
n = names.at(i);
|
||||||
else
|
else
|
||||||
return lastWorking;
|
n = control->qualifiedNameId(names.at(i), n);
|
||||||
#endif
|
|
||||||
|
// once we're qualified enough to get the same symbol, break
|
||||||
|
if (target) {
|
||||||
|
const QList<LookupItem> tresults = target->lookup(n);
|
||||||
|
foreach (const LookupItem &tr, tresults) {
|
||||||
|
if (symbolIdentical(tr.declaration(), symbol))
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -235,8 +235,7 @@ public:
|
|||||||
static QList<const Name *> fullyQualifiedName(Symbol *symbol);
|
static QList<const Name *> fullyQualifiedName(Symbol *symbol);
|
||||||
static QList<const Name *> path(Symbol *symbol);
|
static QList<const Name *> path(Symbol *symbol);
|
||||||
|
|
||||||
const Name *minimalName(const Name *name, Scope *source,
|
static const Name *minimalName(Symbol *symbol, ClassOrNamespace *target, Control *control);
|
||||||
ClassOrNamespace *target) const;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// The current expression.
|
// The current expression.
|
||||||
|
|||||||
@@ -261,13 +261,7 @@ public:
|
|||||||
FullySpecifiedType tn = rewriteType(m_decl->type(), &env, control);
|
FullySpecifiedType tn = rewriteType(m_decl->type(), &env, control);
|
||||||
|
|
||||||
// rewrite the function name
|
// rewrite the function name
|
||||||
QString name;
|
QString name = oo(LookupContext::minimalName(m_decl, targetCoN, control));
|
||||||
const FullySpecifiedType nametype = rewriteType(control->namedType(m_decl->name()), &env, control);
|
|
||||||
if (NamedType *nt = nametype.type()->asNamedType()) {
|
|
||||||
name = oo(nt->name());
|
|
||||||
} else {
|
|
||||||
name = oo(LookupContext::fullyQualifiedName(m_decl));
|
|
||||||
}
|
|
||||||
|
|
||||||
QString defText = oo.prettyType(tn, name) + "\n{\n}";
|
QString defText = oo.prettyType(tn, name) + "\n{\n}";
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user