Class ATNDeserializer

java.lang.Object
org.graalvm.shadowed.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.
  • Field Details

    • SERIALIZED_VERSION

      public static final int SERIALIZED_VERSION
  • Constructor Details

    • ATNDeserializer

      public ATNDeserializer()
    • ATNDeserializer

      public ATNDeserializer(ATNDeserializationOptions deserializationOptions)
  • Method Details

    • deserialize

      public ATN deserialize(char[] data)
    • deserialize

      public ATN deserialize(int[] data)
    • markPrecedenceDecisions

      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 - 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) by
      invalid reference
      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.
    • 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 with encodeIntsWith16BitWords(IntegerList) above. Used only for Java Target.