1
|
|
2
|
|
3
|
|
4
|
|
5
|
|
6
|
|
7
|
|
8
|
|
9
|
|
10
|
|
11
|
|
12
|
|
13
|
|
14
|
|
15
|
|
16
|
|
17
|
|
18
|
|
19
|
|
20
|
|
21
|
|
22
|
|
23
|
|
24
|
|
25
|
|
26
|
#include "ExpressionVisitor.hpp"
|
27
|
#include <ast/expressions/IdentifierExpression.hpp>
|
28
|
#include <ast/expressions/TypeExpression.hpp>
|
29
|
#include <ast/expressions/ListConstructor.hpp>
|
30
|
#include <ast/expressions/SetConstructor.hpp>
|
31
|
#include <ast/expressions/TupleConstructor.hpp>
|
32
|
#include <ast/expressions/AccessExpression.hpp>
|
33
|
#include <ast/expressions/BinaryOperator.hpp>
|
34
|
#include <ast/expressions/TernaryOperator.hpp>
|
35
|
#include <ast/expressions/TupleMapAccessExpression.hpp>
|
36
|
#include <ast/expressions/CallExpression.hpp>
|
37
|
#include <ast/expressions/ForallQuantifier.hpp>
|
38
|
#include <ast/expressions/ExistsQuantifier.hpp>
|
39
|
#include <ast/expressions/UnaryOperator.hpp>
|
40
|
|
41
|
|
42
|
namespace Ast {
|
43
|
|
44
|
|
45
|
ExpressionVisitor::ExpressionVisitor(CallContext* context):
|
46
|
m_context(context)
|
47
|
{}
|
48
|
|
49
|
ExpressionVisitor::~ExpressionVisitor()
|
50
|
{}
|
51
|
|
52
|
|
53
|
void ExpressionVisitor::visitSub(AstElement* subElement, AstElement* parent) {
|
54
|
if (subElement == nullptr)
|
55
|
return;
|
56
|
visitAstElement(subElement, parent);
|
57
|
}
|
58
|
|
59
|
void ExpressionVisitor::visitAstElement(AstElement* element, AstElement* ){
|
60
|
switch (element->nodeType()) {
|
61
|
case AstNodeTypeEnum::statement:
|
62
|
case AstNodeTypeEnum::identifier:
|
63
|
case AstNodeTypeEnum::type:
|
64
|
error();
|
65
|
break;
|
66
|
case AstNodeTypeEnum::expression:
|
67
|
static_cast<Expression*>(element)->accept(*this);
|
68
|
break;
|
69
|
default:
|
70
|
m_context->logError("Internal error. Unknown AST type.");
|
71
|
abort();
|
72
|
}
|
73
|
}
|
74
|
|
75
|
void ExpressionVisitor::error() {
|
76
|
m_context -> logError("Internal error. This visitor only supports expressions.");
|
77
|
abort();
|
78
|
}
|
79
|
|
80
|
|
81
|
void ExpressionVisitor::visit(TypeIdentifier* ) { error(); };
|
82
|
void ExpressionVisitor::visit(EnumIdentifier* ) { error(); };
|
83
|
|
84
|
void ExpressionVisitor::visit(AttributeIdentifier* ) { error(); };
|
85
|
void ExpressionVisitor::visit(LocalVariableIdentifier* ) { error(); };
|
86
|
void ExpressionVisitor::visit(ParameterIdentifier* ) { error(); };
|
87
|
void ExpressionVisitor::visit(ExpressionVariableIdentifier* ) { error(); };
|
88
|
void ExpressionVisitor::visit(MethodIdentifier* ) { error(); };
|
89
|
void ExpressionVisitor::visit(NamedActionIdentifier* ) { error(); };
|
90
|
void ExpressionVisitor::visit(Module* ) { error(); };
|
91
|
void ExpressionVisitor::visit(ConstantIdentifier* ) { error(); };
|
92
|
void ExpressionVisitor::visit(UnspecIdentifierBlock* ) { error(); };
|
93
|
void ExpressionVisitor::visit(SeqIdentifierBlock* ) { error(); };
|
94
|
void ExpressionVisitor::visit(NondetIdentifierBlock* ) { error(); };
|
95
|
void ExpressionVisitor::visit(PrioIdentifierBlock* ) { error(); };
|
96
|
void ExpressionVisitor::visit(MainModule* ) { error(); };
|
97
|
void ExpressionVisitor::visit(IntType* ) { error(); };
|
98
|
void ExpressionVisitor::visit(BoolType* ) { error(); };
|
99
|
void ExpressionVisitor::visit(EnumType* ) { error(); };
|
100
|
void ExpressionVisitor::visit(ListType* ) { error(); };
|
101
|
void ExpressionVisitor::visit(TupleType* ) { error(); };
|
102
|
void ExpressionVisitor::visit(NullType* ) { error(); };
|
103
|
void ExpressionVisitor::visit(PointerType* ) { error(); };
|
104
|
void ExpressionVisitor::visit(FunctionType* ) { error(); };
|
105
|
void ExpressionVisitor::visit(ActionSystemType* ) { error(); };
|
106
|
void ExpressionVisitor::visit(GuardedCommand* ) { error(); };
|
107
|
void ExpressionVisitor::visit(Call* ) { error(); };
|
108
|
void ExpressionVisitor::visit(Assignment* ) { error(); };
|
109
|
void ExpressionVisitor::visit(SeqBlock* ) { error(); };
|
110
|
void ExpressionVisitor::visit(NondetBlock* ) { error(); };
|
111
|
void ExpressionVisitor::visit(PrioBlock* ) { error(); };
|
112
|
void ExpressionVisitor::visit(Skip* ) { error(); };
|
113
|
void ExpressionVisitor::visit(Break* ) { error(); };
|
114
|
void ExpressionVisitor::visit(Abort* ) { error(); };
|
115
|
|
116
|
|
117
|
void ExpressionVisitor::visit(TernaryOperator* ternaryOperator) {
|
118
|
visitSub(ternaryOperator->left(), ternaryOperator);
|
119
|
visitSub(ternaryOperator->mid(), ternaryOperator);
|
120
|
visitSub(ternaryOperator->right(), ternaryOperator);
|
121
|
};
|
122
|
void ExpressionVisitor::visit(BinaryOperator* binaryOperator) {
|
123
|
visitSub(binaryOperator->left(), binaryOperator);
|
124
|
visitSub(binaryOperator->right(), binaryOperator);
|
125
|
};
|
126
|
void ExpressionVisitor::visit(UnaryOperator* unaryOperator) {
|
127
|
visitSub(unaryOperator->child(), unaryOperator);
|
128
|
};
|
129
|
void ExpressionVisitor::visit(ExistsQuantifier* quantifier) {
|
130
|
visitSub(quantifier->child(), quantifier);
|
131
|
};
|
132
|
void ExpressionVisitor::visit(ForallQuantifier* quantifier) {
|
133
|
visitSub(quantifier->child(), quantifier);
|
134
|
};
|
135
|
void ExpressionVisitor::visit(ListConstructor* listConstructor) {
|
136
|
for (auto& elems: listConstructor->elements())
|
137
|
visitSub(elems, listConstructor);
|
138
|
|
139
|
visitSub(listConstructor->comprehension(), listConstructor);
|
140
|
};
|
141
|
void ExpressionVisitor::visit(SetConstructor* setConstructor) {
|
142
|
for (auto& elems: setConstructor->items())
|
143
|
visitSub(elems, setConstructor);
|
144
|
|
145
|
visitSub(setConstructor->comprehension(), setConstructor);
|
146
|
};
|
147
|
void ExpressionVisitor::visit(TupleConstructor* tupleConstructor) {
|
148
|
for (auto& elem: tupleConstructor->values())
|
149
|
visitSub(elem, tupleConstructor);
|
150
|
};
|
151
|
void ExpressionVisitor::visit(ObjectConstructor* ) {};
|
152
|
void ExpressionVisitor::visit(BoolValueExpression* ) {};
|
153
|
void ExpressionVisitor::visit(IntValueExpression* ) {};
|
154
|
void ExpressionVisitor::visit(RefValueExpression* ) {};
|
155
|
void ExpressionVisitor::visit(IdentifierExpression* ) {};
|
156
|
void ExpressionVisitor::visit(TypeExpression* ) {};
|
157
|
void ExpressionVisitor::visit(TupleMapAccessExpression* tupleMapAccessExpression) {
|
158
|
visitSub(tupleMapAccessExpression->argument(), tupleMapAccessExpression);
|
159
|
visitSub(tupleMapAccessExpression->child(), tupleMapAccessExpression);
|
160
|
};
|
161
|
void ExpressionVisitor::visit(CallExpression* callExpression) {
|
162
|
for (auto& arg: callExpression->arguments())
|
163
|
visitSub(arg, callExpression);
|
164
|
visitSub(callExpression->child(), callExpression);
|
165
|
};
|
166
|
void ExpressionVisitor::visit(AccessExpression* accessExpression) {
|
167
|
visitSub(accessExpression->left(), accessExpression);
|
168
|
visitSub(accessExpression->right(), accessExpression);
|
169
|
};
|
170
|
|
171
|
}
|