forked from qt-creator/qt-creator
Revert "C++: fix support for typedef of templated typedefs"
Still crashes when opening the Qt Creator project,
g++ (Ubuntu/Linaro 4.7.2-2ubuntu1) 4.7.2 (Ubuntu 12.10).
This reverts commit 564c9b2842
.
Change-Id: Ief5c0aad463d245f68805f747d277ac298796c3d
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@digia.com>
This commit is contained in:
@@ -719,22 +719,10 @@ ClassOrNamespace *ClassOrNamespace::lookupType_helper(const Name *name,
|
|||||||
if (name->isNameId() || name->isTemplateNameId() || name->isAnonymousNameId()) {
|
if (name->isNameId() || name->isTemplateNameId() || name->isAnonymousNameId()) {
|
||||||
flush();
|
flush();
|
||||||
|
|
||||||
if (name->isTemplateNameId()) {
|
|
||||||
// if it is a base specialization, the 'name' could be an instantiation
|
|
||||||
QMap<const TemplateNameId *, ClassOrNamespace *>::iterator it
|
|
||||||
= _instantiations.find(name->asTemplateNameId());
|
|
||||||
if (it != _instantiations.end())
|
|
||||||
return it.value();
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (Symbol *s, symbols()) {
|
foreach (Symbol *s, symbols()) {
|
||||||
if (Class *klass = s->asClass()) {
|
if (Class *klass = s->asClass()) {
|
||||||
if (klass->identifier() && klass->identifier()->isEqualTo(name->identifier()))
|
if (klass->identifier() && klass->identifier()->isEqualTo(name->identifier()))
|
||||||
return this;
|
return this;
|
||||||
|
|
||||||
if (ClassOrNamespace *typedefedType
|
|
||||||
= resolveTypedef(klass, name, searchInEnclosingScope, origin))
|
|
||||||
return typedefedType;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -758,9 +746,6 @@ ClassOrNamespace *ClassOrNamespace::lookupType_helper(const Name *name,
|
|||||||
}
|
}
|
||||||
|
|
||||||
foreach (ClassOrNamespace *u, usings()) {
|
foreach (ClassOrNamespace *u, usings()) {
|
||||||
// usings are not instantiated for templates
|
|
||||||
if (_templateId && u->_templateId)
|
|
||||||
continue;
|
|
||||||
if (ClassOrNamespace *r = u->lookupType_helper(name,
|
if (ClassOrNamespace *r = u->lookupType_helper(name,
|
||||||
processed,
|
processed,
|
||||||
/*searchInEnclosingScope =*/ false,
|
/*searchInEnclosingScope =*/ false,
|
||||||
@@ -769,21 +754,8 @@ ClassOrNamespace *ClassOrNamespace::lookupType_helper(const Name *name,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return lookupType_helper_inParent(name, processed, searchInEnclosingScope, origin);
|
if (_parent && searchInEnclosingScope)
|
||||||
}
|
return _parent->lookupType_helper(name, processed, searchInEnclosingScope, origin);
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
ClassOrNamespace *ClassOrNamespace::lookupType_helper_inParent(const Name *name, QSet<ClassOrNamespace *> *processed,
|
|
||||||
bool searchInEnclosingScope, ClassOrNamespace *origin)
|
|
||||||
{
|
|
||||||
if (_parent && searchInEnclosingScope) {
|
|
||||||
// for templates _parent is a base specialization,
|
|
||||||
// so we should take here rather _parent of this base specialization
|
|
||||||
ClassOrNamespace *parent = _templateId ? _parent->_parent : _parent;
|
|
||||||
if (parent)
|
|
||||||
return parent->lookupType_helper(name, processed, searchInEnclosingScope, origin);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -823,39 +795,6 @@ ClassOrNamespace *ClassOrNamespace::findSpecializationWithPointer(const Template
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
ClassOrNamespace *ClassOrNamespace::resolveTypedef(Class *klass, const Name *name,
|
|
||||||
bool searchInEnclosingScope,
|
|
||||||
ClassOrNamespace *origin)
|
|
||||||
{
|
|
||||||
// it can be a typedef
|
|
||||||
const unsigned memberClassCount = klass->memberCount();
|
|
||||||
for (unsigned i = 0; i < memberClassCount; ++i) {
|
|
||||||
Symbol *memberClassAsSymbol = klass->memberAt(i);
|
|
||||||
if (Declaration *declaration = memberClassAsSymbol->asDeclaration()) {
|
|
||||||
if (declaration->isTypedef()
|
|
||||||
&& name->identifier()->isEqualTo(declaration->name()->identifier())) {
|
|
||||||
if (NamedType *namedType = declaration->type()->asNamedType()) {
|
|
||||||
QSet<ClassOrNamespace *> innerProcessed;
|
|
||||||
const Name *namedTypeName = namedType->name();
|
|
||||||
const QualifiedNameId *q = namedTypeName->asQualifiedNameId();
|
|
||||||
if (q) {
|
|
||||||
if (name->isEqualTo(q->base()) && name->isEqualTo(q->name()))
|
|
||||||
return lookupType_helper_inParent(name, &innerProcessed,
|
|
||||||
searchInEnclosingScope,
|
|
||||||
origin);
|
|
||||||
if ((klass->identifier()
|
|
||||||
&& klass->identifier()->isEqualTo(q->base()->identifier())))
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
return lookupType_helper(namedTypeName, &innerProcessed, true, origin);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
ClassOrNamespace *ClassOrNamespace::nestedType(const Name *name, ClassOrNamespace *origin)
|
ClassOrNamespace *ClassOrNamespace::nestedType(const Name *name, ClassOrNamespace *origin)
|
||||||
{
|
{
|
||||||
Q_ASSERT(name != 0);
|
Q_ASSERT(name != 0);
|
||||||
@@ -1020,7 +959,7 @@ ClassOrNamespace *ClassOrNamespace::nestedType(const Name *name, ClassOrNamespac
|
|||||||
oo.showReturnTypes = true;
|
oo.showReturnTypes = true;
|
||||||
oo.showTemplateParameters = true;
|
oo.showTemplateParameters = true;
|
||||||
qDebug()<<"cloned"<<oo(clone->type());
|
qDebug()<<"cloned"<<oo(clone->type());
|
||||||
if (Class *klass = clone->asClass()) {
|
if (Class *klass = s->asClass()) {
|
||||||
const unsigned klassMemberCount = klass->memberCount();
|
const unsigned klassMemberCount = klass->memberCount();
|
||||||
for (unsigned i = 0; i < klassMemberCount; ++i){
|
for (unsigned i = 0; i < klassMemberCount; ++i){
|
||||||
Symbol *klassMemberAsSymbol = klass->memberAt(i);
|
Symbol *klassMemberAsSymbol = klass->memberAt(i);
|
||||||
|
@@ -111,9 +111,6 @@ private:
|
|||||||
ClassOrNamespace *lookupType_helper(const Name *name, QSet<ClassOrNamespace *> *processed,
|
ClassOrNamespace *lookupType_helper(const Name *name, QSet<ClassOrNamespace *> *processed,
|
||||||
bool searchInEnclosingScope, ClassOrNamespace *origin);
|
bool searchInEnclosingScope, ClassOrNamespace *origin);
|
||||||
|
|
||||||
ClassOrNamespace *lookupType_helper_inParent(const Name *name, QSet<ClassOrNamespace *> *processed,
|
|
||||||
bool searchInEnclosingScope, ClassOrNamespace *origin);
|
|
||||||
|
|
||||||
ClassOrNamespace *nestedType(const Name *name, ClassOrNamespace *origin);
|
ClassOrNamespace *nestedType(const Name *name, ClassOrNamespace *origin);
|
||||||
|
|
||||||
void instantiateNestedClasses(ClassOrNamespace *enclosingTemplateClass,
|
void instantiateNestedClasses(ClassOrNamespace *enclosingTemplateClass,
|
||||||
@@ -123,8 +120,6 @@ private:
|
|||||||
bool isInstantiateNestedClassNeeded(const QList<Symbol *>& symbols, const Subst &subst) const;
|
bool isInstantiateNestedClassNeeded(const QList<Symbol *>& symbols, const Subst &subst) const;
|
||||||
ClassOrNamespace *findSpecializationWithPointer(const TemplateNameId *templId,
|
ClassOrNamespace *findSpecializationWithPointer(const TemplateNameId *templId,
|
||||||
const TemplateNameIdTable &specializations);
|
const TemplateNameIdTable &specializations);
|
||||||
ClassOrNamespace *resolveTypedef(Class *klass, const Name *name,
|
|
||||||
bool searchInEnclosingScope, ClassOrNamespace *origin);
|
|
||||||
|
|
||||||
CreateBindings *_factory;
|
CreateBindings *_factory;
|
||||||
ClassOrNamespace *_parent;
|
ClassOrNamespace *_parent;
|
||||||
|
@@ -690,15 +690,8 @@ bool ResolveExpression::visit(CallAST *ast)
|
|||||||
}
|
}
|
||||||
|
|
||||||
} else if (Function *funTy = ty->asFunctionType()) {
|
} else if (Function *funTy = ty->asFunctionType()) {
|
||||||
if (maybeValidPrototype(funTy, actualArgumentCount)) {
|
if (maybeValidPrototype(funTy, actualArgumentCount))
|
||||||
LookupItem item;
|
addResult(funTy->returnType().simplified(), scope);
|
||||||
item.setType(funTy->returnType().simplified());
|
|
||||||
item.setScope(scope);
|
|
||||||
// we have to remember a binding because it can be a template instantiation
|
|
||||||
item.setBinding(result.binding());
|
|
||||||
|
|
||||||
_results.append(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if (Class *classTy = ty->asClassType()) {
|
} else if (Class *classTy = ty->asClassType()) {
|
||||||
// Constructor call
|
// Constructor call
|
||||||
|
@@ -1882,138 +1882,3 @@ void CppToolsPlugin::test_completion_QTCREATORBUG9098()
|
|||||||
QVERIFY(completions.contains(QLatin1String("c")));
|
QVERIFY(completions.contains(QLatin1String("c")));
|
||||||
QVERIFY(completions.contains(QLatin1String("B")));
|
QVERIFY(completions.contains(QLatin1String("B")));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CppToolsPlugin::test_completion_typedef_of_templated_typedef_QTCREATORBUG8375()
|
|
||||||
{
|
|
||||||
TestData data;
|
|
||||||
data.srcText =
|
|
||||||
"struct Foo\n"
|
|
||||||
"{ void bar(); };\n"
|
|
||||||
"struct A\n"
|
|
||||||
"{ typedef Foo AFoo; };\n"
|
|
||||||
"template <class T>\n"
|
|
||||||
"struct B\n"
|
|
||||||
"{ typedef typename T::AFoo BFoo; };\n"
|
|
||||||
"struct C : public B<A>\n"
|
|
||||||
"{\n"
|
|
||||||
" void test()\n"
|
|
||||||
" {\n"
|
|
||||||
" BFoo foo;\n"
|
|
||||||
" @\n"
|
|
||||||
" // padding so we get the scope right\n"
|
|
||||||
" }\n"
|
|
||||||
"};\n"
|
|
||||||
;
|
|
||||||
setup(&data);
|
|
||||||
|
|
||||||
Utils::ChangeSet change;
|
|
||||||
QString txt = QLatin1String("foo.");
|
|
||||||
change.insert(data.pos, txt);
|
|
||||||
QTextCursor cursor(data.doc);
|
|
||||||
change.apply(&cursor);
|
|
||||||
data.pos += txt.length();
|
|
||||||
|
|
||||||
QStringList completions = getCompletions(data);
|
|
||||||
|
|
||||||
QCOMPARE(completions.size(), 2);
|
|
||||||
QVERIFY(completions.contains(QLatin1String("Foo")));
|
|
||||||
QVERIFY(completions.contains(QLatin1String("bar")));
|
|
||||||
}
|
|
||||||
|
|
||||||
void CppToolsPlugin::test_completion_typedef_with_the_same_base_name_and_new_type_name()
|
|
||||||
{
|
|
||||||
TestData data;
|
|
||||||
data.srcText =
|
|
||||||
"namespace A\n"
|
|
||||||
"{\n"
|
|
||||||
"struct A { int aa; };\n"
|
|
||||||
"}\n"
|
|
||||||
"struct S\n"
|
|
||||||
"{\n"
|
|
||||||
" typedef A::A A;\n"
|
|
||||||
" A a;\n"
|
|
||||||
"};\n"
|
|
||||||
"void fun()\n"
|
|
||||||
"{\n"
|
|
||||||
" S s;\n"
|
|
||||||
" @\n"
|
|
||||||
" // padding so we get the scope right\n"
|
|
||||||
"};\n"
|
|
||||||
;
|
|
||||||
setup(&data);
|
|
||||||
|
|
||||||
Utils::ChangeSet change;
|
|
||||||
QString txt = QLatin1String("s.a.");
|
|
||||||
change.insert(data.pos, txt);
|
|
||||||
QTextCursor cursor(data.doc);
|
|
||||||
change.apply(&cursor);
|
|
||||||
data.pos += txt.length();
|
|
||||||
|
|
||||||
QStringList completions = getCompletions(data);
|
|
||||||
|
|
||||||
QCOMPARE(completions.size(), 2);
|
|
||||||
QVERIFY(completions.contains(QLatin1String("A")));
|
|
||||||
QVERIFY(completions.contains(QLatin1String("aa")));
|
|
||||||
}
|
|
||||||
|
|
||||||
void CppToolsPlugin::test_completion_qualified_typedef_1()
|
|
||||||
{
|
|
||||||
TestData data;
|
|
||||||
data.srcText =
|
|
||||||
"struct S\n"
|
|
||||||
"{\n"
|
|
||||||
" typedef S::type type;\n"
|
|
||||||
"};\n"
|
|
||||||
"void fun()\n"
|
|
||||||
"{\n"
|
|
||||||
" @\n"
|
|
||||||
" // padding so we get the scope right\n"
|
|
||||||
"};\n"
|
|
||||||
;
|
|
||||||
setup(&data);
|
|
||||||
|
|
||||||
Utils::ChangeSet change;
|
|
||||||
QString txt = QLatin1String("S::");
|
|
||||||
change.insert(data.pos, txt);
|
|
||||||
QTextCursor cursor(data.doc);
|
|
||||||
change.apply(&cursor);
|
|
||||||
data.pos += txt.length();
|
|
||||||
|
|
||||||
QStringList completions = getCompletions(data);
|
|
||||||
|
|
||||||
QCOMPARE(completions.size(), 2);
|
|
||||||
QVERIFY(completions.contains(QLatin1String("S")));
|
|
||||||
QVERIFY(completions.contains(QLatin1String("type")));
|
|
||||||
}
|
|
||||||
|
|
||||||
void CppToolsPlugin::test_completion_qualified_typedef_2()
|
|
||||||
{
|
|
||||||
TestData data;
|
|
||||||
data.srcText =
|
|
||||||
"template <typename T>\n"
|
|
||||||
"struct S\n"
|
|
||||||
"{\n"
|
|
||||||
" typedef S<T>::type type;\n"
|
|
||||||
"};\n"
|
|
||||||
"void fun()\n"
|
|
||||||
"{\n"
|
|
||||||
" @\n"
|
|
||||||
" // padding so we get the scope right\n"
|
|
||||||
"};\n"
|
|
||||||
;
|
|
||||||
setup(&data);
|
|
||||||
|
|
||||||
Utils::ChangeSet change;
|
|
||||||
QString txt = QLatin1String("S<int>::");
|
|
||||||
change.insert(data.pos, txt);
|
|
||||||
QTextCursor cursor(data.doc);
|
|
||||||
change.apply(&cursor);
|
|
||||||
data.pos += txt.length();
|
|
||||||
|
|
||||||
QStringList completions = getCompletions(data);
|
|
||||||
|
|
||||||
QCOMPARE(completions.size(), 2);
|
|
||||||
QVERIFY(completions.contains(QLatin1String("S")));
|
|
||||||
QVERIFY(completions.contains(QLatin1String("type")));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
@@ -124,11 +124,6 @@ private slots:
|
|||||||
void test_completion_typedef_using_templates2();
|
void test_completion_typedef_using_templates2();
|
||||||
void test_completion_namespace_alias_with_many_namespace_declarations();
|
void test_completion_namespace_alias_with_many_namespace_declarations();
|
||||||
void test_completion_QTCREATORBUG9098();
|
void test_completion_QTCREATORBUG9098();
|
||||||
void test_completion_typedef_of_templated_typedef_QTCREATORBUG8375();
|
|
||||||
void test_completion_typedef_with_the_same_base_name_and_new_type_name();
|
|
||||||
void test_completion_qualified_typedef_1();
|
|
||||||
void test_completion_qualified_typedef_2();
|
|
||||||
|
|
||||||
|
|
||||||
void test_format_pointerdeclaration_in_simpledeclarations();
|
void test_format_pointerdeclaration_in_simpledeclarations();
|
||||||
void test_format_pointerdeclaration_in_simpledeclarations_data();
|
void test_format_pointerdeclaration_in_simpledeclarations_data();
|
||||||
|
Reference in New Issue
Block a user