forked from qt-creator/qt-creator
C++: Store lambda captures in the code model.
Done-with: Erik Verbruggen Task-number: QTCREATORBUG-7968 Task-number: QTCREATORBUG-7949 Change-Id: I0cf727052d0a3536ed96ee894b18768c9538c213 Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
This commit is contained in:
10
src/libs/3rdparty/cplusplus/AST.cpp
vendored
10
src/libs/3rdparty/cplusplus/AST.cpp
vendored
@@ -403,12 +403,22 @@ unsigned CallAST::lastToken() const
|
||||
/** \generated */
|
||||
unsigned CaptureAST::firstToken() const
|
||||
{
|
||||
if (amper_token)
|
||||
return amper_token;
|
||||
if (identifier)
|
||||
if (unsigned candidate = identifier->firstToken())
|
||||
return candidate;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** \generated */
|
||||
unsigned CaptureAST::lastToken() const
|
||||
{
|
||||
if (identifier)
|
||||
if (unsigned candidate = identifier->lastToken())
|
||||
return candidate;
|
||||
if (amper_token)
|
||||
return amper_token + 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
6
src/libs/3rdparty/cplusplus/AST.h
vendored
6
src/libs/3rdparty/cplusplus/AST.h
vendored
@@ -4394,8 +4394,14 @@ protected:
|
||||
|
||||
class CaptureAST: public AST
|
||||
{
|
||||
public:
|
||||
unsigned amper_token;
|
||||
NameAST *identifier;
|
||||
|
||||
public:
|
||||
CaptureAST()
|
||||
: amper_token(0)
|
||||
, identifier(0)
|
||||
{}
|
||||
|
||||
virtual CaptureAST *asCapture() { return this; }
|
||||
|
||||
3
src/libs/3rdparty/cplusplus/ASTClone.cpp
vendored
3
src/libs/3rdparty/cplusplus/ASTClone.cpp
vendored
@@ -1703,6 +1703,9 @@ LambdaCaptureAST *LambdaCaptureAST::clone(MemoryPool *pool) const
|
||||
CaptureAST *CaptureAST::clone(MemoryPool *pool) const
|
||||
{
|
||||
CaptureAST *ast = new (pool) CaptureAST;
|
||||
ast->amper_token = amper_token;
|
||||
if (identifier)
|
||||
ast->identifier = identifier->clone(pool);
|
||||
return ast;
|
||||
}
|
||||
|
||||
|
||||
7
src/libs/3rdparty/cplusplus/ASTMatcher.cpp
vendored
7
src/libs/3rdparty/cplusplus/ASTMatcher.cpp
vendored
@@ -2898,6 +2898,13 @@ bool ASTMatcher::match(CaptureAST *node, CaptureAST *pattern)
|
||||
(void) node;
|
||||
(void) pattern;
|
||||
|
||||
pattern->amper_token = node->amper_token;
|
||||
|
||||
if (! pattern->identifier)
|
||||
pattern->identifier = node->identifier;
|
||||
else if (! AST::match(node->identifier, pattern->identifier, this))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -1107,9 +1107,10 @@ public:
|
||||
return __ast;
|
||||
}
|
||||
|
||||
CaptureAST *Capture()
|
||||
CaptureAST *Capture(NameAST *identifier = 0)
|
||||
{
|
||||
CaptureAST *__ast = new (&pool) CaptureAST;
|
||||
__ast->identifier = identifier;
|
||||
return __ast;
|
||||
}
|
||||
|
||||
|
||||
1
src/libs/3rdparty/cplusplus/ASTVisit.cpp
vendored
1
src/libs/3rdparty/cplusplus/ASTVisit.cpp
vendored
@@ -1237,6 +1237,7 @@ void LambdaCaptureAST::accept0(ASTVisitor *visitor)
|
||||
void CaptureAST::accept0(ASTVisitor *visitor)
|
||||
{
|
||||
if (visitor->visit(this)) {
|
||||
accept(identifier, visitor);
|
||||
}
|
||||
visitor->endVisit(this);
|
||||
}
|
||||
|
||||
2
src/libs/3rdparty/cplusplus/Bind.cpp
vendored
2
src/libs/3rdparty/cplusplus/Bind.cpp
vendored
@@ -1069,7 +1069,7 @@ void Bind::capture(CaptureAST *ast)
|
||||
if (! ast)
|
||||
return;
|
||||
|
||||
// See QTCREATORBUG-7968
|
||||
name(ast->identifier);
|
||||
}
|
||||
|
||||
bool Bind::visit(LambdaDeclaratorAST *ast)
|
||||
|
||||
43
src/libs/3rdparty/cplusplus/Parser.cpp
vendored
43
src/libs/3rdparty/cplusplus/Parser.cpp
vendored
@@ -6294,43 +6294,56 @@ bool Parser::parseLambdaCapture(LambdaCaptureAST *&node)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Parser::parseCapture(CaptureAST *&)
|
||||
bool Parser::parseCapture(CaptureAST *&node)
|
||||
{
|
||||
// See QTCREATORBUG-7968
|
||||
|
||||
DEBUG_THIS_RULE();
|
||||
|
||||
if (LA() == T_THIS) {
|
||||
consumeToken();
|
||||
return true;
|
||||
}
|
||||
|
||||
if (LA() == T_AMPER)
|
||||
consumeToken();
|
||||
|
||||
if (LA() == T_IDENTIFIER) {
|
||||
consumeToken();
|
||||
return true;
|
||||
SimpleNameAST *ast = new (_pool) SimpleNameAST;
|
||||
ast->identifier_token = consumeToken();
|
||||
|
||||
} else if (LA() == T_AMPER && LA(2) == T_IDENTIFIER) {
|
||||
consumeToken();
|
||||
consumeToken();
|
||||
return true;
|
||||
|
||||
} else if (LA() == T_THIS) {
|
||||
consumeToken();
|
||||
node = new (_pool) CaptureAST;
|
||||
node->identifier = ast;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Parser::parseCaptureList(CaptureListAST *&)
|
||||
bool Parser::parseCaptureList(CaptureListAST *&node)
|
||||
{
|
||||
DEBUG_THIS_RULE();
|
||||
|
||||
CaptureAST *capture = 0;
|
||||
|
||||
if (parseCapture(capture)) {
|
||||
node = new (_pool) CaptureListAST;
|
||||
node->value = capture;
|
||||
|
||||
CaptureListAST **l = &node->next;
|
||||
while (LA() == T_COMMA) {
|
||||
consumeToken(); // consume `,'
|
||||
|
||||
CaptureAST *capture = 0;
|
||||
parseCapture(capture);
|
||||
if (capture) {
|
||||
*l = new (_pool) CaptureListAST;
|
||||
(*l)->value = capture;
|
||||
l = &(*l)->next;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Parser::parseLambdaDeclarator(LambdaDeclaratorAST *&node)
|
||||
|
||||
Reference in New Issue
Block a user