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