From 4b393cf44814391705506e32ea3e7dc398d0ebb5 Mon Sep 17 00:00:00 2001 From: parrt Date: Tue, 22 Nov 2011 14:33:35 -0800 Subject: [PATCH] rm QStack and use ArrayDeque [git-p4: depot-paths = "//depot/code/antlr4/main/": change = 9427] --- .../Java/src/org/antlr/v4/runtime/Lexer.java | 6 +- .../src/org/antlr/v4/runtime/misc/QStack.java | 78 ------------------- 2 files changed, 3 insertions(+), 81 deletions(-) delete mode 100644 runtime/Java/src/org/antlr/v4/runtime/misc/QStack.java diff --git a/runtime/Java/src/org/antlr/v4/runtime/Lexer.java b/runtime/Java/src/org/antlr/v4/runtime/Lexer.java index b6f7d84d5..b078b7f9e 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/Lexer.java +++ b/runtime/Java/src/org/antlr/v4/runtime/Lexer.java @@ -29,8 +29,8 @@ package org.antlr.v4.runtime; import org.antlr.v4.runtime.atn.LexerATNSimulator; -import org.antlr.v4.runtime.misc.QStack; +import java.util.ArrayDeque; import java.util.EmptyStackException; /** A lexer is recognizer that draws input symbols from a character stream. @@ -85,7 +85,7 @@ public abstract class Lexer extends Recognizer /** The token type for the current token */ public int type; - public QStack modeStack; // TODO: List? + public ArrayDeque modeStack; // TODO: List? public int mode = Lexer.DEFAULT_MODE; /** You can set the text for the current token to override what is in @@ -181,7 +181,7 @@ public abstract class Lexer extends Recognizer public void pushMode(int m) { if ( LexerATNSimulator.debug ) System.out.println("pushMode "+m); - if ( modeStack==null ) modeStack = new QStack(); + if ( modeStack==null ) modeStack = new ArrayDeque(); modeStack.push(mode); mode(m); } diff --git a/runtime/Java/src/org/antlr/v4/runtime/misc/QStack.java b/runtime/Java/src/org/antlr/v4/runtime/misc/QStack.java deleted file mode 100644 index d50791e2e..000000000 --- a/runtime/Java/src/org/antlr/v4/runtime/misc/QStack.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - [The "BSD license"] - Copyright (c) 2011 Terence Parr - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - 3. The name of the author may not be used to endorse or promote products - derived from this software without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.antlr.v4.runtime.misc; - -import java.util.EmptyStackException; - -/** A quicker stack than Stack */ -public class QStack { - T[] elements; - public int sp = -1; - - public QStack() { - elements = (T[])new Object[10]; - } - - public QStack(QStack s) { - elements = (T[])new Object[s.elements.length]; - System.arraycopy(s.elements, 0, elements, 0, s.elements.length); - this.sp = s.sp; - } - - public void push(T fset) { - if ( (sp+1)>=elements.length ) { - T[] f = (T[])new Object[elements.length*2]; - System.arraycopy(elements, 0, f, 0, elements.length); - elements = f; - } - elements[++sp] = fset; - } - - public T peek() { - if ( sp<0 ) throw new EmptyStackException(); - return elements[sp]; - } - - public T get(int i) { - if ( i<0 ) throw new IllegalArgumentException("i<0"); - if ( i>sp ) throw new IllegalArgumentException("i>"+sp); - return elements[sp]; - } - - public T pop() { - if ( sp<0 ) throw new EmptyStackException(); - T o = elements[sp]; - elements[sp] = null; // let gc reclaim that element - sp--; - return o; - } - - public void clear() { sp = -1; } -}