1 4 5 6 7 package com.tc.aspectwerkz.expression.ast; 8 9 class JJTExpressionParserState { 10 private java.util.Stack nodes; 11 12 private java.util.Stack marks; 13 14 private int sp; 16 private int mk; 18 private boolean node_created; 19 20 JJTExpressionParserState() { 21 nodes = new java.util.Stack (); 22 marks = new java.util.Stack (); 23 sp = 0; 24 mk = 0; 25 } 26 27 31 boolean nodeCreated() { 32 return node_created; 33 } 34 35 38 void reset() { 39 nodes.removeAllElements(); 40 marks.removeAllElements(); 41 sp = 0; 42 mk = 0; 43 } 44 45 48 Node rootNode() { 49 return (Node) nodes.elementAt(0); 50 } 51 52 53 void pushNode(Node n) { 54 nodes.push(n); 55 ++sp; 56 } 57 58 61 Node popNode() { 62 if (--sp < mk) { 63 mk = ((Integer ) marks.pop()).intValue(); 64 } 65 return (Node) nodes.pop(); 66 } 67 68 69 Node peekNode() { 70 return (Node) nodes.peek(); 71 } 72 73 76 int nodeArity() { 77 return sp - mk; 78 } 79 80 void clearNodeScope(Node n) { 81 while (sp > mk) { 82 popNode(); 83 } 84 mk = ((Integer ) marks.pop()).intValue(); 85 } 86 87 void openNodeScope(Node n) { 88 marks.push(new Integer (mk)); 89 mk = sp; 90 n.jjtOpen(); 91 } 92 93 97 void closeNodeScope(Node n, int num) { 98 mk = ((Integer ) marks.pop()).intValue(); 99 while (num-- > 0) { 100 Node c = popNode(); 101 c.jjtSetParent(n); 102 n.jjtAddChild(c, num); 103 } 104 n.jjtClose(); 105 pushNode(n); 106 node_created = true; 107 } 108 109 114 void closeNodeScope(Node n, boolean condition) { 115 if (condition) { 116 int a = nodeArity(); 117 mk = ((Integer ) marks.pop()).intValue(); 118 while (a-- > 0) { 119 Node c = popNode(); 120 c.jjtSetParent(n); 121 n.jjtAddChild(c, a); 122 } 123 n.jjtClose(); 124 pushNode(n); 125 node_created = true; 126 } else { 127 mk = ((Integer ) marks.pop()).intValue(); 128 node_created = false; 129 } 130 } 131 } | Popular Tags |