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