Commit fd90c350 authored by Erik Verbruggen's avatar Erik Verbruggen
Browse files

Added AST nodes for compound expressions (a GNU extension).

parent 7cdb15e7
......@@ -293,6 +293,11 @@ bool ResolveExpression::visit(ThisExpressionAST *)
return false;
}
bool ResolveExpression::visit(CompoundExpressionAST *ast)
{
return true; // ###
}
bool ResolveExpression::visit(NestedExpressionAST *ast)
{
accept(ast->expression);
......
......@@ -93,6 +93,7 @@ protected:
virtual bool visit(TypeIdAST *ast);
virtual bool visit(UnaryExpressionAST *ast);
virtual bool visit(CompoundLiteralAST *ast);
virtual bool visit(CompoundExpressionAST *ast);
//names
virtual bool visit(QualifiedNameAST *ast);
......
......@@ -326,6 +326,20 @@ unsigned BoolLiteralAST::lastToken() const
return literal_token + 1;
}
unsigned CompoundExpressionAST::firstToken() const
{
return lparen_token;
}
unsigned CompoundExpressionAST::lastToken() const
{
if (rparen_token)
return rparen_token + 1;
else if (compoundStatement)
return compoundStatement->lastToken();
else
return lparen_token + 1;
}
unsigned CompoundLiteralAST::firstToken() const
{
......@@ -2300,5 +2314,3 @@ unsigned ObjCSynchronizedStatementAST::lastToken() const
if (lparen_token) return lparen_token + 1;
return synchronized_token + 1;
}
......@@ -161,6 +161,7 @@ public:
virtual CastExpressionAST *asCastExpression() { return 0; }
virtual CatchClauseAST *asCatchClause() { return 0; }
virtual ClassSpecifierAST *asClassSpecifier() { return 0; }
virtual CompoundExpressionAST *asCompoundExpression() { return 0; }
virtual CompoundLiteralAST *asCompoundLiteral() { return 0; }
virtual CompoundStatementAST *asCompoundStatement() { return 0; }
virtual ConditionAST *asCondition() { return 0; }
......@@ -700,6 +701,26 @@ protected:
virtual bool match0(AST *, ASTMatcher *);
};
class CPLUSPLUS_EXPORT CompoundExpressionAST: public ExpressionAST
{
public:
unsigned lparen_token;
CompoundStatementAST *compoundStatement;
unsigned rparen_token;
public:
virtual CompoundExpressionAST *asCompoundExpression() { return this; }
virtual unsigned firstToken() const;
virtual unsigned lastToken() const;
virtual CompoundExpressionAST *clone(MemoryPool *pool) const;
protected:
virtual void accept0(ASTVisitor *visitor);
virtual bool match0(AST *, ASTMatcher *);
};
class CPLUSPLUS_EXPORT CompoundLiteralAST: public ExpressionAST
{
public:
......
......@@ -213,6 +213,16 @@ BaseSpecifierAST *BaseSpecifierAST::clone(MemoryPool *pool) const
return ast;
}
CompoundExpressionAST *CompoundExpressionAST::clone(MemoryPool *pool) const
{
CompoundExpressionAST *ast = new (pool) CompoundExpressionAST;
ast->lparen_token = lparen_token;
if (compoundStatement)
ast->compoundStatement = compoundStatement->clone(pool);
ast->rparen_token = rparen_token;
return ast;
}
CompoundLiteralAST *CompoundLiteralAST::clone(MemoryPool *pool) const
{
CompoundLiteralAST *ast = new (pool) CompoundLiteralAST;
......
......@@ -153,6 +153,14 @@ bool BaseSpecifierAST::match0(AST *pattern, ASTMatcher *matcher)
return false;
}
bool CompoundExpressionAST::match0(AST *pattern, ASTMatcher *matcher)
{
if (CompoundExpressionAST *_other = pattern->asCompoundExpression())
return matcher->match(this, _other);
return false;
}
bool CompoundLiteralAST::match0(AST *pattern, ASTMatcher *matcher)
{
if (CompoundLiteralAST *_other = pattern->asCompoundLiteral())
......
......@@ -331,6 +331,23 @@ bool ASTMatcher::match(BaseSpecifierAST *node, BaseSpecifierAST *pattern)
return true;
}
bool ASTMatcher::match(CompoundExpressionAST *node, CompoundExpressionAST *pattern)
{
(void) node;
(void) pattern;
pattern->lparen_token = node->lparen_token;
if (! pattern->compoundStatement)
pattern->compoundStatement = node->compoundStatement;
else if (! AST::match(node->compoundStatement, pattern->compoundStatement, this))
return false;
pattern->rparen_token = node->rparen_token;
return true;
}
bool ASTMatcher::match(CompoundLiteralAST *node, CompoundLiteralAST *pattern)
{
(void) node;
......
......@@ -59,6 +59,7 @@ public:
virtual bool match(CastExpressionAST *node, CastExpressionAST *pattern);
virtual bool match(CatchClauseAST *node, CatchClauseAST *pattern);
virtual bool match(ClassSpecifierAST *node, ClassSpecifierAST *pattern);
virtual bool match(CompoundExpressionAST *node, CompoundExpressionAST *pattern);
virtual bool match(CompoundLiteralAST *node, CompoundLiteralAST *pattern);
virtual bool match(CompoundStatementAST *node, CompoundStatementAST *pattern);
virtual bool match(ConditionAST *node, ConditionAST *pattern);
......
......@@ -153,6 +153,14 @@ void BaseSpecifierAST::accept0(ASTVisitor *visitor)
visitor->endVisit(this);
}
void CompoundExpressionAST::accept0(ASTVisitor *visitor)
{
if (visitor->visit(this)) {
accept(compoundStatement, visitor);
}
visitor->endVisit(this);
}
void CompoundLiteralAST::accept0(ASTVisitor *visitor)
{
if (visitor->visit(this)) {
......
......@@ -122,6 +122,7 @@ public:
virtual bool visit(CastExpressionAST *) { return true; }
virtual bool visit(CatchClauseAST *) { return true; }
virtual bool visit(ClassSpecifierAST *) { return true; }
virtual bool visit(CompoundExpressionAST *) { return true; }
virtual bool visit(CompoundLiteralAST *) { return true; }
virtual bool visit(CompoundStatementAST *) { return true; }
virtual bool visit(ConditionAST *) { return true; }
......@@ -252,6 +253,7 @@ public:
virtual void endVisit(CastExpressionAST *) { }
virtual void endVisit(CatchClauseAST *) { }
virtual void endVisit(ClassSpecifierAST *) { }
virtual void endVisit(CompoundExpressionAST *) { }
virtual void endVisit(CompoundLiteralAST *) { }
virtual void endVisit(CompoundStatementAST *) { }
virtual void endVisit(ConditionAST *) { }
......
......@@ -75,6 +75,7 @@ class CaseStatementAST;
class CastExpressionAST;
class CatchClauseAST;
class ClassSpecifierAST;
class CompoundExpressionAST;
class CompoundLiteralAST;
class CompoundStatementAST;
class ConditionAST;
......
......@@ -287,6 +287,11 @@ bool CheckExpression::visit(ThisExpressionAST *)
return false;
}
bool CheckExpression::visit(CompoundExpressionAST *ast)
{
return true; // ###
}
bool CheckExpression::visit(NestedExpressionAST *ast)
{
FullySpecifiedType exprTy = semantic()->check(ast->expression, _scope);
......
......@@ -94,6 +94,7 @@ protected:
virtual bool visit(UnaryExpressionAST *ast);
virtual bool visit(QtMethodAST *ast);
virtual bool visit(CompoundLiteralAST *ast);
virtual bool visit(CompoundExpressionAST *ast);
//names
virtual bool visit(QualifiedNameAST *ast);
......
......@@ -3437,7 +3437,19 @@ bool Parser::parsePrimaryExpression(ExpressionAST *&node)
return parseThisExpression(node);
case T_LPAREN:
return parseNestedExpression(node);
if (LA(2) == T_LBRACE) {
// GNU extension: '(' '{' statement-list '}' ')'
CompoundExpressionAST *ast = new (_pool) CompoundExpressionAST;
ast->lparen_token = consumeToken();
StatementAST *statement = 0;
parseCompoundStatement(statement);
ast->compoundStatement = statement->asCompoundStatement();
match(T_RPAREN, &ast->rparen_token);
node = ast;
return true;
} else {
return parseNestedExpression(node);
}
case T_SIGNAL:
case T_SLOT:
......@@ -3799,19 +3811,6 @@ bool Parser::parseNestedExpression(ExpressionAST *&node)
DEBUG_THIS_RULE();
if (LA() == T_LPAREN) {
unsigned lparen_token = consumeToken();
if (LA() == T_LBRACE) {
NestedExpressionAST *ast = new (_pool) NestedExpressionAST;
ast->lparen_token = lparen_token;
// ### ast
StatementAST *statement = 0;
parseCompoundStatement(statement);
match(T_RPAREN, &ast->rparen_token);
node = ast;
return true;
}
bool previousTemplateArguments = switchTemplateArguments(false);
ExpressionAST *expression = 0;
......@@ -5275,12 +5274,11 @@ bool Parser::parseObjCContextKeyword(int kind, unsigned &in_token)
{
DEBUG_THIS_RULE();
if (peekAtObjCContextKeyword(kind)) {
in_token = consumeToken();
return true;
} else {
if (!peekAtObjCContextKeyword(kind))
return false;
}
in_token = consumeToken();
return true;
}
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