1 2 3 package org.codehaus.aspectwerkz.expression.ast; 4 5 class JJTExpressionParserState { 6 private java.util.Stack nodes; 7 8 private java.util.Stack marks; 9 10 private int sp; 12 private int mk; 14 private boolean node_created; 15 16 JJTExpressionParserState() { 17 nodes = new java.util.Stack (); 18 marks = new java.util.Stack (); 19 sp = 0; 20 mk = 0; 21 } 22 23 27 boolean nodeCreated() { 28 return node_created; 29 } 30 31 34 void reset() { 35 nodes.removeAllElements(); 36 marks.removeAllElements(); 37 sp = 0; 38 mk = 0; 39 } 40 41 44 Node rootNode() { 45 return (Node) nodes.elementAt(0); 46 } 47 48 49 void pushNode(Node n) { 50 nodes.push(n); 51 ++sp; 52 } 53 54 57 Node popNode() { 58 if (--sp < mk) { 59 mk = ((Integer ) marks.pop()).intValue(); 60 } 61 return (Node) nodes.pop(); 62 } 63 64 65 Node peekNode() { 66 return (Node) nodes.peek(); 67 } 68 69 72 int nodeArity() { 73 return sp - mk; 74 } 75 76 void clearNodeScope(Node n) { 77 while (sp > mk) { 78 popNode(); 79 } 80 mk = ((Integer ) marks.pop()).intValue(); 81 } 82 83 void openNodeScope(Node n) { 84 marks.push(new Integer (mk)); 85 mk = sp; 86 n.jjtOpen(); 87 } 88 89 93 void closeNodeScope(Node n, int num) { 94 mk = ((Integer ) marks.pop()).intValue(); 95 while (num-- > 0) { 96 Node c = popNode(); 97 c.jjtSetParent(n); 98 n.jjtAddChild(c, num); 99 } 100 n.jjtClose(); 101 pushNode(n); 102 node_created = true; 103 } 104 105 110 void closeNodeScope(Node n, boolean condition) { 111 if (condition) { 112 int a = nodeArity(); 113 mk = ((Integer ) marks.pop()).intValue(); 114 while (a-- > 0) { 115 Node c = popNode(); 116 c.jjtSetParent(n); 117 n.jjtAddChild(c, a); 118 } 119 n.jjtClose(); 120 pushNode(n); 121 node_created = true; 122 } else { 123 mk = ((Integer ) marks.pop()).intValue(); 124 node_created = false; 125 } 126 } 127 } | Popular Tags |