31 #include <ast/parser/parse.hpp>
51 AST_Expression e2 = mapTraverseElement(e);
52 switch (e2->expressionType()) {
54 AST_Expression_BinOp b = e2->getAsBinOp();
58 AST_Expression_BooleanNot n = e2->getAsBooleanNot();
62 AST_Expression_UMinus m = e2->getAsUMinus();
66 AST_Expression_Output b = e2->getAsOutput();
67 AST_ExpressionList ls =
new list<AST_Expression>();
72 AST_Expression_If i = e2->getAsIf();
73 return (
newAST_Expression_If(apply(i->condition()), apply(i->then()), i->elseif_list(), apply(i->else_exp())));
76 AST_Expression_Call c = e2->getAsCall();
78 AST_ExpressionListIterator args_it;
79 foreach (args_it, c->arguments()) {
95 if (a->expressionType() != b->expressionType()) {
98 switch (a->expressionType()) {
100 AST_Expression_BinOp binOpA = a->getAsBinOp();
101 AST_Expression_BinOp binOpB = b->getAsBinOp();
102 return (equalTraverse(binOpA->left(), binOpB->left()) && equalTraverse(binOpA->right(), binOpB->right()));
105 return equalTraverseElement(a, b);
114 AST_ExpressionListIterator it;
126 if (a->expressionType() != b->expressionType()) {
129 switch (a->expressionType()) {
131 AST_Expression_ComponentReference compRefA = a->getAsComponentReference();
134 return compareArrays(compRefA, b->getAsComponentReference());
140 AST_ExpressionList argsA = a->getAsDerivative()->arguments();
141 AST_ExpressionList argsB = b->getAsDerivative()->arguments();
142 if (argsA->size() != argsB->size()) {
146 "EqualExp::equalTraverseElement:\n"
147 "AST_Expression_Derivative with more than 1 argument are not supported yet.\n");
148 AST_Expression_ComponentReference compRef1 = a->getAsDerivative()->arguments()->front()->getAsComponentReference();
149 AST_Expression_ComponentReference compRef2 = b->getAsDerivative()->arguments()->front()->getAsComponentReference();
150 return equalTraverse(compRef1, compRef2);
153 AST_Expression_Real realA = a->getAsReal();
154 AST_Expression_Real realB = b->getAsReal();
155 return realA->val() == realB->val();
158 AST_Expression_Integer intA = a->getAsInteger();
159 AST_Expression_Integer intB = b->getAsInteger();
160 return intA->val() == intB->val();
163 string nameA = *(a->getAsCall()->name());
164 string nameB = *(b->getAsCall()->name());
165 if (nameA.compare(nameB)) {
168 AST_ExpressionList ael = a->getAsCall()->arguments();
169 AST_ExpressionList bel = b->getAsCall()->arguments();
170 return _compareList(ael, bel);
173 AST_ExpressionList ael = a->getAsCallArgs()->arguments();
174 AST_ExpressionList bel = b->getAsCallArgs()->arguments();
175 return _compareList(ael, bel);
178 AST_ExpressionList ael = a->getAsBrace()->arguments();
179 AST_ExpressionList bel = b->getAsBrace()->arguments();
180 return _compareList(ael, bel);
183 AST_ExpressionList ael = a->getAsOutput()->expressionList();
184 AST_ExpressionList bel = b->getAsOutput()->expressionList();
185 return _compareList(ael, bel);
188 AST_Expression_UMinus m = a->getAsUMinus();
189 AST_Expression_UMinus m1 = b->getAsUMinus();
190 return equalTraverseElement(m->exp(), m1->exp());
194 "EqualExp::equalTraverseElement:\n"
195 "Incorrect AST_Expression_Type %s",
196 a->expressionType());
204 AST_StringList names = compRef->names();
205 if (names->size() > 0) {
207 "EqualExp::getVariable\n"
208 "AST_Component_Reference with names list bigger than 1 are not supported yet.\n");
219 AST_ExpressionListList indexesListA = arrayA->indexes();
220 AST_ExpressionListList indexesListB = arrayB->indexes();
221 ERROR_UNLESS(indexesListA->size() == indexesListB->size(),
222 "EqualExp::compareArrays:\n"
223 "indexes list sizes should be equal.\n");
225 "EqualExp::compareArrays:\n"
226 "Indexes list sizes greater than 1 are not supported yet.\n");
227 AST_ExpressionList indexesA = indexesListA->front();
228 AST_ExpressionList indexesB = indexesListB->front();
230 "EqualExp::compareArrays:\n"
231 "indexes sizes should be equal.\n");
233 "EqualExp::compareArrays:\n"
234 "Multidimensional arrays are not supported yet.\n");
235 return equalTraverse(indexesA->front(), indexesB->front());
244 switch (e->expressionType()) {
251 AST_Expression_ComponentReference cr = e->getAsComponentReference();
253 if (v->isParameter()) {
270 _symbol_table = symbol_table;
297 switch (e->expressionType()) {
299 AST_Expression_Boolean b = e->getAsBoolean();
325 switch (e->expressionType()) {
327 AST_Expression_Boolean b = e->getAsBoolean();
339 AST_Expression_Output b = e->getAsOutput();
343 AST_Expression_Call call = e->getAsCall();
344 if (
toStr(call->name()) ==
"edge") {
345 return GREATER(call->arguments()->front(),
_R(0.5));
352 AST_Expression_BooleanNot no = e->getAsBooleanNot();
356 AST_Expression_If i = e->getAsIf();
357 AST_Expression eq1 = apply(i->then());
358 AST_Expression eq2 = apply(i->else_exp());
359 AST_Expression cond = apply(i->condition());
381 switch (e->expressionType()) {
383 AST_Expression_Output b = e->getAsOutput();
387 AST_Expression_Call call = e->getAsCall();
388 AST_ExpressionListIterator it;
389 foreach (it, call->arguments()) {
395 AST_Expression_ComponentReference cr = e->getAsComponentReference();
396 if (_pre->find(cr->name()) != _pre->end()) {
402 AST_Expression_BooleanNot no = e->getAsBooleanNot();
418 switch (e->expressionType()) {
420 AST_Expression_Output b = e->getAsOutput();
421 return apply(b->expressionList()->front());
424 AST_Expression_Call call = e->getAsCall();
425 AST_ExpressionListIterator it;
427 foreach (it, call->arguments())
432 AST_Expression_ComponentReference cr = e->getAsComponentReference();
433 return cr->name() ==
toStr(_var);
436 AST_Expression_BooleanNot no = e->getAsBooleanNot();
437 return apply(no->exp());
440 AST_Expression_If i = e->getAsIf();
441 bool eq1 = apply(i->then());
442 bool eq2 = apply(i->else_exp());
443 bool cond = apply(i->condition());
444 return eq1 || eq2 || cond;
469 switch (e->expressionType()) {
471 AST_Expression_Output b = e->getAsOutput();
475 AST_Expression_Call call = e->getAsCall();
476 AST_ExpressionListIterator it;
477 foreach (it, call->arguments()) {
483 AST_Expression_ComponentReference cr = e->getAsComponentReference();
484 if (cr->name() ==
toStr(_pre)) {
490 AST_Expression_BooleanNot no = e->getAsBooleanNot();