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

public Class ATNDeserializer

extends Object
Class Inheritance
Imports
org.antlr.v4.runtime.Token, org.antlr.v4.runtime.misc.IntegerList, .IntervalSet, .Pair, java.io.InvalidClassException, java.util.ArrayList, .Arrays, .List, .Locale

Deserialize ATNs for JavaTarget; it's complicated by the fact that java requires that we serialize the list of integers as 16 bit characters in a string. Other targets will have an array of ints generated and can simply decode the ints back into an ATN.
Author
Sam Harwell

Field Summary

Modifier and TypeField and Description
private final ATNDeserializationOptions
public static final int

Constructor Summary

AccessConstructor and Description
public
public

Method Summary

Modifier and TypeMethod and Description
protected void
checkCondition(boolean condition)

protected void
checkCondition(boolean condition, String message)

public static int[]
public static int[]
decodeIntsEncodedAs16BitWords(char[] data16, boolean trimToSize)

Convert a list of chars (16 uint) that represent a serialized and compressed list of ints for an ATN.

public ATN
deserialize(char[] data)

public ATN
deserialize(int[] data)

private int
deserializeSets(int[] data, int p, List<IntervalSet> sets)

protected Transition
edgeFactory(ATN atn, int type, int src, int trg, int arg1, int arg2, int arg3, List<IntervalSet> sets)

public static IntegerList
encodeIntsWith16BitWords(IntegerList data)

Given a list of integers representing a serialized ATN, encode values too large to fit into 15 bits as two 16bit values.

protected LexerAction
lexerActionFactory(LexerActionType type, int data1, int data2)

protected void
markPrecedenceDecisions(ATN
The ATN.
atn
)

Analyze the StarLoopEntryState states in the specified ATN to set the StarLoopEntryState#isPrecedenceDecision field to the correct value.

protected ATNState
stateFactory(int type, int ruleIndex)

protected static int
toInt(char c)

protected static int
toInt32(char[] data, int offset)

protected static int
toInt32(int[] data, int offset)

protected void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

deserializationOptionsback to summary
private final ATNDeserializationOptions deserializationOptions
SERIALIZED_VERSIONback to summary
public static final int SERIALIZED_VERSION

Constructor Detail

ATNDeserializerback to summary
public ATNDeserializer()
ATNDeserializerback to summary
public ATNDeserializer(ATNDeserializationOptions deserializationOptions)

Method Detail

checkConditionback to summary
protected void checkCondition(boolean condition)
checkConditionback to summary
protected void checkCondition(boolean condition, String message)
decodeIntsEncodedAs16BitWordsback to summary
public static int[] decodeIntsEncodedAs16BitWords(char[] data16)
decodeIntsEncodedAs16BitWordsback to summary
public static int[] decodeIntsEncodedAs16BitWords(char[] data16, boolean trimToSize)

Convert a list of chars (16 uint) that represent a serialized and compressed list of ints for an ATN. This method pairs with encodeIntsWith16BitWords(IntegerList) above. Used only for Java Target.

deserializeback to summary
public ATN deserialize(char[] data)
deserializeback to summary
public ATN deserialize(int[] data)
deserializeSetsback to summary
private int deserializeSets(int[] data, int p, List<IntervalSet> sets)
edgeFactoryback to summary
protected Transition edgeFactory(ATN atn, int type, int src, int trg, int arg1, int arg2, int arg3, List<IntervalSet> sets)
encodeIntsWith16BitWordsback to summary
public static IntegerList encodeIntsWith16BitWords(IntegerList data)

Given a list of integers representing a serialized ATN, encode values too large to fit into 15 bits as two 16bit values. We use the high bit (0x8000_0000) to indicate values requiring two 16 bit words. If the high bit is set, we grab the next value and combine them to get a 31-bit value. The possible input int values are [-1,0x7FFF_FFFF]. | compression/encoding | uint16 count | type | | -------------------------------------------- | ------------ | --------------- | | 0xxxxxxx xxxxxxxx | 1 | uint (15 bit) | | 1xxxxxxx xxxxxxxx yyyyyyyy yyyyyyyy | 2 | uint (16+ bits) | | 11111111 11111111 11111111 11111111 | 2 | int value -1 | This is only used (other than for testing) by org.antlr.v4.codegen.model.SerializedJavaATN to encode ints as char values for the java target, but it is convenient to combine it with the #decodeIntsEncodedAs16BitWords that follows as they are a pair (I did not want to introduce a new class into the runtime). Used only for Java Target.

lexerActionFactoryback to summary
protected LexerAction lexerActionFactory(LexerActionType type, int data1, int data2)
markPrecedenceDecisionsback to summary
protected void markPrecedenceDecisions(ATN atn)

Analyze the StarLoopEntryState states in the specified ATN to set the StarLoopEntryState#isPrecedenceDecision field to the correct value.

Parameters
atn:ATN

The ATN.

stateFactoryback to summary
protected ATNState stateFactory(int type, int ruleIndex)
toIntback to summary
protected static int toInt(char c)
toInt32back to summary
protected static int toInt32(char[] data, int offset)
toInt32back to summary
protected static int toInt32(int[] data, int offset)
verifyATNback to summary
protected void verifyATN(ATN atn)