Top Description Inners Fields Constructors Methods
org.antlr.v4.runtime.atn

public Class ATNConfig

extends Object
Class Inheritance
Known Direct Subclasses
org.antlr.v4.runtime.atn.ATNConfig.SemanticContextATNConfig, org.antlr.v4.runtime.atn.ATNConfig.ActionATNConfig
Imports
org.antlr.v4.runtime.Recognizer, org.antlr.v4.runtime.misc.MurmurHash, .NotNull, .Nullable, .ObjectEqualityComparator, java.util.ArrayDeque, .Deque, .IdentityHashMap, .Map

Represents a location with context in an ATN. The location is identified by the following values:

In addition to these values, ATNConfig stores several properties about paths taken to get to the location which were added over time to help with performance, correctness, and/or debugging.

Due to the use of a graph-structured stack, a single ATNConfig is capable of representing many individual ATN configurations which reached the same location in an ATN by following different paths.

PERF: To conserve memory, ATNConfig is split into several different concrete types. ATNConfig itself stores the minimum amount of information typically used to define an ATNConfig instance. Various derived types provide additional storage space for cases where a non-default value is used for some of the object properties. The ATNConfig#create and ATNConfig#transform methods automatically select the smallest concrete type capable of representing the unique information for any given ATNConfig.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
ATNConfig.ActionATNConfig

This class was derived from ATNConfig purely as a memory optimization.

private static class
ATNConfig.ActionSemanticContextATNConfig

This class was derived from SemanticContextATNConfig purely as a memory optimization.

private static class
ATNConfig.SemanticContextATNConfig

This class was derived from ATNConfig purely as a memory optimization.

Field Summary

Modifier and TypeField and Description
private int
altAndOuterContextDepth

This is a bit-field currently containing the following values.

private PredictionContext
context

The stack of invoking states leading to the rule/states associated with this config.

private final ATNState
state

The ATN state associated with this configuration

private static final int
SUPPRESS_PRECEDENCE_FILTER

This field stores the bit mask for implementing the isPrecedenceFilterSuppressed property as a bit within the existing altAndOuterContextDepth field.

Constructor Summary

AccessConstructor and Description
protected
ATNConfig(ATNState state, int alt, PredictionContext context)

protected

Method Summary

Modifier and TypeMethod and Description
public ATNConfig
appendContext(int context, PredictionContextCache contextCache)

public ATNConfig
private static boolean
public final ATNConfig
clone()

Overrides java.lang.Object.clone.

Creates and returns a copy of this object.
public boolean

Returns:

true if this configuration contains subconfig; otherwise, false.
contains
(ATNConfig
The sub configuration.
subconfig
)

Determines if this ATNConfig fully contains another ATNConfig.

public static ATNConfig
create(ATNState state, int alt, PredictionContext context)

public static ATNConfig
create(ATNState state, int alt, PredictionContext context, SemanticContext semanticContext)

public static ATNConfig
create(ATNState state, int alt, PredictionContext context, SemanticContext semanticContext, LexerActionExecutor lexerActionExecutor)

public boolean
equals(Object
the reference object with which to compare.
o
)

Overrides java.lang.Object.equals.

An ATN configuration is equal to another if both have the same state, they predict the same alternative, and syntactic/semantic contexts are the same.
public boolean
public final int
getAlt()

What alt (or lexer rule) is predicted by this configuration

public final PredictionContext
public LexerActionExecutor
public final int
getOuterContextDepth()

We cannot execute predicates dependent upon local context unless we know for sure we are in the correct context.

public final boolean
public SemanticContext
public final ATNState
getState()

Gets the ATN state associated with this configuration

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for the object.
public boolean
public final boolean
public void
public void
setOuterContextDepth(int outerContextDepth)

public final void
public String

Returns:

A Graphviz graph representing the current ATNConfig.
toDotString
()

Returns a graphical representation of the current ATNConfig in Graphviz format.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
public String
toString(Recognizer<?, ?> recog, boolean showAlt)

public String
toString(Recognizer<?, ?> recog, boolean showAlt, boolean showContext)

public final ATNConfig
transform(ATNState state, boolean checkNonGreedy)

public final ATNConfig
transform(ATNState state, SemanticContext semanticContext, boolean checkNonGreedy)

public final ATNConfig
transform(ATNState state, PredictionContext context, boolean checkNonGreedy)

public final ATNConfig
transform(ATNState state, LexerActionExecutor lexerActionExecutor, boolean checkNonGreedy)

private ATNConfig
transform(ATNState state, PredictionContext context, SemanticContext semanticContext, boolean checkNonGreedy, LexerActionExecutor lexerActionExecutor)

Inherited from java.lang.Object:
finalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

