Commit aa645254 authored by Christian Kamm's avatar Christian Kamm Committed by hjk

C++11: More (expression-list) or brace-init-list.

This time in the 'new' expression. Changed it to make
new C(1, abc...) and new C{1, abc}
work.

Change-Id: I7232798fd083b653ee04ef9ede386d6536133e16
Reviewed-by: default avatarhjk <qthjk@ovi.com>
parent 83da5f68
......@@ -2052,32 +2052,6 @@ unsigned NewExpressionAST::lastToken() const
return 1;
}
/** \generated */
unsigned NewInitializerAST::firstToken() const
{
if (lparen_token)
return lparen_token;
if (expression)
if (unsigned candidate = expression->firstToken())
return candidate;
if (rparen_token)
return rparen_token;
return 0;
}
/** \generated */
unsigned NewInitializerAST::lastToken() const
{
if (rparen_token)
return rparen_token + 1;
if (expression)
if (unsigned candidate = expression->lastToken())
return candidate;
if (lparen_token)
return lparen_token + 1;
return 1;
}
/** \generated */
unsigned ExpressionListParenAST::firstToken() const
{
......
......@@ -198,7 +198,6 @@ public:
virtual NestedNameSpecifierAST *asNestedNameSpecifier() { return 0; }
virtual NewArrayDeclaratorAST *asNewArrayDeclarator() { return 0; }
virtual NewExpressionAST *asNewExpression() { return 0; }
virtual NewInitializerAST *asNewInitializer() { return 0; }
virtual NewTypeIdAST *asNewTypeId() { return 0; }
virtual NoExceptSpecificationAST *asNoExceptSpecification() { return 0; }
virtual NumericLiteralAST *asNumericLiteral() { return 0; }
......@@ -2502,7 +2501,7 @@ public:
NewTypeIdAST *new_type_id;
NewInitializerAST *new_initializer;
ExpressionAST *new_initializer; // either ExpressionListParenAST or BracedInitializerAST
public:
NewExpressionAST()
......@@ -2528,32 +2527,6 @@ protected:
virtual bool match0(AST *, ASTMatcher *);
};
class CPLUSPLUS_EXPORT NewInitializerAST: public AST
{
public:
unsigned lparen_token;
ExpressionAST *expression;
unsigned rparen_token;
public:
NewInitializerAST()
: lparen_token(0)
, expression(0)
, rparen_token(0)
{}
virtual NewInitializerAST *asNewInitializer() { return this; }
virtual unsigned firstToken() const;
virtual unsigned lastToken() const;
virtual NewInitializerAST *clone(MemoryPool *pool) const;
protected:
virtual void accept0(ASTVisitor *visitor);
virtual bool match0(AST *, ASTMatcher *);
};
class CPLUSPLUS_EXPORT NewTypeIdAST: public AST
{
public:
......
......@@ -930,16 +930,6 @@ NewExpressionAST *NewExpressionAST::clone(MemoryPool *pool) const
return ast;
}
NewInitializerAST *NewInitializerAST::clone(MemoryPool *pool) const
{
NewInitializerAST *ast = new (pool) NewInitializerAST;
ast->lparen_token = lparen_token;
if (expression)
ast->expression = expression->clone(pool);
ast->rparen_token = rparen_token;
return ast;
}
NewTypeIdAST *NewTypeIdAST::clone(MemoryPool *pool) const
{
NewTypeIdAST *ast = new (pool) NewTypeIdAST;
......
......@@ -624,14 +624,6 @@ bool NewExpressionAST::match0(AST *pattern, ASTMatcher *matcher)
return false;
}
bool NewInitializerAST::match0(AST *pattern, ASTMatcher *matcher)
{
if (NewInitializerAST *_other = pattern->asNewInitializer())
return matcher->match(this, _other);
return false;
}
bool NewTypeIdAST::match0(AST *pattern, ASTMatcher *matcher)
{
if (NewTypeIdAST *_other = pattern->asNewTypeId())
......
......@@ -1585,23 +1585,6 @@ bool ASTMatcher::match(NewExpressionAST *node, NewExpressionAST *pattern)
return true;
}
bool ASTMatcher::match(NewInitializerAST *node, NewInitializerAST *pattern)
{
(void) node;
(void) pattern;
pattern->lparen_token = node->lparen_token;
if (! pattern->expression)
pattern->expression = node->expression;
else if (! AST::match(node->expression, pattern->expression, this))
return false;
pattern->rparen_token = node->rparen_token;
return true;
}
bool ASTMatcher::match(NewTypeIdAST *node, NewTypeIdAST *pattern)
{
(void) node;
......
......@@ -100,7 +100,6 @@ public:
virtual bool match(NestedNameSpecifierAST *node, NestedNameSpecifierAST *pattern);
virtual bool match(NewArrayDeclaratorAST *node, NewArrayDeclaratorAST *pattern);
virtual bool match(NewExpressionAST *node, NewExpressionAST *pattern);
virtual bool match(NewInitializerAST *node, NewInitializerAST *pattern);
virtual bool match(NewTypeIdAST *node, NewTypeIdAST *pattern);
virtual bool match(NoExceptSpecificationAST *node, NoExceptSpecificationAST *pattern);
virtual bool match(NumericLiteralAST *node, NumericLiteralAST *pattern);
......
......@@ -599,7 +599,7 @@ public:
return __ast;
}
NewExpressionAST *NewExpression(ExpressionListParenAST *new_placement = 0, ExpressionAST *type_id = 0, NewTypeIdAST *new_type_id = 0, NewInitializerAST *new_initializer = 0)
NewExpressionAST *NewExpression(ExpressionListParenAST *new_placement = 0, ExpressionAST *type_id = 0, NewTypeIdAST *new_type_id = 0, ExpressionAST *new_initializer = 0)
{
NewExpressionAST *__ast = new (&pool) NewExpressionAST;
__ast->new_placement = new_placement;
......@@ -609,13 +609,6 @@ public:
return __ast;
}
NewInitializerAST *NewInitializer(ExpressionAST *expression = 0)
{
NewInitializerAST *__ast = new (&pool) NewInitializerAST;
__ast->expression = expression;
return __ast;
}
NewTypeIdAST *NewTypeId(SpecifierListAST *type_specifier_list = 0, PtrOperatorListAST *ptr_operator_list = 0, NewArrayDeclaratorListAST *new_array_declarator_list = 0)
{
NewTypeIdAST *__ast = new (&pool) NewTypeIdAST;
......
......@@ -671,14 +671,6 @@ void NewExpressionAST::accept0(ASTVisitor *visitor)
visitor->endVisit(this);
}
void NewInitializerAST::accept0(ASTVisitor *visitor)
{
if (visitor->visit(this)) {
accept(expression, visitor);
}
visitor->endVisit(this);
}
void NewTypeIdAST::accept0(ASTVisitor *visitor)
{
if (visitor->visit(this)) {
......
......@@ -142,7 +142,6 @@ public:
virtual bool visit(NestedNameSpecifierAST *) { return true; }
virtual bool visit(NewArrayDeclaratorAST *) { return true; }
virtual bool visit(NewExpressionAST *) { return true; }
virtual bool visit(NewInitializerAST *) { return true; }
virtual bool visit(NewTypeIdAST *) { return true; }
virtual bool visit(NoExceptSpecificationAST *) { return true; }
virtual bool visit(NumericLiteralAST *) { return true; }
......@@ -288,7 +287,6 @@ public:
virtual void endVisit(NestedNameSpecifierAST *) {}
virtual void endVisit(NewArrayDeclaratorAST *) {}
virtual void endVisit(NewExpressionAST *) {}
virtual void endVisit(NewInitializerAST *) {}
virtual void endVisit(NewTypeIdAST *) {}
virtual void endVisit(NoExceptSpecificationAST *) {}
virtual void endVisit(NumericLiteralAST *) {}
......
......@@ -105,7 +105,6 @@ class NestedExpressionAST;
class NestedNameSpecifierAST;
class NewArrayDeclaratorAST;
class NewExpressionAST;
class NewInitializerAST;
class NewTypeIdAST;
class NoExceptSpecificationAST;
class NumericLiteralAST;
......
......@@ -580,23 +580,6 @@ FullySpecifiedType Bind::newArrayDeclarator(NewArrayDeclaratorAST *ast, const Fu
return type;
}
bool Bind::visit(NewInitializerAST *ast)
{
(void) ast;
assert(!"unreachable");
return false;
}
void Bind::newInitializer(NewInitializerAST *ast)
{
if (! ast)
return;
// unsigned lparen_token = ast->lparen_token;
ExpressionTy expression = this->expression(ast->expression);
// unsigned rparen_token = ast->rparen_token;
}
bool Bind::visit(NewTypeIdAST *ast)
{
(void) ast;
......@@ -1637,7 +1620,7 @@ bool Bind::visit(NewExpressionAST *ast)
ExpressionTy type_id = this->expression(ast->type_id);
// unsigned rparen_token = ast->rparen_token;
this->newTypeId(ast->new_type_id);
this->newInitializer(ast->new_initializer);
this->expression(ast->new_initializer);
return false;
}
......
......@@ -87,7 +87,6 @@ protected:
const Name *nestedNameSpecifier(NestedNameSpecifierAST *ast);
void newPlacement(ExpressionListParenAST *ast);
FullySpecifiedType newArrayDeclarator(NewArrayDeclaratorAST *ast, const FullySpecifiedType &init);
void newInitializer(NewInitializerAST *ast);
FullySpecifiedType newTypeId(NewTypeIdAST *ast);
OperatorNameId::Kind cppOperator(OperatorAST *ast);
void parameterDeclarationClause(ParameterDeclarationClauseAST *ast, unsigned lparen_token, Function *fun);
......@@ -123,7 +122,6 @@ protected:
virtual bool visit(MemInitializerAST *ast);
virtual bool visit(NestedNameSpecifierAST *ast);
virtual bool visit(NewArrayDeclaratorAST *ast);
virtual bool visit(NewInitializerAST *ast);
virtual bool visit(NewTypeIdAST *ast);
virtual bool visit(OperatorAST *ast);
virtual bool visit(ParameterDeclarationClauseAST *ast);
......
......@@ -5091,20 +5091,13 @@ bool Parser::parseNewArrayDeclarator(NewArrayDeclaratorListAST *&node)
return true;
}
bool Parser::parseNewInitializer(NewInitializerAST *&node)
bool Parser::parseNewInitializer(ExpressionAST *&node)
{
DEBUG_THIS_RULE();
if (LA() == T_LPAREN) {
unsigned lparen_token = consumeToken();
ExpressionAST *expression = 0;
if (LA() == T_RPAREN || parseExpression(expression)) {
NewInitializerAST *ast = new (_pool) NewInitializerAST;
ast->lparen_token = lparen_token;
ast->expression = expression;
match(T_RPAREN, &ast->rparen_token);
node = ast;
return true;
}
return parseExpressionListParen(node);
} else if (_cxx0xEnabled && LA() == T_LBRACE) {
return parseBracedInitList0x(node);
}
return false;
}
......
......@@ -133,7 +133,7 @@ public:
bool parseNewArrayDeclarator(NewArrayDeclaratorListAST *&node);
bool parseNewExpression(ExpressionAST *&node);
bool parseExpressionListParen(ExpressionAST *&node);
bool parseNewInitializer(NewInitializerAST *&node);
bool parseNewInitializer(ExpressionAST *&node);
bool parseNewTypeId(NewTypeIdAST *&node);
bool parseOperator(OperatorAST *&node);
bool parseConversionFunctionId(NameAST *&node);
......
......@@ -594,23 +594,6 @@ void FindUsages::newArrayDeclarator(NewArrayDeclaratorAST *ast)
// unsigned rbracket_token = ast->rbracket_token;
}
bool FindUsages::visit(NewInitializerAST *ast)
{
(void) ast;
Q_ASSERT(!"unreachable");
return false;
}
void FindUsages::newInitializer(NewInitializerAST *ast)
{
if (! ast)
return;
// unsigned lparen_token = ast->lparen_token;
this->expression(ast->expression);
// unsigned rparen_token = ast->rparen_token;
}
bool FindUsages::visit(NewTypeIdAST *ast)
{
(void) ast;
......@@ -1295,7 +1278,7 @@ bool FindUsages::visit(NewExpressionAST *ast)
this->expression(ast->type_id);
// unsigned rparen_token = ast->rparen_token;
this->newTypeId(ast->new_type_id);
this->newInitializer(ast->new_initializer);
this->expression(ast->new_initializer);
return false;
}
......
......@@ -106,7 +106,6 @@ protected:
void nestedNameSpecifier(NestedNameSpecifierAST *ast);
void newPlacement(ExpressionListParenAST *ast);
void newArrayDeclarator(NewArrayDeclaratorAST *ast);
void newInitializer(NewInitializerAST *ast);
void newTypeId(NewTypeIdAST *ast);
void cppOperator(OperatorAST *ast);
void parameterDeclarationClause(ParameterDeclarationClauseAST *ast);
......@@ -138,7 +137,6 @@ protected:
virtual bool visit(MemInitializerAST *ast);
virtual bool visit(NestedNameSpecifierAST *ast);
virtual bool visit(NewArrayDeclaratorAST *ast);
virtual bool visit(NewInitializerAST *ast);
virtual bool visit(NewTypeIdAST *ast);
virtual bool visit(OperatorAST *ast);
virtual bool visit(ParameterDeclarationClauseAST *ast);
......
......@@ -663,13 +663,14 @@ bool CheckSymbols::visit(NewExpressionAST *ast)
if (binding && nameAST) {
int arguments = 0;
if (ast->new_initializer) {
if (ExpressionAST *expr = ast->new_initializer->expression) {
while (BinaryExpressionAST *binExpr = expr->asBinaryExpression()) {
expr = binExpr->right_expression;
++arguments;
}
ExpressionListAST *list = 0;
if (ExpressionListParenAST *exprListParen = ast->new_initializer->asExpressionListParen()) {
list = exprListParen->expression_list;
} else if (BracedInitializerAST *braceInit = ast->new_initializer->asBracedInitializer()) {
list = braceInit->expression_list;
}
for (ExpressionListAST *it = list; it; it = it->next)
++arguments;
}
Scope *scope = enclosingScope();
......
auto x = int{};
auto y = Foo{};
auto z = typename Foo<T>{};
auto d = new C(1, abc...);
auto e = new C{1, 2, 3};
......@@ -906,16 +906,6 @@ virtual bool visit(NewExpressionAST *ast)
return false;
}
virtual bool visit(NewInitializerAST *ast)
{
if (ast->lparen_token)
terminal(ast->lparen_token, ast);
nonterminal(ast->expression);
if (ast->rparen_token)
terminal(ast->rparen_token, ast);
return false;
}
virtual bool visit(NewTypeIdAST *ast)
{
for (SpecifierListAST *iter = ast->type_specifier_list; iter; iter = iter->next)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment