Class ATNConfigSet
- Direct Known Subclasses:
OrderedATNConfigSet
ATNConfig). As
configurations are added to the set, they are merged with other
ATNConfig instances already in the set when possible using the
graph-structured stack.
An instance of this class represents the complete set of positions (with context) in an ATN which would be associated with a single DFA state. Its internal representation is more complex than traditional state used for NFA to DFA conversion due to performance requirements (both improving speed and reducing memory overhead) as well as supporting features such as semantic predicates and non-greedy operators in a form to support ANTLR's prediction algorithm.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate intThis is a list of all configs in this set.private ConflictInfoprivate booleanprivate booleanThis maps (state, alt) -> mergedATNConfig.private booleanWhentrue, this config set represents configurations where the entire outer context has been consumed by the ATN interpreter.private intThis is an "overflow" list holding configs which cannot be merged with one of the configs inmergedConfigsbut have a colliding key. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanbooleanadd(ATNConfig e, PredictionContextCache contextCache) booleanaddAll(Collection<? extends ATNConfig> c) booleanaddAll(Collection<? extends ATNConfig> c, PredictionContextCache contextCache) protected booleanvoidclear()voidclone(boolean readonly) booleanbooleancontainsAll(Collection<?> c) protected final voidbooleanget(int index) booleanprotected longGet the set of all alternatives represented by configurations in this set.intinthashCode()booleanbooleanisEmpty()booleanbooleanfinal booleaniterator()voidvoidoptimizeConfigs(ATNSimulator interpreter) voidremove(int index) booleanbooleanremoveAll(Collection<?> c) booleanretainAll(Collection<?> c) voidsetConflictInfo(ConflictInfo conflictInfo) voidsetOutermostConfigSet(boolean outermostConfigSet) intsize()Object[]toArray()<T> T[]toArray(T[] a) toString()toString(boolean showContext) private voidprivate voidMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface java.util.Set
spliterator
-
Field Details
-
mergedConfigs
This maps (state, alt) -> mergedATNConfig. The key does not account for theATNConfig.getSemanticContext()of the value, which is only a problem if a singleATNConfigSetcontains two configs with the same state and alternative but different semantic contexts. When this case arises, the first config added to this map stays, and the remaining configs are placed inunmerged.This map is only used for optimizing the process of adding configs to the set, and is
nullfor read-only sets stored in the DFA. -
unmerged
This is an "overflow" list holding configs which cannot be merged with one of the configs inmergedConfigsbut have a colliding key. This occurs when two configs in the set have the same state and alternative but different semantic contexts.This list is only used for optimizing the process of adding configs to the set, and is
nullfor read-only sets stored in the DFA. -
configs
This is a list of all configs in this set. -
uniqueAlt
private int uniqueAlt -
conflictInfo
-
hasSemanticContext
private boolean hasSemanticContext -
dipsIntoOuterContext
private boolean dipsIntoOuterContext -
outermostConfigSet
private boolean outermostConfigSetWhentrue, this config set represents configurations where the entire outer context has been consumed by the ATN interpreter. This prevents theParserATNSimulator.closure(org.antlr.v4.runtime.atn.ATNConfigSet, org.antlr.v4.runtime.atn.ATNConfigSet, boolean, boolean, org.antlr.v4.runtime.atn.PredictionContextCache, boolean)from pursuing the global FOLLOW when a rule stop state is reached with an empty prediction context.Note:
outermostConfigSetanddipsIntoOuterContextshould never be true at the same time. -
cachedHashCode
private int cachedHashCode
-
-
Constructor Details
-
ATNConfigSet
public ATNConfigSet() -
ATNConfigSet
-
-
Method Details
-
getRepresentedAlternatives
Get the set of all alternatives represented by configurations in this set. -
isReadOnly
public final boolean isReadOnly() -
isOutermostConfigSet
public boolean isOutermostConfigSet() -
setOutermostConfigSet
public void setOutermostConfigSet(boolean outermostConfigSet) -
getStates
-
optimizeConfigs
-
clone
-
size
public int size() -
isEmpty
public boolean isEmpty() -
contains
-
iterator
-
toArray
-
toArray
public <T> T[] toArray(T[] a) -
add
-
add
-
updatePropertiesForMergedConfig
-
updatePropertiesForAddedConfig
-
canMerge
-
getKey
-
remove
-
containsAll
- Specified by:
containsAllin interfaceCollection<ATNConfig>- Specified by:
containsAllin interfaceSet<ATNConfig>
-
addAll
-
addAll
-
retainAll
-
removeAll
-
clear
public void clear() -
equals
-
hashCode
public int hashCode() -
toString
-
toString
-
getUniqueAlt
public int getUniqueAlt() -
hasSemanticContext
public boolean hasSemanticContext() -
clearExplicitSemanticContext
public void clearExplicitSemanticContext() -
markExplicitSemanticContext
public void markExplicitSemanticContext() -
getConflictInfo
-
setConflictInfo
-
getConflictingAlts
-
isExactConflict
public boolean isExactConflict() -
getDipsIntoOuterContext
public boolean getDipsIntoOuterContext() -
get
-
remove
public void remove(int index) -
ensureWritable
protected final void ensureWritable()
-