altAndOuterContextDepthback to summary
private int altAndOuterContextDepth

This is a bit-field currently containing the following values.

  • 0x00FFFFFF: Alternative
  • 0x7F000000: Outer context depth
  • 0x80000000: Suppress precedence filter
contextback to summary
private PredictionContext context

The stack of invoking states leading to the rule/states associated with this config. We track only those contexts pushed during execution of the ATN simulator.

Annotations
@NotNull
stateback to summary
private final ATNState state

The ATN state associated with this configuration

Annotations
@NotNull
SUPPRESS_PRECEDENCE_FILTERback to summary
private static final int SUPPRESS_PRECEDENCE_FILTER

This field stores the bit mask for implementing the isPrecedenceFilterSuppressed property as a bit within the existing altAndOuterContextDepth field.

Constructor Detail

ATNConfigback to summary
protected ATNConfig(ATNState state, int alt, PredictionContext context)
ATNConfigback to summary
protected ATNConfig(ATNConfig c, ATNState state, PredictionContext context)

Method Detail

appendContextback to summary
public ATNConfig appendContext(int context, PredictionContextCache contextCache)
appendContextback to summary
public ATNConfig appendContext(PredictionContext context, PredictionContextCache contextCache)
checkNonGreedyDecisionback to summary
private static boolean checkNonGreedyDecision(ATNConfig source, ATNState target)
cloneback to summary
public final ATNConfig clone()

Overrides java.lang.Object.clone.

Doc from java.lang.Object.clone.

Creates and returns a copy of this object. The precise meaning of "copy" may depend on the class of the object. The general intent is that, for any object x, the expression:

x.clone() != x
will be true, and that the expression:
x.clone().getClass() == x.getClass()
will be true, but these are not absolute requirements. While it is typically the case that:
x.clone().equals(x)
will be true, this is not an absolute requirement.

By convention, the returned object should be obtained by calling super.clone. If a class and all of its superclasses (except Object) obey this convention, it will be the case that x.clone().getClass() == x.getClass().

By convention, the object returned by this method should be independent of this object (which is being cloned). To achieve this independence, it may be necessary to modify one or more fields of the object returned by super.clone before returning it. Typically, this means copying any mutable objects that comprise the internal "deep structure" of the object being cloned and replacing the references to these objects with references to the copies. If a class contains only primitive fields or references to immutable objects, then it is usually the case that no fields in the object returned by super.clone need to be modified.

Returns:ATNConfig

a clone of this instance.

Annotations
@Override
containsback to summary
public boolean contains(ATNConfig subconfig)

Determines if this ATNConfig fully contains another ATNConfig.

An ATN configuration represents a position (including context) in an ATN during parsing. Since ATNConfig stores the context as a graph, a single ATNConfig instance is capable of representing many ATN configurations which are all in the same "location" but have different contexts. These ATNConfig instances are again merged when they are added to an ATNConfigSet. This method supports ATNConfigSet#contains by evaluating whether a particular ATNConfig contains all of the ATN configurations represented by another ATNConfig.

An ATNConfig a contains another ATNConfig b if all of the following conditions are met:

  • The configurations are in the same state (getState())
  • The configurations predict the same alternative (getAlt())
  • The semantic context of a implies the semantic context of b (this method performs a weaker equality check)
  • Joining the prediction contexts of a and b results in the prediction context of a

This method implements a conservative approximation of containment. As a result, when this method returns {code true} it is known that parsing from subconfig can only recognize a subset of the inputs which can be recognized starting at the current ATNConfig. However, due to the imprecise evaluation of implication for the semantic contexts, no assumptions can be made about the relationship between the configurations when this method returns false.

Parameters
subconfig:ATNConfig

The sub configuration.

Returns:boolean

true if this configuration contains subconfig; otherwise, false.

createback to summary
public static ATNConfig create(ATNState state, int alt, PredictionContext context)
createback to summary
public static ATNConfig create(ATNState state, int alt, PredictionContext context, SemanticContext semanticContext)
createback to summary
public static ATNConfig create(ATNState state, int alt, PredictionContext context, SemanticContext semanticContext, LexerActionExecutor lexerActionExecutor)
equalsback to summary
public boolean equals(Object o)

Overrides java.lang.Object.equals.

An ATN configuration is equal to another if both have the same state, they predict the same alternative, and syntactic/semantic contexts are the same.

Parameters
o:Object

Doc from java.lang.Object.equals.

the reference object with which to compare.

Returns:boolean

Doc from java.lang.Object.equals.

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
equalsback to summary
public boolean equals(ATNConfig other)
getAltback to summary
public final int getAlt()

What alt (or lexer rule) is predicted by this configuration

