[apparmor] [PATCH 07/10] Lindent + some hand cleanups expr-tree

John Johansen john.johansen at canonical.com
Thu Mar 10 20:35:57 UTC 2011


Signed-off-by: John Johansen <john.johansen at canonical.com>
---
 parser/libapparmor_re/expr-tree.cc |  124 +++++++-------
 parser/libapparmor_re/expr-tree.h  |  324 ++++++++++++++++--------------------
 2 files changed, 203 insertions(+), 245 deletions(-)

diff --git a/parser/libapparmor_re/expr-tree.cc b/parser/libapparmor_re/expr-tree.cc
index ef63256..e2d7d92 100644
--- a/parser/libapparmor_re/expr-tree.cc
+++ b/parser/libapparmor_re/expr-tree.cc
@@ -38,35 +38,34 @@
 #include "expr-tree.h"
 #include "apparmor_re.h"
 
-
 /* Use a single static EpsNode as it carries no node specific information */
 EpsNode epsnode;
 
-
-ostream& operator<<(ostream& os, uchar c)
+ostream &operator<<(ostream &os, uchar c)
 {
 	const char *search = "\a\033\f\n\r\t|*+[](). ",
-		*replace = "aefnrt|*+[](). ", *s;
+	    *replace = "aefnrt|*+[](). ", *s;
 
-	if ((s = strchr(search, c)) && *s != '\0')
+	if ((s = strchr(search, c)) && *s != '\0') {
 		os << '\\' << replace[s - search];
-	else if (c < 32 || c >= 127)
-		os << '\\' << '0' << char('0' + (c >> 6))
-		   << char('0' + ((c >> 3) & 7)) << char('0' + (c & 7));
-	else
+	} else if (c < 32 || c >= 127) {
+		os << '\\' << '0' << char ('0' + (c >> 6))
+		<< char ('0' + ((c >> 3) & 7)) << char ('0' + (c & 7));
+	} else {
 		os << (char)c;
+	}
 	return os;
 }
 
 /**
  * Text-dump a state (for debugging).
  */
