1 |
7
|
krennw
|
|
2 |
|
|
|
3 |
|
|
|
4 |
|
|
|
5 |
|
|
|
6 |
|
|
|
7 |
|
|
|
8 |
|
|
|
9 |
|
|
|
10 |
|
|
|
11 |
|
|
|
12 |
|
|
|
13 |
|
|
|
14 |
|
|
|
15 |
|
|
|
16 |
|
|
|
17 |
|
|
|
18 |
|
|
|
19 |
|
|
|
20 |
|
|
|
21 |
|
|
|
22 |
2
|
krennw
|
|
23 |
|
|
|
24 |
|
|
|
25 |
|
|
#pragma once
|
26 |
|
|
|
27 |
|
|
#include <ast/CompleteAstTraversalVisitor.hpp>
|
28 |
|
|
#include <ast/Ast.hpp>
|
29 |
|
|
#include <unordered_map>
|
30 |
|
|
#include <ast/expressions/Quantifier.hpp>
|
31 |
|
|
|
32 |
|
|
namespace Ast {
|
33 |
|
|
|
34 |
|
|
|
35 |
|
|
|
36 |
|
|
|
37 |
|
|
|
38 |
|
|
class DeepCloneVisitor final :
|
39 |
|
|
public CompleteAstTraversalVisitor
|
40 |
|
|
{
|
41 |
|
|
protected:
|
42 |
|
|
Ast* m_cloneAst;
|
43 |
|
|
std::unordered_map<void*, void*> m_mapping;
|
44 |
|
|
Identifier* m_selfreplacement;
|
45 |
|
|
bool m_allowLinksToNonClonedParents;
|
46 |
|
|
bool m_quantifierState;
|
47 |
|
|
|
48 |
|
|
void updateScope(IScope* aScope);
|
49 |
|
|
void checkScope(IScope* aScope);
|
50 |
|
|
Expression* eClone(Expression* anExpr);
|
51 |
|
|
Statement* sClone(Statement* aStatement);
|
52 |
|
|
void symTabClone(SymbolTable* aTable);
|
53 |
|
|
void cloneBlock(Block* aBlock);
|
54 |
|
|
void cloneQuantifier(Quantifier* qf);
|
55 |
|
|
void cloneExpressionList(ExpressionList& aList);
|
56 |
|
|
|
57 |
|
|
void error() {
|
58 |
|
|
m_context->logError("Internal error: Cannot clone a type");
|
59 |
|
|
abort();
|
60 |
|
|
}
|
61 |
|
|
|
62 |
|
|
public:
|
63 |
|
|
DeepCloneVisitor(
|
64 |
|
|
CallContext* context,
|
65 |
|
|
Ast* cloneAst,
|
66 |
|
|
bool linksToNonClonedParents = true,
|
67 |
|
|
const std::unordered_map<void*, void*>* initMapping = nullptr,
|
68 |
|
|
Identifier* selfreplace = nullptr)
|
69 |
|
|
:
|
70 |
|
|
CompleteAstTraversalVisitor( context, false),
|
71 |
|
|
m_cloneAst (cloneAst),
|
72 |
|
|
m_mapping(),
|
73 |
|
|
m_selfreplacement (selfreplace),
|
74 |
|
|
m_allowLinksToNonClonedParents (linksToNonClonedParents),
|
75 |
|
|
m_quantifierState (false)
|
76 |
|
|
{
|
77 |
|
|
if (initMapping != nullptr)
|
78 |
|
|
m_mapping.insert(initMapping->begin(), initMapping->end());
|
79 |
|
|
}
|
80 |
|
|
|
81 |
|
|
std::string returnVisitorName() override {return "DeepCloneVisitor";}
|
82 |
|
|
|
83 |
|
|
void visit(BoolType* ) override { error(); }
|
84 |
|
|
void visit(EnumType* ) override { error(); }
|
85 |
|
|
void visit(FunctionType* ) override { error(); }
|
86 |
|
|
void visit(IntType* ) override { error(); }
|
87 |
|
|
void visit(ListType* ) override { error(); }
|
88 |
|
|
void visit(NullType* ) override { error(); }
|
89 |
|
|
void visit(ActionSystemType* ) override { error(); }
|
90 |
|
|
void visit(TupleType* ) override { error(); }
|
91 |
|
|
|
92 |
|
|
void visit(EnumIdentifier* ) override { error(); }
|
93 |
|
|
void visit(ExpressionVariableIdentifier* ) override { error(); }
|
94 |
|
|
void visit(LocalVariableIdentifier* ) override { error(); }
|
95 |
|
|
void visit(MainModule* ) override { error(); }
|
96 |
|
|
void visit(MethodIdentifier* ) override { error(); }
|
97 |
|
|
void visit(Module* ) override { error(); }
|
98 |
|
|
void visit(NondetIdentifierBlock* ) override{ error(); }
|
99 |
|
|
void visit(ParameterIdentifier* ) override { error(); }
|
100 |
|
|
void visit(PrioIdentifierBlock* ) override { error(); }
|
101 |
|
|
void visit(SeqIdentifierBlock* ) override { error(); }
|
102 |
|
|
void visit(TypeIdentifier* ) override { error(); }
|
103 |
|
|
void visit(UnspecIdentifierBlock* ) override { error(); }
|
104 |
|
|
|
105 |
|
|
|
106 |
|
|
void visit(NamedActionIdentifier* namedActionIdentifier) override;
|
107 |
|
|
void visit(ObjectConstructor* objectConstructor) override;
|
108 |
|
|
|
109 |
|
|
|
110 |
|
|
|
111 |
|
|
void visit(BoolValueExpression* ) override {};
|
112 |
|
|
void visit(IntValueExpression* ) override {};
|
113 |
|
|
void visit(RefValueExpression* ) override {};
|
114 |
|
|
void visit(Skip* ) override { }
|
115 |
|
|
void visit(Break* ) override { error(); }
|
116 |
|
|
void visit(TypeExpression* ) override { }
|
117 |
|
|
|
118 |
|
|
|
119 |
|
|
void visit(NondetBlock* nondetBlock) override;
|
120 |
|
|
void visit(SeqBlock* seqBlock) override;
|
121 |
|
|
void visit(PrioBlock* prioBlock) override;
|
122 |
|
|
void visit(AccessExpression* accessExpression) override;
|
123 |
|
|
void visit(BinaryOperator* binaryOperator) override;
|
124 |
|
|
void visit(Assignment* assignment) override;
|
125 |
|
|
void visit(AttributeIdentifier* attributeIdentifier) override;
|
126 |
|
|
void visit(Call* call) override;
|
127 |
|
|
|
128 |
|
|
void visit(CallExpression* callExpression) override;
|
129 |
|
|
void visit(ExistsQuantifier* quantifier) override;
|
130 |
|
|
void visit(ForallQuantifier* quantifier) override;
|
131 |
|
|
void visit(GuardedCommand* guardedCommand) override;
|
132 |
|
|
void visit(IdentifierExpression* identifierExpression) override;
|
133 |
|
|
void visit(ListConstructor* listConstructor) override;
|
134 |
|
|
void visit(SetConstructor* setConstructor) override;
|
135 |
|
|
void visit(TernaryOperator* ternaryOperator) override;
|
136 |
|
|
void visit(TupleConstructor* tupleConstructor) override;
|
137 |
|
|
void visit(TupleMapAccessExpression* tupleMapAccessExpression) override;
|
138 |
|
|
void visit(UnaryOperator* unaryOperator) override;
|
139 |
|
|
};
|
140 |
|
|
|
141 |
|
|
} |