forked from qt-creator/qt-creator
		
	Recursive definition of CPlusPlus::QualifiedNameId.
Done-with: Erik Verbruggen
This commit is contained in:
		| @@ -256,27 +256,48 @@ private: | ||||
|             _type = control()->namedType(templId); | ||||
|         } | ||||
|  | ||||
|         virtual void visit(const QualifiedNameId *name) | ||||
|         const Name *instantiate(const Name *name) | ||||
|         { | ||||
|             QVarLengthArray<const Name *, 8> names(name->nameCount()); | ||||
|             for (unsigned i = 0; i < name->nameCount(); ++i) { | ||||
|                 const Name *n = name->nameAt(i); | ||||
|             if (! name) | ||||
|                 return name; | ||||
|  | ||||
|                 if (const TemplateNameId *templId = n->asTemplateNameId()) { | ||||
|                     QVarLengthArray<FullySpecifiedType, 8> arguments(templId->templateArgumentCount()); | ||||
|                     for (unsigned templateArgIndex = 0; templateArgIndex < templId->templateArgumentCount(); ++templateArgIndex) { | ||||
|                         FullySpecifiedType argTy = templId->templateArgumentAt(templateArgIndex); | ||||
|                         arguments[templateArgIndex] = q->apply(argTy); | ||||
|                     } | ||||
|             else if (const Name *nameId = name->asNameId()) { | ||||
|                 const Identifier *id = control()->findOrInsertIdentifier(nameId->identifier()->chars(), | ||||
|                                                                          nameId->identifier()->size()); | ||||
|                 return control()->nameId(id); | ||||
|  | ||||
|                     n = control()->templateNameId(templId->identifier(), arguments.data(), arguments.size()); | ||||
|             } else if (const TemplateNameId *templId = name->asTemplateNameId()) { | ||||
|                 QVarLengthArray<FullySpecifiedType, 8> arguments(templId->templateArgumentCount()); | ||||
|                 for (unsigned templateArgIndex = 0; templateArgIndex < templId->templateArgumentCount(); ++templateArgIndex) { | ||||
|                     FullySpecifiedType argTy = templId->templateArgumentAt(templateArgIndex); | ||||
|                     arguments[templateArgIndex] = q->apply(argTy); | ||||
|                 } | ||||
|                 const Identifier *id = control()->findOrInsertIdentifier(templId->identifier()->chars(), | ||||
|                                                                          templId->identifier()->size()); | ||||
|                 return control()->templateNameId(id, arguments.data(), arguments.size()); | ||||
|  | ||||
|             } else if (const QualifiedNameId *qq = name->asQualifiedNameId()) { | ||||
|                 const Name *base = instantiate(qq->base()); | ||||
|                 const Name *name = instantiate(qq->name()); | ||||
|  | ||||
|                 return control()->qualifiedNameId(base, name); | ||||
|  | ||||
|             } else if (const OperatorNameId *op = name->asOperatorNameId()) { | ||||
|                 return control()->operatorNameId(op->kind()); | ||||
|  | ||||
|             } else if (const ConversionNameId *c = name->asConversionNameId()) { | ||||
|                 FullySpecifiedType ty = q->apply(c->type()); | ||||
|                 return control()->conversionNameId(ty); | ||||
|  | ||||
|                 names[i] = n; | ||||
|             } | ||||
|  | ||||
|             const QualifiedNameId *q = control()->qualifiedNameId(names.data(), names.size(), name->isGlobal()); | ||||
|             _type = control()->namedType(q); | ||||
|             return 0; | ||||
|         } | ||||
|  | ||||
|         virtual void visit(const QualifiedNameId *name) | ||||
|         { | ||||
|             if (const Name *n = instantiate(name)) | ||||
|                 _type = control()->namedType(n); | ||||
|         } | ||||
|  | ||||
|         virtual void visit(const DestructorNameId *name) | ||||
|   | ||||
| @@ -47,6 +47,18 @@ namespace { | ||||
|  | ||||
| using namespace CPlusPlus; | ||||
|  | ||||
| static void addNames(const Name *name, QList<const Name *> *names) | ||||
| { | ||||
|     if (! name) | ||||
|         return; | ||||
|     else if (name->isNameId() || name->isTemplateNameId()) | ||||
|         names->append(name); | ||||
|     else if (const QualifiedNameId *q = name->asQualifiedNameId()) { | ||||
|         addNames(q->base(), names); | ||||
|         addNames(q->name(), names); | ||||
|     } | ||||
| } | ||||
|  | ||||
| static void fullyQualifiedName_helper(Symbol *symbol, QList<const Name *> *names) | ||||
| { | ||||
|     if (! symbol) | ||||
| @@ -56,23 +68,16 @@ static void fullyQualifiedName_helper(Symbol *symbol, QList<const Name *> *names | ||||
|  | ||||
|     if (symbol->name()) { | ||||
|         if (symbol->isClass() || symbol->isNamespace()) { | ||||
|             if (const QualifiedNameId *q = symbol->name()->asQualifiedNameId()) { | ||||
|                 for (unsigned i = 0; i < q->nameCount(); ++i) | ||||
|                     names->append(q->nameAt(i)); | ||||
|             addNames(symbol->name(), names); | ||||
|  | ||||
|             } else if (symbol->name()->isNameId() || symbol->name()->isTemplateNameId()) { | ||||
|                 names->append(symbol->name()); | ||||
|             } | ||||
|         } else if (symbol->isObjCClass() || symbol->isObjCBaseClass() || symbol->isObjCProtocol() | ||||
|                 || symbol->isObjCForwardClassDeclaration() || symbol->isObjCForwardProtocolDeclaration() | ||||
|                 || symbol->isForwardClassDeclaration()) { | ||||
|             if (symbol->name()) | ||||
|                 names->append(symbol->name()); | ||||
|             addNames(symbol->name(), names); | ||||
|  | ||||
|         } else if (symbol->isFunction()) { | ||||
|             if (const QualifiedNameId *q = symbol->name()->asQualifiedNameId()) { | ||||
|                 for (unsigned i = 0; i < q->nameCount() - 1; ++i) | ||||
|                     names->append(q->nameAt(i)); | ||||
|             } | ||||
|             if (const QualifiedNameId *q = symbol->name()->asQualifiedNameId()) | ||||
|                 addNames(q->base(), names); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -142,6 +147,9 @@ const Name *LookupContext::minimalName(const Name *name, | ||||
|                                        Scope *source, | ||||
|                                        ClassOrNamespace *target) const | ||||
| { | ||||
|     qWarning() << "TODO:" << Q_FUNC_INFO; | ||||
|  | ||||
| #if 0 | ||||
|     Q_ASSERT(name); | ||||
|     Q_ASSERT(source); | ||||
|     Q_ASSERT(target); | ||||
| @@ -153,7 +161,7 @@ const Name *LookupContext::minimalName(const Name *name, | ||||
|     Symbol *canonicalSymbol = symbols.first(); | ||||
|     std::vector<const Name *> fqNames = fullyQualifiedName(canonicalSymbol).toVector().toStdVector(); | ||||
|     if (const QualifiedNameId *qId = name->asQualifiedNameId()) | ||||
|         fqNames.push_back(qId->nameAt(qId->nameCount() - 1)); | ||||
|         fqNames.push_back(qId->name()); | ||||
|     else | ||||
|         fqNames.push_back(name); | ||||
|  | ||||
| @@ -172,6 +180,8 @@ const Name *LookupContext::minimalName(const Name *name, | ||||
|         return lastWorking->nameAt(0); | ||||
|     else | ||||
|         return lastWorking; | ||||
| #endif | ||||
|     return 0; | ||||
| } | ||||
|  | ||||
|  | ||||
| @@ -396,21 +406,11 @@ QList<Symbol *> ClassOrNamespace::lookup_helper(const Name *name, bool searchInE | ||||
|  | ||||
|     if (name) { | ||||
|         if (const QualifiedNameId *q = name->asQualifiedNameId()) { | ||||
|             ClassOrNamespace *binding = this; | ||||
|             if (! q->base()) | ||||
|                 result = globalNamespace()->find(q->name()); | ||||
|  | ||||
|             if (q->isGlobal()) | ||||
|                 binding = globalNamespace(); | ||||
|  | ||||
|             if (q->nameCount() == 1) | ||||
|                 return binding->find(q->unqualifiedNameId()); | ||||
|  | ||||
|             binding = binding->lookupType(q->nameAt(0)); | ||||
|  | ||||
|             for (unsigned index = 1; binding && index < q->nameCount() - 1; ++index) | ||||
|                 binding = binding->findType(q->nameAt(index)); | ||||
|  | ||||
|             if (binding) | ||||
|                 result = binding->find(q->unqualifiedNameId()); | ||||
|             else if (ClassOrNamespace *binding = lookupType(q->base())) | ||||
|                 result = binding->find(q->name()); | ||||
|  | ||||
|             return result; | ||||
|         } | ||||
| @@ -533,17 +533,14 @@ ClassOrNamespace *ClassOrNamespace::lookupType_helper(const Name *name, | ||||
|                                                       bool searchInEnclosingScope) | ||||
| { | ||||
|     if (const QualifiedNameId *q = name->asQualifiedNameId()) { | ||||
|         ClassOrNamespace *e = this; | ||||
|  | ||||
|         if (q->isGlobal()) | ||||
|             e = globalNamespace(); | ||||
|         if (! q->base()) | ||||
|             return globalNamespace()->findType(q->name()); | ||||
|  | ||||
|         e = e->lookupType(q->nameAt(0)); | ||||
|         else if (ClassOrNamespace *binding = lookupType(q->base())) | ||||
|             return binding->findType(q->name()); | ||||
|  | ||||
|         for (unsigned index = 1; e && index < q->nameCount(); ++index) | ||||
|             e = e->findType(q->nameAt(index)); | ||||
|  | ||||
|         return e; | ||||
|         return 0; | ||||
|  | ||||
|     } else if (! processed->contains(this)) { | ||||
|         processed->insert(this); | ||||
| @@ -653,12 +650,10 @@ ClassOrNamespace *ClassOrNamespace::findOrCreateType(const Name *name) | ||||
|         return this; | ||||
|  | ||||
|     if (const QualifiedNameId *q = name->asQualifiedNameId()) { | ||||
|         ClassOrNamespace *e = this; | ||||
|         if (! q->base()) | ||||
|             return globalNamespace()->findOrCreateType(q->name()); | ||||
|  | ||||
|         for (unsigned i = 0; e && i < q->nameCount(); ++i) | ||||
|             e = e->findOrCreateType(q->nameAt(i)); | ||||
|  | ||||
|         return e; | ||||
|         return findOrCreateType(q->base())->findOrCreateType(q->name()); | ||||
|  | ||||
|     } else if (name->isNameId() || name->isTemplateNameId()) { | ||||
|         ClassOrNamespace *e = nestedType(name); | ||||
| @@ -871,7 +866,7 @@ bool CreateBindings::visit(UsingDeclaration *u) | ||||
| { | ||||
|     if (u->name()) { | ||||
|         if (const QualifiedNameId *q = u->name()->asQualifiedNameId()) { | ||||
|             if (const NameId *unqualifiedId = q->unqualifiedNameId()->asNameId()) { | ||||
|             if (const NameId *unqualifiedId = q->name()->asNameId()) { | ||||
|                 if (ClassOrNamespace *delegate = _currentClassOrNamespace->lookupType(q)) { | ||||
|                     ClassOrNamespace *b = _currentClassOrNamespace->findOrCreateType(unqualifiedId); | ||||
|                     b->addUsing(delegate); | ||||
|   | ||||
| @@ -246,14 +246,10 @@ void NamePrettyPrinter::visit(const ConversionNameId *name) | ||||
|  | ||||
| void NamePrettyPrinter::visit(const QualifiedNameId *name) | ||||
| { | ||||
|     if (name->isGlobal()) | ||||
|         _name += QLatin1String("::"); | ||||
|  | ||||
|     for (unsigned index = 0; index < name->nameCount(); ++index) { | ||||
|         if (index != 0) | ||||
|             _name += QLatin1String("::"); | ||||
|         _name += operator()(name->nameAt(index)); | ||||
|     } | ||||
|     if (name->base()) | ||||
|         _name += operator()(name->base()); | ||||
|     _name += QLatin1String("::"); | ||||
|     _name += operator()(name->name()); | ||||
| } | ||||
|  | ||||
| void NamePrettyPrinter::visit(const SelectorNameId *name) | ||||
|   | ||||
| @@ -221,11 +221,10 @@ bool ResolveExpression::visit(NewExpressionAST *ast) | ||||
|  | ||||
| bool ResolveExpression::visit(TypeidExpressionAST *) | ||||
| { | ||||
|     const Name *std_type_info[2]; | ||||
|     std_type_info[0] = control()->nameId(control()->findOrInsertIdentifier("std")); | ||||
|     std_type_info[1] = control()->nameId(control()->findOrInsertIdentifier("type_info")); | ||||
|     const Name *stdName = control()->nameId(control()->findOrInsertIdentifier("std")); | ||||
|     const Name *tiName = control()->nameId(control()->findOrInsertIdentifier("type_info")); | ||||
|     const Name *q = control()->qualifiedNameId(control()->qualifiedNameId(/* :: */ 0, stdName), tiName); | ||||
|  | ||||
|     const Name *q = control()->qualifiedNameId(std_type_info, 2, /*global=*/ true); | ||||
|     FullySpecifiedType ty(control()->namedType(q)); | ||||
|     addResult(ty, _scope); | ||||
|  | ||||
| @@ -314,14 +313,11 @@ void ResolveExpression::thisObject() | ||||
|                 addResult(ptrTy, fun->scope()); | ||||
|                 break; | ||||
|             } else if (const QualifiedNameId *q = fun->name()->asQualifiedNameId()) { | ||||
|                 const Name *nestedNameSpecifier = 0; | ||||
|                 if (q->nameCount() == 1 && q->isGlobal()) | ||||
|                     nestedNameSpecifier = q->nameAt(0); | ||||
|                 else | ||||
|                     nestedNameSpecifier = control()->qualifiedNameId(q->names(), q->nameCount() - 1); | ||||
|                 FullySpecifiedType classTy(control()->namedType(nestedNameSpecifier)); | ||||
|                 FullySpecifiedType ptrTy(control()->pointerType(classTy)); | ||||
|                 addResult(ptrTy, fun->scope()); | ||||
|                 if (q->base()) { | ||||
|                     FullySpecifiedType classTy(control()->namedType(q->base())); | ||||
|                     FullySpecifiedType ptrTy(control()->pointerType(classTy)); | ||||
|                     addResult(ptrTy, fun->scope()); | ||||
|                 } | ||||
|                 break; | ||||
|             } | ||||
|         } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user