1 2 3 21 22 23 package org.apache.cayenne.exp.parser; 24 25 class JJTExpressionParserState { 26 private java.util.Stack nodes; 27 private java.util.Stack marks; 28 29 private int sp; private int mk; private boolean node_created; 32 33 JJTExpressionParserState() { 34 nodes = new java.util.Stack (); 35 marks = new java.util.Stack (); 36 sp = 0; 37 mk = 0; 38 } 39 40 43 boolean nodeCreated() { 44 return node_created; 45 } 46 47 49 void reset() { 50 nodes.removeAllElements(); 51 marks.removeAllElements(); 52 sp = 0; 53 mk = 0; 54 } 55 56 58 Node rootNode() { 59 return (Node)nodes.elementAt(0); 60 } 61 62 63 void pushNode(Node n) { 64 nodes.push(n); 65 ++sp; 66 } 67 68 70 Node popNode() { 71 if (--sp < mk) { 72 mk = ((Integer )marks.pop()).intValue(); 73 } 74 return (Node)nodes.pop(); 75 } 76 77 78 Node peekNode() { 79 return (Node)nodes.peek(); 80 } 81 82 84 int nodeArity() { 85 return sp - mk; 86 } 87 88 89 void clearNodeScope(Node n) { 90 while (sp > mk) { 91 popNode(); 92 } 93 mk = ((Integer )marks.pop()).intValue(); 94 } 95 96 97 void openNodeScope(Node n) { 98 marks.push(new Integer (mk)); 99 mk = sp; 100 n.jjtOpen(); 101 } 102 103 104 108 void closeNodeScope(Node n, int num) { 109 mk = ((Integer )marks.pop()).intValue(); 110 while (num-- > 0) { 111 Node c = popNode(); 112 c.jjtSetParent(n); 113 n.jjtAddChild(c, num); 114 } 115 n.jjtClose(); 116 pushNode(n); 117 node_created = true; 118 } 119 120 121 126 void closeNodeScope(Node n, boolean condition) { 127 if (condition) { 128 int a = nodeArity(); 129 mk = ((Integer )marks.pop()).intValue(); 130 while (a-- > 0) { 131 Node c = popNode(); 132 c.jjtSetParent(n); 133 n.jjtAddChild(c, a); 134 } 135 n.jjtClose(); 136 pushNode(n); 137 node_created = true; 138 } else { 139 mk = ((Integer )marks.pop()).intValue(); 140 node_created = false; 141 } 142 } 143 } 144 | Popular Tags |