getContextback to summary
public final PredictionContext getContext()
Annotations
@NotNull
getLexerActionExecutorback to summary
public LexerActionExecutor getLexerActionExecutor()
Annotations
@Nullable
getOuterContextDepthback to summary
public final int getOuterContextDepth()

We cannot execute predicates dependent upon local context unless we know for sure we are in the correct context. Because there is no way to do this efficiently, we simply cannot evaluate dependent predicates unless we are in the rule that initially invokes the ATN simulator.

closure() tracks the depth of how far we dip into the outer context: depth > 0. Note that it may not be totally accurate depth since I don't ever decrement. TODO: make it a boolean then

getReachesIntoOuterContextback to summary
public final boolean getReachesIntoOuterContext()
getSemanticContextback to summary
public SemanticContext getSemanticContext()
Annotations
@NotNull
getStateback to summary
public final ATNState getState()

Gets the ATN state associated with this configuration

Annotations
@NotNull
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object.

Annotations
@Override
hasPassedThroughNonGreedyDecisionback to summary
public boolean hasPassedThroughNonGreedyDecision()
isPrecedenceFilterSuppressedback to summary
public final boolean isPrecedenceFilterSuppressed()
setContextback to summary
public void setContext(PredictionContext context)
setOuterContextDepthback to summary
public void setOuterContextDepth(int outerContextDepth)
setPrecedenceFilterSuppressedback to summary
public final void setPrecedenceFilterSuppressed(boolean value)
toDotStringback to summary
public String toDotString()

Returns a graphical representation of the current ATNConfig in Graphviz format. The graph can be stored to a .dot file and then rendered to an image using Graphviz.

Returns:String

A Graphviz graph representing the current ATNConfig.

See Also
http://www.graphviz.org/
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override
toStringback to summary
public String toString(Recognizer<?, ?> recog, boolean showAlt)
toStringback to summary
public String toString(Recognizer<?, ?> recog, boolean showAlt, boolean showContext)
transformback to summary
public final ATNConfig transform(ATNState state, boolean checkNonGreedy)
transformback to summary
public final ATNConfig transform(ATNState state, SemanticContext semanticContext, boolean checkNonGreedy)
transformback to summary
public final ATNConfig transform(ATNState state, PredictionContext context, boolean checkNonGreedy)
transformback to summary
public final ATNConfig transform(ATNState state, LexerActionExecutor lexerActionExecutor, boolean checkNonGreedy)
transformback to summary
private ATNConfig transform(ATNState state, PredictionContext context, SemanticContext semanticContext, boolean checkNonGreedy, LexerActionExecutor lexerActionExecutor)
org.antlr.v4.runtime.atn back to summary

private Class ATNConfig.ActionATNConfig

extends ATNConfig
Class Inheritance

This class was derived from ATNConfig purely as a memory optimization. It allows for the creation of an ATNConfig with a lexer action.

See the ATNConfig documentation for more information about conserving memory through the use of several concrete types.

Field Summary

Modifier and TypeField and Description
private final LexerActionExecutor
private final boolean

Constructor Summary

AccessConstructor and Description
public
ActionATNConfig(LexerActionExecutor lexerActionExecutor, ATNState state, int alt, PredictionContext context, boolean passedThroughNonGreedyDecision)

protected
ActionATNConfig(LexerActionExecutor lexerActionExecutor, ATNConfig c, ATNState state, PredictionContext context, boolean passedThroughNonGreedyDecision)

Method Summary

Modifier and TypeMethod and Description
public LexerActionExecutor
public boolean
Inherited from org.antlr.v4.runtime.atn.ATNConfig:
appendContextappendContextclonecontainscreatecreatecreateequalsequalsgetAltgetContextgetOuterContextDepthgetReachesIntoOuterContextgetSemanticContextgetStatehashCodeisPrecedenceFilterSuppressedsetContextsetOuterContextDepthsetPrecedenceFilterSuppressedtoDotStringtoStringtoStringtoStringtransformtransformtransformtransform

Field Detail

lexerActionExecutorback to summary
private final LexerActionExecutor lexerActionExecutor
passedThroughNonGreedyDecisionback to summary
private final boolean passedThroughNonGreedyDecision

Constructor Detail

ActionATNConfigback to summary
public ActionATNConfig(LexerActionExecutor lexerActionExecutor, ATNState state, int alt, PredictionContext context, boolean passedThroughNonGreedyDecision)
ActionATNConfigback to summary
protected ActionATNConfig(LexerActionExecutor lexerActionExecutor, ATNConfig c, ATNState state, PredictionContext context, boolean passedThroughNonGreedyDecision)

Method Detail

getLexerActionExecutorback to summary
public LexerActionExecutor getLexerActionExecutor()

