Package org.antlr.v4.runtime.atn
Class ATNSimulator
- java.lang.Object
-
- org.antlr.v4.runtime.atn.ATNSimulator
-
- Direct Known Subclasses:
LexerATNSimulator
,ParserATNSimulator
public abstract class ATNSimulator extends Object
-
-
Field Summary
Fields Modifier and Type Field Description ATN
atn
static DFAState
ERROR
Must distinguish between missing edge and edge we know leads nowherestatic UUID
SERIALIZED_UUID
Deprecated.UseATNDeserializer.checkCondition(boolean)
instead.static int
SERIALIZED_VERSION
Deprecated.UseATNDeserializer.SERIALIZED_VERSION
instead.protected PredictionContextCache
sharedContextCache
The context cache maps all PredictionContext objects that are equals() to a single cached copy.
-
Constructor Summary
Constructors Constructor Description ATNSimulator(ATN atn, PredictionContextCache sharedContextCache)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static void
checkCondition(boolean condition)
Deprecated.UseATNDeserializer.checkCondition(boolean)
instead.static void
checkCondition(boolean condition, String message)
Deprecated.UseATNDeserializer.checkCondition(boolean, String)
instead.void
clearDFA()
Clear the DFA cache used by the current instance.static ATN
deserialize(char[] data)
Deprecated.UseATNDeserializer.deserialize(char[])
instead.static Transition
edgeFactory(ATN atn, int type, int src, int trg, int arg1, int arg2, int arg3, List<IntervalSet> sets)
PredictionContext
getCachedContext(PredictionContext context)
PredictionContextCache
getSharedContextCache()
abstract void
reset()
static ATNState
stateFactory(int type, int ruleIndex)
Deprecated.UseATNDeserializer.stateFactory(int, int)
instead.static int
toInt(char c)
Deprecated.UseATNDeserializer.toInt(char)
instead.static int
toInt32(char[] data, int offset)
Deprecated.UseATNDeserializer.toInt32(char[], int)
instead.static long
toLong(char[] data, int offset)
Deprecated.UseATNDeserializer.toLong(char[], int)
instead.static UUID
toUUID(char[] data, int offset)
Deprecated.UseATNDeserializer.toUUID(char[], int)
instead.
-
-
-
Field Detail
-
SERIALIZED_VERSION
@Deprecated public static final int SERIALIZED_VERSION
Deprecated.UseATNDeserializer.SERIALIZED_VERSION
instead.
-
SERIALIZED_UUID
@Deprecated public static final UUID SERIALIZED_UUID
Deprecated.UseATNDeserializer.checkCondition(boolean)
instead.This is the current serialized UUID.
-
ERROR
public static final DFAState ERROR
Must distinguish between missing edge and edge we know leads nowhere
-
atn
public final ATN atn
-
sharedContextCache
protected final PredictionContextCache sharedContextCache
The context cache maps all PredictionContext objects that are equals() to a single cached copy. This cache is shared across all contexts in all ATNConfigs in all DFA states. We rebuild each ATNConfigSet to use only cached nodes/graphs in addDFAState(). We don't want to fill this during closure() since there are lots of contexts that pop up but are not used ever again. It also greatly slows down closure().This cache makes a huge difference in memory and a little bit in speed. For the Java grammar on java.*, it dropped the memory requirements at the end from 25M to 16M. We don't store any of the full context graphs in the DFA because they are limited to local context only, but apparently there's a lot of repetition there as well. We optimize the config contexts before storing the config set in the DFA states by literally rebuilding them with cached subgraphs only.
I tried a cache for use during closure operations, that was whacked after each adaptivePredict(). It cost a little bit more time I think and doesn't save on the overall footprint so it's not worth the complexity.
-
-
Constructor Detail
-
ATNSimulator
public ATNSimulator(ATN atn, PredictionContextCache sharedContextCache)
-
-
Method Detail
-
reset
public abstract void reset()
-
clearDFA
public void clearDFA()
Clear the DFA cache used by the current instance. Since the DFA cache may be shared by multiple ATN simulators, this method may affect the performance (but not accuracy) of other parsers which are being used concurrently.- Throws:
UnsupportedOperationException
- if the current instance does not support clearing the DFA.- Since:
- 4.3
-
getSharedContextCache
public PredictionContextCache getSharedContextCache()
-
getCachedContext
public PredictionContext getCachedContext(PredictionContext context)
-
deserialize
@Deprecated public static ATN deserialize(char[] data)
Deprecated.UseATNDeserializer.deserialize(char[])
instead.
-
checkCondition
@Deprecated public static void checkCondition(boolean condition)
Deprecated.UseATNDeserializer.checkCondition(boolean)
instead.
-
checkCondition
@Deprecated public static void checkCondition(boolean condition, String message)
Deprecated.UseATNDeserializer.checkCondition(boolean, String)
instead.
-
toInt
@Deprecated public static int toInt(char c)
Deprecated.UseATNDeserializer.toInt(char)
instead.
-
toInt32
@Deprecated public static int toInt32(char[] data, int offset)
Deprecated.UseATNDeserializer.toInt32(char[], int)
instead.
-
toLong
@Deprecated public static long toLong(char[] data, int offset)
Deprecated.UseATNDeserializer.toLong(char[], int)
instead.
-
toUUID
@Deprecated public static UUID toUUID(char[] data, int offset)
Deprecated.UseATNDeserializer.toUUID(char[], int)
instead.
-
edgeFactory
@Deprecated public static Transition edgeFactory(ATN atn, int type, int src, int trg, int arg1, int arg2, int arg3, List<IntervalSet> sets)
-
stateFactory
@Deprecated public static ATNState stateFactory(int type, int ruleIndex)
Deprecated.UseATNDeserializer.stateFactory(int, int)
instead.
-
-