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 "sequenceexpression.h"
00036
00037 SequenceExpression::SequenceExpression(Expression * _left, Expression * _right):
00038 Expression(et_sequence), delete_recursively(true) {
00039 exps.push_back(_left);
00040 exps.push_back(_right);
00041 }
00042
00043 SequenceExpression::~SequenceExpression() {
00044 for (unsigned i = 0; i < exps.size() && delete_recursively; i++) {
00045 delete exps[i];
00046 }
00047 }
00048
00049 void SequenceExpression::scopeCheck(vector < unsigned >&def_vars,
00050 vector < unsigned >&introduced_vars,
00051 vector < unsigned >&violating_vars) {
00052 for (unsigned i = 0; i < exps.size(); i++) {
00053 vector < unsigned >def_vars_cpy = def_vars;
00054
00055 exps[i]->scopeCheck(def_vars_cpy, introduced_vars, violating_vars);
00056 }
00057 }
00058
00059 void SequenceExpression::replaceVarId(unsigned old_id, unsigned new_id) {
00060 for (unsigned i = 0; i < exps.size(); i++) {
00061 exps[i]->replaceVarId(old_id, new_id);
00062 }
00063 }
00064
00065 void SequenceExpression::mergeSequences() {
00066 for (unsigned i = 0; i < exps.size(); i++) {
00067 exps[i]->mergeSequences();
00068 }
00069
00070 vector < Expression * >new_exps;
00071 for (unsigned i = 0; i < exps.size(); i++) {
00072 if (exps[i]->getType() == et_sequence) {
00073 SequenceExpression *se_sub = (SequenceExpression *) exps[i];
00074
00075 vector < Expression * >*sub = se_sub->getExps();
00076 for (unsigned i = 0; i < sub->size(); i++) {
00077 new_exps.push_back((*sub)[i]);
00078 }
00079 se_sub->unsetRecursiveDelete();
00080 delete se_sub;
00081 } else {
00082 new_exps.push_back(exps[i]);
00083 }
00084 }
00085 exps = new_exps;
00086 }
00087
00088 void SequenceExpression::extractFSAMap(FSAMap * fsamap, unsigned parent_var) {
00089 for (unsigned i = 0; i < exps.size(); i++) {
00090 exps[i]->extractFSAMap(fsamap, parent_var);
00091 }
00092 }
00093
00094 void SequenceExpression::extractParVarMap(ParVarMap * parvarmap) {
00095 for (unsigned i = 0; i < exps.size(); i++) {
00096 exps[i]->extractParVarMap(parvarmap);
00097 }
00098 }
00099
00100 void SequenceExpression::extractDependencies(vector < DependencySet * >*depset) {
00101 for (unsigned i = 0; i < exps.size(); i++) {
00102 exps[i]->extractDependencies(depset);
00103 }
00104 }
00105
00106 Expression *SequenceExpression::placeSignOffs(vector <
00107 SignOffExpression * >&signoffs) {
00108 for (unsigned i = 0; i < exps.size(); i++) {
00109 exps[i] = exps[i]->placeSignOffs(signoffs);
00110 }
00111
00112 return this;
00113 }
00114
00115 void SequenceExpression::rewriteWhereExps() {
00116 for (unsigned i = 0; i < exps.size(); i++) {
00117 exps[i]->rewriteWhereExps();
00118 }
00119 }
00120
00121 void SequenceExpression::rewriteEmptyFuncts() {
00122 for (unsigned i = 0; i < exps.size(); i++) {
00123 exps[i]->rewriteEmptyFuncts();
00124 }
00125 }
00126
00127 void SequenceExpression::rewriteVarstepCondExps() {
00128 for (unsigned i = 0; i < exps.size(); i++) {
00129 exps[i]->rewriteVarstepCondExps();
00130 }
00131 }
00132
00133 void SequenceExpression::rewriteAggregateFuncts() {
00134 for (unsigned i = 0; i < exps.size(); i++) {
00135 exps[i]->rewriteAggregateFuncts();
00136 }
00137 }
00138
00139 void SequenceExpression::rewriteVarsteps() {
00140 for (unsigned i = 0; i < exps.size(); i++) {
00141 if (exps[i]->getType() == et_varstep) {
00142 VarStepExpression *sub = ((VarStepExpression *) exps[i])->clone();
00143 delete exps[i];
00144 VarExpression *tmpvar =
00145 new VarExpression(VarName::getInstance()->getFreshVarname(),
00146 true);
00147 ForExpression *forexp =
00148 new ForExpression(tmpvar, sub, tmpvar->clone());
00149 exps[i] = forexp;
00150 } else {
00151 exps[i]->rewriteVarsteps();
00152 }
00153 }
00154 }
00155
00156 void SequenceExpression::print(OutputStream & dos) const {
00157 bool bprint = false;
00158
00159 for (unsigned i = 0; i < exps.size(); i++) {
00160 if (!bprint && exps[i]->getType() != et_comment
00161 && exps[i]->getType() != et_doc) {
00162 dos << "(" << NEWLINE << incrementIndents();
00163 bprint = true;
00164 }
00165 dos << writeIndents() << (*exps[i]);
00166 if (i < exps.size() - 1 && exps[i]->getType() != et_comment
00167 && exps[i]->getType() != et_doc) {
00168 dos << ",";
00169 }
00170 if (exps[i]->getType() != et_comment && exps[i]->getType() != et_doc) {
00171 dos << NEWLINE;
00172
00173 }
00174 }
00175
00176 if (bprint) {
00177 dos << decrementIndents();
00178 }
00179
00180 dos << writeIndents();
00181
00182 if (bprint) {
00183 dos << ")";
00184 }
00185 }
00186
00187 void SequenceExpression::init(BufferNode * root) {
00188 for (unsigned i = 0; i < exps.size(); i++) {
00189 exps[i]->init(root);
00190 }
00191 }
00192
00193 void SequenceExpression::eval(OutputStream & eos, Environment * env,
00194 unsigned modus) {
00195 switch (modus) {
00196
00197 case EVAL_QUERY:
00198 case EVAL_SIGNOFF:
00199 for (unsigned i = 0; i < exps.size(); i++) {
00200 exps[i]->eval(eos, env, modus);
00201 }
00202 break;
00203
00204 default:
00205 throw
00206 RuntimeException("SequenceExpression: Illegal Evaluation Mode",
00207 eid_runtime_illegalmode);
00208 break;
00209 }
00210 }
00211
00212 bool SequenceExpression::containsDirectOutput() {
00213 for (unsigned i = 0; i < exps.size(); i++) {
00214 switch (exps[i]->getType()) {
00215 case et_nodeconstr:
00216 case et_stringconst:
00217 return true;
00218 case et_numericconst:
00219 return true;
00220 case et_sequence:
00221 case et_if:
00222 if (exps[i]->containsDirectOutput()) {
00223 return true;
00224 }
00225 default:
00226 break;
00227 }
00228 }
00229
00230 return false;
00231 }