1 /*
   2  * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 /* Generated By:JJTree: Do not edit this line. JJTParserState.java */
  27 
  28 package com.sun.jmx.snmp.IPAcl;
  29 
  30 class JJTParserState {
  31   private java.util.Stack<Node> nodes;
  32   private java.util.Stack<Integer> marks;
  33 
  34   private int sp;               // number of nodes on stack
  35   private int mk;               // current mark
  36   private boolean node_created;
  37 
  38   JJTParserState() {
  39     nodes = new java.util.Stack<>();
  40     marks = new java.util.Stack<>();
  41     sp = 0;
  42     mk = 0;
  43   }
  44 
  45   /* Determines whether the current node was actually closed and
  46      pushed.  This should only be called in the final user action of a
  47      node scope.  */
  48   boolean nodeCreated() {
  49     return node_created;
  50   }
  51 
  52   /* Call this to reinitialize the node stack.  It is called
  53      automatically by the parser's ReInit() method. */
  54   void reset() {
  55     nodes.removeAllElements();
  56     marks.removeAllElements();
  57     sp = 0;
  58     mk = 0;
  59   }
  60 
  61   /* Returns the root node of the AST.  It only makes sense to call
  62      this after a successful parse. */
  63   Node rootNode() {
  64     return nodes.elementAt(0);
  65   }
  66 
  67   /* Pushes a node on to the stack. */
  68   void pushNode(Node n) {
  69     nodes.push(n);
  70     ++sp;
  71   }
  72 
  73   /* Returns the node on the top of the stack, and remove it from the
  74      stack.  */
  75   Node popNode() {
  76     if (--sp < mk) {
  77       mk = marks.pop().intValue();
  78     }
  79     return nodes.pop();
  80   }
  81 
  82   /* Returns the node currently on the top of the stack. */
  83   Node peekNode() {
  84     return nodes.peek();
  85   }
  86 
  87   /* Returns the number of children on the stack in the current node
  88      scope. */
  89   int nodeArity() {
  90     return sp - mk;
  91   }
  92 
  93 
  94   void clearNodeScope(Node n) {
  95     while (sp > mk) {
  96       popNode();
  97     }
  98     mk = marks.pop().intValue();
  99   }
 100 
 101 
 102   void openNodeScope(Node n) {
 103     marks.push(mk);
 104     mk = sp;
 105     n.jjtOpen();
 106   }
 107 
 108 
 109   /* A definite node is constructed from a specified number of
 110      children.  That number of nodes are popped from the stack and
 111      made the children of the definite node.  Then the definite node
 112      is pushed on to the stack. */
 113   void closeNodeScope(Node n, int num) {
 114     mk = marks.pop().intValue();
 115     while (num-- > 0) {
 116       Node c = popNode();
 117       c.jjtSetParent(n);
 118       n.jjtAddChild(c, num);
 119     }
 120     n.jjtClose();
 121     pushNode(n);
 122     node_created = true;
 123   }
 124 
 125 
 126   /* A conditional node is constructed if its condition is true.  All
 127      the nodes that have been pushed since the node was opened are
 128      made children of the the conditional node, which is then pushed
 129      on to the stack.  If the condition is false the node is not
 130      constructed and they are left on the stack. */
 131   void closeNodeScope(Node n, boolean condition) {
 132     if (condition) {
 133       int a = nodeArity();
 134       mk = marks.pop().intValue();
 135       while (a-- > 0) {
 136         Node c = popNode();
 137         c.jjtSetParent(n);
 138         n.jjtAddChild(c, a);
 139       }
 140       n.jjtClose();
 141       pushNode(n);
 142       node_created = true;
 143     } else {
 144       mk = marks.pop().intValue();
 145       node_created = false;
 146     }
 147   }
 148 }