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 "projectiondfastate.h"
00036
00038 ProjectionDFAState::ProjectionDFAState(ProjectionTree * _pt, PassiveProjectionTree * _ppt):
00039 parent(NULL),
00040 config(new TokenConfiguration(_pt)),
00041
00042 pconfig(new PassiveProjectionTreeConfiguration(_ppt)),
00043
00044 transitions(this) {
00045 update();
00046 }
00047
00048 ProjectionDFAState::ProjectionDFAState(ProjectionDFAState * _parent, PassiveProjectionTreeConfiguration * _pconfig):
00049 parent(_parent), config(NULL), pconfig(_pconfig), transitions(NULL) {
00050 }
00051
00053 ProjectionDFAState::ProjectionDFAState(ProjectionDFAState * _parent, TokenConfiguration * _config, PassiveProjectionTreeConfiguration * _pconfig):
00054 parent(_parent), config(_config), pconfig(_pconfig), transitions(this) {
00055 update();
00056 }
00057
00058 ProjectionDFAState::~ProjectionDFAState() {
00059 delete config;
00060 delete pconfig;
00061 }
00062
00063 void ProjectionDFAState::update() {
00064
00065
00066 config->createRoleList(roles, role_counts);
00067
00068
00069 keep_node = ((parent && parent->isOutput()) ||
00070 (config && config->isOutput()) ||
00071 (config && config->hasActiveToken()) ||
00072 (pconfig && pconfig->hasActiveNodes()) ||
00073 (parent && parent->getTokenConfiguration()->forceChildKeep()));
00074
00075 keep_subtree = config->keepSubtree();
00076 is_output = (parent && parent->isOutput()) || config->isOutput();
00077 skip_subtree = config->skipSubtree();
00078
00079
00080 for (unsigned i = 0; i < roles.size(); i++) {
00081 if (roles[i]->isDosRole()) {
00082 for (unsigned j = 0; j < role_counts[i]; j++) {
00083 cumulative_roles.push_back(roles[i]->getId());
00084 }
00085 } else {
00086 for (unsigned j = 0; j < role_counts[i]; j++) {
00087 non_cumulative_roles.push_back(roles[i]->getId());
00088 }
00089 }
00090 }
00091 }
00092
00093 void ProjectionDFAState::print(OutputStream & dos) {
00094 print(dos, 0);
00095 }
00096
00097 ProjectionDFAState *ProjectionDFAState::takeTransition(TAG t, short &t_type) {
00098 if (keep_subtree) {
00099 t_type = TRANSITION_KEEP_SUBTREE;
00100 return this;
00101 } else if (skip_subtree) {
00102 t_type = TRANSITION_SKIP_SUBTREE;
00103 return this;
00104 } else {
00105 ProjectionDFAState *transition = transitions.takeTransition(t, t_type);
00106
00107 if (t_type == TRANSITION_UNKNOWN) {
00108 computeTransition(t);
00109 transition = transitions.takeTransition(t, t_type);
00110 }
00111 if (transition == NULL) {
00112 t_type = TRANSITION_SKIP_SUBTREE;
00113 return this;
00114 } else {
00115 return transition;
00116 }
00117 }
00118 }
00119
00120 ProjectionDFAState *ProjectionDFAState::takeTextTransition() {
00121 return transitions.takeTextTransition(isRoot());
00122 }
00123
00124 void ProjectionDFAState::print(OutputStream & dos, unsigned indents,
00125 bool is_text) {
00126 dos << "config=";
00127 if (!config) {
00128 dos << "[]";
00129 } else {
00130 config->print(dos, is_text);
00131 }
00132 if (!is_text && !keep_node) {
00133 dos << ", [interleave]";
00134 }
00135
00136 if (keep_node)
00137 dos << ", [keep_node]";
00138
00139 dos << ", roles=[";
00140 for (unsigned i = 0; i < roles.size(); i++) {
00141 if (i > 0)
00142 dos << ",";
00143 dos << role_counts[i] << "*r" << roles[i]->getId();
00144 }
00145 dos << "]";
00146 if (keep_subtree)
00147 dos << ", (keep_sub)";
00148 if (skip_subtree)
00149 dos << ", (skip_sub)";
00150 dos << NEWLINE;
00151
00152 transitions.print(dos, indents);
00153 }
00154
00155 void ProjectionDFAState::computeTransition(TAG t) {
00156
00157
00158
00159 transitions.computeTransition(this, t);
00160 }