diff --git a/src/libs/cplusplus/FindUsages.cpp b/src/libs/cplusplus/FindUsages.cpp index 08b861f012f..88285e2d86a 100644 --- a/src/libs/cplusplus/FindUsages.cpp +++ b/src/libs/cplusplus/FindUsages.cpp @@ -282,7 +282,7 @@ void FindUsages::checkExpression(unsigned startToken, unsigned endToken, Scope * const unsigned begin = tokenAt(startToken).begin(); const unsigned end = tokenAt(endToken).end(); - const QString expression = _source.mid(begin, end - begin); + const QByteArray expression = _source.mid(begin, end - begin); // qDebug() << "*** check expression:" << expression; if (! scope) diff --git a/src/libs/cplusplus/TypeOfExpression.cpp b/src/libs/cplusplus/TypeOfExpression.cpp index 1b564aaeeb4..f6f6159b785 100644 --- a/src/libs/cplusplus/TypeOfExpression.cpp +++ b/src/libs/cplusplus/TypeOfExpression.cpp @@ -71,32 +71,31 @@ void TypeOfExpression::init(Document::Ptr thisDocument, const Snapshot &snapshot m_environment.clear(); } -QList TypeOfExpression::operator()(const QString &expression, +QList TypeOfExpression::operator()(const QByteArray &utf8code, Scope *scope, PreprocessMode mode) { - QString code = expression; - + Document::Ptr expressionDoc; if (mode == Preprocess) - code = preprocessedExpression(expression); - - Document::Ptr expressionDoc = documentForExpression(code); + expressionDoc = documentForExpression(preprocessedExpression(utf8code)); + else + expressionDoc = documentForExpression(utf8code); expressionDoc->check(); return this->operator ()(extractExpressionAST(expressionDoc), expressionDoc, scope); } -QList TypeOfExpression::reference(const QString &expression, + +QList TypeOfExpression::reference(const QByteArray &utf8code, Scope *scope, PreprocessMode mode) { - QString code = expression; - + Document::Ptr expressionDoc; if (mode == Preprocess) - code = preprocessedExpression(expression); - - Document::Ptr expressionDoc = documentForExpression(code); + expressionDoc = documentForExpression(preprocessedExpression(utf8code)); + else + expressionDoc = documentForExpression(utf8code); expressionDoc->check(); return reference(extractExpressionAST(expressionDoc), expressionDoc, scope); } @@ -141,9 +140,9 @@ QList TypeOfExpression::reference(ExpressionAST *expression, return items; } -QString TypeOfExpression::preprocess(const QString &expression) const +QByteArray TypeOfExpression::preprocess(const QByteArray &utf8code) const { - return preprocessedExpression(expression); + return preprocessedExpression(utf8code); } ExpressionAST *TypeOfExpression::ast() const @@ -174,12 +173,11 @@ ExpressionAST *TypeOfExpression::extractExpressionAST(Document::Ptr doc) const return doc->translationUnit()->ast()->asExpression(); } -Document::Ptr TypeOfExpression::documentForExpression(const QString &expression) const +Document::Ptr TypeOfExpression::documentForExpression(const QByteArray &utf8code) const { // create the expression's AST. Document::Ptr doc = Document::create(QLatin1String("")); - const QByteArray bytes = expression.toUtf8(); - doc->setSource(bytes); + doc->setSource(utf8code); doc->parse(Document::ParseExpression); return doc; } @@ -198,10 +196,10 @@ void TypeOfExpression::processEnvironment(Document::Ptr doc, Environment *env, } } -QString TypeOfExpression::preprocessedExpression(const QString &expression) const +QByteArray TypeOfExpression::preprocessedExpression(const QByteArray &utf8code) const { - if (expression.trimmed().isEmpty()) - return expression; + if (utf8code.trimmed().isEmpty()) + return utf8code; if (! m_environment) { Environment *env = new Environment(); // ### cache the environment. @@ -211,9 +209,6 @@ QString TypeOfExpression::preprocessedExpression(const QString &expression) cons m_environment = QSharedPointer(env); } - const QByteArray code = expression.toUtf8(); Preprocessor preproc(0, m_environment.data()); - const QByteArray preprocessedCode = preproc("", code); - return QString::fromUtf8(preprocessedCode.constData(), preprocessedCode.size()); + return preproc("", utf8code); } - diff --git a/src/libs/cplusplus/TypeOfExpression.h b/src/libs/cplusplus/TypeOfExpression.h index bdbfff34646..2cab82f299a 100644 --- a/src/libs/cplusplus/TypeOfExpression.h +++ b/src/libs/cplusplus/TypeOfExpression.h @@ -40,6 +40,7 @@ #include #include #include +#include namespace CPlusPlus { @@ -81,7 +82,7 @@ public: * @param expression The expression to evaluate. * @param scope The scope enclosing the expression. */ - QList operator()(const QString &expression, + QList operator()(const QByteArray &utf8code, Scope *scope, PreprocessMode mode = NoPreprocess); @@ -101,7 +102,7 @@ public: Document::Ptr document, Scope *scope); - QList reference(const QString &expression, + QList reference(const QByteArray &utf8code, Scope *scope, PreprocessMode mode = NoPreprocess); @@ -109,7 +110,7 @@ public: Document::Ptr document, Scope *scope); - QString preprocess(const QString &expression) const; + QByteArray preprocess(const QByteArray &utf8code) const; /** * Returns the AST of the last evaluated expression. @@ -126,12 +127,12 @@ public: private: ExpressionAST *extractExpressionAST(Document::Ptr doc) const; - Document::Ptr documentForExpression(const QString &expression) const; + Document::Ptr documentForExpression(const QByteArray &utf8code) const; void processEnvironment(Document::Ptr doc, Environment *env, QSet *processed) const; - QString preprocessedExpression(const QString &expression) const; + QByteArray preprocessedExpression(const QByteArray &utf8code) const; private: Document::Ptr m_thisDocument; diff --git a/src/plugins/analyzerbase/analyzerutils.cpp b/src/plugins/analyzerbase/analyzerutils.cpp index d0794917fc6..8dbfc80d878 100644 --- a/src/plugins/analyzerbase/analyzerutils.cpp +++ b/src/plugins/analyzerbase/analyzerutils.cpp @@ -109,7 +109,7 @@ CPlusPlus::Symbol *AnalyzerUtils::findSymbolUnderCursor() CPlusPlus::TypeOfExpression typeOfExpression; typeOfExpression.init(doc, snapshot); - const QList &lookupItems = typeOfExpression(expression, scope); + const QList &lookupItems = typeOfExpression(expression.toUtf8(), scope); if (lookupItems.isEmpty()) return 0; diff --git a/src/plugins/cppeditor/cppchecksymbols.cpp b/src/plugins/cppeditor/cppchecksymbols.cpp index b5f5c01df32..e95adfb167f 100644 --- a/src/plugins/cppeditor/cppchecksymbols.cpp +++ b/src/plugins/cppeditor/cppchecksymbols.cpp @@ -508,8 +508,7 @@ bool CheckSymbols::visit(MemberAccessAST *ast) const QByteArray expression = _doc->source().mid(start.begin(), end.end() - start.begin()); const QList candidates = - typeOfExpression(QLatin1String(expression), enclosingScope(), - TypeOfExpression::Preprocess); + typeOfExpression(expression, enclosingScope(), TypeOfExpression::Preprocess); addClassMember(candidates, ast->member_name); } } @@ -534,8 +533,8 @@ bool CheckSymbols::visit(CallAST *ast) const QByteArray expression = textOf(access); const QList candidates = - typeOfExpression(QLatin1String(expression), enclosingScope(), - TypeOfExpression::Preprocess); + typeOfExpression(expression, enclosingScope(), + TypeOfExpression::Preprocess); NameAST *memberName = access->member_name; if (QualifiedNameAST *q = memberName->asQualifiedName()) @@ -552,7 +551,7 @@ bool CheckSymbols::visit(CallAST *ast) exprName = q->unqualified_name; const QList candidates = - typeOfExpression(QLatin1String(textOf(idExpr)), enclosingScope(), + typeOfExpression(textOf(idExpr), enclosingScope(), TypeOfExpression::Preprocess); addVirtualMethod(candidates, exprName, argumentCount); } diff --git a/src/plugins/cppeditor/cppeditor.cpp b/src/plugins/cppeditor/cppeditor.cpp index 6411264261d..88be82d64ff 100644 --- a/src/plugins/cppeditor/cppeditor.cpp +++ b/src/plugins/cppeditor/cppeditor.cpp @@ -362,7 +362,8 @@ struct CanonicalSymbol static Symbol *canonicalSymbol(Scope *scope, const QString &code, TypeOfExpression &typeOfExpression) { - const QList results = typeOfExpression(code, scope, TypeOfExpression::Preprocess); + const QList results = + typeOfExpression(code.toUtf8(), scope, TypeOfExpression::Preprocess); for (int i = results.size() - 1; i != -1; --i) { const LookupItem &r = results.at(i); @@ -1374,7 +1375,8 @@ CPPEditorWidget::Link CPPEditorWidget::findLinkAt(const QTextCursor &cursor, TypeOfExpression typeOfExpression; typeOfExpression.init(doc, snapshot); - const QList resolvedSymbols = typeOfExpression.reference(expression, scope, TypeOfExpression::Preprocess); + const QList resolvedSymbols = + typeOfExpression.reference(expression.toUtf8(), scope, TypeOfExpression::Preprocess); if (!resolvedSymbols.isEmpty()) { LookupItem result = skipForwardDeclarations(resolvedSymbols); diff --git a/src/plugins/cppeditor/cppelementevaluator.cpp b/src/plugins/cppeditor/cppelementevaluator.cpp index bde17af2ff8..8e0c7bb4614 100644 --- a/src/plugins/cppeditor/cppelementevaluator.cpp +++ b/src/plugins/cppeditor/cppelementevaluator.cpp @@ -121,7 +121,7 @@ void CppElementEvaluator::execute() TypeOfExpression typeOfExpression; typeOfExpression.init(doc, snapshot); - const QList &lookupItems = typeOfExpression(expression, scope); + const QList &lookupItems = typeOfExpression(expression.toUtf8(), scope); if (lookupItems.isEmpty()) return; diff --git a/src/plugins/cppeditor/cppfunctiondecldeflink.cpp b/src/plugins/cppeditor/cppfunctiondecldeflink.cpp index fa6f9442c41..d6fb74bf5fb 100644 --- a/src/plugins/cppeditor/cppfunctiondecldeflink.cpp +++ b/src/plugins/cppeditor/cppfunctiondecldeflink.cpp @@ -575,7 +575,8 @@ Utils::ChangeSet FunctionDeclDefLink::changes(const Snapshot &snapshot, int targ newDeclText[i] = QLatin1Char('\n'); } newDeclText.append(QLatin1String("{}")); - const QString newDeclTextPreprocessed = typeOfExpression.preprocess(newDeclText); + const QString newDeclTextPreprocessed = + QString::fromUtf8(typeOfExpression.preprocess(newDeclText.toUtf8())); Document::Ptr newDeclDoc = Document::create(QLatin1String("")); newDeclDoc->setSource(newDeclTextPreprocessed.toUtf8()); diff --git a/src/plugins/cppeditor/cppquickfixes.cpp b/src/plugins/cppeditor/cppquickfixes.cpp index 86ec09f5815..34844936e88 100644 --- a/src/plugins/cppeditor/cppquickfixes.cpp +++ b/src/plugins/cppeditor/cppquickfixes.cpp @@ -1681,9 +1681,10 @@ private: typeOfExpression.init(assistInterface()->semanticInfo().doc, assistInterface()->snapshot(), assistInterface()->context().bindings()); Scope *scope = currentFile->scopeAt(binaryAST->firstToken()); - const QList result = typeOfExpression(currentFile->textOf(binaryAST->right_expression), - scope, - TypeOfExpression::Preprocess); + const QList result = + typeOfExpression(currentFile->textOf(binaryAST->right_expression).toUtf8(), + scope, + TypeOfExpression::Preprocess); if (! result.isEmpty()) { diff --git a/src/plugins/cpptools/cppcompletionassist.cpp b/src/plugins/cpptools/cppcompletionassist.cpp index bd551469e15..ca17afe2ce7 100644 --- a/src/plugins/cpptools/cppcompletionassist.cpp +++ b/src/plugins/cpptools/cppcompletionassist.cpp @@ -1051,7 +1051,7 @@ bool CppCompletionAssistProcessor::tryObjCCompletion() if (!scope) return false; - const QList items = (*m_model->m_typeOfExpression)(expr, scope); + const QList items = (*m_model->m_typeOfExpression)(expr.toUtf8(), scope); LookupContext lookupContext(thisDocument, m_interface->snapshot()); foreach (const LookupItem &item, items) { @@ -1254,7 +1254,7 @@ int CppCompletionAssistProcessor::startCompletionInternal(const QString fileName if (expression.isEmpty()) { if (m_model->m_completionOperator == T_EOF_SYMBOL || m_model->m_completionOperator == T_COLON_COLON) { - (void) (*m_model->m_typeOfExpression)(expression, scope); + (void) (*m_model->m_typeOfExpression)(expression.toUtf8(), scope); globalCompletion(scope); if (m_completions.isEmpty()) return -1; @@ -1267,14 +1267,15 @@ int CppCompletionAssistProcessor::startCompletionInternal(const QString fileName } } + QByteArray utf8Exp = expression.toUtf8(); QList results = - (*m_model->m_typeOfExpression)(expression, scope, TypeOfExpression::Preprocess); + (*m_model->m_typeOfExpression)(utf8Exp, scope, TypeOfExpression::Preprocess); if (results.isEmpty()) { if (m_model->m_completionOperator == T_SIGNAL || m_model->m_completionOperator == T_SLOT) { if (! (expression.isEmpty() || expression == QLatin1String("this"))) { expression = QLatin1String("this"); - results = (*m_model->m_typeOfExpression)(expression, scope); + results = (*m_model->m_typeOfExpression)(utf8Exp, scope); } if (results.isEmpty()) @@ -1295,7 +1296,7 @@ int CppCompletionAssistProcessor::startCompletionInternal(const QString fileName // Resolve the type of this expression const QList results = - (*m_model->m_typeOfExpression)(baseExpression, scope, + (*m_model->m_typeOfExpression)(baseExpression.toUtf8(), scope, TypeOfExpression::Preprocess); // If it's a class, add completions for the constructors diff --git a/src/plugins/qmljstools/qmljsfindexportedcpptypes.cpp b/src/plugins/qmljstools/qmljsfindexportedcpptypes.cpp index ed5b2974e30..e266f76b112 100644 --- a/src/plugins/qmljstools/qmljsfindexportedcpptypes.cpp +++ b/src/plugins/qmljstools/qmljsfindexportedcpptypes.cpp @@ -506,7 +506,7 @@ static QString toQmlType(const FullySpecifiedType &type) static Class *lookupClass(const QString &expression, Scope *scope, TypeOfExpression &typeOf) { - QList results = typeOf(expression, scope); + QList results = typeOf(expression.toUtf8(), scope); Class *klass = 0; foreach (const LookupItem &item, results) { if (item.declaration()) { @@ -576,7 +576,7 @@ static LanguageUtils::FakeMetaObject::Ptr buildFakeMetaObject( if (QtEnum *qtEnum = member->asQtEnum()) { // find the matching enum Enum *e = 0; - QList result = typeOf(namePrinter(qtEnum->name()), klass); + QList result = typeOf(namePrinter(qtEnum->name()).toUtf8(), klass); foreach (const LookupItem &item, result) { if (item.declaration()) { e = item.declaration()->asEnum(); @@ -648,7 +648,7 @@ static void buildContextProperties( foreach (const ContextProperty &property, contextPropertyDescriptions) { Scope *scope = doc->scopeAt(property.line, property.column); - QList results = typeOf(property.expression, scope); + QList results = typeOf(property.expression.toUtf8(), scope); QString typeName; if (!results.isEmpty()) { LookupItem result = results.first();