diff options
author | Nikolai Kosjar <nikolai.kosjar@digia.com> | 2014-06-26 15:07:31 -0400 |
---|---|---|
committer | Nikolai Kosjar <nikolai.kosjar@digia.com> | 2014-07-04 12:35:13 +0200 |
commit | 8ff225d9d6ab6f5ebc0872cccd96b05b19312d04 (patch) | |
tree | ec09ec16151b074f9ad96d6c06f00c9bf0699b7a | |
parent | 995d1f777f3dd0481a676815ea7622461da6f92f (diff) | |
download | qt-creator-8ff225d9d6ab6f5ebc0872cccd96b05b19312d04.tar.gz |
C++: Fix (Find)LocalSymbols for lambda parameters
Change-Id: I5cb69749b4f15e4f70dea410aa6f943c4189c502
Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
-rw-r--r-- | src/libs/3rdparty/cplusplus/AST.h | 3 | ||||
-rw-r--r-- | src/libs/3rdparty/cplusplus/Bind.cpp | 1 | ||||
-rw-r--r-- | src/plugins/cpptools/cpplocalsymbols.cpp | 13 | ||||
-rw-r--r-- | src/plugins/cpptools/cpplocalsymbols_test.cpp | 12 |
4 files changed, 29 insertions, 0 deletions
diff --git a/src/libs/3rdparty/cplusplus/AST.h b/src/libs/3rdparty/cplusplus/AST.h index d102db0fe0..76213cc2c3 100644 --- a/src/libs/3rdparty/cplusplus/AST.h +++ b/src/libs/3rdparty/cplusplus/AST.h @@ -4455,6 +4455,9 @@ public: ExceptionSpecificationAST *exception_specification; TrailingReturnTypeAST *trailing_return_type; +public: // annotations + Function *symbol; + public: LambdaDeclaratorAST() : lparen_token(0) diff --git a/src/libs/3rdparty/cplusplus/Bind.cpp b/src/libs/3rdparty/cplusplus/Bind.cpp index 7fd65e24d4..e6245eb036 100644 --- a/src/libs/3rdparty/cplusplus/Bind.cpp +++ b/src/libs/3rdparty/cplusplus/Bind.cpp @@ -1098,6 +1098,7 @@ Function *Bind::lambdaDeclarator(LambdaDeclaratorAST *ast) if (ast->trailing_return_type) _type = this->trailingReturnType(ast->trailing_return_type, _type); fun->setReturnType(_type); + ast->symbol = fun; // unsigned lparen_token = ast->lparen_token; FullySpecifiedType type; diff --git a/src/plugins/cpptools/cpplocalsymbols.cpp b/src/plugins/cpptools/cpplocalsymbols.cpp index 18606167a7..e491589fc6 100644 --- a/src/plugins/cpptools/cpplocalsymbols.cpp +++ b/src/plugins/cpptools/cpplocalsymbols.cpp @@ -175,6 +175,19 @@ protected: _scopeStack.removeLast(); } + virtual bool visit(LambdaExpressionAST *ast) + { + if (ast->lambda_declarator && ast->lambda_declarator->symbol) + enterScope(ast->lambda_declarator->symbol); + return true; + } + + virtual void endVisit(LambdaExpressionAST *ast) + { + if (ast->lambda_declarator && ast->lambda_declarator->symbol) + _scopeStack.removeLast(); + } + virtual bool visit(CompoundStatementAST *ast) { if (ast->symbol) diff --git a/src/plugins/cpptools/cpplocalsymbols_test.cpp b/src/plugins/cpptools/cpplocalsymbols_test.cpp index eb986b8430..2a238755dd 100644 --- a/src/plugins/cpptools/cpplocalsymbols_test.cpp +++ b/src/plugins/cpptools/cpplocalsymbols_test.cpp @@ -157,6 +157,18 @@ void CppToolsPlugin::test_cpplocalsymbols_data() << Result(_("local"), 3, 8, 5) << Result(_("local"), 4, 12, 5) << Result(_("arg"), 4, 20, 3)); + + QTest::newRow("lambda") + << _("void f()\n" + "{\n" + " auto func = [](int arg) { return arg; };\n" + " func(1);\n" + "}\n") + << (QList<Result>() + << Result(_("func"), 2, 10, 4) + << Result(_("arg"), 2, 24, 3) + << Result(_("arg"), 2, 38, 3) + << Result(_("func"), 3, 5, 4)); } void CppToolsPlugin::test_cpplocalsymbols() |