Overrides org.antlr.v4.runtime.atn.ATNConfig.getLexerActionExecutor.

Annotations
@Override
hasPassedThroughNonGreedyDecisionback to summary
public boolean hasPassedThroughNonGreedyDecision()

Overrides org.antlr.v4.runtime.atn.ATNConfig.hasPassedThroughNonGreedyDecision.

Annotations
@Override
org.antlr.v4.runtime.atn back to summary

private Class ATNConfig.ActionSemanticContextATNConfig

extends SemanticContextATNConfig
Class Inheritance

This class was derived from SemanticContextATNConfig purely as a memory optimization. It allows for the creation of an ATNConfig with both a lexer action and a non-default semantic context.

See the ATNConfig documentation for more information about conserving memory through the use of several concrete types.

Field Summary

Modifier and TypeField and Description
private final LexerActionExecutor
private final boolean

Constructor Summary

AccessConstructor and Description
public
ActionSemanticContextATNConfig(LexerActionExecutor lexerActionExecutor, SemanticContext semanticContext, ATNState state, int alt, PredictionContext context, boolean passedThroughNonGreedyDecision)

public
ActionSemanticContextATNConfig(LexerActionExecutor lexerActionExecutor, SemanticContext semanticContext, ATNConfig c, ATNState state, PredictionContext context, boolean passedThroughNonGreedyDecision)

Method Summary

Modifier and TypeMethod and Description
public LexerActionExecutor
public boolean
Inherited from org.antlr.v4.runtime.atn.ATNConfig.SemanticContextATNConfig:
getSemanticContext

Field Detail

lexerActionExecutorback to summary
private final LexerActionExecutor lexerActionExecutor
passedThroughNonGreedyDecisionback to summary
private final boolean passedThroughNonGreedyDecision

Constructor Detail

ActionSemanticContextATNConfigback to summary
public ActionSemanticContextATNConfig(LexerActionExecutor lexerActionExecutor, SemanticContext semanticContext, ATNState state, int alt, PredictionContext context, boolean passedThroughNonGreedyDecision)
ActionSemanticContextATNConfigback to summary
public ActionSemanticContextATNConfig(LexerActionExecutor lexerActionExecutor, SemanticContext semanticContext, ATNConfig c, ATNState state, PredictionContext context, boolean passedThroughNonGreedyDecision)

Method Detail

getLexerActionExecutorback to summary
public LexerActionExecutor getLexerActionExecutor()

Overrides org.antlr.v4.runtime.atn.ATNConfig.getLexerActionExecutor.

Annotations
@Override
hasPassedThroughNonGreedyDecisionback to summary
public boolean hasPassedThroughNonGreedyDecision()

Overrides org.antlr.v4.runtime.atn.ATNConfig.hasPassedThroughNonGreedyDecision.

Annotations
@Override
org.antlr.v4.runtime.atn back to summary

private Class ATNConfig.SemanticContextATNConfig

extends ATNConfig
Class Inheritance
Known Direct Subclasses
org.antlr.v4.runtime.atn.ATNConfig.ActionSemanticContextATNConfig

This class was derived from ATNConfig purely as a memory optimization. It allows for the creation of an ATNConfig with a non-default semantic context.

See the ATNConfig documentation for more information about conserving memory through the use of several concrete types.

Field Summary

Modifier and TypeField and Description
private final SemanticContext

Constructor Summary

AccessConstructor and Description
public
SemanticContextATNConfig(SemanticContext semanticContext, ATNState state, int alt, PredictionContext context)

public

Method Summary

Modifier and TypeMethod and Description
public SemanticContext
Inherited from org.antlr.v4.runtime.atn.ATNConfig:
appendContextappendContextclonecontainscreatecreatecreateequalsequalsgetAltgetContextgetLexerActionExecutorgetOuterContextDepthgetReachesIntoOuterContextgetStatehashCodehasPassedThroughNonGreedyDecisionisPrecedenceFilterSuppressedsetContextsetOuterContextDepthsetPrecedenceFilterSuppressedtoDotStringtoStringtoStringtoStringtransformtransformtransformtransform

Field Detail

semanticContextback to summary
private final SemanticContext semanticContext
Annotations
@NotNull

Constructor Detail

SemanticContextATNConfigback to summary
public SemanticContextATNConfig(SemanticContext semanticContext, ATNState state, int alt, PredictionContext context)
SemanticContextATNConfigback to summary
public SemanticContextATNConfig(SemanticContext semanticContext, ATNConfig c, ATNState state, PredictionContext context)

Method Detail

getSemanticContextback to summary
public SemanticContext getSemanticContext()

Overrides org.antlr.v4.runtime.atn.ATNConfig.getSemanticContext.

Annotations
@Override