1 /* Generated By:JJTree: Do not edit this line. JJTAnnotationParserState.java */
2 package org.codehaus.aspectwerkz.annotation.expression.ast;
3
4 class JJTAnnotationParserState {
5 private java.util.Stack nodes;
6
7 private java.util.Stack marks;
8
9 private int sp; // number of nodes on stack
10
11 private int mk; // current mark
12
13 private boolean node_created;
14
15 JJTAnnotationParserState() {
16 nodes = new java.util.Stack();
17 marks = new java.util.Stack();
18 sp = 0;
19 mk = 0;
20 }
21
22 /*
23 * Determines whether the current node was actually closed and pushed. This should only be called in the final user
24 * action of a node scope.
25 */
26 boolean nodeCreated() {
27 return node_created;
28 }
29
30 /*
31 * Call this to reinitialize the node stack. It is called automatically by the parser's ReInit() method.
32 */
33 void reset() {
34 nodes.removeAllElements();
35 marks.removeAllElements();
36 sp = 0;
37 mk = 0;
38 }
39
40 /*
41 * Returns the root node of the AST. It only makes sense to call this after a successful parse.
42 */
43 Node rootNode() {
44 return (Node) nodes.elementAt(0);
45 }
46
47 /* Pushes a node on to the stack. */
48 void pushNode(Node n) {
49 nodes.push(n);
50 ++sp;
51 }
52
53 /*
54 * Returns the node on the top of the stack, and remove it from the stack.
55 */
56 Node popNode() {
57 if (--sp < mk) {
58 mk = ((Integer) marks.pop()).intValue();
59 }
60 return (Node) nodes.pop();
61 }
62
63 /* Returns the node currently on the top of the stack. */
64 Node peekNode() {
65 return (Node) nodes.peek();
66 }
67
68 /*
69 * Returns the number of children on the stack in the current node scope.
70 */
71 int nodeArity() {
72 return sp - mk;
73 }
74
75 void clearNodeScope(Node n) {
76 while (sp > mk) {
77 popNode();
78 }
79 mk = ((Integer) marks.pop()).intValue();
80 }
81
82 void openNodeScope(Node n) {
83 marks.push(new Integer(mk));
84 mk = sp;
85 n.jjtOpen();
86 }
87
88 /*
89 * A definite node is constructed from a specified number of children. That number of nodes are popped from the
90 * stack and made the children of the definite node. Then the definite node is pushed on to the stack.
91 */
92 void closeNodeScope(Node n, int num) {
93 mk = ((Integer) marks.pop()).intValue();
94 while (num-- > 0) {
95 Node c = popNode();
96 c.jjtSetParent(n);
97 n.jjtAddChild(c, num);
98 }
99 n.jjtClose();
100 pushNode(n);
101 node_created = true;
102 }
103
104 /*
105 * A conditional node is constructed if its condition is true. All the nodes that have been pushed since the node
106 * was opened are made children of the the conditional node, which is then pushed on to the stack. If the condition
107 * is false the node is not constructed and they are left on the stack.
108 */
109 void closeNodeScope(Node n, boolean condition) {
110 if (condition) {
111 int a = nodeArity();
112 mk = ((Integer) marks.pop()).intValue();
113 while (a-- > 0) {
114 Node c = popNode();
115 c.jjtSetParent(n);
116 n.jjtAddChild(c, a);
117 }
118 n.jjtClose();
119 pushNode(n);
120 node_created = true;
121 } else {
122 mk = ((Integer) marks.pop()).intValue();
123 node_created = false;
124 }
125 }
126 }