root / trunk / compiler / cppAst / ast / expressions / Expression.cpp @ 5
1 | 2 | krennw | /**
|
---|---|---|---|
2 | *
|
||
3 | * OOAS Compiler - C++ AST
|
||
4 | *
|
||
5 | * Copyright 2015, AIT Austrian Institute of Technology.
|
||
6 | * All rights reserved.
|
||
7 | *
|
||
8 | * SEE THE "LICENSE" FILE FOR THE TERMS UNDER WHICH THIS FILE IS PROVIDED.
|
||
9 | *
|
||
10 | * If you modify the file please update the list of contributors below to in-
|
||
11 | * clude your name. Please also stick to the coding convention of using TABs
|
||
12 | * to do the basic (block-level) indentation and spaces for anything after
|
||
13 | * that. (Enable the display of special chars and it should be pretty obvious
|
||
14 | * what this means.) Also, remove all trailing whitespace.
|
||
15 | *
|
||
16 | * Contributors:
|
||
17 | * Willibald Krenn (AIT)
|
||
18 | * Stephan Zimmerer (AIT)
|
||
19 | * Christoph Czurda (AIT)
|
||
20 | *
|
||
21 | */
|
||
22 | |||
23 | |||
24 | |||
25 | #include "Expression.hpp" |
||
26 | #include <ast/expressions/TernaryOperator.hpp> |
||
27 | #include <ast/expressions/BinaryOperator.hpp> |
||
28 | #include <ast/expressions/UnaryOperator.hpp> |
||
29 | #include <ast/expressions/ForallQuantifier.hpp> |
||
30 | #include <ast/expressions/ExistsQuantifier.hpp> |
||
31 | #include <ast/expressions/ListConstructor.hpp> |
||
32 | #include <ast/expressions/TupleConstructor.hpp> |
||
33 | #include <ast/expressions/ObjectConstructor.hpp> |
||
34 | #include <ast/expressions/IdentifierExpression.hpp> |
||
35 | #include <ast/expressions/TypeExpression.hpp> |
||
36 | #include <ast/expressions/TupleMapAccessExpression.hpp> |
||
37 | #include <ast/expressions/CallExpression.hpp> |
||
38 | #include <ast/expressions/AccessExpression.hpp> |
||
39 | #include <ast/expressions/ValueExpression.hpp> |
||
40 | #include <ast/expressions/SetConstructor.hpp> |
||
41 | #include <ast/expressions/TupleMapAccessExpression.hpp> |
||
42 | #include <ast/expressions/CallExpression.hpp> |
||
43 | #include <ast/expressions/AccessExpression.hpp> |
||
44 | |||
45 | namespace Ast {
|
||
46 | |||
47 | |||
48 | static void abstractError(ExpressionKind ) { |
||
49 | throw new Base::NotImplementedException(); |
||
50 | } |
||
51 | |||
52 | |||
53 | |||
54 | Base::FuncPtr Expression::s_exprVmt [2][EXPRESSIONKIND_NR_ITEMS] =
|
||
55 | { |
||
56 | { |
||
57 | /* conditional = 0, */ (Base::FuncPtr) &TernaryOperator::create,
|
||
58 | /* domresby = 1, */ (Base::FuncPtr) &abstractError, // ops on maps not supported |
||
59 | /* domresto = 2, */ (Base::FuncPtr) &abstractError, // ops on maps not supported |
||
60 | /* rngresby = 3, */ (Base::FuncPtr) &abstractError, // ops on maps not supported |
||
61 | /* rngresto = 4, */ (Base::FuncPtr) &abstractError, // ops on maps not supported |
||
62 | /* munion = 5, */ (Base::FuncPtr) &abstractError, // ops on maps not supported |
||
63 | /* conc = 6, */ (Base::FuncPtr) &BinaryOperator::create,
|
||
64 | /* diff = 7, */ (Base::FuncPtr) &BinaryOperator::create,
|
||
65 | /* inter = 8, */ (Base::FuncPtr) &BinaryOperator::create,
|
||
66 | /* elemin = 9, */ (Base::FuncPtr) &BinaryOperator::create,
|
||
67 | /* notelemin = 10, */ (Base::FuncPtr) &BinaryOperator::create,
|
||
68 | /* subset = 11, */ (Base::FuncPtr) &BinaryOperator::create,
|
||
69 | /* _union = 12, */ (Base::FuncPtr) &BinaryOperator::create,
|
||
70 | /* div = 13, */ (Base::FuncPtr) &BinaryOperator::create,
|
||
71 | /* greater = 14, */ (Base::FuncPtr) &BinaryOperator::create,
|
||
72 | /* greaterequal = 15, */ (Base::FuncPtr) &BinaryOperator::create,
|
||
73 | /* idiv = 16, */ (Base::FuncPtr) &BinaryOperator::create,
|
||
74 | /* less = 17, */ (Base::FuncPtr) &BinaryOperator::create,
|
||
75 | /* lessequal = 18, */ (Base::FuncPtr) &BinaryOperator::create,
|
||
76 | /* minus = 19, */ (Base::FuncPtr) &BinaryOperator::create,
|
||
77 | /* mod = 20, */ (Base::FuncPtr) &BinaryOperator::create,
|
||
78 | /* pow = 21, */ (Base::FuncPtr) &BinaryOperator::create,
|
||
79 | /* prod = 22, */ (Base::FuncPtr) &BinaryOperator::create,
|
||
80 | /* sum = 23, */ (Base::FuncPtr) &BinaryOperator::create,
|
||
81 | /* _and = 24, */ (Base::FuncPtr) &BinaryOperator::create,
|
||
82 | /* biimplies = 25, */ (Base::FuncPtr) &BinaryOperator::create,
|
||
83 | /* implies = 26, */ (Base::FuncPtr) &BinaryOperator::create,
|
||
84 | /* _or = 27, */ (Base::FuncPtr) &BinaryOperator::create,
|
||
85 | /* equal = 28, */ (Base::FuncPtr) &BinaryOperator::create,
|
||
86 | /* notequal = 29, */ (Base::FuncPtr) &BinaryOperator::create,
|
||
87 | /* seqmod_mapoverride = 30, */ (Base::FuncPtr) &abstractError,
|
||
88 | /* dom = 31, */ (Base::FuncPtr) &abstractError, // ops on maps not supported |
||
89 | /* range = 32, */ (Base::FuncPtr) &abstractError, // ops on maps not supported |
||
90 | /* merge = 33, */ (Base::FuncPtr) &abstractError, // ops on maps not supported |
||
91 | /* card = 34, */ (Base::FuncPtr) &UnaryOperator::create,
|
||
92 | /* dconc = 35, */ (Base::FuncPtr) &UnaryOperator::create,
|
||
93 | /* dinter = 36, */ (Base::FuncPtr) &UnaryOperator::create,
|
||
94 | /* dunion = 37, */ (Base::FuncPtr) &UnaryOperator::create,
|
||
95 | /* elems = 38, */ (Base::FuncPtr) &UnaryOperator::create,
|
||
96 | /* head = 39, */ (Base::FuncPtr) &UnaryOperator::create,
|
||
97 | /* inds = 40, */ (Base::FuncPtr) &UnaryOperator::create,
|
||
98 | /* len = 41, */ (Base::FuncPtr) &UnaryOperator::create,
|
||
99 | /* tail = 42, */ (Base::FuncPtr) &UnaryOperator::create,
|
||
100 | /* unminus = 43, */ (Base::FuncPtr) &UnaryOperator::create,
|
||
101 | /* unplus = 44, */ (Base::FuncPtr) &UnaryOperator::create,
|
||
102 | /* _not = 45, */ (Base::FuncPtr) &UnaryOperator::create,
|
||
103 | /* abs = 46, */ (Base::FuncPtr) &UnaryOperator::create,
|
||
104 | /* forall = 47, */ (Base::FuncPtr) &ForallQuantifier::create,
|
||
105 | /* exists = 48, */ (Base::FuncPtr) &ExistsQuantifier::create,
|
||
106 | /* ListConstr = 49, */ (Base::FuncPtr) &ListConstructor::create,
|
||
107 | /* SetConstr = 50, */ (Base::FuncPtr) &SetConstructor::create,
|
||
108 | /* MapConstr = 51, */ (Base::FuncPtr) &abstractError, // ops on maps not supported |
||
109 | /* TupleConstr = 52, */ (Base::FuncPtr) &TupleConstructor::create,
|
||
110 | /* ObjectConstr = 53, */ (Base::FuncPtr) &ObjectConstructor::create,
|
||
111 | /* QValConstr = 54, */ (Base::FuncPtr) &abstractError,
|
||
112 | /* Identifier = 55, */ (Base::FuncPtr) &IdentifierExpression::create,
|
||
113 | /* UnresolvedIdentifier = 56, */ (Base::FuncPtr) &abstractError,
|
||
114 | /* Type = 57, */ (Base::FuncPtr) &TypeExpression::create,
|
||
115 | /* TupleMapAccess = 58, */ (Base::FuncPtr) &TupleMapAccessExpression::create,
|
||
116 | /* Call = 59, */ (Base::FuncPtr) &CallExpression::create,
|
||
117 | /* Access = 60, */ (Base::FuncPtr) &AccessExpression::create,
|
||
118 | /* Primed = 61, */ (Base::FuncPtr) &abstractError,
|
||
119 | /* Cast = 62, */ (Base::FuncPtr) &UnaryOperator::create,
|
||
120 | /* foldLR = 63, */ (Base::FuncPtr) &TernaryOperator::create,
|
||
121 | /* foldRL = 64, */ (Base::FuncPtr) &abstractError,
|
||
122 | /* Value_Integer = 65, */ (Base::FuncPtr) &IntValueExpression::create,
|
||
123 | /* Value_Bool = 66, */ (Base::FuncPtr) &BoolValueExpression::create,
|
||
124 | /* Value_Reference = 67, */ (Base::FuncPtr) &RefValueExpression::create
|
||
125 | }, |
||
126 | { |
||
127 | /* conditional = 0, */ (Base::FuncPtr) &TernaryOperator::createCopy,
|
||
128 | /* domresby = 1, */ (Base::FuncPtr) &abstractError, // ops on maps not supported |
||
129 | /* domresto = 2, */ (Base::FuncPtr) &abstractError, // ops on maps not supported |
||
130 | /* rngresby = 3, */ (Base::FuncPtr) &abstractError, // ops on maps not supported |
||
131 | /* rngresto = 4, */ (Base::FuncPtr) &abstractError, // ops on maps not supported |
||
132 | /* munion = 5, */ (Base::FuncPtr) &abstractError, // ops on maps not supported |
||
133 | /* conc = 6, */ (Base::FuncPtr) &BinaryOperator::createCopy,
|
||
134 | /* diff = 7, */ (Base::FuncPtr) &BinaryOperator::createCopy,
|
||
135 | /* inter = 8, */ (Base::FuncPtr) &BinaryOperator::createCopy,
|
||
136 | /* elemin = 9, */ (Base::FuncPtr) &BinaryOperator::createCopy,
|
||
137 | /* notelemin = 10, */ (Base::FuncPtr) &BinaryOperator::createCopy,
|
||
138 | /* subset = 11, */ (Base::FuncPtr) &BinaryOperator::createCopy,
|
||
139 | /* _union = 12, */ (Base::FuncPtr) &BinaryOperator::createCopy,
|
||
140 | /* div = 13, */ (Base::FuncPtr) &BinaryOperator::createCopy,
|
||
141 | /* greater = 14, */ (Base::FuncPtr) &BinaryOperator::createCopy,
|
||
142 | /* greaterequal = 15, */ (Base::FuncPtr) &BinaryOperator::createCopy,
|
||
143 | /* idiv = 16, */ (Base::FuncPtr) &BinaryOperator::createCopy,
|
||
144 | /* less = 17, */ (Base::FuncPtr) &BinaryOperator::createCopy,
|
||
145 | /* lessequal = 18, */ (Base::FuncPtr) &BinaryOperator::createCopy,
|
||
146 | /* minus = 19, */ (Base::FuncPtr) &BinaryOperator::createCopy,
|
||
147 | /* mod = 20, */ (Base::FuncPtr) &BinaryOperator::createCopy,
|
||
148 | /* pow = 21, */ (Base::FuncPtr) &BinaryOperator::createCopy,
|
||
149 | /* prod = 22, */ (Base::FuncPtr) &BinaryOperator::createCopy,
|
||
150 | /* sum = 23, */ (Base::FuncPtr) &BinaryOperator::createCopy,
|
||
151 | /* _and = 24, */ (Base::FuncPtr) &BinaryOperator::createCopy,
|
||
152 | /* biimplies = 25, */ (Base::FuncPtr) &BinaryOperator::createCopy,
|
||
153 | /* implies = 26, */ (Base::FuncPtr) &BinaryOperator::createCopy,
|
||
154 | /* _or = 27, */ (Base::FuncPtr) &BinaryOperator::createCopy,
|
||
155 | /* equal = 28, */ (Base::FuncPtr) &BinaryOperator::createCopy,
|
||
156 | /* notequal = 29, */ (Base::FuncPtr) &BinaryOperator::createCopy,
|
||
157 | /* seqmod_mapoverride = 30, */ (Base::FuncPtr) &abstractError,
|
||
158 | /* dom = 31, */ (Base::FuncPtr) &abstractError, // ops on maps not supported |
||
159 | /* range = 32, */ (Base::FuncPtr) &abstractError, // ops on maps not supported |
||
160 | /* merge = 33, */ (Base::FuncPtr) &abstractError, // ops on maps not supported |
||
161 | /* card = 34, */ (Base::FuncPtr) &UnaryOperator::createCopy,
|
||
162 | /* dconc = 35, */ (Base::FuncPtr) &UnaryOperator::createCopy,
|
||
163 | /* dinter = 36, */ (Base::FuncPtr) &UnaryOperator::createCopy,
|
||
164 | /* dunion = 37, */ (Base::FuncPtr) &UnaryOperator::createCopy,
|
||
165 | /* elems = 38, */ (Base::FuncPtr) &UnaryOperator::createCopy,
|
||
166 | /* head = 39, */ (Base::FuncPtr) &UnaryOperator::createCopy,
|
||
167 | /* inds = 40, */ (Base::FuncPtr) &UnaryOperator::createCopy,
|
||
168 | /* len = 41, */ (Base::FuncPtr) &UnaryOperator::createCopy,
|
||
169 | /* tail = 42, */ (Base::FuncPtr) &UnaryOperator::createCopy,
|
||
170 | /* unminus = 43, */ (Base::FuncPtr) &UnaryOperator::createCopy,
|
||
171 | /* unplus = 44, */ (Base::FuncPtr) &UnaryOperator::createCopy,
|
||
172 | /* _not = 45, */ (Base::FuncPtr) &UnaryOperator::createCopy,
|
||
173 | /* abs = 46, */ (Base::FuncPtr) &UnaryOperator::createCopy,
|
||
174 | /* forall = 47, */ (Base::FuncPtr) &ForallQuantifier::createCopy,
|
||
175 | /* exists = 48, */ (Base::FuncPtr) &ExistsQuantifier::createCopy,
|
||
176 | /* ListConstr = 49, */ (Base::FuncPtr) &ListConstructor::createCopy,
|
||
177 | /* SetConstr = 50, */ (Base::FuncPtr) &SetConstructor::createCopy,
|
||
178 | /* MapConstr = 51, */ (Base::FuncPtr) &abstractError, // ops on maps not supported |
||
179 | /* TupleConstr = 52, */ (Base::FuncPtr) &TupleConstructor::createCopy,
|
||
180 | /* ObjectConstr = 53, */ (Base::FuncPtr) &ObjectConstructor::createCopy,
|
||
181 | /* QValConstr = 54, */ (Base::FuncPtr) &abstractError,
|
||
182 | /* Identifier = 55, */ (Base::FuncPtr) &IdentifierExpression::createCopy,
|
||
183 | /* UnresolvedIdentifier = 56, */ (Base::FuncPtr) &abstractError,
|
||
184 | /* Type = 57, */ (Base::FuncPtr) &TypeExpression::createCopy,
|
||
185 | /* TupleMapAccess = 58, */ (Base::FuncPtr) &TupleMapAccessExpression::createCopy,
|
||
186 | /* Call = 59, */ (Base::FuncPtr) &CallExpression::createCopy,
|
||
187 | /* Access = 60, */ (Base::FuncPtr) &AccessExpression::createCopy,
|
||
188 | /* Primed = 61, */ (Base::FuncPtr) &abstractError,
|
||
189 | /* Cast = 62, */ (Base::FuncPtr) &UnaryOperator::createCopy,
|
||
190 | /* foldLR = 63, */ (Base::FuncPtr) &TernaryOperator::createCopy,
|
||
191 | /* foldRL = 64, */ (Base::FuncPtr) &abstractError,
|
||
192 | /* Value_Integer = 65, */ (Base::FuncPtr) &IntValueExpression::createCopy,
|
||
193 | /* Value_Bool = 66, */ (Base::FuncPtr) &BoolValueExpression::createCopy,
|
||
194 | /* Value_Reference = 67, */ (Base::FuncPtr) &RefValueExpression::createCopy
|
||
195 | } |
||
196 | }; |
||
197 | |||
198 | |||
199 | Expression* Expression::createVirtual(ExpressionKind k) { |
||
200 | return (std::uint8_t)k < EXPRESSIONKIND_NR_ITEMS ? ((ConstrPtr)s_exprVmt[0][(std::uint8_t)k])(k) : nullptr; |
||
201 | } |
||
202 | |||
203 | Expression* Expression::createVirtual(const Expression& toCopy) {
|
||
204 | std::uint8_t kind ((std::uint8_t)toCopy.kind()); |
||
205 | return ((CopyConstrPtr)s_exprVmt[1][kind])(toCopy); |
||
206 | } |
||
207 | |||
208 | void Expression::accept(IAstVisitor& ) {
|
||
209 | throw new Base::NotImplementedException(); |
||
210 | }; |
||
211 | |||
212 | } |