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 "executor.h"
00036
00044 extern int parse_query(DocExpression * _doc);
00045
00050 extern Expression *parsed_query;
00051
00052 Executor::Executor(CmdLine * _cmd):
00053 debug_ostream(NULL), eval_ostream(NULL), query(NULL),
00054 buffer(NULL), fsamap(NULL), parvarmap(NULL), penv(NULL),
00055 vt(NULL), depset(new vector < DependencySet * >()), pt(NULL),
00056 ppt(NULL), pdfa(NULL), cmd(_cmd) {
00057 }
00058
00059 Executor::~Executor() {
00060
00061 bool debug_ostream_write = debug_ostream && debug_ostream->isWriteable();
00062
00063 if (cmd->debug) {
00064 if (debug_ostream_write) {
00065 (*debug_ostream) << NEWLINE << "[Executor] Cleaning Up Now..." <<
00066 NEWLINE;
00067 } else {
00068 cout << endl << "[Executor] Cleaning Up Now..." << endl;
00069 }
00070 }
00071 if (cmd->debug) {
00072 if (debug_ostream_write) {
00073 (*debug_ostream) << "Deleting Query..." << NEWLINE;
00074 } else {
00075 cout << "Deleting Query..." << endl;
00076 }
00077 }
00078 delete query;
00079
00080 if (cmd->debug) {
00081 if (debug_ostream_write) {
00082 (*debug_ostream) << "Deleting Buffer..." << NEWLINE;
00083 } else {
00084 cout << "Deleting Buffer..." << endl;
00085 }
00086 }
00087 delete buffer;
00088
00089 if (cmd->debug) {
00090 if (debug_ostream_write) {
00091 (*debug_ostream) << "Deleting PathEnvironment..." << NEWLINE;
00092 } else {
00093 cout << "Deleting PathEnvironment..." << endl;
00094 }
00095 }
00096 delete penv;
00097
00098 if (cmd->debug) {
00099 if (debug_ostream_write) {
00100 (*debug_ostream) << "Deleting VariableTree..." << NEWLINE;
00101 } else {
00102 cout << "Deleting VariableTree..." << endl;
00103 }
00104 }
00105 delete vt;
00106
00107 if (cmd->debug) {
00108 if (debug_ostream_write) {
00109 (*debug_ostream) << "Deleting DependencySet..." << NEWLINE;
00110 } else {
00111 cout << "Deleting DependencySet..." << endl;
00112 }
00113 }
00114 for (unsigned i = 0; i < depset->size(); i++) {
00115 delete(*depset)[i];
00116 }
00117 delete depset;
00118
00119 if (cmd->debug) {
00120 if (debug_ostream_write) {
00121 (*debug_ostream) << "Deleting ProjectionTree..." << NEWLINE;
00122 } else {
00123 cout << "Deleting ProjectionTree..." << endl;
00124 }
00125 }
00126 delete pt;
00127
00128 if (cmd->debug) {
00129 if (debug_ostream_write) {
00130 (*debug_ostream) << "Deleting PassiveProjectionTree..." << NEWLINE;
00131 } else {
00132 cout << "Deleting PassiveProjectionTree..." << endl;
00133 }
00134 }
00135 delete ppt;
00136
00137 if (cmd->debug) {
00138 if (debug_ostream_write) {
00139 (*debug_ostream) << "Deleting ProjectionDFA..." << NEWLINE;
00140 } else {
00141 cout << "Deleting ProjectionDFA..." << endl;
00142 }
00143 }
00144 delete pdfa;
00145
00146
00147 if (cmd->debug) {
00148 if (debug_ostream_write) {
00149 (*debug_ostream) << "Deleting FSAMap Object..." << NEWLINE;
00150 } else {
00151 cout << "Deleting FSAMap Object..." << endl;
00152 }
00153 }
00154 delete FSAMap::getInstance();
00155
00156 if (cmd->debug) {
00157 if (debug_ostream_write) {
00158 (*debug_ostream) << "Deleting ParVarMap Object..." << NEWLINE;
00159 } else {
00160 cout << "Deleting ParVarMap Object..." << endl;
00161 }
00162 }
00163 delete ParVarMap::getInstance();
00164
00165 if (cmd->debug) {
00166 if (debug_ostream_write) {
00167 (*debug_ostream) << "Deleting RoleList Object..." << NEWLINE;
00168 } else {
00169 cout << "Deleting RoleList Object..." << endl;
00170 }
00171 }
00172 delete RoleList::getInstance();
00173
00174 if (cmd->debug) {
00175 if (debug_ostream_write) {
00176 (*debug_ostream) << "Deleting StreamPreProcessor Object..." <<
00177 NEWLINE;
00178 } else {
00179 cout << "Deleting StreamPreProcessor Object..." << endl;
00180 }
00181 }
00182 delete StreamPreProcessor::getInstance();
00183
00184 if (cmd->debug) {
00185 if (debug_ostream_write) {
00186 (*debug_ostream) << "Deleting TagMap Object..." << NEWLINE;
00187 } else {
00188 cout << "Deleting TagMap Object..." << endl;
00189 }
00190 }
00191 delete TagMap::getInstance();
00192
00193 if (cmd->debug) {
00194 if (debug_ostream_write) {
00195 (*debug_ostream) << "Deleting VarName Object..." << NEWLINE;
00196 } else {
00197 cout << "Deleting VarName Object..." << endl;
00198 }
00199 }
00200 delete VarName::getInstance();
00201
00202 if (cmd->debug) {
00203 if (debug_ostream_write) {
00204 (*debug_ostream) << "Deleting CmdLine and StreamManager Object..."
00205 << NEWLINE;
00206 } else {
00207 cout << "Deleting CmdLine and StreamManager Object..." << endl;
00208 }
00209 }
00210 delete cmd;
00211 delete StreamManager::getInstance();
00212
00213
00214 }
00215
00216
00217 void Executor::start() {
00218
00219 if (!cmd->preprocess_stream_debug && !cmd->preprocess_stream_no_debug) {
00220
00221
00222 try {
00223 initStreams();
00224 }
00225 catch(IOStreamException & e) {
00226 cout << e.getDebugMsg();
00227 e.terminate();
00228 }
00229 catch(Exception & e) {
00230 cout << e.getDebugMsg();
00231 e.terminate();
00232 }
00233
00234 try {
00235
00236 parseQuery();
00237 optimizeQuery();
00238
00239
00240 collectQueryInformation();
00241 buildVariableTree();
00242 buildDependencies();
00243 buildProjectionTree();
00244
00245
00246 buildSignOffQuery();
00247
00248
00249 initProjectionDFA();
00250 initStreamParser();
00251
00252
00253 if (StreamManager::getInstance()->getXMLInputStream()->
00254 getType() == it_null)
00255 return;
00256
00257 evalQuery();
00258 finalDebugPrint(false);
00259
00260 }
00261 catch(IOStreamException & e) {
00262 (*debug_ostream) << e.getDebugMsg();
00263 e.terminate();
00264 }
00265 catch(ParseException & e) {
00266 (*debug_ostream) << e.getDebugMsg();
00267 e.terminate();
00268 }
00269 catch(RuntimeException & e) {
00270 (*debug_ostream) << e.getDebugMsg();
00271 e.terminate();
00272 }
00273 catch(InvalidCastException & e) {
00274 (*debug_ostream) << e.getDebugMsg();
00275 e.terminate();
00276 }
00277 catch(Exception & e) {
00278 (*debug_ostream) << e.getDebugMsg();
00279 e.terminate();
00280 }
00281
00282 } else {
00283
00284
00285 try {
00286 initStreams();
00287 }
00288 catch(IOStreamException & e) {
00289 cout << e.getDebugMsg();
00290 e.terminate();
00291 }
00292 catch(Exception & e) {
00293 cout << e.getDebugMsg();
00294 e.terminate();
00295 }
00296
00297 try {
00298
00299 parseQuery();
00300 optimizeQuery();
00301
00302
00303 collectQueryInformation();
00304 buildVariableTree();
00305 buildDependencies();
00306 buildProjectionTree();
00307
00308
00309 initProjectionDFA();
00310 initStreamParser();
00311
00312
00313 if (StreamManager::getInstance()->getXMLInputStream()->
00314 getType() == it_null)
00315 return;
00316
00317
00318 preprocessStream();
00319 finalDebugPrint(true);
00320
00321 }
00322 catch(IOStreamException & e) {
00323 (*debug_ostream) << e.getDebugMsg();
00324 e.terminate();
00325 }
00326 catch(ParseException & e) {
00327 (*debug_ostream) << e.getDebugMsg();
00328 e.terminate();
00329 }
00330 catch(RuntimeException & e) {
00331 (*debug_ostream) << e.getDebugMsg();
00332 e.terminate();
00333 }
00334 catch(InvalidCastException & e) {
00335 (*debug_ostream) << e.getDebugMsg();
00336 e.terminate();
00337 }
00338 catch(Exception & e) {
00339 (*debug_ostream) << e.getDebugMsg();
00340 e.terminate();
00341 }
00342 }
00343 }
00344
00345 void Executor::initStreams() {
00346
00347 InputStream *query_istream = NULL;
00348 InputStream *xml_istream = NULL;
00349
00350 switch (cmd->query_istream_type) {
00351 case it_file:
00352 query_istream = new FileInputStream(cmd->query_arg);
00353 break;
00354 case it_null:
00355 query_istream = new NullInputStream();
00356 break;
00357 case it_socket:
00358 query_istream = new SocketInputStream();
00359 break;
00360 case it_stdin:
00361 query_istream = new StdinInputStream();
00362 break;
00363 }
00364
00365 query_istream->open();
00366 if (!query_istream->isReadable()) {
00367 throw IOStreamException("Query Input Stream is Not Readable",
00368 eid_stream_input);
00369 }
00370
00371 switch (cmd->xml_istream_type) {
00372 case it_file:
00373 xml_istream = new FileInputStream(cmd->xml_arg);
00374 break;
00375 case it_null:
00376 xml_istream = new NullInputStream();
00377 break;
00378 case it_socket:
00379 xml_istream = new SocketInputStream();
00380 break;
00381 case it_stdin:
00382 xml_istream = new StdinInputStream();
00383 break;
00384 }
00385
00386
00387
00388
00389 switch (cmd->dout_ostream_type) {
00390 case ot_file:
00391 debug_ostream = new FileOutputStream(cmd->dout_arg);
00392 break;
00393 case ot_null:
00394 debug_ostream = new NullOutputStream();
00395 break;
00396 case ot_socket:
00397 debug_ostream = new SocketOutputStream();
00398 break;
00399 case ot_stdout:
00400 debug_ostream = new StdoutOutputStream();
00401 break;
00402 }
00403
00404 debug_ostream->open();
00405 if (!debug_ostream->isWriteable()) {
00406 throw IOStreamException("Debug Output Stream is Not Writeable",
00407 eid_stream_output);
00408 }
00409
00410 switch (cmd->eout_ostream_type) {
00411 case ot_file:
00412 eval_ostream = new FileOutputStream(cmd->eout_arg);
00413 break;
00414 case ot_null:
00415 eval_ostream = new NullOutputStream();
00416 break;
00417 case ot_socket:
00418 eval_ostream = new SocketOutputStream();
00419 break;
00420 case ot_stdout:
00421 eval_ostream = new StdoutOutputStream();
00422 break;
00423 }
00424
00425 eval_ostream->open();
00426 if (!eval_ostream->isWriteable()) {
00427 throw IOStreamException("Result Output Stream is Not Writeable",
00428 eid_stream_output);
00429 }
00430
00431 StreamManager::initInstance(query_istream, xml_istream, debug_ostream,
00432 eval_ostream);
00433 }
00434
00435 void Executor::parseQuery() {
00436
00437 DocExpression *doc = new DocExpression();
00438
00439 parse_query(doc);
00440
00441 query = parsed_query;
00442
00443 if (!doc->isEmptyPath()) {
00444 StreamManager::getInstance()->getXMLInputStream()->setArg(doc->
00445 getPath());
00446 }
00447
00448 StreamManager::getInstance()->getXMLInputStream()->open();
00449 if (!StreamManager::getInstance()->getXMLInputStream()->isReadable()) {
00450 throw IOStreamException("XML Input Stream is Not Readable",
00451 eid_stream_input);
00452 }
00453
00454 if (doc->isEmptyPath()) {
00455 doc->
00456 setPath(strdup
00457 (StreamManager::getInstance()->getXMLInputStream()->
00458 getArg()));
00459 }
00460
00461 if (cmd->debug) {
00462 (*debug_ostream) << NEWLINE << NEWLINE;
00463 (*debug_ostream) << "###############################################" <<
00464 NEWLINE;
00465 (*debug_ostream) << "############## Stream Information #############" <<
00466 NEWLINE;
00467 (*debug_ostream) << "###############################################" <<
00468 NEWLINE;
00469 StreamManager::getInstance()->print();
00470 }
00471
00472 if (cmd->debug) {
00473 (*debug_ostream) << NEWLINE << NEWLINE;
00474 (*debug_ostream) << "###############################################" <<
00475 NEWLINE;
00476 (*debug_ostream) << "#################### Query ####################" <<
00477 NEWLINE;
00478 (*debug_ostream) << "###############################################" <<
00479 NEWLINE;
00480 (*debug_ostream) << (*query) << NEWLINE;
00481 }
00482
00483 if (cmd->debug) {
00484 (*debug_ostream) << NEWLINE << NEWLINE;
00485 (*debug_ostream) << "###############################################" <<
00486 NEWLINE;
00487 (*debug_ostream) << "################### VARSq #####################" <<
00488 NEWLINE;
00489 (*debug_ostream) << "###############################################" <<
00490 NEWLINE;
00491 (*debug_ostream) << "VARSq = {";
00492 VarName::getInstance()->print((*debug_ostream));
00493 (*debug_ostream) << "}" << NEWLINE;
00494 }
00495 }
00496
00497 void Executor::optimizeQuery() {
00498
00499
00500 query->rewriteWhereExps();
00501 query->rewriteEmptyFuncts();
00502 query->rewriteVarstepCondExps();
00503 query->rewriteAggregateFuncts();
00504 query->mergeSequences();
00505
00506 if (cmd->debug) {
00507 (*debug_ostream) << NEWLINE << NEWLINE;
00508 (*debug_ostream) << "###############################################" <<
00509 NEWLINE;
00510 (*debug_ostream) << "############# Preprocessed Query ##############" <<
00511 NEWLINE;
00512 (*debug_ostream) << "###############################################" <<
00513 NEWLINE;
00514 (*debug_ostream) << (*query) << NEWLINE;
00515 }
00516 #ifdef REWRITE_VARSTEPS
00517 query->rewriteVarsteps();
00518 #endif // #ifdef REWRITE_VARSTEPS
00519
00520 if (cmd->debug) {
00521 (*debug_ostream) << NEWLINE << NEWLINE;
00522 (*debug_ostream) << "###############################################" <<
00523 NEWLINE;
00524 (*debug_ostream) << "############### Optimized Query ###############" <<
00525 NEWLINE;
00526 (*debug_ostream) << "###############################################" <<
00527 NEWLINE;
00528 #ifndef NO_OPTIMIZATIONS
00529 (*debug_ostream) << (*query) << NEWLINE;
00530 #else
00531 (*debug_ostream) << "Not Available!" << NEWLINE;
00532 (*debug_ostream) << "Please Recompile Disabling -DNO_OPTIMIZATIONS." <<
00533 NEWLINE;
00534 #endif // #ifndef NO_OPTIMIZATIONS
00535 }
00536
00537 if (cmd->debug) {
00538 (*debug_ostream) << NEWLINE << NEWLINE;
00539 (*debug_ostream) << "###############################################" <<
00540 NEWLINE;
00541 (*debug_ostream) << "################## VARSq* #####################" <<
00542 NEWLINE;
00543 (*debug_ostream) << "###############################################" <<
00544 NEWLINE;
00545 #ifndef NO_OPTIMIZATIONS
00546 (*debug_ostream) << "VARSq* = {";
00547 VarName::getInstance()->print((*debug_ostream));
00548 (*debug_ostream) << "}" << NEWLINE;
00549 #else
00550 (*debug_ostream) << "Not Available!" << NEWLINE;
00551 (*debug_ostream) << "Please Recompile Disabling -DNO_OPTIMIZATIONS." <<
00552 NEWLINE;
00553 #endif // #ifndef NO_OPTIMIZATIONS
00554 }
00555 }
00556
00557 void Executor::collectQueryInformation() {
00558
00559 fsamap = FSAMap::getInstance();
00560 query->extractFSAMap(fsamap, TAGID_ROOT);
00561 if (cmd->debug) {
00562 (*debug_ostream) << NEWLINE << NEWLINE;
00563 (*debug_ostream) << "###############################################" <<
00564 NEWLINE;
00565 (*debug_ostream) << "############### FSA Computation ###############" <<
00566 NEWLINE;
00567 (*debug_ostream) << "###############################################" <<
00568 NEWLINE;
00569 fsamap->print((*debug_ostream));
00570 }
00571
00572 parvarmap = ParVarMap::getInstance();
00573 query->extractParVarMap(parvarmap);
00574 if (cmd->debug) {
00575 (*debug_ostream) << NEWLINE << NEWLINE;
00576 (*debug_ostream) << "###############################################" <<
00577 NEWLINE;
00578 (*debug_ostream) << "############# ParVar Computation ##############" <<
00579 NEWLINE;
00580 (*debug_ostream) << "###############################################" <<
00581 NEWLINE;
00582 parvarmap->print((*debug_ostream));
00583 }
00584
00585 penv = new PathEnvironment();
00586 ppt = new PassiveProjectionTree(penv);
00587 if (cmd->debug) {
00588 (*debug_ostream) << NEWLINE << NEWLINE;
00589 (*debug_ostream) << "###############################################" <<
00590 NEWLINE;
00591 (*debug_ostream) << "############## Path Environment ###############" <<
00592 NEWLINE;
00593 (*debug_ostream) << "###############################################" <<
00594 NEWLINE;
00595 penv->print((*debug_ostream));
00596 }
00597
00598
00599 RoleList::initInstance(penv);
00600 }
00601
00602 void Executor::buildVariableTree() {
00603
00604 vt = new VariableTree();
00605 if (cmd->debug) {
00606 (*debug_ostream) << NEWLINE << NEWLINE;
00607 (*debug_ostream) << "###############################################" <<
00608 NEWLINE;
00609 (*debug_ostream) << "################ Variable Tree ################" <<
00610 NEWLINE;
00611 (*debug_ostream) << "###############################################" <<
00612 NEWLINE;
00613 vt->print((*debug_ostream));
00614 }
00615 }
00616
00617 void Executor::buildDependencies() {
00618
00619 vector < unsigned >*varsq = parvarmap->getVarsq();
00620
00621 for (unsigned i = 0; i < varsq->size(); i++) {
00622 depset->push_back(new DependencySet((*varsq)[i]));
00623 }
00624
00625 query->extractDependencies(depset);
00626 if (cmd->debug) {
00627 (*debug_ostream) << NEWLINE << NEWLINE;
00628 (*debug_ostream) << "###############################################" <<
00629 NEWLINE;
00630 (*debug_ostream) << "####### Original Dependencies w/o Roles #######" <<
00631 NEWLINE;
00632 (*debug_ostream) << "###############################################" <<
00633 NEWLINE;
00634 for (unsigned i = 0; i < depset->size(); i++) {
00635
00636 (*debug_ostream) << "dep(" << "$"
00637 << VarName::getInstance()->getVarname((*depset)[i]->getVar())
00638 << ") = {";
00639 (*depset)[i]->print((*debug_ostream));
00640 (*debug_ostream) << "}" << NEWLINE;
00641
00642 }
00643 }
00644 #ifndef NO_OPTIMIZATIONS
00645 for (unsigned i = 0; i < depset->size(); i++) {
00646 if ((*depset)[i]->hasTuples()) {
00647 (*depset)[i]->removeSyntacticallyEqualTuple(ppt);
00648 }
00649 }
00650
00651 for (unsigned i = 0; i < depset->size(); i++) {
00652 if ((*depset)[i]->hasTuples()) {
00653 (*depset)[i]->removeSemanticallyContainedTuple(ppt);
00654 }
00655 }
00656 #endif // #ifndef NO_OPTIMIZATIONS
00657
00658 if (cmd->debug) {
00659 (*debug_ostream) << NEWLINE << NEWLINE;
00660 (*debug_ostream) << "###############################################" <<
00661 NEWLINE;
00662 (*debug_ostream) << "###### Optimized Dependencies w/o Roles #######" <<
00663 NEWLINE;
00664 (*debug_ostream) << "###############################################" <<
00665 NEWLINE;
00666 #ifndef NO_OPTIMIZATIONS
00667 for (unsigned i = 0; i < depset->size(); i++) {
00668
00669 (*debug_ostream) << "dep(" << "$" << VarName::getInstance()->
00670 getVarname((*depset)[i]->getVar()) << ") = {";
00671 (*depset)[i]->print((*debug_ostream));
00672 (*debug_ostream) << "}" << NEWLINE;
00673
00674 }
00675 #else
00676 (*debug_ostream) << "Not Available!" << NEWLINE;
00677 (*debug_ostream) << "Please Recompile Disabling -DNO_OPTIMIZATIONS." <<
00678 NEWLINE;
00679 #endif // #ifndef NO_OPTIMIZATIONS
00680 }
00681 }
00682
00683 void Executor::buildProjectionTree() {
00684
00685 pt = new ProjectionTree(vt, depset);
00686 if (cmd->debug) {
00687 (*debug_ostream) << NEWLINE << NEWLINE;
00688 (*debug_ostream) << "###############################################" <<
00689 NEWLINE;
00690 (*debug_ostream) << "### Original/Optimized Dependencies w/ Roles ##" <<
00691 NEWLINE;
00692 (*debug_ostream) << "###############################################" <<
00693 NEWLINE;
00694 for (unsigned i = 0; i < depset->size(); i++) {
00695
00696 (*debug_ostream) << "dep(" << "$"
00697 << VarName::getInstance()->getVarname((*depset)[i]->
00698 getVar()) << ") = {";
00699 (*depset)[i]->print((*debug_ostream));
00700 (*debug_ostream) << "}" << NEWLINE;
00701
00702 }
00703 }
00704
00705 if (cmd->debug) {
00706 (*debug_ostream) << NEWLINE << NEWLINE;
00707 (*debug_ostream) << "###############################################" <<
00708 NEWLINE;
00709 (*debug_ostream) << "########### Original ProjectionTree ###########" <<
00710 NEWLINE;
00711 (*debug_ostream) << "###############################################" <<
00712 NEWLINE;
00713 pt->print((*debug_ostream));
00714 }
00715 #ifndef NO_OPTIMIZATIONS
00716 pt->removeUnneededNodes(ppt);
00717 pt->removeRedundantRoles(ppt);
00718 #endif // #ifndef NO_OPTIMIZATIONS
00719
00720 if (cmd->debug) {
00721 (*debug_ostream) << NEWLINE << NEWLINE;
00722 (*debug_ostream) << "###############################################" <<
00723 NEWLINE;
00724 (*debug_ostream) << "########## Optimized ProjectionTree ###########" <<
00725 NEWLINE;
00726 (*debug_ostream) << "###############################################" <<
00727 NEWLINE;
00728 #ifndef NO_OPTIMIZATIONS
00729 pt->print((*debug_ostream));
00730 #else
00731 (*debug_ostream) << "Not Available!" << NEWLINE;
00732 (*debug_ostream) << "Please Recompile Disabling -DNO_OPTIMIZATIONS." <<
00733 NEWLINE;
00734 #endif // #ifndef NO_OPTIMIZATIONS
00735 }
00736
00737 if (cmd->debug) {
00738 (*debug_ostream) << NEWLINE << NEWLINE;
00739 (*debug_ostream) << "###############################################" <<
00740 NEWLINE;
00741 (*debug_ostream) << "############ PassiveProjectionTree ############" <<
00742 NEWLINE;
00743 (*debug_ostream) << "###############################################" <<
00744 NEWLINE;
00745 #ifndef NO_OPTIMIZATIONS
00746 ppt->print((*debug_ostream));
00747 #else
00748 (*debug_ostream) << "Not Available!" << NEWLINE;
00749 (*debug_ostream) << "Please Recompile Disabling -DNO_OPTIMIZATIONS." <<
00750 NEWLINE;
00751 #endif // #ifndef NO_OPTIMIZATIONS
00752 }
00753
00754 pt->labelTree();
00755 if (cmd->debug) {
00756 (*debug_ostream) << NEWLINE << NEWLINE;
00757 (*debug_ostream) << "###############################################" <<
00758 NEWLINE;
00759 (*debug_ostream) << "############ ProjectionTree Labels ############" <<
00760 NEWLINE;
00761 (*debug_ostream) << "###############################################" <<
00762 NEWLINE;
00763 pt->getLabels()->print((*debug_ostream));
00764 }
00765 }
00766
00767 void Executor::buildSignOffQuery() {
00768
00769 RoleList *role_list = RoleList::getInstance();
00770
00771 vector < Role * >*roles = role_list->getRoles();
00772
00773 if (cmd->debug) {
00774 (*debug_ostream) << NEWLINE << NEWLINE;
00775 (*debug_ostream) << "###############################################" <<
00776 NEWLINE;
00777 (*debug_ostream) << "######## SignOff Query (XQ Rewriting) #########" <<
00778 NEWLINE;
00779 (*debug_ostream) << "###############################################" <<
00780 NEWLINE;
00781
00782 (*debug_ostream) << "### ROLES TO INSERT SIGNOFFS FOR (" << roles->
00783 size() << ")" << NEWLINE;
00784 for (unsigned i = 0; i < roles->size(); i++) {
00785 (*roles)[i]->printExtended((*debug_ostream));
00786 (*debug_ostream) << NEWLINE;
00787 }
00788 (*debug_ostream) << NEWLINE;
00789 }
00790
00791 role_list->sortRolesForSignOffs();
00792
00793 if (cmd->debug) {
00794 (*debug_ostream) << "### SORTED ROLES FOR SIGNOFFS" << NEWLINE;
00795 for (unsigned i = 0; i < roles->size(); i++) {
00796 (*roles)[i]->printExtended((*debug_ostream));
00797 (*debug_ostream) << NEWLINE;
00798 }
00799 (*debug_ostream) << NEWLINE;
00800 }
00801
00802 vector < SignOffExpression * >signoffs;
00803 for (unsigned i = 0; i < roles->size(); i++) {
00804 signoffs.push_back((*roles)[i]->getSignOffExpression());
00805 if (cmd->debug) {
00806 (*debug_ostream) << "---> " << *(signoffs[signoffs.size() - 1]) <<
00807 NEWLINE;
00808 }
00809 }
00810
00811 insertSignOffs(signoffs);
00812 query->mergeSequences();
00813
00814 if (cmd->debug) {
00815 (*debug_ostream) << NEWLINE;
00816 (*debug_ostream) << "### REWRITTEN QUERY:" << NEWLINE;
00817 (*debug_ostream) << (*query);
00818 (*debug_ostream) << NEWLINE << NEWLINE;
00819 (*debug_ostream) << "****************************************"
00820 << "***************************************"
00821 << NEWLINE
00822 << "ATTENTION-IMPORTANT-ATTENTION-IMPORTANT-"
00823 << "ATTENTION-IMPORTANT-ATTENTION-IMPORTANT"
00824 << NEWLINE
00825 << "****************************************"
00826 << "***************************************"
00827 << NEWLINE
00828 << "!!! While rewriting if-expressions is made explicit "
00829 << "in the paper, the !!!"
00830 << NEWLINE
00831 << "!!! implementation does NOT rewrite if-expressions but "
00832 << "instead solves !!!"
00833 << NEWLINE
00834 << "!!! this issue internally by a different evaluation "
00835 << "strategy. !!!"
00836 << NEWLINE
00837 << "****************************************"
00838 << "***************************************"
00839 << NEWLINE
00840 << "ATTENTION-IMPORTANT-ATTENTION-IMPORTANT-"
00841 << "ATTENTION-IMPORTANT-ATTENTION-IMPORTANT"
00842 << NEWLINE
00843 << "****************************************"
00844 << "***************************************" << NEWLINE;
00845 }
00846 }
00847
00848 void Executor::insertSignOffs(vector < SignOffExpression * >&signoffs) {
00849
00850
00851 for (unsigned i = 0; i < signoffs.size(); i++) {
00852 if (signoffs[i]->getVar() == TAGID_ROOT) {
00853 SequenceExpression *sexp =
00854 new SequenceExpression(query, signoffs[i]);
00855 query = sexp;
00856 }
00857 }
00858
00859
00860 query = query->placeSignOffs(signoffs);
00861 }
00862
00863 void Executor::initProjectionDFA() {
00864
00865 pdfa = new ProjectionDFA(pt, ppt);
00866 if (cmd->debug) {
00867 (*debug_ostream) << NEWLINE << NEWLINE;
00868 (*debug_ostream) << "###############################################" <<
00869 NEWLINE;
00870 (*debug_ostream) << "########### Initial Projection DFA ###########" <<
00871 NEWLINE;
00872 (*debug_ostream) << "###############################################" <<
00873 NEWLINE;
00874 pdfa->print((*debug_ostream));
00875 }
00876 }
00877
00878 void Executor::initStreamParser() {
00879
00880
00881 buffer = new Buffer(pdfa);
00882 StreamPreProcessor::initInstance(buffer, pdfa);
00883
00884 if (cmd->debug) {
00885 (*debug_ostream) << NEWLINE << NEWLINE;
00886 (*debug_ostream) << "###############################################" <<
00887 NEWLINE;
00888 (*debug_ostream) << "################### Stream ####################" <<
00889 NEWLINE;
00890 (*debug_ostream) << "###############################################" <<
00891 NEWLINE;
00892 buffer->debugPrint((*debug_ostream));
00893 }
00894 }
00895
00896 void Executor::preprocessStream() {
00897
00898 (*debug_ostream) << NEWLINE << NEWLINE;
00899 if (cmd->debug) {
00900 (*debug_ostream) << "###############################################" <<
00901 NEWLINE;
00902 (*debug_ostream) << "################### Stream ####################" <<
00903 NEWLINE;
00904 (*debug_ostream) << "###############################################" <<
00905 NEWLINE;
00906 (*debug_ostream) << "StreamPreprocessMode... Patience Please..." <<
00907 NEWLINE << NEWLINE;
00908 StreamPreProcessor::getInstance()->readAll();
00909 buffer->debugPrint((*debug_ostream));
00910 } else {
00911 StreamPreProcessor::getInstance()->readAll();
00912 buffer->print((*debug_ostream));
00913 }
00914 (*debug_ostream) << NEWLINE;
00915 }
00916
00917 void Executor::evalQuery() {
00918
00919 Environment *env = new Environment(buffer->getRoot());
00920
00921 if (cmd->debug) {
00922 (*debug_ostream) << NEWLINE << NEWLINE;
00923 (*debug_ostream) << "###############################################" <<
00924 NEWLINE;
00925 (*debug_ostream) << "################### Result ####################" <<
00926 NEWLINE;
00927 (*debug_ostream) << "###############################################" <<
00928 NEWLINE;
00929 if (debug_ostream->getType() != ot_stdout
00930 || eval_ostream->getType() != ot_stdout) {
00931 (*debug_ostream) << "Result Output Stream Redirected To ";
00932 switch (eval_ostream->getType()) {
00933 case ot_file:
00934 (*debug_ostream) << "FILE";
00935 break;
00936 case ot_null:
00937 (*debug_ostream) << "NULL";
00938 break;
00939 case ot_socket:
00940 (*debug_ostream) << "SOCKET";
00941 break;
00942 case ot_stdout:
00943 (*debug_ostream) << "STDOUT";
00944 break;
00945 }
00946 if (eval_ostream->getArg()) {
00947 (*debug_ostream) << ": \"" << eval_ostream->getArg() << "\"";
00948 }
00949 }
00950 }
00951
00952 query->init(buffer->getRoot());
00953 query->eval((*eval_ostream), env, EVAL_QUERY);
00954 buffer->getRoot()->clear();
00955 (*debug_ostream) << NEWLINE;
00956
00957 delete env;
00958 }
00959
00960 void Executor::finalDebugPrint(bool sppmode) {
00961
00962 if (cmd->debug && !sppmode) {
00963 (*debug_ostream) << NEWLINE << NEWLINE;
00964 (*debug_ostream) << "###############################################" <<
00965 NEWLINE;
00966 (*debug_ostream) << "################ Final Buffer #################" <<
00967 NEWLINE;
00968 (*debug_ostream) << "###############################################" <<
00969 NEWLINE;
00970 buffer->debugPrint((*debug_ostream));
00971 }
00972
00973 if (cmd->debug) {
00974 (*debug_ostream) << NEWLINE << NEWLINE;
00975 (*debug_ostream) << "###############################################" <<
00976 NEWLINE;
00977 (*debug_ostream) << "############## Final Tagname Map ##############" <<
00978 NEWLINE;
00979 (*debug_ostream) << "###############################################" <<
00980 NEWLINE;
00981 TagMap::getInstance()->print((*debug_ostream));
00982 }
00983
00984 if (cmd->debug) {
00985 (*debug_ostream) << NEWLINE << NEWLINE;
00986 (*debug_ostream) << "###############################################" <<
00987 NEWLINE;
00988 (*debug_ostream) << "############ Final Projection DFA #############" <<
00989 NEWLINE;
00990 (*debug_ostream) << "###############################################" <<
00991 NEWLINE;
00992 pdfa->print((*debug_ostream));
00993 }
00994 }