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 "projectiontree.h"
00036
00037 ProjectionTree::ProjectionTree(VariableTree * _vt, vector < DependencySet * >*_depset):
00038 root(new ProjectionTreeNode(NULL, TAGID_ROOT, NULL, false,
00039 RoleList::getInstance()->
00040 getFreshRole(TAGID_ROOT, rt_root, NULL), false)),
00041 roleinfo(RoleList::getInstance()), labels(NULL) {
00042 createProjectionTree(_vt->getRootNode(), _depset);
00043 }
00044
00045 ProjectionTree::~ProjectionTree() {
00046 delete root;
00047 delete labels;
00048 }
00049
00050 void ProjectionTree::insertNode(int parent_var, int introduced_var,
00051 PathExpression * path, bool dep, Role * role,
00052 bool direct_output) {
00053 root->insertNode(parent_var, introduced_var, path, dep, role,
00054 direct_output);
00055 }
00056
00057 void ProjectionTree::print(OutputStream & dos) {
00058 root->print(dos);
00059 }
00060
00061 void ProjectionTree::labelTree() {
00062 labels = new ProjectionTreeLabels(root);
00063 labels->updateParentPredecessorInformation();
00064 }
00065
00066 void ProjectionTree::removeUnneededNodes(PassiveProjectionTree * ppt) {
00067 root->removeUnneededNodes(ppt);
00068 }
00069
00070 void ProjectionTree::removeRedundantRoles(PassiveProjectionTree * ppt) {
00071 root->removeRedundantRoles(ppt);
00072 }
00073
00074 void ProjectionTree::createProjectionTree(VariableTreeNode * varnode,
00075 vector < DependencySet * >*depset) {
00076 vector < DependencyTuple * >*tuples;
00077 Role *r;
00078 ParVarMap *parvarmap = ParVarMap::getInstance();
00079
00080 vector < VariableTreeNode * >*childnodes = varnode->getChildren();
00081 for (unsigned i = 0; i < childnodes->size(); i++) {
00082 r = RoleList::getInstance()->getFreshRole((*childnodes)[i]->getVar(),
00083 rt_variable, NULL);
00084 insertNode(parvarmap->getParVar((*childnodes)[i]->getVar()),
00085 (*childnodes)[i]->getVar(),
00086 parvarmap->getPath((*childnodes)[i]->getVar()),
00087 false, r, (*childnodes)[i]->isDirectOutput());
00088
00089 createProjectionTree((*childnodes)[i], depset);
00090
00091 for (unsigned j = 0; j < depset->size(); j++) {
00092 if ((*depset)[j]->getVar() == (*childnodes)[i]->getVar()
00093 && (*depset)[j]->hasTuples()) {
00094 tuples = (*depset)[j]->getTuples();
00095 for (unsigned k = 0; k < tuples->size(); k++) {
00096 ROLE_TYPE dep_type =
00097 (*tuples)[k]->isCondTuple()? rt_condition : rt_output;
00098 r = RoleList::getInstance()->getFreshRole((*depset)[j]->getVar(),
00099 dep_type,
00100 (*tuples)[k]->
00101 getPath());
00102 insertNode((*depset)[j]->getVar(),
00103 -1,
00104 (*tuples)[k]->getPath(),
00105 true,
00106 r,
00107 false);
00108 (*tuples)[k]->setRole(r);
00109 }
00110 }
00111 }
00112 }
00113 if (varnode->getVar() == TAGID_ROOT && (*depset)[TAGID_ROOT]->hasTuples()) {
00114 vector < DependencyTuple * >*tuples =
00115 (*depset)[TAGID_ROOT]->getTuples();
00116 for (unsigned k = 0; k < tuples->size(); k++) {
00117 ROLE_TYPE dep_type =
00118 (*tuples)[k]->isCondTuple()? rt_condition : rt_output;
00119 Role *r = RoleList::getInstance()->getFreshRole((*depset)[TAGID_ROOT]->getVar(),
00120 dep_type,
00121 (*tuples)[k]->
00122 getPath());
00123 insertNode((*depset)[TAGID_ROOT]->getVar(),
00124 -1,
00125 (*tuples)[k]->getPath(),
00126 true,
00127 r,
00128 false);
00129 (*tuples)[k]->setRole(r);
00130 }
00131 }
00132 }