Package org.antlr.v4.runtime.atn
Class ATNDeserializer
- java.lang.Object
-
- org.antlr.v4.runtime.atn.ATNDeserializer
-
public class ATNDeserializer extends Object
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
Fields Modifier and Type Field Description static int
SERIALIZED_VERSION
-
Constructor Summary
Constructors Constructor Description ATNDeserializer()
ATNDeserializer(ATNDeserializationOptions deserializationOptions)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
checkCondition(boolean condition)
protected void
checkCondition(boolean condition, String message)
static int[]
decodeIntsEncodedAs16BitWords(char[] data16)
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.ATN
deserialize(char[] data)
ATN
deserialize(int[] data)
protected Transition
edgeFactory(ATN atn, int type, int src, int trg, int arg1, int arg2, int arg3, List<IntervalSet> sets)
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 atn)
Analyze theStarLoopEntryState
states in the specified ATN to set theStarLoopEntryState.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
verifyATN(ATN atn)
-
-
-
Constructor Detail
-
ATNDeserializer
public ATNDeserializer()
-
ATNDeserializer
public ATNDeserializer(ATNDeserializationOptions deserializationOptions)
-
-
Method Detail
-
deserialize
public ATN deserialize(char[] data)
-
deserialize
public ATN deserialize(int[] data)
-
markPrecedenceDecisions
protected void markPrecedenceDecisions(ATN atn)
Analyze theStarLoopEntryState
states in the specified ATN to set theStarLoopEntryState.isPrecedenceDecision
field to the correct value.- Parameters:
atn
- The ATN.
-
verifyATN
protected void verifyATN(ATN atn)
-
checkCondition
protected void checkCondition(boolean condition)
-
checkCondition
protected void checkCondition(boolean condition, String message)
-
toInt
protected static int toInt(char c)
-
toInt32
protected static int toInt32(char[] data, int offset)
-
toInt32
protected static int toInt32(int[] data, int offset)
-
edgeFactory
protected Transition edgeFactory(ATN atn, int type, int src, int trg, int arg1, int arg2, int arg3, List<IntervalSet> sets)
-
stateFactory
protected ATNState stateFactory(int type, int ruleIndex)
-
lexerActionFactory
protected LexerAction lexerActionFactory(LexerActionType type, int data1, int data2)
-
encodeIntsWith16BitWords
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) bySerializedJavaATN
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.
-
decodeIntsEncodedAs16BitWords
public static int[] decodeIntsEncodedAs16BitWords(char[] data16)
-
decodeIntsEncodedAs16BitWords
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 withencodeIntsWith16BitWords(IntegerList)
above. Used only for Java Target.
-
-