2
0
mirror of https://gitlab.com/apparmor/apparmor synced 2025-08-31 06:16:03 +00:00

Merge from trunk rev 1424: Move expression tree node labeling into expr

node themselves to reduce memory usage and make node labeling per dfa
rather than global.

Nominated-by: John Johansen <john.johansen@canonical.com>
Acked-By: Steve Beattie <sbeattie@ubuntu.com>
This commit is contained in:
Steve Beattie
2010-07-12 15:53:51 -07:00
parent 8187d02864
commit ac1a585bbe

View File

@@ -102,6 +102,7 @@
/* child 0 is left, child 1 is right */ /* child 0 is left, child 1 is right */
Node *child[2]; Node *child[2];
unsigned int label; /* unique number for debug etc */
/** /**
* We need reference counting for AcceptNodes: sharing AcceptNodes * We need reference counting for AcceptNodes: sharing AcceptNodes
* avoids introducing duplicate States with identical accept values. * avoids introducing duplicate States with identical accept values.
@@ -1208,12 +1209,11 @@ regexp_error(Node **, const char *text, const char *error)
* Assign a consecutive number to each node. This is only needed for * Assign a consecutive number to each node. This is only needed for
* pretty-printing the debug output. * pretty-printing the debug output.
*/ */
map<Node *, int> node_label;
void label_nodes(Node *root) void label_nodes(Node *root)
{ {
int nodes = 0; int nodes = 0;
for (depth_first_traversal i(root); i; i++) for (depth_first_traversal i(root); i; i++)
node_label.insert(make_pair(*i, nodes++)); i->label = nodes++;
} }
/** /**
@@ -1225,7 +1225,7 @@ ostream& operator<<(ostream& os, const State& state)
if (!state.empty()) { if (!state.empty()) {
State::iterator i = state.begin(); State::iterator i = state.begin();
for(;;) { for(;;) {
os << node_label[*i]; os << (*i)->label;
if (++i == state.end()) if (++i == state.end())
break; break;
os << ','; os << ',';
@@ -1240,15 +1240,15 @@ ostream& operator<<(ostream& os, const State& state)
*/ */
void dump_syntax_tree(ostream& os, Node *node) { void dump_syntax_tree(ostream& os, Node *node) {
for (depth_first_traversal i(node); i; i++) { for (depth_first_traversal i(node); i; i++) {
os << node_label[*i] << '\t'; os << i->label << '\t';
if ((*i)->child[0] == 0) if ((*i)->child[0] == 0)
os << **i << '\t' << (*i)->followpos << endl; os << **i << '\t' << (*i)->followpos << endl;
else { else {
if ((*i)->child[1] == 0) if ((*i)->child[1] == 0)
os << node_label[(*i)->child[0]] << **i; os << (*i)->child[0]->label << **i;
else else
os << node_label[(*i)->child[0]] << **i os << (*i)->child[0]->label << **i
<< node_label[(*i)->child[1]]; << (*i)->child[1]->label;
os << '\t' << (*i)->firstpos os << '\t' << (*i)->firstpos
<< (*i)->lastpos << endl; << (*i)->lastpos << endl;
} }