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 "existscondexpression.h"
00036
00037 ExistsCondExpression::ExistsCondExpression(VarExpression * _var):
00038 CondExpression(ect_exists), var(_var), varstep(NULL), bit(NULL) {
00039 }
00040
00041 ExistsCondExpression::ExistsCondExpression(VarStepExpression * _varstep):
00042 CondExpression(ect_exists), var(NULL), varstep(_varstep), bit(NULL) {
00043 }
00044
00045 ExistsCondExpression::~ExistsCondExpression() {
00046 delete var;
00047 delete varstep;
00048 delete bit;
00049 }
00050
00051 void ExistsCondExpression::scopeCheck(vector < unsigned >&def_vars,
00052 vector < unsigned >&introduced_vars,
00053 vector < unsigned >&violating_vars) {
00054 if (var) {
00055 var->scopeCheck(def_vars, introduced_vars, violating_vars);
00056 } else {
00057 varstep->scopeCheck(def_vars, introduced_vars, violating_vars);
00058 }
00059 }
00060
00061 void ExistsCondExpression::replaceVarId(unsigned old_id, unsigned new_id) {
00062 if (var) {
00063 var->replaceVarId(old_id, new_id);
00064 } else {
00065 varstep->replaceVarId(old_id, new_id);
00066 }
00067 }
00068
00069 void ExistsCondExpression::extractDependencies(vector <
00070 DependencySet * >*depset) {
00071 if (varstep && varstep->getPath() && !varstep->getPath()->isEmptyPath()) {
00072 PathExpression *p = varstep->getPath();
00073 unsigned var = varstep->getId();
00074
00075 for (unsigned i = 0; i < depset->size(); i++) {
00076 if ((*depset)[i]->getVar() == var) {
00077 (*depset)[i]->insertTuple(p, true, false, true);
00078 break;
00079 }
00080 }
00081 }
00082 }
00083
00084 void ExistsCondExpression::print(OutputStream & dos) const {
00085 if (var) {
00086 dos << "fn:exists(" << (*var) << ")";
00087 } else {
00088 dos << "fn:exists(" << (*varstep) << ")";
00089 }
00090 }
00091
00092 void ExistsCondExpression::init(BufferNode * root) {
00093 delete bit;
00094
00095 bit =
00096 var ? new BufferIterator(root, NULL) : new BufferIterator(root,
00097 varstep->
00098 getPath());
00099 }
00100
00101 bool ExistsCondExpression::evalCond(OutputStream & eos, Environment * env,
00102 unsigned modus) {
00103
00104 switch (modus) {
00105
00106 case EVAL_QUERY:
00107 {
00108 var ? bit->init(env->getNodeBinding(var->getId())) :
00109 bit->init(env->getNodeBinding(varstep->getId()));
00110
00111 BufferNode *cur = bit->getNext();
00112
00113 bit->reset();
00114
00115 return cur ? true : false;
00116 }
00117
00118 case EVAL_SIGNOFF:
00119 break;
00120
00121 default:
00122 throw
00123 RuntimeException
00124 ("ExistsCondExpression: Illegal Evaluation Mode",
00125 eid_runtime_illegalmode);
00126 break;
00127 }
00128
00129 return false;
00130 }