IndexedTypeIdentifier typeIdentifierFromTemplateArgument(ParseSession* session, TemplateArgumentAST *node) { IndexedTypeIdentifier id; if(node->expression) { id = IndexedTypeIdentifier(session->stringForNode(node), true); }else if(node->type_id) { //Parse the pointer operators TypeCompiler tc(session); tc.run(node->type_id->type_specifier); id = IndexedTypeIdentifier(tc.identifier()); //node->type_id->type_specifier->cv if(node->type_id->type_specifier) id.setIsConstant(parseConstVolatile(session, node->type_id->type_specifier->cv) & AbstractType::ConstModifier); if(node->type_id->declarator && node->type_id->declarator->ptr_ops) { const ListNode<PtrOperatorAST*> *it = node->type_id->declarator->ptr_ops->toFront(); const ListNode<PtrOperatorAST*> *end = it; ///@todo check ordering, eventually walk the list in reversed order do { if(it->element && it->element->op) { ///@todo What about ptr-to-member? int kind = session->token_stream->kind(it->element->op); if(kind == '&') { //We're handling a 'reference' id.setIsReference(true); } else if(kind == Token_and) { //We're handling an rvalue-reference id.setIsReference(true); id.setIsRValue(true); } else { //We're handling a real pointer id.setPointerDepth(id.pointerDepth()+1); if(it->element->cv) { id.setIsConstPointer(id.pointerDepth()-1, parseConstVolatile(session, it->element->cv) & AbstractType::ConstModifier); } } } it = it->next; } while (it != end); } else if (node->type_id->declarator && node->type_id->declarator->array_dimensions) { ///FIXME: find a way to put this information into the identifier /// e.g.: id.setArrayDepth(id.arrayDepth() + 1) ? const ListNode< ExpressionAST* >* it = node->type_id->declarator->array_dimensions->toFront(); const ListNode< ExpressionAST* >* end = node->type_id->declarator->array_dimensions-> toBack(); do { QualifiedIdentifier qid = id.identifier(); Identifier last = qid.last(); qid.pop(); last.setIdentifier(last.toString() + "[]"); qid.push(last); id.setIdentifier(IndexedQualifiedIdentifier( qid )); it = it->next; } while (it != end); } } return id; }
QualifiedIdentifier InstantiationInformation::applyToIdentifier(const QualifiedIdentifier& id) const { QualifiedIdentifier ret; if(id.count() > 1) { ret = id; ret.pop(); if(previousInstantiationInformation.index()) ret = previousInstantiationInformation.information().applyToIdentifier(ret); } Identifier lastId(id.last()); KDevVarLengthArray<IndexedTypeIdentifier> oldTemplateIdentifiers; for(uint a = 0; a < lastId.templateIdentifiersCount(); ++a) oldTemplateIdentifiers.append(lastId.templateIdentifier(a)); lastId.clearTemplateIdentifiers(); for(uint a = 0; a < templateParametersSize(); ++a) { if(templateParameters()[a].abstractType()) { lastId.appendTemplateIdentifier(IndexedTypeIdentifier(templateParameters()[a].abstractType()->toString(), true)); }else{ lastId.appendTemplateIdentifier((uint) oldTemplateIdentifiers.size() > a ? oldTemplateIdentifiers[a] : IndexedTypeIdentifier()); } } for(int a = templateParametersSize(); a < oldTemplateIdentifiers.size(); ++a) lastId.appendTemplateIdentifier(oldTemplateIdentifiers[a]); ret.push(lastId); return ret; }
QList<QVariant> DUChainItemData::highlighting() const { DUChainReadLocker lock;; Declaration* decl = m_item.m_item.data(); if(!decl) { return QList<QVariant>(); } if(FunctionDefinition* def = dynamic_cast<FunctionDefinition*>(decl)) { if(def->declaration()) { decl = def->declaration(); } } QTextCharFormat boldFormat; boldFormat.setFontWeight(QFont::Bold); QTextCharFormat normalFormat; int prefixLength = 0; QString signature; TypePtr<FunctionType> function = decl->type<FunctionType>(); if(function) { signature = function->partToString( FunctionType::SignatureArguments ); } //Only highlight the last part of the qualified identifier, so the scope doesn't distract too much QualifiedIdentifier id = decl->qualifiedIdentifier(); QString fullId = id.toString(); QString lastId; if(!id.isEmpty()) { lastId = id.last().toString(); } prefixLength += fullId.length() - lastId.length(); QList<QVariant> ret; ret << 0; ret << prefixLength; ret << QVariant(normalFormat); ret << prefixLength; ret << lastId.length(); ret << QVariant(boldFormat); if(!signature.isEmpty()) { ret << prefixLength + lastId.length(); ret << signature.length(); ret << QVariant(normalFormat); } return ret; }
DeclarationPointer getDeclarationOrSignal(const QualifiedIdentifier& id, const DUContext* context, bool searchInParent) { QString identifier = id.last().toString(); if (identifier.startsWith(QLatin1String("on")) && identifier.size() > 2) { // The use may have typed the name of a QML slot (onFoo), try to get // the declaration of its corresponding signal (foo) identifier = identifier.at(2).toLower() + identifier.mid(3); DeclarationPointer decl = getDeclaration(QualifiedIdentifier(identifier), context, searchInParent); if (decl) { ClassFunctionDeclaration* classFuncDecl = dynamic_cast<ClassFunctionDeclaration *>(decl.data()); if (classFuncDecl && classFuncDecl->isSignal()) { // Removing "on" has given the identifier of a QML signal, return // it instead of the name of its slot return decl; } } } // No signal found, fall back to normal behavior return getDeclaration(id, context, searchInParent); }
void UseBuilder::visitTraitAliasStatement(TraitAliasStatementAst *node) { if (node->conflictIdentifierSequence) { const KDevPG::ListNode< NamespacedIdentifierAst* >* it = node->conflictIdentifierSequence->front(); forever { buildNamespaceUses(it->element, ClassDeclarationType); if ( it->hasNext() ) { it = it->next; } else { break; } } } DUChainWriteLocker lock; DeclarationPointer dec = findDeclarationImport(ClassDeclarationType, identifierForNamespace(node->importIdentifier->identifier, m_editor)); if (dec) { QualifiedIdentifier original = identifierPairForNode(node->importIdentifier->methodIdentifier).second; QList <Declaration*> list = dec.data()->internalContext()->findLocalDeclarations(original.last(), dec.data()->internalContext()->range().start); if (!list.isEmpty()) { UseBuilderBase::newUse(node->importIdentifier->methodIdentifier, DeclarationPointer(list.first())); } } lock.unlock(); visitTraitAliasIdentifier(node->importIdentifier); }