[apparmor] [PATCH 05/20] Move nodes around to put one child nodes together and two child nodes togeth
John Johansen
john.johansen at canonical.com
Fri Nov 5 05:51:01 GMT 2010
Signed-off-by: John Johansen <john.johansen at canonical.com>
---
parser/libapparmor_re/regexp.y | 84 ++++++++++++++++++++--------------------
1 files changed, 42 insertions(+), 42 deletions(-)
diff --git a/parser/libapparmor_re/regexp.y b/parser/libapparmor_re/regexp.y
index 29bb954..35068ea 100644
--- a/parser/libapparmor_re/regexp.y
+++ b/parser/libapparmor_re/regexp.y
@@ -348,60 +348,50 @@
}
};
- /* Match a pair of consecutive nodes. */
- class CatNode : public TwoChildNode {
+ /* Match a node zero or more times. (This is a unary operator.) */
+ class StarNode : public OneChildNode {
public:
- CatNode(Node *left, Node *right) :
- TwoChildNode(left, right) { }
- void compute_nullable()
+ StarNode(Node *left) :
+ OneChildNode(left)
{
- nullable = child[0]->nullable && child[1]->nullable;
+ nullable = true;
}
void compute_firstpos()
{
- if (child[0]->nullable)
- firstpos = child[0]->firstpos + child[1]->firstpos;
- else
- firstpos = child[0]->firstpos;
+ firstpos = child[0]->firstpos;
}
void compute_lastpos()
{
- if (child[1]->nullable)
- lastpos = child[0]->lastpos + child[1]->lastpos;
- else
- lastpos = child[1]->lastpos;
+ lastpos = child[0]->lastpos;
}
void compute_followpos()
{
- NodeSet from = child[0]->lastpos, to = child[1]->firstpos;
+ NodeSet from = child[0]->lastpos, to = child[0]->firstpos;
for(NodeSet::iterator i = from.begin(); i != from.end(); i++) {
(*i)->followpos.insert(to.begin(), to.end());
}
}
int eq(Node *other) {
- if (dynamic_cast<CatNode *>(other)) {
- if (!child[0]->eq(other->child[0]))
- return 0;
- return child[1]->eq(other->child[1]);
- }
+ if (dynamic_cast<StarNode *>(other))
+ return child[0]->eq(other->child[0]);
return 0;
}
ostream& dump(ostream& os)
{
+ os << '(';
child[0]->dump(os);
- child[1]->dump(os);
- return os;
- //return os << ' ';
+ return os << ")*";
}
};
- /* Match a node zero or more times. (This is a unary operator.) */
- class StarNode : public OneChildNode {
+ /* Match a node one or more times. (This is a unary operator.) */
+ class PlusNode : public OneChildNode {
public:
- StarNode(Node *left) :
- OneChildNode(left)
+ PlusNode(Node *left) :
+ OneChildNode(left) { }
+ void compute_nullable()
{
- nullable = true;
+ nullable = child[0]->nullable;
}
void compute_firstpos()
{
@@ -419,7 +409,7 @@
}
}
int eq(Node *other) {
- if (dynamic_cast<StarNode *>(other))
+ if (dynamic_cast<PlusNode *>(other))
return child[0]->eq(other->child[0]);
return 0;
}
@@ -427,44 +417,54 @@
{
os << '(';
child[0]->dump(os);
- return os << ")*";
+ return os << ")+";
}
};
- /* Match a node one or more times. (This is a unary operator.) */
- class PlusNode : public OneChildNode {
+ /* Match a pair of consecutive nodes. */
+ class CatNode : public TwoChildNode {
public:
- PlusNode(Node *left) :
- OneChildNode(left) { }
+ CatNode(Node *left, Node *right) :
+ TwoChildNode(left, right) { }
void compute_nullable()
{
- nullable = child[0]->nullable;
+ nullable = child[0]->nullable && child[1]->nullable;
}
void compute_firstpos()
{
- firstpos = child[0]->firstpos;
+ if (child[0]->nullable)
+ firstpos = child[0]->firstpos + child[1]->firstpos;
+ else
+ firstpos = child[0]->firstpos;
}
void compute_lastpos()
{
- lastpos = child[0]->lastpos;
+ if (child[1]->nullable)
+ lastpos = child[0]->lastpos + child[1]->lastpos;
+ else
+ lastpos = child[1]->lastpos;
}
void compute_followpos()
{
- NodeSet from = child[0]->lastpos, to = child[0]->firstpos;
+ NodeSet from = child[0]->lastpos, to = child[1]->firstpos;
for(NodeSet::iterator i = from.begin(); i != from.end(); i++) {
(*i)->followpos.insert(to.begin(), to.end());
}
}
int eq(Node *other) {
- if (dynamic_cast<PlusNode *>(other))
- return child[0]->eq(other->child[0]);
+ if (dynamic_cast<CatNode *>(other)) {
+ if (!child[0]->eq(other->child[0]))
+ return 0;
+ return child[1]->eq(other->child[1]);
+ }
return 0;
}
ostream& dump(ostream& os)
{
- os << '(';
child[0]->dump(os);
- return os << ")+";
+ child[1]->dump(os);
+ return os;
+ //return os << ' ';
}
};
--
1.7.1
More information about the AppArmor
mailing list