public abstract class PredictionContext extends Object
Modifier and Type | Field and Description |
---|---|
int |
cachedHashCode
Stores the computed hash code of this
PredictionContext . |
static EmptyPredictionContext |
EMPTY
Represents
$ in local context prediction, which means wildcard. |
static int |
EMPTY_RETURN_STATE
Represents
$ in an array in full context mode, when $
doesn't mean wildcard: $ + x = [$,x] . |
static int |
globalNodeCount |
int |
id |
Modifier | Constructor and Description |
---|---|
protected |
PredictionContext(int cachedHashCode) |
public static final EmptyPredictionContext EMPTY
$
in local context prediction, which means wildcard.
*+x = *
.public static final int EMPTY_RETURN_STATE
$
in an array in full context mode, when $
doesn't mean wildcard: $ + x = [$,x]
. Here,
$
= EMPTY_RETURN_STATE
.public static int globalNodeCount
public final int id
public final int cachedHashCode
PredictionContext
. The hash
code is computed in parts to match the following reference algorithm.
private int referenceHashCode() { int hash =MurmurHash.initialize()
(INITIAL_HASH
); for (int i = 0; i <size()
; i++) { hash =MurmurHash.update(int, int)
(hash,getParent(int)
(i)); } for (int i = 0; i <size()
; i++) { hash =MurmurHash.update(int, int)
(hash,getReturnState(int)
(i)); } hash =MurmurHash.finish(int, int)
(hash, 2 *size()
); return hash; }
public static PredictionContext fromRuleContext(@NotNull ATN atn, RuleContext outerContext)
RuleContext
tree to a PredictionContext
graph.
Return EMPTY
if outerContext
is empty or null.public abstract int size()
public abstract PredictionContext getParent(int index)
public abstract int getReturnState(int index)
public boolean isEmpty()
EMPTY
context is in set.public boolean hasEmptyPath()
protected static int calculateEmptyHashCode()
protected static int calculateHashCode(PredictionContext parent, int returnState)
protected static int calculateHashCode(PredictionContext[] parents, int[] returnStates)
public static PredictionContext merge(PredictionContext a, PredictionContext b, boolean rootIsWildcard, DoubleKeyMap<PredictionContext,PredictionContext,PredictionContext> mergeCache)
public static PredictionContext mergeSingletons(SingletonPredictionContext a, SingletonPredictionContext b, boolean rootIsWildcard, DoubleKeyMap<PredictionContext,PredictionContext,PredictionContext> mergeCache)
SingletonPredictionContext
instances.
Stack tops equal, parents merge is same; return left graph.a
- the first SingletonPredictionContext
b
- the second SingletonPredictionContext
rootIsWildcard
- true
if this is a local-context merge,
otherwise false to indicate a full-context mergemergeCache
- public static PredictionContext mergeRoot(SingletonPredictionContext a, SingletonPredictionContext b, boolean rootIsWildcard)
a
or b
is
EMPTY
. In the following diagrams, the symbol $
is used
to represent EMPTY
.
rootIsWildcard
is true.
EMPTY
is superset of any graph; return EMPTY
.EMPTY
and anything is #EMPTY
, so merged parent is
#EMPTY
; return left graph.rootIsWildcard
is false.
Must keep all contexts; EMPTY
in array is a special value (and
null parent).a
- the first SingletonPredictionContext
b
- the second SingletonPredictionContext
rootIsWildcard
- true
if this is a local-context merge,
otherwise false to indicate a full-context mergepublic static PredictionContext mergeArrays(ArrayPredictionContext a, ArrayPredictionContext b, boolean rootIsWildcard, DoubleKeyMap<PredictionContext,PredictionContext,PredictionContext> mergeCache)
ArrayPredictionContext
instances.
Different tops, different parents.SingletonPredictionContext
.protected static void combineCommonParents(PredictionContext[] parents)
parents
; merge any equals()
ones.public static String toDOTString(PredictionContext context)
public static PredictionContext getCachedContext(@NotNull PredictionContext context, @NotNull PredictionContextCache contextCache, @NotNull IdentityHashMap<PredictionContext,PredictionContext> visited)
public static List<PredictionContext> getAllContextNodes(PredictionContext context)
public static void getAllContextNodes_(PredictionContext context, List<PredictionContext> nodes, Map<PredictionContext,PredictionContext> visited)
public String toString(@Nullable Recognizer<?,?> recog)
public String toString(@Nullable Recognizer<?,?> recog, RuleContext stop)
public String[] toStrings(Recognizer<?,?> recognizer, int currentState)
public String[] toStrings(Recognizer<?,?> recognizer, PredictionContext stop, int currentState)
Copyright © 1992-2013 ANTLR. All Rights Reserved.