From 3bf99d6d88b2d6c32aed5a2dc9fe6262e6e2d791 Mon Sep 17 00:00:00 2001 From: Sam Harwell Date: Mon, 30 Jul 2012 13:56:19 -0500 Subject: [PATCH] Add IntervalSet.toIntegerList(), use IntegerStack to hold mode stack in Lexer --- .../Java/src/org/antlr/v4/runtime/Lexer.java | 4 +-- .../antlr/v4/runtime/misc/IntervalSet.java | 28 ++++++++++--------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/runtime/Java/src/org/antlr/v4/runtime/Lexer.java b/runtime/Java/src/org/antlr/v4/runtime/Lexer.java index 34b2fe426..55322153c 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/Lexer.java +++ b/runtime/Java/src/org/antlr/v4/runtime/Lexer.java @@ -29,9 +29,9 @@ package org.antlr.v4.runtime; import org.antlr.v4.runtime.atn.LexerATNSimulator; +import org.antlr.v4.runtime.misc.IntegerStack; import org.antlr.v4.runtime.misc.Interval; -import java.util.ArrayDeque; import java.util.ArrayList; import java.util.EmptyStackException; import java.util.List; @@ -91,7 +91,7 @@ public abstract class Lexer extends Recognizer /** The token type for the current token */ public int _type; - public ArrayDeque _modeStack = new ArrayDeque(); + public final IntegerStack _modeStack = new IntegerStack(); public int _mode = Lexer.DEFAULT_MODE; /** You can set the text for the current token to override what is in diff --git a/runtime/Java/src/org/antlr/v4/runtime/misc/IntervalSet.java b/runtime/Java/src/org/antlr/v4/runtime/misc/IntervalSet.java index dc1f25062..21dd7a271 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/misc/IntervalSet.java +++ b/runtime/Java/src/org/antlr/v4/runtime/misc/IntervalSet.java @@ -530,6 +530,20 @@ public class IntervalSet implements IntSet { return n; } + public IntegerList toIntegerList() { + IntegerList values = new IntegerList(size()); + int n = intervals.size(); + for (int i = 0; i < n; i++) { + Interval I = intervals.get(i); + int a = I.a; + int b = I.b; + for (int v=a; v<=b; v++) { + values.add(v); + } + } + return values; + } + @Override public List toList() { List values = new ArrayList(); @@ -579,19 +593,7 @@ public class IntervalSet implements IntSet { } public int[] toArray() { - int[] values = new int[size()]; - int n = intervals.size(); - int j = 0; - for (int i = 0; i < n; i++) { - Interval I = intervals.get(i); - int a = I.a; - int b = I.b; - for (int v=a; v<=b; v++) { - values[j] = v; - j++; - } - } - return values; + return toIntegerList().toArray(); } @Override