forked from qt-creator/qt-creator
C++: code completion for lambda calls
support for lambdas, e.g.:
struct S { int bar; };
[]() { return new S; } ()->bar;
[] { return new S; } ()->bar;
[]() ->S* { return new S(); } ()->bar;
[]() throw() { return new S(); } ()->bar;
[]() throw()->S* { return new S(); } ()->bar;
Task-number: QTCREATORBUG-9523
Change-Id: I43fbf6f0ee0bb11411c53c984df75ef33a276466
Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
This commit is contained in:
committed by
Erik Verbruggen
parent
ab15d38726
commit
46461fc183
@@ -176,6 +176,30 @@ int ExpressionUnderCursor::startOfExpression_helper(BackwardsScanner &tk, int in
|
||||
else if (tk[lessIndex - 1].is(T_SLOT))
|
||||
return startOfExpression(tk, lessIndex);
|
||||
}
|
||||
} else if (tk[matchingBraceIndex - 1].is(T_RBRACE)) {
|
||||
// lambda: [](){} ()
|
||||
int leftBraceIndex = tk.startOfMatchingBrace(matchingBraceIndex);
|
||||
if (matchingBraceIndex != leftBraceIndex) {
|
||||
int currentIndex = leftBraceIndex;
|
||||
while (currentIndex >= 0) {
|
||||
if (tk[currentIndex-1].is(T_RPAREN)) {
|
||||
int leftParenIndex = tk.startOfMatchingBrace(currentIndex);
|
||||
if (tk[leftParenIndex-1].is(T_THROW)) {
|
||||
currentIndex = leftParenIndex-1;
|
||||
} else if (tk[leftParenIndex-1].is(T_RBRACKET)) {
|
||||
int leftBracketIndex = tk.startOfMatchingBrace(leftParenIndex);
|
||||
if (leftBracketIndex != leftParenIndex-1)
|
||||
return leftBracketIndex;
|
||||
}
|
||||
} else if (tk[currentIndex-1].is(T_RBRACKET)) {
|
||||
int leftBracketIndex = tk.startOfMatchingBrace(currentIndex);
|
||||
if (leftBracketIndex != currentIndex-1)
|
||||
return leftBracketIndex;
|
||||
} else {
|
||||
--currentIndex;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return startOfExpression(tk, matchingBraceIndex);
|
||||
}
|
||||
|
||||
@@ -366,6 +366,18 @@ bool ResolveExpression::visit(CompoundExpressionAST *ast)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ResolveExpression::visit(LambdaExpressionAST *ast)
|
||||
{
|
||||
accept(ast->statement);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ResolveExpression::visit(ReturnStatementAST *ast)
|
||||
{
|
||||
accept(ast->expression);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ResolveExpression::visit(NestedExpressionAST *ast)
|
||||
{
|
||||
accept(ast->expression);
|
||||
@@ -626,6 +638,11 @@ bool ResolveExpression::visit(CallAST *ast)
|
||||
{
|
||||
const QList<LookupItem> baseResults = resolve(ast->base_expression, _scope);
|
||||
|
||||
if (ast->base_expression->asLambdaExpression()) {
|
||||
_results = baseResults;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Compute the types of the actual arguments.
|
||||
unsigned actualArgumentCount = 0;
|
||||
|
||||
|
||||
@@ -104,6 +104,8 @@ protected:
|
||||
virtual bool visit(UnaryExpressionAST *ast);
|
||||
virtual bool visit(CompoundLiteralAST *ast);
|
||||
virtual bool visit(CompoundExpressionAST *ast);
|
||||
virtual bool visit(LambdaExpressionAST *ast);
|
||||
virtual bool visit(ReturnStatementAST *ast);
|
||||
|
||||
//names
|
||||
virtual bool visit(QualifiedNameAST *ast);
|
||||
|
||||
Reference in New Issue
Block a user