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:
Nikolai Kosjar
2012-10-25 16:22:42 +02:00
parent be516c7c6e
commit 9f38f7bfbc
12 changed files with 103 additions and 23 deletions

View File

@@ -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;
}

View File

@@ -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; }

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -1107,9 +1107,10 @@ public:
return __ast;
}
CaptureAST *Capture()
CaptureAST *Capture(NameAST *identifier = 0)
{
CaptureAST *__ast = new (&pool) CaptureAST;
__ast->identifier = identifier;
return __ast;
}

View File

@@ -1237,6 +1237,7 @@ void LambdaCaptureAST::accept0(ASTVisitor *visitor)
void CaptureAST::accept0(ASTVisitor *visitor)
{
if (visitor->visit(this)) {
accept(identifier, visitor);
}
visitor->endVisit(this);
}

View File

@@ -1069,7 +1069,7 @@ void Bind::capture(CaptureAST *ast)
if (! ast)
return;
// See QTCREATORBUG-7968
name(ast->identifier);
}
bool Bind::visit(LambdaDeclaratorAST *ast)

View File

@@ -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)