00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00035 #include "condoperandexpression.h"
00036 #include "operandexpression.h"
00037
00038 CondOperandExpression::CondOperandExpression(OperandExpression * _left,
00039 COMP_TYPE _op,
00040 OperandExpression *
00041 _right):CondExpression
00042 (ect_operand),
00043 left(_left),
00044 op(_op),
00045 right(_right) {
00046 }
00047
00048 CondOperandExpression::~CondOperandExpression() {
00049 delete left;
00050 delete right;
00051 }
00052
00053 void CondOperandExpression::scopeCheck(vector < unsigned >&def_vars,
00054 vector < unsigned >&introduced_vars,
00055 vector < unsigned >&violating_vars) {
00056 left->scopeCheck(def_vars, introduced_vars, violating_vars);
00057 right->scopeCheck(def_vars, introduced_vars, violating_vars);
00058 }
00059
00060 void CondOperandExpression::replaceVarId(unsigned old_id, unsigned new_id) {
00061 left->replaceVarId(old_id, new_id);
00062 right->replaceVarId(old_id, new_id);
00063 }
00064
00065 void CondOperandExpression::extractFSAMap(FSAMap * fsamap, unsigned parent_var) {
00066 left->extractFSAMap(fsamap, parent_var);
00067 right->extractFSAMap(fsamap, parent_var);
00068 }
00069
00070 void CondOperandExpression::extractParVarMap(ParVarMap * parvarmap) {
00071 left->extractParVarMap(parvarmap);
00072 right->extractParVarMap(parvarmap);
00073 }
00074
00075 void CondOperandExpression::extractDependencies(vector <
00076 DependencySet * >*depset) {
00077 left->extractDependencies(depset);
00078 right->extractDependencies(depset);
00079 }
00080
00081 Expression *CondOperandExpression::placeSignOffs(vector <
00082 SignOffExpression *
00083 >&signoffs) {
00084 left = (OperandExpression *) left->placeSignOffs(signoffs);
00085 right = (OperandExpression *) right->placeSignOffs(signoffs);
00086
00087 return this;
00088 }
00089
00090 void CondOperandExpression::rewriteEmptyFuncts() {
00091 left->rewriteEmptyFuncts();
00092 right->rewriteEmptyFuncts();
00093 }
00094
00095 void CondOperandExpression::rewriteVarstepCondExps() {
00096 left->rewriteVarstepCondExps();
00097 right->rewriteVarstepCondExps();
00098 }
00099
00100 void CondOperandExpression::rewriteAggregateFuncts() {
00101 left->rewriteAggregateFuncts();
00102 right->rewriteAggregateFuncts();
00103 }
00104
00105 void CondOperandExpression::print(OutputStream & dos) const {
00106 dos << (*left) << " ";
00107 switch (op) {
00108 case ct_lt:
00109 dos << "<";
00110 break;
00111 case ct_leq:
00112 dos << "<=";
00113 break;
00114 case ct_eq:
00115 dos << "=";
00116 break;
00117 case ct_gt:
00118 dos << ">";
00119 break;
00120 case ct_geq:
00121 dos << ">=";
00122 break;
00123 case ct_neq:
00124 dos << "!=";
00125 break;
00126 }
00127 dos << " " << (*right);
00128 }
00129
00130 void CondOperandExpression::init(BufferNode * root) {
00131 left->init(root);
00132 right->init(root);
00133 }
00134
00135 bool CondOperandExpression::evalCond(OutputStream & eos, Environment * env,
00136 unsigned modus) {
00137
00138
00139 switch (modus) {
00140
00141 case EVAL_QUERY:
00142 {
00143
00144 OperandExpression *lop = NULL;
00145 OperandExpression *rop = NULL;
00146 COMP_TYPE ct;
00147
00148 if (right->isSingleValued()) {
00149 lop = right;
00150 rop = left;
00151 ct = invertOperator(op);
00152 } else {
00153 lop = left;
00154 rop = right;
00155 ct = op;
00156 }
00157
00158
00159 lop->prepareOperand(eos, env, modus);
00160 rop->prepareOperand(eos, env, modus);
00161
00162 Value *lval = lop->getNextValue();
00163
00164 while (lval != NULL) {
00165 Value *rval = rop->getNextValue();
00166
00167 while (rval != NULL) {
00168 if (evalRelOp(lval, ct, rval)) {
00169 lop->unprepareOperand();
00170 rop->unprepareOperand();
00171 return true;
00172 }
00173 rval = rop->getNextValue();
00174 }
00175 rop->unprepareOperand();
00176 lval = lop->getNextValue();
00177 }
00178
00179 lop->unprepareOperand();
00180 rop->unprepareOperand();
00181
00182 break;
00183 }
00184
00185 case EVAL_SIGNOFF:
00186 break;
00187
00188 default:
00189 throw
00190 RuntimeException
00191 ("CondOperandExpression: Illegal Evaluation Mode",
00192 eid_runtime_illegalmode);
00193 break;
00194 }
00195
00196 return false;
00197 }
00198
00199 bool CondOperandExpression::evalRelOp(Value * left, COMP_TYPE comp,
00200 Value * right) {
00201
00202 if (left->type == xsd_numeric || right->type == xsd_numeric) {
00203 switch (comp) {
00204 case ct_lt:
00205 return left->getNumVal() < right->getNumVal();
00206 case ct_leq:
00207 return left->getNumVal() <= right->getNumVal();
00208 case ct_eq:
00209 return left->getNumVal() == right->getNumVal();
00210 case ct_gt:
00211 return left->getNumVal() > right->getNumVal();
00212 case ct_geq:
00213 return left->getNumVal() >= right->getNumVal();
00214 case ct_neq:
00215 return left->getNumVal() != right->getNumVal();
00216 default:
00217 return false;
00218 }
00219 } else {
00220 switch (comp) {
00221 case ct_lt:
00222 return strcmp(left->getStrVal(), right->getStrVal()) < 0;
00223 case ct_leq:
00224 return strcmp(left->getStrVal(), right->getStrVal()) <= 0;
00225 case ct_eq:
00226 return strcmp(left->getStrVal(), right->getStrVal()) == 0;
00227 case ct_gt:
00228 return strcmp(left->getStrVal(), right->getStrVal()) > 0;
00229 case ct_geq:
00230 return strcmp(left->getStrVal(), right->getStrVal()) >= 0;
00231 case ct_neq:
00232 return strcmp(left->getStrVal(), right->getStrVal()) != 0;
00233 default:
00234 return false;
00235 }
00236 }
00237 }
00238
00239 COMP_TYPE CondOperandExpression::invertOperator(COMP_TYPE ot) {
00240 switch (ot) {
00241 case ct_lt:
00242 return ct_gt;
00243 case ct_leq:
00244 return ct_geq;
00245 case ct_gt:
00246 return ct_lt;
00247 case ct_geq:
00248 return ct_leq;
00249 case ct_eq:
00250 case ct_neq:
00251 default:
00252 return ot;
00253 }
00254 }