187 * since it was put there
188 *
189 * @param node the node expected to be popped, used to detect unbalanced pushes/pops
190 * @return the node that was popped
191 */
192 @SuppressWarnings("unchecked")
193 public <T extends Node> T pop(final T node) {
194 --sp;
195 final LexicalContextNode popped = stack[sp];
196 stack[sp] = null;
197 if (popped instanceof Flags) {
198 return (T)((Flags<?>)popped).setFlag(this, flags[sp]);
199 }
200
201 return (T)popped;
202 }
203
204 /**
205 * Explicitly apply flags to the topmost element on the stack. This is only valid to use from a
206 * {@code NodeVisitor.leaveXxx()} method and only on the node being exited at the time. It is not mandatory to use,
207 * as {@link #pop(LexicalContextNode)} will apply the flags automatically, but this method can be used to apply them
208 * during the {@code leaveXxx()} method in case its logic depends on the value of the flags.
209 * @param node the node to apply the flags to. Must be the topmost node on the stack.
210 * @return the passed in node, or a modified node (if any flags were modified)
211 */
212 public <T extends LexicalContextNode & Flags<T>> T applyTopFlags(final T node) {
213 assert node == peek();
214 return node.setFlag(this, flags[sp - 1]);
215 }
216
217 /**
218 * Return the top element in the context
219 * @return the node that was pushed last
220 */
221 public LexicalContextNode peek() {
222 return stack[sp - 1];
223 }
224
225 /**
226 * Check if a node is in the lexical context
227 * @param node node to check for
|
187 * since it was put there
188 *
189 * @param node the node expected to be popped, used to detect unbalanced pushes/pops
190 * @return the node that was popped
191 */
192 @SuppressWarnings("unchecked")
193 public <T extends Node> T pop(final T node) {
194 --sp;
195 final LexicalContextNode popped = stack[sp];
196 stack[sp] = null;
197 if (popped instanceof Flags) {
198 return (T)((Flags<?>)popped).setFlag(this, flags[sp]);
199 }
200
201 return (T)popped;
202 }
203
204 /**
205 * Explicitly apply flags to the topmost element on the stack. This is only valid to use from a
206 * {@code NodeVisitor.leaveXxx()} method and only on the node being exited at the time. It is not mandatory to use,
207 * as {@link #pop(Node)} will apply the flags automatically, but this method can be used to apply them
208 * during the {@code leaveXxx()} method in case its logic depends on the value of the flags.
209 * @param node the node to apply the flags to. Must be the topmost node on the stack.
210 * @return the passed in node, or a modified node (if any flags were modified)
211 */
212 public <T extends LexicalContextNode & Flags<T>> T applyTopFlags(final T node) {
213 assert node == peek();
214 return node.setFlag(this, flags[sp - 1]);
215 }
216
217 /**
218 * Return the top element in the context
219 * @return the node that was pushed last
220 */
221 public LexicalContextNode peek() {
222 return stack[sp - 1];
223 }
224
225 /**
226 * Check if a node is in the lexical context
227 * @param node node to check for
|