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 "varexpression.h"
00036
00037 VarExpression::VarExpression():
00038 OperandExpression(et_var, et_operandvar), id(TAGID_ROOT), bit(NULL) {
00039 }
00040
00041 VarExpression::VarExpression(const char *_name):OperandExpression(et_var,
00042 et_operandvar),
00043 id(VarName::getInstance()->insertVarname(_name)),
00044 bit(NULL) {
00045 free((char *) _name);
00046 }
00047
00048 VarExpression::VarExpression(const char *_name,
00049 bool _force):OperandExpression(et_var,
00050 et_operandvar),
00051 id(VarName::getInstance()->insertVarname(_name, _force)),
00052 bit(NULL) {
00053 free((char *) _name);
00054 }
00055
00056 VarExpression::VarExpression(EXP_TYPE _type,
00057 unsigned _id):OperandExpression(_type,
00058 et_operandvarstep),
00059 id(_id),
00060 bit(NULL) {
00061 }
00062
00063 VarExpression::~VarExpression() {
00064 delete bit;
00065 }
00066
00067 void VarExpression::scopeCheck(vector < unsigned >&def_vars,
00068 vector < unsigned >&introduced_vars,
00069 vector < unsigned >&violating_vars) {
00070 for (unsigned i = 0; i < def_vars.size(); i++) {
00071 if (id == def_vars[i]) {
00072 return;
00073 }
00074 }
00075
00076 violating_vars.push_back(id);
00077 }
00078
00079 void VarExpression::replaceVarId(unsigned old_id, unsigned new_id) {
00080 if (id == old_id) {
00081 id = new_id;
00082 }
00083 }
00084
00085 void VarExpression::extractDependencies(vector < DependencySet * >*depset) {
00086 for (unsigned i = 0; i < depset->size(); i++) {
00087 if ((*depset)[i]->getVar() == id) {
00088 (*depset)[i]->insertTuple(NULL, false, true, false);
00089 break;
00090 }
00091 }
00092 }
00093
00094 void VarExpression::print(OutputStream & dos) const {
00095 dos << "$" << VarName::getInstance()->getVarname(id);
00096 }
00097
00098 void VarExpression::init(BufferNode * root) {
00099 delete bit;
00100
00101 bit = new BufferIterator(root, NULL);
00102 }
00103
00104 void VarExpression::eval(OutputStream & eos, Environment * env, unsigned modus) {
00105
00106 switch (modus) {
00107
00108 case EVAL_QUERY:
00109 {
00110 bit->init(env->getNodeBinding(id));
00111 BufferNode *cur = bit->getNext(READ_UP_TO_CLOSE_BASE);
00112
00113 cur->print(eos);
00114 bit->clear();
00115 break;
00116 }
00117
00118 case EVAL_SIGNOFF:
00119 break;
00120
00121 default:
00122 throw RuntimeException("VarExpression: Illegal Evaluation Mode",
00123 eid_runtime_illegalmode);
00124 break;
00125 }
00126 }
00127
00128 VarExpression *VarExpression::clone() {
00129 VarExpression *varexp = new VarExpression();
00130
00131 varexp->setId(id);
00132
00133 return varexp;
00134 }
00135
00136 void VarExpression::prepareOperand(OutputStream & eos, Environment * env,
00137 unsigned modus) {
00138 bit->init(env->getNodeBinding(id));
00139 }
00140
00141 void VarExpression::unprepareOperand() {
00142 bit->reset();
00143 }
00144
00145 Value *VarExpression::getNextValue() {
00146 BufferNode *cur = bit->getNext(READ_UP_TO_CLOSE_CONTEXT);
00147
00148 if (cur) {
00149 cur_val.setStrVal(cur->getPCDataRepresentation());
00150 return &cur_val;
00151 } else {
00152 return NULL;
00153 }
00154 }