KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > debugger > jpda > expr > JJTJavaParserState


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 /* Generated By:JJTree: Do not edit this line. JJTJavaParserState.java */
21
22 package org.netbeans.modules.debugger.jpda.expr;
23
24 class JJTJavaParserState {
25   private java.util.Stack JavaDoc<Node> nodes;
26   private java.util.Stack JavaDoc<Integer JavaDoc> marks;
27
28   private int sp; // number of nodes on stack
29
private int mk; // current mark
30
private boolean node_created;
31
32   JJTJavaParserState() {
33     nodes = new java.util.Stack JavaDoc<Node>();
34     marks = new java.util.Stack JavaDoc<Integer JavaDoc>();
35     sp = 0;
36     mk = 0;
37   }
38
39   /* Determines whether the current node was actually closed and
40      pushed. This should only be called in the final user action of a
41      node scope. */

42   boolean nodeCreated() {
43     return node_created;
44   }
45
46   /* Call this to reinitialize the node stack. It is called
47      automatically by the parser's ReInit() method. */

48   void reset() {
49     nodes.removeAllElements();
50     marks.removeAllElements();
51     sp = 0;
52     mk = 0;
53   }
54
55   /* Returns the root node of the AST. It only makes sense to call
56      this after a successful parse. */

57   Node rootNode() {
58     return nodes.elementAt(0);
59   }
60
61   /* Pushes a node on to the stack. */
62   void pushNode(Node n) {
63     nodes.push(n);
64     ++sp;
65   }
66
67   /* Returns the node on the top of the stack, and remove it from the
68      stack. */

69   Node popNode() {
70     if (--sp < mk) {
71       mk = marks.pop().intValue();
72     }
73     return nodes.pop();
74   }
75
76   /* Returns the node currently on the top of the stack. */
77   Node peekNode() {
78     return nodes.peek();
79   }
80
81   /* Returns the number of children on the stack in the current node
82      scope. */

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 JavaDoc(mk));
98     mk = sp;
99     n.jjtOpen();
100   }
101
102
103   /* A definite node is constructed from a specified number of
104      children. That number of nodes are popped from the stack and
105      made the children of the definite node. Then the definite node
106      is pushed on to the stack. */

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   /* A conditional node is constructed if its condition is true. All
121      the nodes that have been pushed since the node was opened are
122      made children of the the conditional node, which is then pushed
123      on to the stack. If the condition is false the node is not
124      constructed and they are left on the stack. */

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