diff options
author | Roberto Raggi <roberto.raggi@nokia.com> | 2010-06-23 14:38:41 +0200 |
---|---|---|
committer | Roberto Raggi <roberto.raggi@nokia.com> | 2010-06-23 14:39:14 +0200 |
commit | da817310c2c07a107d21e743370a09d4adfc4852 (patch) | |
tree | ac7efd8d5e9bebf5dd3dbf9a4b3e385a6bc44376 /src/plugins/cppeditor | |
parent | ed2862acce3f22bd1d7c83203eb445696426d438 (diff) | |
download | qt-creator-da817310c2c07a107d21e743370a09d4adfc4852.tar.gz |
Get rid of PostfixExpressionAST and store the base expression together with the PostfixAST nodes.
Diffstat (limited to 'src/plugins/cppeditor')
-rw-r--r-- | src/plugins/cppeditor/cppeditor.cpp | 10 | ||||
-rw-r--r-- | src/plugins/cppeditor/cppquickfix.cpp | 95 |
2 files changed, 43 insertions, 62 deletions
diff --git a/src/plugins/cppeditor/cppeditor.cpp b/src/plugins/cppeditor/cppeditor.cpp index 2fba70c6de..a078ee72ff 100644 --- a/src/plugins/cppeditor/cppeditor.cpp +++ b/src/plugins/cppeditor/cppeditor.cpp @@ -346,15 +346,11 @@ protected: return false; } - virtual bool visit(PostfixExpressionAST *ast) + virtual bool visit(MemberAccessAST *ast) { + // accept only the base expression accept(ast->base_expression); - for (PostfixListAST *it = ast->postfix_expression_list; it; it = it->next) { - PostfixAST *fx = it->value; - if (fx->asMemberAccess() != 0) - continue; // skip members - accept(fx); - } + // and ignore the member name. return false; } diff --git a/src/plugins/cppeditor/cppquickfix.cpp b/src/plugins/cppeditor/cppquickfix.cpp index b0dadc8260..f4baa73299 100644 --- a/src/plugins/cppeditor/cppquickfix.cpp +++ b/src/plugins/cppeditor/cppquickfix.cpp @@ -783,40 +783,32 @@ public: virtual int match(const QList<AST *> &path) { + stringLiteral = 0; + isObjCStringLiteral = false; + if (path.isEmpty()) - return -1; + return -1; // nothing to do - int index = path.size() - 1; - stringLiteral = path[index]->asStringLiteral(); + stringLiteral = path.last()->asStringLiteral(); - if (!stringLiteral) + if (! stringLiteral) return -1; - isObjCStringLiteral = charAt(startOf(stringLiteral)) == QLatin1Char('@'); - - // check if it is already wrapped in QLatin1String or -Literal - if (index-2 < 0) - return index; + else if (path.size() > 1) { + if (CallAST *call = path.at(path.size() - 2)->asCall()) { + if (call->base_expression) { + if (SimpleNameAST *functionName = call->base_expression->asSimpleName()) { + const QByteArray id(tokenAt(functionName->identifier_token).identifier->chars()); - CallAST *call = path[index-1]->asCall(); - PostfixExpressionAST *postfixExp = path[index-2]->asPostfixExpression(); - if (call && postfixExp - && postfixExp->base_expression - && postfixExp->postfix_expression_list - && postfixExp->postfix_expression_list->value == call) - { - NameAST *callName = postfixExp->base_expression->asName(); - if (!callName) - return index; - - QByteArray callNameString(tokenAt(callName->firstToken()).spell()); - if (callNameString == "QLatin1String" - || callNameString == "QLatin1Literal" - ) - return -1; + if (id == "QLatin1String" || id == "QLatin1Literal") + return -1; // skip it + } + } + } } - return index; + isObjCStringLiteral = charAt(startOf(stringLiteral)) == QLatin1Char('@'); + return path.size() - 1; // very high priority } virtual void createChanges() @@ -845,7 +837,9 @@ class CStringToNSString: public CppQuickFixOperation { public: CStringToNSString(TextEditor::BaseTextEditor *editor) - : CppQuickFixOperation(editor), stringLiteral(0), qlatin1Call(0) + : CppQuickFixOperation(editor) + , stringLiteral(0) + , qlatin1Call(0) {} virtual QString description() const @@ -855,43 +849,34 @@ public: virtual int match(const QList<AST *> &path) { + stringLiteral = 0; + qlatin1Call = 0; + if (path.isEmpty()) - return -1; + return -1; // nothing to do - int index = path.size() - 1; - stringLiteral = path[index]->asStringLiteral(); + stringLiteral = path.last()->asStringLiteral(); - if (!stringLiteral) + if (! stringLiteral) return -1; - if (charAt(startOf(stringLiteral)) == QLatin1Char('@')) - return -1; + else if (charAt(startOf(stringLiteral)) == QLatin1Char('@')) + return -1; // it's already an objc string literal. - // check if it is already wrapped in QLatin1String or -Literal - if (index-2 < 0) - return index; - - CallAST *call = path[index-1]->asCall(); - PostfixExpressionAST *postfixExp = path[index-2]->asPostfixExpression(); - if (call && postfixExp - && postfixExp->base_expression - && postfixExp->postfix_expression_list - && postfixExp->postfix_expression_list->value == call) - { - NameAST *callName = postfixExp->base_expression->asName(); - if (!callName) - return index; + else if (path.size() > 1) { + if (CallAST *call = path.at(path.size() - 2)->asCall()) { + if (call->base_expression) { + if (SimpleNameAST *functionName = call->base_expression->asSimpleName()) { + const QByteArray id(tokenAt(functionName->identifier_token).identifier->chars()); - if (!(postfixExp->postfix_expression_list->next)) { - QByteArray callNameString(tokenAt(callName->firstToken()).spell()); - if (callNameString == "QLatin1String" - || callNameString == "QLatin1Literal" - ) - qlatin1Call = postfixExp; + if (id == "QLatin1String" || id == "QLatin1Literal") + qlatin1Call = call; + } + } } } - return index; + return path.size() - 1; // very high priority } virtual void createChanges() @@ -910,7 +895,7 @@ public: private: StringLiteralAST *stringLiteral; - PostfixExpressionAST *qlatin1Call; + CallAST *qlatin1Call; }; } // end of anonymous namespace |