JJTJspParserState.java
001 /* Generated By:JavaCC: Do not edit this line. JJTJspParserState.java Version 4.1 */
002 package net.sourceforge.pmd.lang.jsp.ast;
003 
004 import net.sourceforge.pmd.lang.ast.Node;
005 
006 public class JJTJspParserState {
007   private java.util.List nodes;
008   private java.util.List marks;
009 
010   private int sp;        // number of nodes on stack
011   private int mk;        // current mark
012   private boolean node_created;
013 
014   public JJTJspParserState() {
015     nodes = new java.util.ArrayList();
016     marks = new java.util.ArrayList();
017     sp = 0;
018     mk = 0;
019   }
020 
021   /* Determines whether the current node was actually closed and
022      pushed.  This should only be called in the final user action of a
023      node scope.  */
024   public boolean nodeCreated() {
025     return node_created;
026   }
027 
028   /* Call this to reinitialize the node stack.  It is called
029      automatically by the parser's ReInit() method. */
030   public void reset() {
031     nodes.clear();
032     marks.clear();
033     sp = 0;
034     mk = 0;
035   }
036 
037   /* Returns the root node of the AST.  It only makes sense to call
038      this after a successful parse. */
039   public Node rootNode() {
040     return (Node)nodes.get(0);
041   }
042 
043   /* Pushes a node on to the stack. */
044   public void pushNode(Node n) {
045     nodes.add(n);
046     ++sp;
047   }
048 
049   /* Returns the node on the top of the stack, and remove it from the
050      stack.  */
051   public Node popNode() {
052     if (--sp < mk) {
053       mk = ((Integer)marks.remove(marks.size()-1)).intValue();
054     }
055     return (Node)nodes.remove(nodes.size()-1);
056   }
057 
058   /* Returns the node currently on the top of the stack. */
059   public Node peekNode() {
060     return (Node)nodes.get(nodes.size()-1);
061   }
062 
063   /* Returns the number of children on the stack in the current node
064      scope. */
065   public int nodeArity() {
066     return sp - mk;
067   }
068 
069 
070   public void clearNodeScope(Node n) {
071     while (sp > mk) {
072       popNode();
073     }
074     mk = ((Integer)marks.remove(marks.size()-1)).intValue();
075   }
076 
077 
078   public void openNodeScope(Node n) {
079     marks.add(new Integer(mk));
080     mk = sp;
081     n.jjtOpen();
082   }
083 
084 
085   /* A definite node is constructed from a specified number of
086      children.  That number of nodes are popped from the stack and
087      made the children of the definite node.  Then the definite node
088      is pushed on to the stack. */
089   public void closeNodeScope(Node n, int num) {
090     mk = ((Integer)marks.remove(marks.size()-1)).intValue();
091     while (num-- > 0) {
092       Node c = popNode();
093       c.jjtSetParent(n);
094       n.jjtAddChild(c, num);
095     }
096     n.jjtClose();
097     pushNode(n);
098     node_created = true;
099   }
100 
101 
102   /* A conditional node is constructed if its condition is true.  All
103      the nodes that have been pushed since the node was opened are
104      made children of the conditional node, which is then pushed
105      on to the stack.  If the condition is false the node is not
106      constructed and they are left on the stack. */
107   public void closeNodeScope(Node n, boolean condition) {
108     if (condition) {
109       int a = nodeArity();
110       mk = ((Integer)marks.remove(marks.size()-1)).intValue();
111       while (a-- > 0) {
112         Node c = popNode();
113         c.jjtSetParent(n);
114         n.jjtAddChild(c, a);
115       }
116       n.jjtClose();
117       pushNode(n);
118       node_created = true;
119     else {
120       mk = ((Integer)marks.remove(marks.size()-1)).intValue();
121       node_created = false;
122     }
123   }
124 }
125 /* JavaCC - OriginalChecksum=d16c33f88464be769fa14a7d8f0b5d07 (do not edit this line) */