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 "signoffexpression.h"
00036
00037 SignOffExpression::SignOffExpression(VarExpression * _var, Role * _role):
00038 Expression(et_signoff), var(_var), varstep(NULL), exec_var(var->clone()),
00039 exec_varstep(NULL), role(_role), bit(NULL) {
00040 }
00041
00042 SignOffExpression::SignOffExpression(VarStepExpression * _varstep, Role * _role):
00043 Expression(et_signoff), var(NULL), varstep(_varstep), exec_var(NULL),
00044 exec_varstep(varstep->cloneWithoutFinalDosNodeAndAttributes()), role(_role),
00045 bit(NULL) {
00046
00047 if (exec_varstep->getPath()->isEmptyPath()) {
00048 exec_var = new VarExpression();
00049 exec_var->setId(exec_varstep->getId());
00050 delete exec_varstep;
00051
00052 exec_varstep = NULL;
00053 }
00054 }
00055
00056 SignOffExpression::~SignOffExpression() {
00057 delete var;
00058 delete varstep;
00059 delete exec_var;
00060 delete exec_varstep;
00061
00062
00063 delete bit;
00064 }
00065
00066 void SignOffExpression::scopeCheck(vector < unsigned >&def_vars,
00067 vector < unsigned >&introduced_vars,
00068 vector < unsigned >&violating_vars) {
00069 if (var) {
00070 var->scopeCheck(def_vars, introduced_vars, violating_vars);
00071 } else {
00072 varstep->scopeCheck(def_vars, introduced_vars, violating_vars);
00073 }
00074 }
00075
00076 void SignOffExpression::replaceVarId(unsigned old_id, unsigned new_id) {
00077 if (var) {
00078 var->replaceVarId(old_id, new_id);
00079 exec_var->replaceVarId(old_id, new_id);
00080 } else {
00081 varstep->replaceVarId(old_id, new_id);
00082 if (exec_var) {
00083 exec_var->replaceVarId(old_id, new_id);
00084 } else {
00085 exec_varstep->replaceVarId(old_id, new_id);
00086 }
00087 }
00088 }
00089
00090 void SignOffExpression::print(OutputStream & dos) const {
00091 if (var) {
00092 dos << "signOff(" << (*var) << "," << (*role) << ")";
00093 dos << " [" << (*exec_var) << "]";
00094 } else {
00095 dos << "signOff(" << (*varstep) << "," << (*role) << ")";
00096 if (exec_var) {
00097 dos << " [" << (*exec_var) << "]";
00098 } else {
00099 dos << " [" << (*exec_varstep) << "]";
00100 }
00101 }
00102 }
00103
00104 void SignOffExpression::init(BufferNode * root) {
00105 delete bit;
00106
00107 bit =
00108 exec_var ? new BufferIterator(root, NULL) : new BufferIterator(root,
00109 exec_var
00110 ? NULL
00111 :
00112 exec_varstep->
00113 getPath
00114 ());
00115 }
00116
00117 void SignOffExpression::eval(OutputStream & eos, Environment * env,
00118 unsigned modus) {
00119
00120
00121
00122
00123
00124
00125 exec_var ? bit->init(env->getNodeBinding(exec_var->getId())) :
00126 bit->init(env->getNodeBinding(exec_varstep->getId()));
00127
00128 while (BufferNode * cur =
00129 bit->getNext(READ_UP_TO_CLOSE_NONE, LOCK_CONTEXT_ALWAYS_CLEAR)) {
00130 cur->removeRoleFromNode(role);
00131 }
00132 bit->clear();
00133 }
00134
00135 unsigned SignOffExpression::getVar() {
00136 if (var) {
00137 return var->getId();
00138 } else {
00139 return varstep->getId();
00140 }
00141 }