diff --git a/duchain/declarationbuilder.h b/duchain/declarationbuilder.h --- a/duchain/declarationbuilder.h +++ b/duchain/declarationbuilder.h @@ -117,7 +117,7 @@ template T* visitVariableDeclaration(Python::Ast* node, Declaration* previous=nullptr, AbstractType::Ptr type = AbstractType::Ptr(), VisitVariableFlags flags=NoVisitVariableFlags); - template T* visitVariableDeclaration(Identifier* node, Ast* originalAst = nullptr, Declaration* previous=nullptr, + template T* visitVariableDeclaration(Identifier* node, Declaration* previous=nullptr, AbstractType::Ptr type = AbstractType::Ptr(), VisitVariableFlags flags=NoVisitVariableFlags); @@ -207,8 +207,7 @@ * @brief python-specific version of openDeclaration which scans for existing declarations in previous versions of * this top-context in a more intelligent way. * Use this in normal declaratonbuilder code if you can't use visitVariableDeclaration. */ - template T* eventuallyReopenDeclaration(Python::Identifier* name, Python::Ast* range, - FitDeclarationType mustFitType); + template T* eventuallyReopenDeclaration(Python::Identifier* name, FitDeclarationType mustFitType); template QList reopenFittingDeclaration(QList declarations, FitDeclarationType mustFitType, @@ -259,16 +258,10 @@ Declaration* findDeclarationInContext(QStringList dottedNameIdentifier, TopDUContext* ctx) const; private: - template T* openDeclaration(Identifier* name, Ast* range, DeclarationFlags flags = NoFlags) + template T* openDeclaration(Identifier* name, DeclarationFlags flags = NoFlags) { - T* decl = DeclarationBuilderBase::openDeclaration(name, range, flags); - decl->setAlwaysForceDirect(true); - return decl; - }; - template T* openDeclaration(const QualifiedIdentifier& id, const RangeInRevision& newRange, - DeclarationFlags flags = NoFlags) - { - T* decl = DeclarationBuilderBase::openDeclaration(id, newRange, flags); + T* decl = DeclarationBuilderBase::openDeclaration(KDevelop::Identifier(name->value), + editorFindRange(name, name), flags); decl->setAlwaysForceDirect(true); return decl; }; diff --git a/duchain/declarationbuilder.cpp b/duchain/declarationbuilder.cpp --- a/duchain/declarationbuilder.cpp +++ b/duchain/declarationbuilder.cpp @@ -124,15 +124,15 @@ DeclarationBuilderBase::closeDeclaration(); } -template T* DeclarationBuilder::eventuallyReopenDeclaration(Identifier* name, Ast* range, FitDeclarationType mustFitType) +template T* DeclarationBuilder::eventuallyReopenDeclaration(Identifier* name, FitDeclarationType mustFitType) { QList existingDeclarations = existingDeclarationsForNode(name); - + Declaration* dec = nullptr; - reopenFittingDeclaration(existingDeclarations, mustFitType, editorFindRange(range, range), &dec); + reopenFittingDeclaration(existingDeclarations, mustFitType, editorFindRange(name, name), &dec); bool declarationOpened = (bool) dec; if ( ! declarationOpened ) { - dec = openDeclaration(name, range); + dec = openDeclaration(name); } Q_ASSERT(dynamic_cast(dec)); return static_cast(dec); @@ -150,11 +150,10 @@ if ( currentVariableDefinition->context != ExpressionAst::Context::Store ) { return nullptr; } - Identifier* id = currentVariableDefinition->identifier; - return visitVariableDeclaration(id, currentVariableDefinition, previous, type, flags); + return visitVariableDeclaration(currentVariableDefinition->identifier, previous, type, flags); } else if ( node->astType == Ast::IdentifierAstType ) { - return visitVariableDeclaration(static_cast(node), nullptr, previous, type, flags); + return visitVariableDeclaration(static_cast(node), previous, type, flags); } else { qCWarning(KDEV_PYTHON_DUCHAIN) << "cannot create variable declaration for non-(name|identifier) AST, this is a programming error"; @@ -227,13 +226,11 @@ return remainingDeclarations; } -template T* DeclarationBuilder::visitVariableDeclaration(Identifier* node, Ast* originalAst, Declaration* previous, +template T* DeclarationBuilder::visitVariableDeclaration(Identifier* node, Declaration* previous, AbstractType::Ptr type, VisitVariableFlags flags) { DUChainWriteLocker lock; - Ast* rangeNode = originalAst ? originalAst : node; - RangeInRevision range = editorFindRange(rangeNode, rangeNode); - + RangeInRevision range = editorFindRange(node, node); // ask the correction file library if there's a user-specified type for this object if ( AbstractType::Ptr hint = m_correctionHelper->hintForLocal(node->value) ) { type = hint; @@ -279,7 +276,7 @@ if ( currentContext() && currentContext()->type() == DUContext::Class && ! haveFittingDeclaration ) { // If the current context is a class, then this is a class member variable. if ( ! dec ) { - dec = openDeclaration(identifierForNode(node), range); + dec = openDeclaration(node); Q_ASSERT(! declarationOpened); declarationOpened = true; } @@ -292,7 +289,7 @@ // This name did not previously appear in the user code, so a new variable is declared // check whether a declaration from a previous parser pass must be updated if ( ! dec ) { - dec = openDeclaration(identifierForNode(node), range); + dec = openDeclaration(node); Q_ASSERT(! declarationOpened); declarationOpened = true; } @@ -573,7 +570,6 @@ ) { aliasDeclaration = Helper::resolveAliasDeclaration(aliasDeclaration); AliasDeclaration* adecl = eventuallyReopenDeclaration(&temporaryIdentifier, - &temporaryIdentifier, AliasDeclarationType); if ( adecl ) { adecl->setAliasedDeclaration(aliasDeclaration); @@ -1094,8 +1090,7 @@ { if ( element.isAlias ) { DUChainWriteLocker lock; - Python::Identifier* identifier = target->identifier; - AliasDeclaration* decl = eventuallyReopenDeclaration(identifier, target, AliasDeclarationType); + AliasDeclaration* decl = eventuallyReopenDeclaration(target->identifier, AliasDeclarationType); decl->setAliasedDeclaration(element.declaration.data()); closeDeclaration(); } @@ -1191,7 +1186,7 @@ if ( isAlreadyOpen ) { activateAlreadyOpenedContext(internal); visitVariableDeclaration( - attrib->attribute, attrib, attributeDeclaration, element.type, AbortIfReopenMismatch + attrib->attribute, attributeDeclaration, element.type, AbortIfReopenMismatch ); closeAlreadyOpenedContext(internal); } @@ -1199,7 +1194,7 @@ injectContext(internal.data()); Declaration* dec = visitVariableDeclaration( - attrib->attribute, attrib, attributeDeclaration, element.type, AbortIfReopenMismatch + attrib->attribute, attributeDeclaration, element.type, AbortIfReopenMismatch ); if ( dec ) { dec->setRange(RangeInRevision(internal->range().start, internal->range().start)); @@ -1350,7 +1345,7 @@ StructureType::Ptr type(new StructureType()); DUChainWriteLocker lock; - ClassDeclaration* dec = eventuallyReopenDeclaration(node->name, node->name, NoTypeRequired); + ClassDeclaration* dec = eventuallyReopenDeclaration(node->name, NoTypeRequired); eventuallyAssignInternalContext(); dec->setKind(KDevelop::Declaration::Type); @@ -1443,7 +1438,7 @@ FunctionType::Ptr type(new FunctionType()); DUChainWriteLocker lock; - FunctionDeclaration* dec = eventuallyReopenDeclaration(node->name, node->name, + FunctionDeclaration* dec = eventuallyReopenDeclaration(node->name, FunctionDeclarationType); Q_ASSERT(dec->isFunctionDeclaration()); @@ -1746,7 +1741,7 @@ if ( currentIndex == 1 && workingOnDeclaration->isClassMethod() ) { DUChainWriteLocker lock; AliasDeclaration* decl = eventuallyReopenDeclaration(arg->argumentName, - arg, AliasDeclarationType); + AliasDeclarationType); if ( ! m_currentClassTypes.isEmpty() ) { auto classDecl = m_currentClassTypes.last()->declaration(topContext()); @@ -1858,7 +1853,7 @@ DUChainWriteLocker lock; QList< Declaration* > existing = top->findLocalDeclarations(qid.first()); if ( ! existing.empty() ) { - AliasDeclaration* ndec = openDeclaration(id, node); + AliasDeclaration* ndec = openDeclaration(id); ndec->setAliasedDeclaration(existing.first()); closeDeclaration(); } @@ -1868,7 +1863,7 @@ dec->setRange(editorFindRange(id, id)); dec->setAutoDeclaration(true); closeContext(); - AliasDeclaration* ndec = openDeclaration(id, node); + AliasDeclaration* ndec = openDeclaration(id); ndec->setAliasedDeclaration(dec); closeDeclaration(); }