-ostream& operator<<(ostream& os, const NodeSet& state)
+ostream &operator<<(ostream &os, const NodeSet &state)
 {
 	os << '{';
 	if (!state.empty()) {
 		NodeSet::iterator i = state.begin();
-		for(;;) {
+		for (;;) {
 			os << (*i)->label;
 			if (++i == state.end())
 				break;
@@ -77,7 +76,7 @@ ostream& operator<<(ostream& os, const NodeSet& state)
 	return os;
 }
 
-ostream& operator<<(ostream& os, Node& node)
+ostream &operator<<(ostream &os, Node &node)
 {
 	node.dump(os);
 	return os;
@@ -88,16 +87,15 @@ ostream& operator<<(ostream& os, Node& node)
  */
 unsigned long hash_NodeSet(NodeSet *ns)
 {
-        unsigned long hash = 5381;
+	unsigned long hash = 5381;
 
 	for (NodeSet::iterator i = ns->begin(); i != ns->end(); i++) {
-		hash = ((hash << 5) + hash) + (unsigned long) *i;
+		hash = ((hash << 5) + hash) + (unsigned long)*i;
 	}
 
-        return hash;
+	return hash;
 }
 
-
 /**
  * label_nodes - label the node positions for pretty-printing debug output
  *
@@ -114,7 +112,7 @@ void label_nodes(Node *root)
 /**
  * Text-dump the syntax tree (for debugging).
  */
-void Node::dump_syntax_tree(ostream& os)
+void Node::dump_syntax_tree(ostream &os)
 {
 	for (depth_first_traversal i(this); i; i++) {
 		os << i->label << '\t';
@@ -125,9 +123,8 @@ void Node::dump_syntax_tree(ostream& os)
 				os << (*i)->child[0]->label << **i;
 			else
 				os << (*i)->child[0]->label << **i
-				   << (*i)->child[1]->label;
-			os << '\t' << (*i)->firstpos
-			   << (*i)->lastpos << endl;
+				    << (*i)->child[1]->label;
+			os << '\t' << (*i)->firstpos << (*i)->lastpos << endl;
 		}
 	}
 	os << endl;
@@ -173,7 +170,8 @@ void Node::dump_syntax_tree(ostream& os)
  *        a   b                    c   T
  *
  */
-static void rotate_node(Node *t, int dir) {
+static void rotate_node(Node *t, int dir)
+{
 	// (a | b) | c -> a | (b | c)
 	// (ab)c -> a(bc)
 	Node *left = t->child[dir];
@@ -191,7 +189,7 @@ void normalize_tree(Node *t, int dir)
 	for (;;) {
 		if ((&epsnode == t->child[dir]) &&
 		    (&epsnode != t->child[!dir]) &&
-		     dynamic_cast<TwoChildNode *>(t)) {
+		    dynamic_cast<TwoChildNode *>(t)) {
 			// (E | a) -> (a | E)
 			// Ea -> aE
 			Node *c = t->child[dir];
@@ -229,8 +227,7 @@ void normalize_tree(Node *t, int dir)
 #if 0
 static Node *merge_charset(Node *a, Node *b)
 {
-	if (dynamic_cast<CharNode *>(a) &&
-	    dynamic_cast<CharNode *>(b)) {
+	if (dynamic_cast<CharNode *>(a) && dynamic_cast<CharNode *>(b)) {
 		Chars chars;
 		chars.insert(dynamic_cast<CharNode *>(a)->c);
 		chars.insert(dynamic_cast<CharNode *>(b)->c);
@@ -249,7 +246,6 @@ static Node *merge_charset(Node *a, Node *b)
 			to->insert(*i);
 		return b;
 	}
-
 	//return ???;
 }
 
@@ -311,7 +307,6 @@ static Node *basic_alt_factor(Node *t, int dir)
 		t->release();
 		return tmp;
 	}
-
 	// (ab) | (ac) -> a(b|c)
 	if (dynamic_cast<CatNode *>(t->child[dir]) &&
 	    dynamic_cast<CatNode *>(t->child[!dir]) &&
@@ -326,7 +321,6 @@ static Node *basic_alt_factor(Node *t, int dir)
 		left->child[!dir] = t;
 		return left;
 	}
-
 	// a | (ab) -> a (E | b) -> a (b | E)
 	if (dynamic_cast<CatNode *>(t->child[!dir]) &&
 	    t->child[dir]->eq(t->child[!dir]->child[dir])) {
@@ -337,7 +331,6 @@ static Node *basic_alt_factor(Node *t, int dir)
 		c->child[!dir] = t;
 		return c;
 	}
-
 	// ab | (a) -> a (b | E)
 	if (dynamic_cast<CatNode *>(t->child[dir]) &&
 	    t->child[dir]->child[dir]->eq(t->child[!dir])) {
@@ -354,8 +347,7 @@ static Node *basic_alt_factor(Node *t, int dir)
 
 static Node *basic_simplify(Node *t, int dir)
 {
-	if (dynamic_cast<CatNode *>(t) &&
-	    &epsnode == t->child[!dir]) {
+	if (dynamic_cast<CatNode *>(t) && &epsnode == t->child[!dir]) {
 		// aE -> a
 		Node *tmp = t->child[dir];
 		t->child[dir] = NULL;
@@ -383,7 +375,7 @@ Node *simplify_tree_base(Node *t, int dir, bool &mod)
 	if (dynamic_cast<ImportantNode *>(t))
 		return t;
 
-	for (int i=0; i < 2; i++) {
+	for (int i = 0; i < 2; i++) {
 		if (t->child[i]) {
 			Node *c = simplify_tree_base(t->child[i], dir, mod);
 			if (c != t->child[i]) {
@@ -402,7 +394,6 @@ Node *simplify_tree_base(Node *t, int dir, bool &mod)
 			continue;
 		}
 
-
 		/* all tests after this must meet 2 alt node condition */
 		if (!dynamic_cast<AltNode *>(t) ||
 		    !dynamic_cast<AltNode *>(t->child[!dir]))
@@ -412,7 +403,7 @@ Node *simplify_tree_base(Node *t, int dir, bool &mod)
 		// a | (b | (c | a)) -> (b | (c | a))
 		Node *p = t;
 		Node *i = t->child[!dir];
-		for (;dynamic_cast<AltNode *>(i); p = i, i = i->child[!dir]) {
+		for (; dynamic_cast<AltNode *>(i); p = i, i = i->child[!dir]) {
 			if (t->child[dir]->eq(i->child[dir])) {
 				Node *tmp = t->child[!dir];
 				t->child[!dir] = NULL;
@@ -429,7 +420,6 @@ Node *simplify_tree_base(Node *t, int dir, bool &mod)
 			t = tmp;
 			continue;
 		}
-
 		//exact match didn't work, try factoring front
 		//a | (ac | (ad | () -> (a (E | c)) | (...)
 		//ab | (ac | (...)) -> (a (b | c)) | (...)
@@ -439,10 +429,10 @@ Node *simplify_tree_base(Node *t, int dir, bool &mod)
 		Node *subject = t->child[dir];
 		Node *a = subject;
 		if (dynamic_cast<CatNode *>(subject))
-		    a = subject->child[dir];
+			a = subject->child[dir];
 
 		for (pp = p = t, i = t->child[!dir];
-		     dynamic_cast<AltNode *>(i); ) {
+		     dynamic_cast<AltNode *>(i);) {
 			if ((dynamic_cast<CatNode *>(i->child[dir]) &&
 			     a->eq(i->child[dir]->child[dir])) ||
 			    (a->eq(i->child[dir]))) {
@@ -458,14 +448,15 @@ Node *simplify_tree_base(Node *t, int dir, bool &mod)
 				i = p->child[!dir];
 				count++;
 			} else {
-				pp = p; p = i; i = i->child[!dir];
+				pp = p;
+				p = i;
+				i = i->child[!dir];
 			}
 		}
 
 		// last altnode in chain check other dir as well
 		if ((dynamic_cast<CatNode *>(i) &&
-		     a->eq(i->child[dir])) ||
-		    (a->eq(i))) {
+		     a->eq(i->child[dir])) || (a->eq(i))) {
 			count++;
 			if (t == p) {
 				t->child[dir] = subject;
@@ -501,7 +492,7 @@ int debug_tree(Node *t)
 
 static void count_tree_nodes(Node *t, struct node_counts *counts)
 {
-	if (dynamic_cast<AltNode *>(t)) {
+	if (dynamic_cast <AltNode *>(t)) {
 		counts->alt++;
 		count_tree_nodes(t->child[0], counts);
 		count_tree_nodes(t->child[1], counts);
@@ -537,7 +528,11 @@ Node *simplify_tree(Node *t, dfaflags_t flags)
 	if (flags & DFA_DUMP_TREE_STATS) {
 		struct node_counts counts = { 0, 0, 0, 0, 0, 0, 0, 0 };
 		count_tree_nodes(t, &counts);
-		fprintf(stderr, "expr tree: c %d, [] %d, [^] %d, | %d, + %d, * %d, . %d, cat %d\n", counts.charnode, counts.charset, counts.notcharset, counts.alt, counts.plus, counts.star, counts.any, counts.cat);
+		fprintf(stderr,
+			"expr tree: c %d, [] %d, [^] %d, | %d, + %d, * %d, . %d, cat %d\n",
+			counts.charnode, counts.charset, counts.notcharset,
+			counts.alt, counts.plus, counts.star, counts.any,
+			counts.cat);
 	}
 	do {
 		update = false;
@@ -553,23 +548,27 @@ Node *simplify_tree(Node *t, dfaflags_t flags)
 		for (int count = 0; count < 2; count++) {
 			bool modified;
 			do {
-			    modified = false;
-			    if (flags & DFA_CONTROL_TREE_NORMAL)
-				normalize_tree(t, dir);
-			    t = simplify_tree_base(t, dir, modified);
-			    if (modified)
-				update = true;
+				modified = false;
+				if (flags & DFA_CONTROL_TREE_NORMAL)
+					normalize_tree(t, dir);
+				t = simplify_tree_base(t, dir, modified);
+				if (modified)
+					update = true;
 			} while (modified);
 			if (flags & DFA_CONTROL_TREE_LEFT)
 				dir++;
 			else
 				dir--;
 		}
-	} while(update);
+	} while (update);
 	if (flags & DFA_DUMP_TREE_STATS) {
 		struct node_counts counts = { 0, 0, 0, 0, 0, 0, 0, 0 };
 		count_tree_nodes(t, &counts);
-		fprintf(stderr, "simplified expr tree: c %d, [] %d, [^] %d, | %d, + %d, * %d, . %d, cat %d\n", counts.charnode, counts.charset, counts.notcharset, counts.alt, counts.plus, counts.star, counts.any, counts.cat);
+		fprintf(stderr,
+			"simplified expr tree: c %d, [] %d, [^] %d, | %d, + %d, * %d, . %d, cat %d\n",
+			counts.charnode, counts.charset, counts.notcharset,
+			counts.alt, counts.plus, counts.star, counts.any,
+			counts.cat);
 	}
 	return t;
 }
@@ -580,25 +579,24 @@ Node *simplify_tree(Node *t, dfaflags_t flags)
  */
 void flip_tree(Node *node)
 {
-    for (depth_first_traversal i(node); i; i++) {
-	if (CatNode *cat = dynamic_cast<CatNode *>(*i)) {
-	    swap(cat->child[0], cat->child[1]);
+	for (depth_first_traversal i(node); i; i++) {
+		if (CatNode * cat = dynamic_cast<CatNode *>(*i)) {
+			swap(cat->child[0], cat->child[1]);
+		}
 	}
-    }
 }
 
-void dump_regexp_rec(ostream& os, Node *tree)
+void dump_regexp_rec(ostream &os, Node *tree)
 {
-    if (tree->child[0])
-	dump_regexp_rec(os, tree->child[0]);
-    os << *tree;
-    if (tree->child[1])
-	dump_regexp_rec(os, tree->child[1]);
+	if (tree->child[0])
+		dump_regexp_rec(os, tree->child[0]);
+	os << *tree;
+	if (tree->child[1])
+		dump_regexp_rec(os, tree->child[1]);
 }
 
-void dump_regexp(ostream& os, Node *tree)
+void dump_regexp(ostream &os, Node *tree)
 {
-    dump_regexp_rec(os, tree);
-    os << endl;
+	dump_regexp_rec(os, tree);
+	os << endl;
 }
-
diff --git a/parser/libapparmor_re/expr-tree.h b/parser/libapparmor_re/expr-tree.h
index c88283c..92c78ad 100644
--- a/parser/libapparmor_re/expr-tree.h
+++ b/parser/libapparmor_re/expr-tree.h
@@ -46,15 +46,14 @@
 using namespace std;
 
 typedef unsigned char uchar;
-typedef set<uchar> Chars;
+typedef set <uchar> Chars;
 
-ostream& operator<<(ostream& os, uchar c);
+ostream & operator<<(ostream &os, uchar c);
 
 /* Compute the union of two sets. */
-template<class T>
-set<T> operator+(const set<T>& a, const set<T>& b)
+template <class T> set <T> operator+(const set <T> &a, const set <T> &b)
 {
-	set<T> c(a);
+	set < T > c(a);
 	c.insert(b.begin(), b.end());
 	return c;
 }
@@ -72,7 +71,7 @@ typedef set <ImportantNode *> NodeSet;
 /**
  * Text-dump a state (for debugging).
  */
-ostream& operator<<(ostream& os, const NodeSet& state);
+ostream & operator<<(ostream &os, const NodeSet &state);
 
 /**
  * Out-edges from a state to another: we store the follow-set of Nodes
@@ -83,27 +82,33 @@ ostream& operator<<(ostream& os, const NodeSet& state);
  * enumerating all the explicit tranitions for default matches.
  */
 typedef struct NodeCases {
-	typedef map<uchar, NodeSet *>::iterator iterator;
+	typedef map <uchar, NodeSet *>::iterator iterator;
 	iterator begin() { return cases.begin(); }
 	iterator end() { return cases.end(); }
 
-	NodeCases() : otherwise(0) { }
-	map<uchar, NodeSet *> cases;
+	NodeCases(): otherwise(0) { }
+	map <uchar, NodeSet *> cases;
 	NodeSet *otherwise;
-} NodeCases;
+}
 
+NodeCases;
 
-ostream& operator<<(ostream& os, Node& node);
+ostream & operator<<(ostream &os, Node &node);
 
 /* An abstract node in the syntax tree. */
 class Node {
-public:
-	Node() :
-	    nullable(false) { child[0] = child[1] = 0; }
-	Node(Node *left) :
-	    nullable(false) { child[0] = left; child[1] = 0; }
-	Node(Node *left, Node *right) :
-	    nullable(false) { child[0] = left; child[1] = right; }
+      public:
+	Node(): nullable(false) { child[0] = child[1] = 0; }
+	Node(Node *left):nullable(false)
+	{
+		child[0] = left;
+		child[1] = 0;
+	}
+	Node(Node *left, Node *right): nullable(false)
+	{
+		child[0] = left;
+		child[1] = right;
+	}
 	virtual ~Node()
 	{
 		if (child[0])
@@ -121,8 +126,8 @@ public:
 	virtual void compute_lastpos() = 0;
 	virtual void compute_followpos() { }
 	virtual int eq(Node *other) = 0;
-	virtual ostream& dump(ostream& os) = 0;
-	void dump_syntax_tree(ostream& os);
+	virtual ostream &dump(ostream &os) = 0;
+	void dump_syntax_tree(ostream &os);
 
 	bool nullable;
 	NodeSet firstpos, lastpos, followpos;
@@ -139,33 +144,32 @@ public:
 	virtual void release(void) { delete this; }
 };
 
-
-class InnerNode : public Node {
-public:
-	InnerNode() : Node() { };
-	InnerNode(Node *left) : Node(left) {};
-	InnerNode(Node *left, Node *right) : Node(left, right) { };
+class InnerNode:public Node {
+      public:
+	InnerNode():Node() { };
+	InnerNode(Node *left): Node(left) { };
+	InnerNode(Node *left, Node *right): Node(left, right) { };
 };
 
-class OneChildNode : public InnerNode {
-public:
-	OneChildNode(Node *left) : InnerNode(left) { };
+class OneChildNode:public InnerNode {
+      public:
+	OneChildNode(Node *left): InnerNode(left) { };
 };
 
-class TwoChildNode : public InnerNode {
-public:
-	TwoChildNode(Node *left, Node *right) :  InnerNode(left, right) { };
+class TwoChildNode:public InnerNode {
+      public:
+	TwoChildNode(Node *left, Node *right): InnerNode(left, right) { };
 };
 
-class LeafNode : public Node {
-public:
-	LeafNode() : Node() { };
+class LeafNode:public Node {
+      public:
+	LeafNode(): Node() { };
 };
 
 /* Match nothing (//). */
-class EpsNode : public LeafNode {
-public:
-	EpsNode() : LeafNode()
+class EpsNode:public LeafNode {
+      public:
+	EpsNode(): LeafNode()
 	{
 		nullable = true;
 		label = 0;
@@ -181,11 +185,11 @@ public:
 	void compute_lastpos() { }
 	int eq(Node *other)
 	{
-		if (dynamic_cast<EpsNode *>(other))
+		if (dynamic_cast <EpsNode *>(other))
 			return 1;
 		return 0;
 	}
-	ostream& dump(ostream& os)
+	ostream &dump(ostream &os)
 	{
 		return os << "[]";
 	}
@@ -196,32 +200,27 @@ public:
  * characters that the regular expression matches. We also consider
  * AcceptNodes import: they indicate when a regular expression matches.
  */
-class ImportantNode : public LeafNode {
-public:
-	ImportantNode() : LeafNode() { }
-	void compute_firstpos()
-	{
-		firstpos.insert(this);
-	}
-	void compute_lastpos() {
-		lastpos.insert(this);
-	}
-	virtual void follow(NodeCases& cases) = 0;
+class ImportantNode:public LeafNode {
+      public:
+	ImportantNode():LeafNode() { }
+	void compute_firstpos() { firstpos.insert(this); }
+	void compute_lastpos() { lastpos.insert(this); }
+	virtual void follow(NodeCases &cases) = 0;
 };
 
 /* common base class for all the different classes that contain
  * character information.
  */
-class CNode : public ImportantNode {
-public:
-	CNode() : ImportantNode() { }
+class CNode:public ImportantNode {
+      public:
+	CNode():ImportantNode() { }
 };
 
 /* Match one specific character (/c/). */
-class CharNode : public CNode {
-public:
-	CharNode(uchar c) : c(c) { }
-	void follow(NodeCases& cases)
+class CharNode:public CNode {
+      public:
+	CharNode(uchar c) :c(c) { }
+	void follow(NodeCases &cases)
 	{
 		NodeSet **x = &cases.cases[c];
 		if (!*x) {
@@ -240,7 +239,7 @@ public:
 		}
 		return 0;
 	}
-	ostream& dump(ostream& os)
+	ostream & dump(ostream &os)
 	{
 		return os << c;
 	}
@@ -249,10 +248,10 @@ public:
 };
 
 /* Match a set of characters (/[abc]/). */
-class CharSetNode : public CNode {
-public:
-	CharSetNode(Chars& chars) : chars(chars) { }
-	void follow(NodeCases& cases)
+class CharSetNode:public CNode {
+      public:
+	CharSetNode(Chars &chars):chars(chars) { }
+	void follow(NodeCases & cases)
 	{
 		for (Chars::iterator i = chars.begin(); i != chars.end(); i++) {
 			NodeSet **x = &cases.cases[*i];
@@ -272,14 +271,13 @@ public:
 			return 0;
 
 		for (Chars::iterator i = chars.begin(), j = o->chars.begin();
-		     i != chars.end() && j != o->chars.end();
-		     i++, j++) {
+		     i != chars.end() && j != o->chars.end(); i++, j++) {
 			if (*i != *j)
 				return 0;
 		}
 		return 1;
 	}
-	ostream& dump(ostream& os)
+	ostream &dump(ostream &os)
 	{
 		os << '[';
 		for (Chars::iterator i = chars.begin(); i != chars.end(); i++)
@@ -291,10 +289,10 @@ public:
 };
 
 /* Match all except one character (/[^abc]/). */
-class NotCharSetNode : public CNode {
-public:
-	NotCharSetNode(Chars& chars) : chars(chars) { }
-	void follow(NodeCases& cases)
+class NotCharSetNode:public CNode {
+      public:
+	NotCharSetNode(Chars &chars):chars(chars) { }
+	void follow(NodeCases & cases)
 	{
 		if (!cases.otherwise)
 			cases.otherwise = new NodeSet;
@@ -321,14 +319,13 @@ public:
 			return 0;
 
 		for (Chars::iterator i = chars.begin(), j = o->chars.begin();
-		     i != chars.end() && j != o->chars.end();
-		     i++, j++) {
+		     i != chars.end() && j != o->chars.end(); i++, j++) {
 			if (*i != *j)
 				return 0;
 		}
 		return 1;
 	}
-	ostream& dump(ostream& os)
+	ostream &dump(ostream &os)
 	{
 		os << "[^";
 		for (Chars::iterator i = chars.begin(); i != chars.end(); i++)
@@ -340,10 +337,10 @@ public:
 };
 
 /* Match any character (/./). */
-class AnyCharNode : public CNode {
-public:
+class AnyCharNode:public CNode {
+      public:
 	AnyCharNode() { }
-	void follow(NodeCases& cases)
+	void follow(NodeCases & cases)
 	{
 		if (!cases.otherwise)
 			cases.otherwise = new NodeSet;
@@ -354,22 +351,20 @@ public:
 	}
 	int eq(Node *other)
 	{
-		if (dynamic_cast<AnyCharNode *>(other))
+		if (dynamic_cast <AnyCharNode *>(other))
 			return 1;
 		return 0;
 	}
-	ostream& dump(ostream& os) {
-		return os << ".";
-	}
+	ostream & dump(ostream &os) { return os << "."; }
 };
 
 /**
  * Indicate that a regular expression matches. An AcceptNode itself
  * doesn't match anything, so it will never generate any transitions.
  */
-class AcceptNode : public ImportantNode {
-public:
-	AcceptNode() {}
+class AcceptNode:public ImportantNode {
+      public:
+	AcceptNode() { }
 	void release(void)
 	{
 		/* don't delete AcceptNode via release as they are shared, and
@@ -377,7 +372,7 @@ public:
 		 */
 	}
 
-	void follow(NodeCases& cases __attribute__((unused)))
+	void follow(NodeCases &cases __attribute__ ((unused)))
 	{
 		/* Nothing to follow. */
 	}
@@ -385,40 +380,32 @@ public:
 	/* requires accept nodes to be common by pointer */
 	int eq(Node *other)
 	{
-		if (dynamic_cast<AcceptNode *>(other))
+		if (dynamic_cast < AcceptNode * >(other))
 			return (this == other);
 		return 0;
 	}
 };
 
 /* Match a node zero or more times. (This is a unary operator.) */
-class StarNode : public OneChildNode {
-public:
-	StarNode(Node *left) : OneChildNode(left)
-	{
-		nullable = true;
-	}
-	void compute_firstpos()
-	{
-		firstpos = child[0]->firstpos;
-	}
-	void compute_lastpos()
-	{
-		lastpos = child[0]->lastpos;
-	}
+class StarNode:public OneChildNode {
+      public:
+	StarNode(Node *left): OneChildNode(left) { nullable = true; }
+	void compute_firstpos() { firstpos = child[0]->firstpos; }
+	void compute_lastpos() { lastpos = child[0]->lastpos; }
 	void compute_followpos()
 	{
 		NodeSet from = child[0]->lastpos, to = child[0]->firstpos;
-		for(NodeSet::iterator i = from.begin(); i != from.end(); i++) {
+		for (NodeSet::iterator i = from.begin(); i != from.end(); i++) {
 			(*i)->followpos.insert(to.begin(), to.end());
 		}
 	}
-	int eq(Node *other) {
+	int eq(Node *other)
+	{
 		if (dynamic_cast<StarNode *>(other))
 			return child[0]->eq(other->child[0]);
 		return 0;
 	}
-	ostream& dump(ostream& os)
+	ostream & dump(ostream &os)
 	{
 		os << '(';
 		child[0]->dump(os);
@@ -427,36 +414,26 @@ public:
 };
 
 /* Match a node one or more times. (This is a unary operator.) */
-class PlusNode : public OneChildNode {
-public:
-	PlusNode(Node *left) : OneChildNode(left) { }
-	void compute_nullable()
-	{
-		nullable = child[0]->nullable;
-	}
-	void compute_firstpos()
-	{
-		firstpos = child[0]->firstpos;
-	}
-	void compute_lastpos()
-	{
-		lastpos = child[0]->lastpos;
+class PlusNode:public OneChildNode {
+      public:
+	PlusNode(Node *left): OneChildNode(left) {
 	}
+	void compute_nullable() { nullable = child[0]->nullable; }
+	void compute_firstpos() { firstpos = child[0]->firstpos; }
+	void compute_lastpos() { lastpos = child[0]->lastpos; }
 	void compute_followpos()
 	{
 		NodeSet from = child[0]->lastpos, to = child[0]->firstpos;
-		for(NodeSet::iterator i = from.begin(); i != from.end(); i++) {
+		for (NodeSet::iterator i = from.begin(); i != from.end(); i++) {
 			(*i)->followpos.insert(to.begin(), to.end());
 		}
 	}
-	int eq(Node *other)
-	{
+	int eq(Node *other) {
 		if (dynamic_cast<PlusNode *>(other))
 			return child[0]->eq(other->child[0]);
 		return 0;
 	}
-	ostream& dump(ostream& os)
-	{
+	ostream &dump(ostream &os) {
 		os << '(';
 		child[0]->dump(os);
 		return os << ")+";
@@ -464,9 +441,9 @@ public:
 };
 
 /* Match a pair of consecutive nodes. */
-class CatNode : public TwoChildNode {
-public:
-	CatNode(Node *left, Node *right) : TwoChildNode(left, right) { }
+class CatNode:public TwoChildNode {
+      public:
+	CatNode(Node *left, Node *right): TwoChildNode(left, right) { }
 	void compute_nullable()
 	{
 		nullable = child[0]->nullable && child[1]->nullable;
@@ -488,11 +465,12 @@ public:
 	void compute_followpos()
 	{
 		NodeSet from = child[0]->lastpos, to = child[1]->firstpos;
-		for(NodeSet::iterator i = from.begin(); i != from.end(); i++) {
+		for (NodeSet::iterator i = from.begin(); i != from.end(); i++) {
 			(*i)->followpos.insert(to.begin(), to.end());
 		}
 	}
-	int eq(Node *other) {
+	int eq(Node *other)
+	{
 		if (dynamic_cast<CatNode *>(other)) {
 			if (!child[0]->eq(other->child[0]))
 				return 0;
@@ -500,7 +478,7 @@ public:
 		}
 		return 0;
 	}
-	ostream& dump(ostream& os)
+	ostream &dump(ostream &os)
 	{
 		child[0]->dump(os);
 		child[1]->dump(os);
@@ -509,9 +487,9 @@ public:
 };
 
 /* Match one of two alternative nodes. */
-class AltNode : public TwoChildNode {
-public:
-	AltNode(Node *left, Node *right) : TwoChildNode(left, right) { }
+class AltNode:public TwoChildNode {
+      public:
+	AltNode(Node *left, Node *right): TwoChildNode(left, right) { }
 	void compute_nullable()
 	{
 		nullable = child[0]->nullable || child[1]->nullable;
@@ -524,7 +502,8 @@ public:
 	{
 		firstpos = child[0]->firstpos + child[1]->firstpos;
 	}
-	int eq(Node *other) {
+	int eq(Node *other)
+	{
 		if (dynamic_cast<AltNode *>(other)) {
 			if (!child[0]->eq(other->child[0]))
 				return 0;
@@ -532,7 +511,7 @@ public:
 		}
 		return 0;
 	}
-	ostream& dump(ostream& os)
+	ostream &dump(ostream &os)
 	{
 		os << '(';
 		child[0]->dump(os);
@@ -543,37 +522,22 @@ public:
 	}
 };
 
-
 /* Traverse the syntax tree depth-first in an iterator-like manner. */
 class depth_first_traversal {
-	stack<Node *> pos;
-	void push_left(Node *node)
-	{
+	stack <Node *>pos;
+	void push_left(Node *node) {
 		pos.push(node);
 
-		while (dynamic_cast<InnerNode *>(node)) {
+		while (dynamic_cast <InnerNode *>(node)) {
 			pos.push(node->child[0]);
 			node = node->child[0];
 		}
 	}
-
-public:
-	depth_first_traversal(Node *node)
-	{
-		push_left(node);
-	}
-	Node *operator*()
-	{
-		return pos.top();
-	}
-	Node* operator->()
-	{
-		return pos.top();
-	}
-	operator bool()
-	{
-		return !pos.empty();
-	}
+      public:
+	depth_first_traversal(Node *node) { push_left(node); }
+	Node *operator*() { return pos.top(); }
+	Node *operator->() { return pos.top(); }
+	operator  bool() { return !pos.empty(); }
 	void operator++(int)
 	{
 		Node *last = pos.top();
@@ -582,7 +546,7 @@ public:
 		if (!pos.empty()) {
 			/* no need to dynamic cast, as we just popped a node so
 			 * the top node must be an inner node */
-			InnerNode *node = (InnerNode *)(pos.top());
+			InnerNode *node = (InnerNode *) (pos.top());
 			if (node->child[1] && node->child[1] != last) {
 				push_left(node->child[1]);
 			}
@@ -616,36 +580,32 @@ void flip_tree(Node *node);
  * new ones when constructing the DFA.
  */
 struct deref_less_than {
-	bool operator()(pair <unsigned long, NodeSet *> const & lhs,
-			pair <unsigned long, NodeSet *> const & rhs) const
-		{
-			if (lhs.first == rhs.first)
-				return *(lhs.second) < *(rhs.second);
-			else
-				return lhs.first < rhs.first;
-		}
+	bool operator() (pair <unsigned long, NodeSet *>const &lhs,
+			 pair <unsigned long, NodeSet *>const &rhs)const {
+		if (lhs.first == rhs.first)
+			return *(lhs.second) < *(rhs.second);
+		else
+			return lhs.first < rhs.first;
+	}
+};
+
+class MatchFlag:public AcceptNode {
+      public:
+	MatchFlag(uint32_t flag, uint32_t audit): flag(flag), audit(audit) { }
+	ostream &dump(ostream &os) { return os << '<' << flag << '>'; }
+
+	uint32_t flag;
+	uint32_t audit;
 };
 
-class MatchFlag : public AcceptNode {
-public:
-MatchFlag(uint32_t flag, uint32_t audit) : flag(flag), audit(audit) {}
-    ostream& dump(ostream& os)
-    {
-	return os << '<' << flag << '>';
-    }
-
-    uint32_t flag;
-    uint32_t audit;
- };
-
-class ExactMatchFlag : public MatchFlag {
-public:
-    ExactMatchFlag(uint32_t flag, uint32_t audit) : MatchFlag(flag, audit) {}
+class ExactMatchFlag:public MatchFlag {
+      public:
+	ExactMatchFlag(uint32_t flag, uint32_t audit): MatchFlag(flag, audit) {}
 };
 
-class DenyMatchFlag : public MatchFlag {
-public:
-    DenyMatchFlag(uint32_t flag, uint32_t quiet) : MatchFlag(flag, quiet) {}
+class DenyMatchFlag:public MatchFlag {
+      public:
+	DenyMatchFlag(uint32_t flag, uint32_t quiet): MatchFlag(flag, quiet) {}
 };
 
 #endif /* __LIBAA_RE_EXPR */
-- 
1.7.1




More information about the AppArmor mailing list