Introduced IdExpressionAST.

This commit is contained in:
Roberto Raggi
2010-08-02 12:04:59 +02:00
parent 6226cfe1fc
commit 6324bf4460
15 changed files with 164 additions and 60 deletions

View File

@@ -4211,3 +4211,21 @@ unsigned AttributeSpecifierAST::lastToken() const
return 0;
}
/** \generated */
unsigned IdExpressionAST::firstToken() const
{
if (name)
if (unsigned candidate = name->firstToken())
return candidate;
return 0;
}
/** \generated */
unsigned IdExpressionAST::lastToken() const
{
if (name)
if (unsigned candidate = name->lastToken())
return candidate;
return 0;
}

View File

@@ -201,6 +201,7 @@ public:
virtual FunctionDeclaratorAST *asFunctionDeclarator() { return 0; }
virtual FunctionDefinitionAST *asFunctionDefinition() { return 0; }
virtual GotoStatementAST *asGotoStatement() { return 0; }
virtual IdExpressionAST *asIdExpression() { return 0; }
virtual IfStatementAST *asIfStatement() { return 0; }
virtual LabeledStatementAST *asLabeledStatement() { return 0; }
virtual LambdaCaptureAST *asLambdaCapture() { return 0; }
@@ -337,7 +338,7 @@ public:
virtual DeclarationAST *clone(MemoryPool *pool) const = 0;
};
class CPLUSPLUS_EXPORT NameAST: public ExpressionAST
class CPLUSPLUS_EXPORT NameAST: public AST
{
public: // annotations
const Name *name;
@@ -965,6 +966,28 @@ protected:
virtual bool match0(AST *, ASTMatcher *);
};
class CPLUSPLUS_EXPORT IdExpressionAST: public ExpressionAST
{
public:
NameAST *name;
public:
IdExpressionAST()
: name(0)
{}
virtual IdExpressionAST *asIdExpression() { return this; }
virtual unsigned firstToken() const;
virtual unsigned lastToken() const;
virtual IdExpressionAST *clone(MemoryPool *pool) const;
protected:
virtual void accept0(ASTVisitor *visitor);
virtual bool match0(AST *, ASTMatcher *);
};
class CPLUSPLUS_EXPORT CompoundExpressionAST: public ExpressionAST
{
public:

View File

@@ -273,6 +273,14 @@ BaseSpecifierAST *BaseSpecifierAST::clone(MemoryPool *pool) const
return ast;
}
IdExpressionAST *IdExpressionAST::clone(MemoryPool *pool) const
{
IdExpressionAST *ast = new (pool) IdExpressionAST;
if (name)
ast->name = name->clone(pool);
return ast;
}
CompoundExpressionAST *CompoundExpressionAST::clone(MemoryPool *pool) const
{
CompoundExpressionAST *ast = new (pool) CompoundExpressionAST;

View File

@@ -201,6 +201,14 @@ bool BaseSpecifierAST::match0(AST *pattern, ASTMatcher *matcher)
return false;
}
bool IdExpressionAST::match0(AST *pattern, ASTMatcher *matcher)
{
if (IdExpressionAST *_other = pattern->asIdExpression())
return matcher->match(this, _other);
return false;
}
bool CompoundExpressionAST::match0(AST *pattern, ASTMatcher *matcher)
{
if (CompoundExpressionAST *_other = pattern->asCompoundExpression())

View File

@@ -427,6 +427,19 @@ bool ASTMatcher::match(BaseSpecifierAST *node, BaseSpecifierAST *pattern)
return true;
}
bool ASTMatcher::match(IdExpressionAST *node, IdExpressionAST *pattern)
{
(void) node;
(void) pattern;
if (! pattern->name)
pattern->name = node->name;
else if (! AST::match(node->name, pattern->name, this))
return false;
return true;
}
bool ASTMatcher::match(CompoundExpressionAST *node, CompoundExpressionAST *pattern)
{
(void) node;

View File

@@ -90,6 +90,7 @@ public:
virtual bool match(FunctionDeclaratorAST *node, FunctionDeclaratorAST *pattern);
virtual bool match(FunctionDefinitionAST *node, FunctionDefinitionAST *pattern);
virtual bool match(GotoStatementAST *node, GotoStatementAST *pattern);
virtual bool match(IdExpressionAST *node, IdExpressionAST *pattern);
virtual bool match(IfStatementAST *node, IfStatementAST *pattern);
virtual bool match(LabeledStatementAST *node, LabeledStatementAST *pattern);
virtual bool match(LinkageBodyAST *node, LinkageBodyAST *pattern);

View File

@@ -205,6 +205,14 @@ void BaseSpecifierAST::accept0(ASTVisitor *visitor)
visitor->endVisit(this);
}
void IdExpressionAST::accept0(ASTVisitor *visitor)
{
if (visitor->visit(this)) {
accept(name, visitor);
}
visitor->endVisit(this);
}
void CompoundExpressionAST::accept0(ASTVisitor *visitor)
{
if (visitor->visit(this)) {

View File

@@ -151,6 +151,7 @@ public:
virtual bool visit(FunctionDeclaratorAST *) { return true; }
virtual bool visit(FunctionDefinitionAST *) { return true; }
virtual bool visit(GotoStatementAST *) { return true; }
virtual bool visit(IdExpressionAST *) { return true; }
virtual bool visit(IfStatementAST *) { return true; }
virtual bool visit(LabeledStatementAST *) { return true; }
virtual bool visit(LinkageBodyAST *) { return true; }
@@ -293,6 +294,7 @@ public:
virtual void endVisit(FunctionDeclaratorAST *) { }
virtual void endVisit(FunctionDefinitionAST *) { }
virtual void endVisit(GotoStatementAST *) { }
virtual void endVisit(IdExpressionAST *) { }
virtual void endVisit(IfStatementAST *) { }
virtual void endVisit(LabeledStatementAST *) { }
virtual void endVisit(LinkageBodyAST *) { }

View File

@@ -108,6 +108,7 @@ class ForeachStatementAST;
class FunctionDeclaratorAST;
class FunctionDefinitionAST;
class GotoStatementAST;
class IdExpressionAST;
class IfStatementAST;
class LabeledStatementAST;
class LambdaCaptureAST;

View File

@@ -3822,7 +3822,9 @@ bool Parser::parsePrimaryExpression(ExpressionAST *&node)
default: {
NameAST *name = 0;
if (parseNameId(name)) {
node = name;
IdExpressionAST *ast = new (_pool) IdExpressionAST;
ast->name = name;
node = ast;
return true;
}
break;