Commit 807f17b5 authored by Roberto Raggi's avatar Roberto Raggi
Browse files

Added the ability to clone AST nodes. Please, note that this is not finished...

Added the ability to clone AST nodes. Please, note that this is not finished yet. So don't try to use it.
parent 3005f284
......@@ -408,6 +408,19 @@ unsigned AttributeSpecifierAST::lastToken() const
return attribute_token + 1;
}
AttributeSpecifierAST *AttributeSpecifierAST::clone(MemoryPool *pool) const
{
AttributeSpecifierAST *ast = new (pool) AttributeSpecifierAST;
ast->attribute_token = attribute_token;
ast->first_lparen_token = first_lparen_token;
ast->second_lparen_token = second_lparen_token;
if (attributes)
ast->attributes = attributes->clone(pool);
ast->first_rparen_token = first_rparen_token;
ast->second_rparen_token = second_rparen_token;
return ast;
}
void AttributeSpecifierAST::accept0(ASTVisitor *visitor)
{
if (visitor->visit(this)) {
......@@ -442,6 +455,20 @@ unsigned AttributeAST::lastToken() const
return identifier_token + 1;
}
AttributeAST *AttributeAST::clone(MemoryPool *pool) const
{
AttributeAST *ast = new (pool) AttributeAST;
ast->identifier_token = identifier_token;
ast->lparen_token = lparen_token;
ast->tag_token = tag_token;
if (expression_list)
ast->expression_list = expression_list->clone(pool);
ast->rparen_token = rparen_token;
if (next)
ast->next = next->clone(pool);
return ast;
}
void AttributeAST::accept0(ASTVisitor *visitor)
{
if (visitor->visit(this)) {
......@@ -450,6 +477,15 @@ void AttributeAST::accept0(ASTVisitor *visitor)
}
}
AccessDeclarationAST *AccessDeclarationAST::clone(MemoryPool *pool) const
{
AccessDeclarationAST *ast = new (pool) AccessDeclarationAST;
ast->access_specifier_token = access_specifier_token;
ast->slots_token = slots_token;
ast->colon_token = colon_token;
return ast;
}
void AccessDeclarationAST::accept0(ASTVisitor *visitor)
{
if (visitor->visit(this)) {
......@@ -470,6 +506,16 @@ unsigned AccessDeclarationAST::lastToken() const
return access_specifier_token + 1;
}
ArrayAccessAST *ArrayAccessAST::clone(MemoryPool *pool) const
{
ArrayAccessAST *ast = new (pool) ArrayAccessAST;
ast->lbracket_token = lbracket_token;
if (expression)
ast->expression = expression->clone(pool);
ast->rbracket_token = rbracket_token;
return ast;
}
void ArrayAccessAST::accept0(ASTVisitor *visitor)
{
if (visitor->visit(this)) {
......@@ -491,6 +537,16 @@ unsigned ArrayAccessAST::lastToken() const
return lbracket_token + 1;
}
ArrayDeclaratorAST *ArrayDeclaratorAST::clone(MemoryPool *pool) const
{
ArrayDeclaratorAST *ast = new (pool) ArrayDeclaratorAST;
ast->lbracket_token = lbracket_token;
if (expression)
ast->expression = expression->clone(pool);
ast->rbracket_token = rbracket_token;
return ast;
}
void ArrayDeclaratorAST::accept0(ASTVisitor *visitor)
{
if (visitor->visit(this)) {
......@@ -512,11 +568,20 @@ unsigned ArrayDeclaratorAST::lastToken() const
return lbracket_token + 1;
}
ArrayInitializerAST *ArrayInitializerAST::clone(MemoryPool *pool) const
{
ArrayInitializerAST *ast = new (pool) ArrayInitializerAST;
ast->lbrace_token = lbrace_token;
if (expression_list)
ast->expression_list = expression_list->clone(pool);
ast->rbrace_token = rbrace_token;
return ast;
}
void ArrayInitializerAST::accept0(ASTVisitor *visitor)
{
if (visitor->visit(this)) {
for (ExpressionListAST *expr = expression_list;expr;
expr = expr->next)
for (ExpressionListAST *expr = expression_list; expr; expr = expr->next)
accept(expr->expression, visitor);
}
}
......@@ -539,6 +604,18 @@ unsigned ArrayInitializerAST::lastToken() const
return lbrace_token + 1;
}
AsmDefinitionAST *AsmDefinitionAST::clone(MemoryPool *pool) const
{
AsmDefinitionAST *ast = new (pool) AsmDefinitionAST;
ast->asm_token = asm_token;
if (cv_qualifier_seq)
ast->cv_qualifier_seq = cv_qualifier_seq->clone(pool);
ast->lparen_token = lparen_token;
ast->rparen_token = rparen_token;
ast->semicolon_token = semicolon_token;
return ast;
}
void AsmDefinitionAST::accept0(ASTVisitor *visitor)
{
if (visitor->visit(this)) {
......@@ -569,6 +646,18 @@ unsigned AsmDefinitionAST::lastToken() const
return asm_token + 1;
}
BaseSpecifierAST *BaseSpecifierAST::clone(MemoryPool *pool) const
{
BaseSpecifierAST *ast = new (pool) BaseSpecifierAST;
ast->token_virtual = token_virtual;
ast->token_access_specifier = token_access_specifier;
if (name)
ast->name = name->clone(pool);
if (next)
ast->next = next->clone(pool);
return ast;
}
void BaseSpecifierAST::accept0(ASTVisitor *visitor)
{
if (visitor->visit(this)) {
......@@ -611,6 +700,17 @@ unsigned QtMethodAST::lastToken() const
return method_token + 1;
}
QtMethodAST *QtMethodAST::clone(MemoryPool *pool) const
{
QtMethodAST *ast = new (pool) QtMethodAST;
ast->method_token = method_token;
ast->lparen_token = lparen_token;
if (declarator)
ast->declarator = declarator->clone(pool);
ast->rparen_token = rparen_token;
return ast;
}
void QtMethodAST::accept0(ASTVisitor *visitor)
{
if (visitor->visit(this)) {
......@@ -618,6 +718,17 @@ void QtMethodAST::accept0(ASTVisitor *visitor)
}
}
BinaryExpressionAST *BinaryExpressionAST::clone(MemoryPool *pool) const
{
BinaryExpressionAST *ast = new (pool) BinaryExpressionAST;
if (left_expression)
ast->left_expression = left_expression->clone(pool);
ast->binary_op_token = binary_op_token;
if (right_expression)
ast->right_expression = right_expression->clone(pool);
return ast;
}
void BinaryExpressionAST::accept0(ASTVisitor *visitor)
{
if (visitor->visit(this)) {
......@@ -640,6 +751,13 @@ unsigned BinaryExpressionAST::lastToken() const
return left_expression->lastToken();
}
BoolLiteralAST *BoolLiteralAST::clone(MemoryPool *pool) const
{
BoolLiteralAST *ast = new (pool) BoolLiteralAST;
ast->token = token;
return ast;
}
void BoolLiteralAST::accept0(ASTVisitor *visitor)
{
if (visitor->visit(this)) {
......@@ -656,6 +774,14 @@ unsigned BoolLiteralAST::lastToken() const
return token + 1;
}
BreakStatementAST *BreakStatementAST::clone(MemoryPool *pool) const
{
BreakStatementAST *ast = new (pool) BreakStatementAST;
ast->break_token = break_token;
ast->semicolon_token = semicolon_token;
return ast;
}
void BreakStatementAST::accept0(ASTVisitor *visitor)
{
if (visitor->visit(this)) {
......@@ -674,6 +800,16 @@ unsigned BreakStatementAST::lastToken() const
return break_token + 1;
}
CallAST *CallAST::clone(MemoryPool *pool) const
{
CallAST *ast = new (pool) CallAST;
ast->lparen_token = lparen_token;
if (expression_list)
ast->expression_list = expression_list;
ast->rparen_token = rparen_token;
return ast;
}
void CallAST::accept0(ASTVisitor *visitor)
{
if (visitor->visit(this)) {
......@@ -699,6 +835,18 @@ unsigned CallAST::lastToken() const
return lparen_token + 1;
}
CaseStatementAST *CaseStatementAST::clone(MemoryPool *pool) const
{
CaseStatementAST *ast = new (pool) CaseStatementAST;
ast->case_token = case_token;
if (expression)
ast->expression = expression->clone(pool);
ast->colon_token = colon_token;
if (statement)
ast->statement = statement->clone(pool);
return ast;
}
void CaseStatementAST::accept0(ASTVisitor *visitor)
{
if (visitor->visit(this)) {
......@@ -721,6 +869,18 @@ unsigned CaseStatementAST::lastToken() const
return case_token + 1;
}
CastExpressionAST *CastExpressionAST::clone(MemoryPool *pool) const
{
CastExpressionAST *ast = new (pool) CastExpressionAST;
ast->lparen_token = lparen_token;
if (type_id)
ast->type_id = type_id->clone(pool);
ast->rparen_token = rparen_token;
if (expression)
ast->expression = expression->clone(pool);
return ast;
}
void CastExpressionAST::accept0(ASTVisitor *visitor)
{
if (visitor->visit(this)) {
......@@ -743,6 +903,21 @@ unsigned CastExpressionAST::lastToken() const
return lparen_token + 1;
}
CatchClauseAST *CatchClauseAST::clone(MemoryPool *pool) const
{
CatchClauseAST *ast = new (pool) CatchClauseAST;
ast->catch_token = catch_token;
ast->lparen_token = lparen_token;
if (exception_declaration)
ast->exception_declaration = exception_declaration->clone(pool);
ast->rparen_token = rparen_token;
if (statement)
ast->statement = statement->clone(pool);
if (next)
ast->next = next->clone(pool);
return ast;
}
void CatchClauseAST::accept0(ASTVisitor *visitor)
{
if (visitor->visit(this)) {
......@@ -772,6 +947,24 @@ unsigned CatchClauseAST::lastToken() const
return catch_token + 1;
}
ClassSpecifierAST *ClassSpecifierAST::clone(MemoryPool *pool) const
{
ClassSpecifierAST *ast = new (pool) ClassSpecifierAST;
ast->classkey_token = classkey_token;
if (attributes)
ast->attributes = attributes->clone(pool);
if (name)
ast->name = name->clone(pool);
ast->colon_token = colon_token;
if (base_clause)
ast->base_clause = base_clause->clone(pool);
ast->lbrace_token = lbrace_token;
if (member_specifiers)
ast->member_specifiers = member_specifiers->clone(pool);
ast->rbrace_token = rbrace_token;
return ast;
}
void ClassSpecifierAST::accept0(ASTVisitor *visitor)
{
if (visitor->visit(this)) {
......@@ -822,6 +1015,16 @@ unsigned ClassSpecifierAST::lastToken() const
return classkey_token + 1;
}
CompoundStatementAST *CompoundStatementAST::clone(MemoryPool *pool) const
{
CompoundStatementAST *ast = new (pool) CompoundStatementAST;
ast->lbrace_token = lbrace_token;
if (statements)
ast->statements = statements->clone(pool);
ast->rbrace_token = rbrace_token;
return ast;
}
void CompoundStatementAST::accept0(ASTVisitor *visitor)
{
if (visitor->visit(this)) {
......@@ -848,6 +1051,16 @@ unsigned CompoundStatementAST::lastToken() const
return lbrace_token + 1;
}
ConditionAST *ConditionAST::clone(MemoryPool *pool) const
{
ConditionAST *ast = new (pool) ConditionAST;
if (type_specifier)
ast->type_specifier = type_specifier->clone(pool);
if (declarator)
ast->declarator = declarator->clone(pool);
return ast;
}
void ConditionAST::accept0(ASTVisitor *visitor)
{
if (visitor->visit(this)) {
......@@ -879,6 +1092,20 @@ unsigned ConditionAST::lastToken() const
return 0;
}
ConditionalExpressionAST *ConditionalExpressionAST::clone(MemoryPool *pool) const
{
ConditionalExpressionAST *ast = new (pool) ConditionalExpressionAST;
if (condition)
ast->condition = condition->clone(pool);
ast->question_token = question_token;
if (left_expression)
ast->left_expression = left_expression->clone(pool);
ast->colon_token = colon_token;
if (right_expression)
ast->right_expression = right_expression->clone(pool);
return ast;
}
void ConditionalExpressionAST::accept0(ASTVisitor *visitor)
{
if (visitor->visit(this)) {
......@@ -909,6 +1136,14 @@ unsigned ConditionalExpressionAST::lastToken() const
return 0;
}
ContinueStatementAST *ContinueStatementAST::clone(MemoryPool *pool) const
{
ContinueStatementAST *ast = new (pool) ContinueStatementAST;
ast->continue_token = continue_token;
ast->semicolon_token = semicolon_token;
return ast;
}
void ContinueStatementAST::accept0(ASTVisitor *visitor)
{
if (visitor->visit(this)) {
......@@ -927,6 +1162,17 @@ unsigned ContinueStatementAST::lastToken() const
return continue_token + 1;
}
ConversionFunctionIdAST *ConversionFunctionIdAST::clone(MemoryPool *pool) const
{
ConversionFunctionIdAST *ast = new (pool) ConversionFunctionIdAST;
ast->operator_token = operator_token;
if (type_specifier)
ast->type_specifier = type_specifier->clone(pool);
if (ptr_operators)
ast->ptr_operators = ptr_operators->clone(pool);
return ast;
}
void ConversionFunctionIdAST::accept0(ASTVisitor *visitor)
{
if (visitor->visit(this)) {
......@@ -958,6 +1204,21 @@ unsigned ConversionFunctionIdAST::lastToken() const
return operator_token + 1;
}
CppCastExpressionAST *CppCastExpressionAST::clone(MemoryPool *pool) const
{
CppCastExpressionAST *ast = new (pool) CppCastExpressionAST;
ast->cast_token = cast_token;
ast->less_token = less_token;
if (type_id)
ast->type_id = type_id->clone(pool);
ast->greater_token = greater_token;
ast->lparen_token = lparen_token;
if (expression)
ast->expression = expression->clone(pool);
ast->rparen_token = rparen_token;
return ast;
}
void CppCastExpressionAST::accept0(ASTVisitor *visitor)
{
if (visitor->visit(this)) {
......@@ -988,6 +1249,15 @@ unsigned CppCastExpressionAST::lastToken() const
return cast_token + 1;
}
CtorInitializerAST *CtorInitializerAST::clone(MemoryPool *pool) const
{
CtorInitializerAST *ast = new (pool) CtorInitializerAST;
ast->colon_token = colon_token;
if (member_initializers)
ast->member_initializers = member_initializers->clone(pool);
return ast;
}
void CtorInitializerAST::accept0(ASTVisitor *visitor)
{
if (visitor->visit(this)) {
......@@ -1011,6 +1281,22 @@ unsigned CtorInitializerAST::lastToken() const
return colon_token + 1;
}
DeclaratorAST *DeclaratorAST::clone(MemoryPool *pool) const
{
DeclaratorAST *ast = new (pool) DeclaratorAST;
if (ptr_operators)
ast->ptr_operators = ptr_operators->clone(pool);
if (core_declarator)
ast->core_declarator = core_declarator->clone(pool);
if (postfix_declarators)
ast->postfix_declarators = postfix_declarators->clone(pool);
if (attributes)
ast->attributes = attributes->clone(pool);
if (initializer)
ast->initializer = initializer->clone(pool);
return ast;
}
void DeclaratorAST::accept0(ASTVisitor *visitor)
{
if (visitor->visit(this)) {
......@@ -1069,6 +1355,14 @@ unsigned DeclaratorAST::lastToken() const
return 0;
}
DeclarationStatementAST *DeclarationStatementAST::clone(MemoryPool *pool) const
{
DeclarationStatementAST *ast = new (pool) DeclarationStatementAST;
if (declaration)
ast->declaration = declaration->clone(pool);
return ast;
}
void DeclarationStatementAST::accept0(ASTVisitor *visitor)
{
if (visitor->visit(this)) {
......@@ -1086,6 +1380,14 @@ unsigned DeclarationStatementAST::lastToken() const
return declaration->lastToken();
}
DeclaratorIdAST *DeclaratorIdAST::clone(MemoryPool *pool) const
{
DeclaratorIdAST *ast = new (pool) DeclaratorIdAST;
if (name)
ast->name = name->clone(pool);
return ast;
}
void DeclaratorIdAST::accept0(ASTVisitor *visitor)
{
if (visitor->visit(this)) {
......@@ -1103,6 +1405,16 @@ unsigned DeclaratorIdAST::lastToken() const
return name->lastToken();
}
DeclaratorListAST *DeclaratorListAST::clone(MemoryPool *pool) const
{
DeclaratorListAST *ast = new (pool) DeclaratorListAST;
if (declarator)
ast->declarator = declarator->clone(pool);
if (next)
ast->next = next->clone(pool);
return ast;
}
void DeclaratorListAST::accept0(ASTVisitor *visitor)
{
if (visitor->visit(this)) {
......@@ -1125,6 +1437,18 @@ unsigned DeclaratorListAST::lastToken() const
return 0;
}
DeleteExpressionAST *DeleteExpressionAST::clone(MemoryPool *pool) const
{
DeleteExpressionAST *ast = new (pool) DeleteExpressionAST;
ast->scope_token = scope_token;
ast->delete_token = delete_token;
ast->lbracket_token = lbracket_token;
ast->rbracket_token = rbracket_token;
if (expression)
ast->expression = expression->clone(pool);
return ast;
}
void DeleteExpressionAST::accept0(ASTVisitor *visitor)
{
if (visitor->visit(this)) {
......@@ -1152,6 +1476,14 @@ unsigned DeleteExpressionAST::lastToken() const
return scope_token + 1;
}
DestructorNameAST *DestructorNameAST::clone(MemoryPool *pool) const
{
DestructorNameAST *ast = new (pool) DestructorNameAST;
ast->tilde_token = tilde_token;
ast->identifier_token = identifier_token;
return ast;
}
void DestructorNameAST::accept0(ASTVisitor *visitor)
{
if (visitor->visit(this)) {
......@@ -1170,6 +1502,21 @@ unsigned DestructorNameAST::lastToken() const
return tilde_token + 1;
}
DoStatementAST *DoStatementAST::clone(MemoryPool *pool) const
{
DoStatementAST *ast = new (pool) DoStatementAST;
ast->do_token = do_token;
if (statement)
ast->statement = statement->clone(pool);
ast->while_token = while_token;
ast->lparen_token = lparen_token;
if (expression)
ast->expression = expression->clone(pool);
ast->rparen_token = rparen_token;
ast->semicolon_token = semicolon_token;
return ast;
}
void DoStatementAST::accept0(ASTVisitor *visitor)
{
if (visitor->visit(this)) {
......@@ -1200,6 +1547,15 @@ unsigned DoStatementAST::lastToken() const
return do_token + 1;
}
ElaboratedTypeSpecifierAST *ElaboratedTypeSpecifierAST::clone(MemoryPool *pool) const
{
ElaboratedTypeSpecifierAST *ast = new (pool) ElaboratedTypeSpecifierAST;
ast->classkey_token = classkey_token;
if (name)
ast->name = name->clone(pool);
return ast;
}
void ElaboratedTypeSpecifierAST::accept0(ASTVisitor *visitor)
{
if (visitor->visit(this)) {
......@@ -1219,6 +1575,13 @@ unsigned ElaboratedTypeSpecifierAST::lastToken() const
return classkey_token + 1;
}
EmptyDeclarationAST *EmptyDeclarationAST::clone(MemoryPool *pool) const
{
EmptyDeclarationAST *ast = new (pool) EmptyDeclarationAST;
ast->semicolon_token = semicolon_token;
return ast;
}
void EmptyDeclarationAST::accept0(ASTVisitor *visitor)
{
if (visitor->visit(this)) {
......@@ -1235,6 +1598,19 @@ unsigned EmptyDeclarationAST::lastToken() const
return semicolon_token + 1;
}
EnumSpecifierAST *EnumSpecifierAST::clone(MemoryPool *pool) const
{
EnumSpecifierAST *ast = new (pool) EnumSpecifierAST;
ast->enum_token = enum_token;
if (name)
ast->name = name->clone(pool);
ast->lbrace_token = lbrace_token;
if (enumerators)
ast->enumerators = enumerators->clone(pool);
ast->rbrace_token = rbrace_token;
return ast;
}
void EnumSpecifierAST::accept0(ASTVisitor *visitor)
{
if (visitor->visit(this)) {
......@@ -1268,6 +1644,18 @@ unsigned EnumSpecifierAST::lastToken() const
return enum_token + 1;
}
EnumeratorAST *EnumeratorAST::clone(MemoryPool *pool) const
{
EnumeratorAST *ast = new (pool) EnumeratorAST;
ast->identifier_token = identifier_token;
ast->equal_token = equal_token;
if (expression)
ast->expression = expression->clone(pool);
if (next)
ast->next = next->clone(pool);
return ast;
}
void EnumeratorAST::