// Resolves auto and decltype initializer string QList<LookupItem> TypeResolver::resolveDeclInitializer( CreateBindings &factory, const Declaration *decl, const QSet<const Declaration* > &declarationsBeingResolved, const Identifier *id) { const StringLiteral *initializationString = decl->getInitializer(); if (initializationString == 0) return QList<LookupItem>(); const QByteArray &initializer = QByteArray::fromRawData(initializationString->chars(), initializationString->size()).trimmed(); // Skip lambda-function initializers if (initializer.length() > 0 && initializer[0] == '[') return QList<LookupItem>(); TypeOfExpression exprTyper; exprTyper.setExpandTemplates(true); Document::Ptr doc = factory.snapshot().document(QString::fromLocal8Bit(decl->fileName())); exprTyper.init(doc, factory.snapshot(), factory.sharedFromThis(), declarationsBeingResolved); Document::Ptr exprDoc = documentForExpression(exprTyper.preprocessedExpression(initializer)); factory.addExpressionDocument(exprDoc); exprDoc->check(); if (id) { DeduceAutoCheck deduceAuto(id, exprDoc->translationUnit()); if (deduceAuto._block) return QList<LookupItem>(); } return exprTyper(extractExpressionAST(exprDoc), exprDoc, decl->enclosingScope()); }
// @todo: Consider refactoring code from CPPEditor::findLinkAt into here. void CppElementEvaluator::execute() { clear(); if (!m_modelManager) return; const Snapshot &snapshot = m_modelManager->snapshot(); Document::Ptr doc = snapshot.document(m_editor->editorDocument()->fileName()); if (!doc) return; int line = 0; int column = 0; const int pos = m_tc.position(); m_editor->convertPosition(pos, &line, &column); checkDiagnosticMessage(pos); if (!matchIncludeFile(doc, line) && !matchMacroInUse(doc, pos)) { CppTools::moveCursorToEndOfIdentifier(&m_tc); // Fetch the expression's code ExpressionUnderCursor expressionUnderCursor; const QString &expression = expressionUnderCursor(m_tc); Scope *scope = doc->scopeAt(line, column); TypeOfExpression typeOfExpression; typeOfExpression.init(doc, snapshot); // make possible to instantiate templates typeOfExpression.setExpandTemplates(true); const QList<LookupItem> &lookupItems = typeOfExpression(expression.toUtf8(), scope); if (lookupItems.isEmpty()) return; const LookupItem &lookupItem = lookupItems.first(); // ### TODO: select best candidate. handleLookupItemMatch(snapshot, lookupItem, typeOfExpression.context()); } }