root/trunk/compiler/cppAst/ast/DeepCloneVisitor.hpp
7 | krennw | /**
|
|
*
|
|||
* OOAS Compiler - C++ AST
|
|||
*
|
|||
* Copyright 2015, AIT Austrian Institute of Technology.
|
|||
* All rights reserved.
|
|||
*
|
|||
* SEE THE "LICENSE" FILE FOR THE TERMS UNDER WHICH THIS FILE IS PROVIDED.
|
|||
*
|
|||
* If you modify the file please update the list of contributors below to in-
|
|||
* clude your name. Please also stick to the coding convention of using TABs
|
|||
* to do the basic (block-level) indentation and spaces for anything after
|
|||
* that. (Enable the display of special chars and it should be pretty obvious
|
|||
* what this means.) Also, remove all trailing whitespace.
|
|||
*
|
|||
* Contributors:
|
|||
* Willibald Krenn (AIT)
|
|||
* Stephan Zimmerer (AIT)
|
|||
* Christoph Czurda (AIT)
|
|||
*
|
|||
*/
|
|||
2 | krennw | ||
#pragma once
|
|||
#include <ast/CompleteAstTraversalVisitor.hpp>
|
|||
#include <ast/Ast.hpp>
|
|||
#include <unordered_map>
|
|||
#include <ast/expressions/Quantifier.hpp>
|
|||
namespace Ast {
|
|||
/**
|
|||
* Based on the OoaDeepCloneVisitor from the Java frontend. Takes a shallow
|
|||
* copy of an AST element and makes it a deep copy.
|
|||
*/
|
|||
class DeepCloneVisitor final :
|
|||
public CompleteAstTraversalVisitor
|
|||
{
|
|||
protected:
|
|||
Ast* m_cloneAst;
|
|||
std::unordered_map<void*, void*> m_mapping;
|
|||
Identifier* m_selfreplacement;
|
|||
bool m_allowLinksToNonClonedParents;
|
|||
bool m_quantifierState;
|
|||
void updateScope(IScope* aScope);
|
|||
void checkScope(IScope* aScope);
|
|||
Expression* eClone(Expression* anExpr);
|
|||
Statement* sClone(Statement* aStatement);
|
|||
void symTabClone(SymbolTable* aTable);
|
|||
void cloneBlock(Block* aBlock);
|
|||
void cloneQuantifier(Quantifier* qf);
|
|||
void cloneExpressionList(ExpressionList& aList);
|
|||
void error() {
|
|||
m_context->logError("Internal error: Cannot clone a type");
|
|||
abort();
|
|||
}
|
|||
public:
|
|||
DeepCloneVisitor(
|
|||
CallContext* context,
|
|||
Ast* cloneAst,
|
|||
bool linksToNonClonedParents = true,
|
|||
const std::unordered_map<void*, void*>* initMapping = nullptr,
|
|||
Identifier* selfreplace = nullptr)
|
|||
:
|
|||
CompleteAstTraversalVisitor( context, false),
|
|||
m_cloneAst (cloneAst),
|
|||
m_mapping(),
|
|||
m_selfreplacement (selfreplace),
|
|||
m_allowLinksToNonClonedParents (linksToNonClonedParents),
|
|||
m_quantifierState (false)
|
|||
{
|
|||
if (initMapping != nullptr)
|
|||
m_mapping.insert(initMapping->begin(), initMapping->end());
|
|||
}
|
|||
std::string returnVisitorName() override {return "DeepCloneVisitor";}
|
|||
void visit(BoolType* ) override { error(); }
|
|||
void visit(EnumType* ) override { error(); }
|
|||
void visit(FunctionType* ) override { error(); }
|
|||
void visit(IntType* ) override { error(); }
|
|||
void visit(ListType* ) override { error(); }
|
|||
void visit(NullType* ) override { error(); }
|
|||
void visit(ActionSystemType* ) override { error(); }
|
|||
void visit(TupleType* ) override { error(); }
|
|||
void visit(EnumIdentifier* ) override { error(); }
|
|||
void visit(ExpressionVariableIdentifier* ) override { error(); }
|
|||
void visit(LocalVariableIdentifier* ) override { error(); }
|
|||
void visit(MainModule* ) override { error(); }
|
|||
void visit(MethodIdentifier* ) override { error(); }
|
|||
void visit(Module* ) override { error(); }
|
|||
void visit(NondetIdentifierBlock* ) override{ error(); }
|
|||
void visit(ParameterIdentifier* ) override { error(); }
|
|||
void visit(PrioIdentifierBlock* ) override { error(); }
|
|||
void visit(SeqIdentifierBlock* ) override { error(); }
|
|||
void visit(TypeIdentifier* ) override { error(); }
|
|||
void visit(UnspecIdentifierBlock* ) override { error(); }
|
|||
void visit(NamedActionIdentifier* namedActionIdentifier) override;
|
|||
void visit(ObjectConstructor* objectConstructor) override;
|
|||
// void visit(AbortStatement* abortStatement) override { }
|
|||
void visit(BoolValueExpression* ) override {};
|
|||
void visit(IntValueExpression* ) override {};
|
|||
void visit(RefValueExpression* ) override {};
|
|||
void visit(Skip* ) override { }
|
|||
void visit(Break* ) override { error(); }
|
|||
void visit(TypeExpression* ) override { /*we do not clone types*/ }
|
|||
void visit(NondetBlock* nondetBlock) override;
|
|||
void visit(SeqBlock* seqBlock) override;
|
|||
void visit(PrioBlock* prioBlock) override;
|
|||
void visit(AccessExpression* accessExpression) override;
|
|||
void visit(BinaryOperator* binaryOperator) override;
|
|||
void visit(Assignment* assignment) override;
|
|||
void visit(AttributeIdentifier* attributeIdentifier) override;
|
|||
void visit(Call* call) override;
|
|||
void visit(CallExpression* callExpression) override;
|
|||
void visit(ExistsQuantifier* quantifier) override;
|
|||
void visit(ForallQuantifier* quantifier) override;
|
|||
void visit(GuardedCommand* guardedCommand) override;
|
|||
void visit(IdentifierExpression* identifierExpression) override;
|
|||
void visit(ListConstructor* listConstructor) override;
|
|||
void visit(SetConstructor* setConstructor) override;
|
|||
void visit(TernaryOperator* ternaryOperator) override;
|
|||
void visit(TupleConstructor* tupleConstructor) override;
|
|||
void visit(TupleMapAccessExpression* tupleMapAccessExpression) override;
|
|||
void visit(UnaryOperator* unaryOperator) override;
|
|||
};
|
|||
} /* namespace Ast */
|