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

public Class ATNConfig

extends Object
Class Inheritance
Known Direct Subclasses
org.antlr.v4.runtime.atn.LexerATNConfig
Imports
org.antlr.v4.runtime.Recognizer, org.antlr.v4.runtime.misc.DoubleKeyMap, .MurmurHash, java.util.Objects

A tuple: (ATN state, predicted alt, syntactic, semantic context). The syntactic context is a graph-structured stack node whose path(s) to the root is the rule invocation(s) chain used to arrive at the state. The semantic context is the tree of semantic predicates encountered before reaching an ATN state.

Field Summary

Modifier and TypeField and Description
public final int
alt

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

public PredictionContext
context

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

public int
reachesIntoOuterContext

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

public final SemanticContext
public 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 reachesIntoOuterContext field.

Constructor Summary

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

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

public
public
ATNConfig(ATNConfig c, ATNState state, SemanticContext semanticContext)

public
ATNConfig(ATNConfig c, SemanticContext semanticContext)

public
public
ATNConfig(ATNConfig c, ATNState state, PredictionContext context, SemanticContext semanticContext)

Method Summary

Modifier and TypeMethod and Description
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
getOuterContextDepth()

This method gets the value of the reachesIntoOuterContext field as it existed prior to the introduction of the isPrecedenceFilterSuppressed method.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.
public final boolean
public final void
public String
toString()

Overrides java.lang.Object.toString.

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

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

altback to summary
public final int alt

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

contextback to summary
public 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.

reachesIntoOuterContextback to summary
public int reachesIntoOuterContext

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

For memory efficiency, the isPrecedenceFilterSuppressed method is also backed by this field. Since the field is publicly accessible, the highest bit which would not cause the value to become negative is used to store this field. This choice minimizes the risk that code which only compares this value to 0 would be affected by the new purpose of the flag. It also ensures the performance of the existing ATNConfig constructors as well as certain operations like ATNConfigSet#add(ATNConfig, DoubleKeyMap) method are completely unaffected by the change.

semanticContextback to summary
public final SemanticContext semanticContext
stateback to summary
public final ATNState state

The ATN state associated with this configuration

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 reachesIntoOuterContext field.

Constructor Detail

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

Method Detail

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)
getOuterContextDepthback to summary
public final int getOuterContextDepth()

This method gets the value of the reachesIntoOuterContext field as it existed prior to the introduction of the isPrecedenceFilterSuppressed method.

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this 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
isPrecedenceFilterSuppressedback to summary
public final boolean isPrecedenceFilterSuppressed()
setPrecedenceFilterSuppressedback to summary
public final void setPrecedenceFilterSuppressed(boolean value)
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)