expressir 1.2.4 → 1.2.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (312) hide show
  1. checksums.yaml +4 -4
  2. data/.cross_rubies +0 -6
  3. data/.github/workflows/rake.yml +200 -21
  4. data/.gitignore +7 -2
  5. data/.gitmodules +3 -0
  6. data/.rubocop.yml +13 -4
  7. data/README.adoc +8 -0
  8. data/Rakefile +4 -1
  9. data/bin/console +0 -1
  10. data/bin/rspec +3 -3
  11. data/exe/expressir +4 -2
  12. data/exe/format +1 -1
  13. data/exe/format-test +25 -25
  14. data/exe/generate-parser +16 -13
  15. data/expressir.gemspec +12 -10
  16. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/CMakeLists.txt +44 -34
  17. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/antlr4cpp-vs2013.vcxproj +11 -5
  18. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/antlr4cpp-vs2013.vcxproj.filters +0 -3
  19. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/antlr4cpp-vs2015.vcxproj +11 -4
  20. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/antlr4cpp-vs2015.vcxproj.filters +0 -3
  21. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/antlr4cpp-vs2017.vcxproj +11 -4
  22. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/antlr4cpp-vs2017.vcxproj.filters +0 -3
  23. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/antlr4cpp-vs2019.vcxproj +11 -4
  24. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/antlr4cpp-vs2019.vcxproj.filters +0 -3
  25. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/antlrcpp.xcodeproj/project.pbxproj +20 -20
  26. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/ANTLRFileStream.cpp +0 -6
  27. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/ANTLRInputStream.cpp +30 -19
  28. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/ANTLRInputStream.h +13 -10
  29. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/CommonToken.cpp +2 -4
  30. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/DefaultErrorStrategy.cpp +16 -13
  31. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/Exceptions.cpp +2 -2
  32. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/Exceptions.h +2 -2
  33. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/FailedPredicateException.cpp +5 -4
  34. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/FailedPredicateException.h +1 -1
  35. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/IntStream.h +0 -6
  36. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/Lexer.cpp +0 -1
  37. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/Lexer.h +0 -13
  38. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/LexerInterpreter.cpp +0 -15
  39. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/LexerInterpreter.h +1 -7
  40. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/Parser.cpp +47 -27
  41. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/Parser.h +0 -6
  42. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/ParserInterpreter.cpp +27 -39
  43. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/ParserInterpreter.h +1 -7
  44. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/ParserRuleContext.cpp +19 -22
  45. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/ParserRuleContext.h +20 -20
  46. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/RecognitionException.cpp +0 -1
  47. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/Recognizer.cpp +16 -27
  48. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/Recognizer.h +10 -21
  49. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/RuleContext.cpp +4 -3
  50. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/RuleContext.h +5 -1
  51. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/RuntimeMetaData.cpp +2 -1
  52. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/Token.h +0 -32
  53. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/TokenStreamRewriter.cpp +1 -1
  54. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/TokenStreamRewriter.h +2 -7
  55. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/UnbufferedCharStream.cpp +15 -18
  56. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/UnbufferedCharStream.h +12 -18
  57. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/Version.h +42 -0
  58. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/Vocabulary.cpp +13 -45
  59. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/Vocabulary.h +11 -26
  60. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/antlr4-common.h +19 -61
  61. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/antlr4-runtime.h +7 -5
  62. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATN.cpp +4 -55
  63. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATN.h +34 -20
  64. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNConfig.cpp +30 -35
  65. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNConfig.h +35 -32
  66. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNConfigSet.cpp +58 -54
  67. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNConfigSet.h +77 -31
  68. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNDeserializationOptions.cpp +22 -32
  69. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNDeserializationOptions.h +22 -24
  70. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNDeserializer.cpp +335 -462
  71. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNDeserializer.h +9 -68
  72. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNSimulator.cpp +9 -39
  73. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNSimulator.h +6 -22
  74. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNState.cpp +10 -26
  75. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNState.h +41 -42
  76. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNStateType.cpp +33 -0
  77. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNStateType.h +36 -0
  78. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ActionTransition.cpp +2 -6
  79. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ActionTransition.h +4 -2
  80. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ArrayPredictionContext.cpp +49 -22
  81. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ArrayPredictionContext.h +20 -12
  82. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/AtomTransition.cpp +1 -5
  83. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/AtomTransition.h +5 -2
  84. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/BasicBlockStartState.h +4 -2
  85. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/BasicState.h +4 -2
  86. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/BlockEndState.h +5 -3
  87. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/BlockStartState.h +10 -1
  88. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/DecisionInfo.h +1 -1
  89. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/DecisionState.cpp +0 -5
  90. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/DecisionState.h +12 -8
  91. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/EpsilonTransition.cpp +2 -6
  92. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/EpsilonTransition.h +6 -3
  93. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LL1Analyzer.cpp +139 -106
  94. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LL1Analyzer.h +9 -48
  95. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerATNConfig.cpp +16 -33
  96. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerATNConfig.h +12 -12
  97. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerATNSimulator.cpp +69 -82
  98. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerATNSimulator.h +15 -33
  99. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerAction.cpp +12 -6
  100. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerAction.h +45 -11
  101. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerActionExecutor.cpp +48 -44
  102. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerActionExecutor.h +31 -18
  103. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerActionType.h +3 -1
  104. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerChannelAction.cpp +14 -26
  105. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerChannelAction.h +12 -16
  106. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerCustomAction.cpp +15 -32
  107. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerCustomAction.h +12 -24
  108. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerIndexedCustomAction.cpp +23 -29
  109. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerIndexedCustomAction.h +13 -19
  110. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerModeAction.cpp +13 -26
  111. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerModeAction.h +12 -16
  112. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerMoreAction.cpp +6 -17
  113. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerMoreAction.h +12 -16
  114. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerPopModeAction.cpp +6 -17
  115. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerPopModeAction.h +12 -16
  116. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerPushModeAction.cpp +13 -26
  117. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerPushModeAction.h +12 -16
  118. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerSkipAction.cpp +6 -17
  119. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerSkipAction.h +11 -15
  120. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerTypeAction.cpp +13 -26
  121. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerTypeAction.h +13 -17
  122. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LoopEndState.h +5 -1
  123. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/NotSetTransition.cpp +1 -6
  124. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/NotSetTransition.h +4 -2
  125. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/OrderedATNConfigSet.cpp +6 -2
  126. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/OrderedATNConfigSet.h +8 -3
  127. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ParserATNSimulator.cpp +164 -151
  128. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ParserATNSimulator.h +26 -19
  129. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ParserATNSimulatorOptions.h +50 -0
  130. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PlusBlockStartState.h +5 -1
  131. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PlusLoopbackState.h +5 -2
  132. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PrecedencePredicateTransition.cpp +2 -11
  133. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PrecedencePredicateTransition.h +15 -9
  134. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredicateEvalInfo.cpp +2 -2
  135. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredicateEvalInfo.h +2 -2
  136. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredicateTransition.cpp +4 -14
  137. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredicateTransition.h +22 -11
  138. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredictionContext.cpp +255 -338
  139. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredictionContext.h +86 -127
  140. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredictionContextCache.cpp +56 -0
  141. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredictionContextCache.h +64 -0
  142. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredictionContextMergeCache.cpp +167 -0
  143. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredictionContextMergeCache.h +101 -0
  144. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredictionContextMergeCacheOptions.h +71 -0
  145. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredictionContextType.h +21 -0
  146. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredictionMode.cpp +18 -17
  147. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredictionMode.h +1 -1
  148. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ProfilingATNSimulator.cpp +2 -2
  149. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ProfilingATNSimulator.h +2 -2
  150. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/RangeTransition.cpp +1 -5
  151. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/RangeTransition.h +4 -2
  152. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/RuleStartState.h +4 -3
  153. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/RuleStopState.h +4 -2
  154. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/RuleTransition.cpp +1 -5
  155. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/RuleTransition.h +5 -3
  156. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/SemanticContext.cpp +197 -156
  157. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/SemanticContext.h +92 -81
  158. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/SemanticContextType.h +23 -0
  159. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/SerializedATNView.h +101 -0
  160. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/SetTransition.cpp +2 -6
  161. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/SetTransition.h +11 -3
  162. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/SingletonPredictionContext.cpp +39 -34
  163. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/SingletonPredictionContext.h +17 -10
  164. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/StarBlockStartState.h +5 -2
  165. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/StarLoopEntryState.h +4 -2
  166. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/StarLoopbackState.cpp +6 -6
  167. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/StarLoopbackState.h +6 -2
  168. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/TokensStartState.h +5 -2
  169. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/Transition.cpp +1 -9
  170. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/Transition.h +11 -22
  171. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/TransitionType.cpp +27 -0
  172. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/TransitionType.h +33 -0
  173. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/WildcardTransition.cpp +1 -5
  174. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/WildcardTransition.h +4 -2
  175. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/dfa/DFA.cpp +9 -21
  176. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/dfa/DFA.h +20 -15
  177. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/dfa/DFASerializer.cpp +1 -8
  178. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/dfa/DFASerializer.h +4 -4
  179. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/dfa/DFAState.cpp +9 -50
  180. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/dfa/DFAState.h +57 -48
  181. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/dfa/LexerDFASerializer.cpp +1 -4
  182. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/dfa/LexerDFASerializer.h +3 -4
  183. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/InterpreterDataReader.cpp +2 -2
  184. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/InterpreterDataReader.h +3 -1
  185. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/Interval.cpp +1 -29
  186. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/Interval.h +10 -10
  187. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/IntervalSet.cpp +7 -20
  188. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/IntervalSet.h +1 -9
  189. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/MurmurHash.cpp +54 -68
  190. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/MurmurHash.h +34 -14
  191. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/Any.cpp +0 -5
  192. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/Any.h +1 -155
  193. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/Arrays.h +39 -0
  194. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/BitSet.h +1 -1
  195. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/CPPUtils.cpp +12 -53
  196. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/CPPUtils.h +16 -29
  197. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/Casts.h +34 -0
  198. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/Declarations.h +0 -2
  199. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/StringUtils.cpp +25 -33
  200. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/StringUtils.h +2 -62
  201. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/Unicode.h +28 -0
  202. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/Utf8.cpp +242 -0
  203. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/Utf8.h +54 -0
  204. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/AbstractParseTreeVisitor.h +13 -12
  205. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ErrorNode.h +7 -2
  206. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ErrorNodeImpl.cpp +36 -5
  207. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ErrorNodeImpl.h +14 -4
  208. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/IterativeParseTreeWalker.cpp +14 -19
  209. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ParseTree.cpp +0 -3
  210. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ParseTree.h +13 -4
  211. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ParseTreeType.h +22 -0
  212. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ParseTreeVisitor.h +4 -4
  213. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ParseTreeWalker.cpp +8 -9
  214. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ParseTreeWalker.h +4 -4
  215. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/TerminalNode.h +10 -2
  216. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/TerminalNodeImpl.cpp +2 -5
  217. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/TerminalNodeImpl.h +4 -5
  218. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/pattern/ParseTreePatternMatcher.cpp +1 -2
  219. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathLexer.cpp +128 -119
  220. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathLexer.h +18 -27
  221. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/tests/Utf8Test.cpp +110 -0
  222. data/ext/express-parser/antlrgen/Express.interp +1 -1
  223. data/ext/express-parser/antlrgen/ExpressBaseListener.cpp +1 -1
  224. data/ext/express-parser/antlrgen/ExpressBaseListener.h +1 -1
  225. data/ext/express-parser/antlrgen/ExpressBaseVisitor.cpp +1 -1
  226. data/ext/express-parser/antlrgen/ExpressBaseVisitor.h +200 -200
  227. data/ext/express-parser/antlrgen/ExpressLexer.cpp +645 -1129
  228. data/ext/express-parser/antlrgen/ExpressLexer.h +20 -27
  229. data/ext/express-parser/antlrgen/ExpressLexer.interp +1 -1
  230. data/ext/express-parser/antlrgen/ExpressListener.cpp +1 -1
  231. data/ext/express-parser/antlrgen/ExpressListener.h +1 -1
  232. data/ext/express-parser/antlrgen/ExpressParser.cpp +1754 -1447
  233. data/ext/express-parser/antlrgen/ExpressParser.h +219 -223
  234. data/ext/express-parser/antlrgen/ExpressVisitor.cpp +1 -1
  235. data/ext/express-parser/antlrgen/ExpressVisitor.h +200 -200
  236. data/ext/express-parser/express_parser.cpp +294 -86
  237. data/ext/express-parser/extconf.rb +13 -12
  238. data/lib/expressir/config.rb +1 -1
  239. data/lib/expressir/express/parser.rb +3 -4
  240. data/lib/expressir/express/visitor.rb +7 -5
  241. data/lib/expressir/model.rb +78 -78
  242. data/lib/expressir/version.rb +1 -1
  243. data/rakelib/antlr4-native.rake +161 -0
  244. data/rakelib/cross-ruby.rake +213 -162
  245. data/spec/acceptance/version_spec.rb +17 -2
  246. data/spec/expressir/express/cache_spec.rb +23 -5
  247. data/spec/expressir/express/formatter_spec.rb +54 -8
  248. data/spec/expressir/express/parser_spec.rb +47 -11
  249. data/spec/expressir/model/model_element_spec.rb +198 -146
  250. data/spec/spec_helper.rb +7 -0
  251. metadata +81 -93
  252. data/demo.rb +0 -18
  253. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNSerializer.cpp +0 -621
  254. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNSerializer.h +0 -61
  255. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/AbstractPredicateTransition.cpp +0 -14
  256. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/AbstractPredicateTransition.h +0 -24
  257. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/BasicBlockStartState.cpp +0 -12
  258. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/BasicState.cpp +0 -12
  259. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/BlockEndState.cpp +0 -15
  260. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/BlockStartState.cpp +0 -9
  261. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/EmptyPredictionContext.cpp +0 -35
  262. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/EmptyPredictionContext.h +0 -27
  263. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LoopEndState.cpp +0 -12
  264. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/Makefile +0 -67
  265. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PlusBlockStartState.cpp +0 -12
  266. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PlusLoopbackState.cpp +0 -12
  267. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/RuleStartState.cpp +0 -16
  268. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/RuleStopState.cpp +0 -12
  269. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/StarBlockStartState.cpp +0 -12
  270. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/StarLoopEntryState.cpp +0 -15
  271. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/TokensStartState.cpp +0 -12
  272. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/guid.cpp +0 -303
  273. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/guid.h +0 -112
  274. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ErrorNode.cpp +0 -9
  275. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/TerminalNode.cpp +0 -9
  276. data/original/examples/ap233/ap233e1_arm_lf_stepmod-2010-11-12.exp +0 -9589
  277. data/original/examples/ap233/ap233e1_arm_lf_stepmod-2010-11-12.owl +0 -36619
  278. data/original/examples/ap233/ap233e1_arm_lf_stepmod-2010-11-12.xml +0 -13294
  279. data/original/examples/employment/eclipse/.project +0 -17
  280. data/original/examples/employment/eclipse/Export/Employment.png +0 -0
  281. data/original/examples/employment/eclipse/Express/employment_schema.exp +0 -33
  282. data/original/examples/employment/eclipse/Express/employment_schema.xmi +0 -77
  283. data/original/examples/employment/eclipse/Express/employment_schema.xml +0 -93
  284. data/original/examples/employment/eclipse/Models/Employment.uml +0 -4
  285. data/original/examples/employment/eclipse/Models/Employment.umldi +0 -240
  286. data/original/examples/employment/eclipse/readme.txt +0 -7
  287. data/original/examples/employment/employment_schema.exp +0 -33
  288. data/original/examples/employment/employment_schema.rb +0 -232
  289. data/original/examples/employment/employment_schema.xml +0 -93
  290. data/original/examples/employment/employment_schema___module.rb +0 -46
  291. data/original/examples/employment/employment_schema___p28attr.rb +0 -126
  292. data/original/examples/employment/employment_schema___p28inst.rb +0 -26
  293. data/original/examples/employment/example_employment_data.xml +0 -1
  294. data/original/examples/employment/example_employment_data_copy.xml +0 -1
  295. data/original/examples/employment/example_employment_reader.rb +0 -30
  296. data/original/examples/employment/example_employment_writer.rb +0 -51
  297. data/original/examples/plcs/ap239e1_arm_lf_dexlib_2010-01-06.exp +0 -3710
  298. data/original/examples/plcs/ap239e1_arm_lf_dexlib_2010-01-06.owl +0 -35880
  299. data/original/examples/plcs/ap239e1_arm_lf_dexlib_2010-01-06.xmi +0 -15357
  300. data/original/examples/plcs/ap239e1_arm_lf_dexlib_2010-01-06.xml +0 -9468
  301. data/original/examples/plcs/ap239e2_arm_lf_stepmod-2010-01-25.exp +0 -8404
  302. data/original/examples/plcs/ap239e2_arm_lf_stepmod-2010-01-25.owl +0 -43147
  303. data/original/examples/plcs/ap239e2_arm_lf_stepmod-2010-01-25.xmi +0 -18341
  304. data/original/examples/plcs/ap239e2_arm_lf_stepmod-2010-01-25.xml +0 -11632
  305. data/original/exp2ruby.rb +0 -525
  306. data/original/expsm.rb +0 -34
  307. data/original/mapping_owl.rb +0 -1018
  308. data/original/mapping_sysml.rb +0 -2281
  309. data/original/mapping_uml2.rb +0 -599
  310. data/original/mapping_uml2_eclipse.rb +0 -433
  311. data/original/reeper.rb +0 -134
  312. data/spec/expressr_spec.rb +0 -5
@@ -33,12 +33,13 @@
33
33
  #include "atn/SetTransition.h"
34
34
  #include "atn/NotSetTransition.h"
35
35
  #include "atn/WildcardTransition.h"
36
+ #include "atn/TransitionType.h"
36
37
  #include "Token.h"
37
38
 
38
39
  #include "misc/IntervalSet.h"
39
40
  #include "Exceptions.h"
40
41
  #include "support/CPPUtils.h"
41
- #include "support/StringUtils.h"
42
+ #include "support/Casts.h"
42
43
 
43
44
  #include "atn/LexerCustomAction.h"
44
45
  #include "atn/LexerChannelAction.h"
@@ -51,7 +52,10 @@
51
52
 
52
53
  #include "atn/ATNDeserializer.h"
53
54
 
55
+ #include <cassert>
56
+ #include <mutex>
54
57
  #include <string>
58
+ #include <vector>
55
59
 
56
60
  using namespace antlr4;
57
61
  using namespace antlr4::atn;
@@ -59,108 +63,199 @@ using namespace antlrcpp;
59
63
 
60
64
  namespace {
61
65
 
62
- uint32_t deserializeInt32(const std::vector<uint16_t>& data, size_t offset) {
63
- return (uint32_t)data[offset] | ((uint32_t)data[offset + 1] << 16);
64
- }
65
-
66
- ssize_t readUnicodeInt(const std::vector<uint16_t>& data, int& p) {
67
- return static_cast<ssize_t>(data[p++]);
68
- }
66
+ void checkCondition(bool condition, std::string_view message) {
67
+ if (!condition) {
68
+ throw IllegalStateException(std::string(message));
69
+ }
70
+ }
69
71
 
70
- ssize_t readUnicodeInt32(const std::vector<uint16_t>& data, int& p) {
71
- auto result = deserializeInt32(data, p);
72
- p += 2;
73
- return static_cast<ssize_t>(result);
74
- }
72
+ void checkCondition(bool condition) {
73
+ checkCondition(condition, "");
74
+ }
75
75
 
76
- // We templatize this on the function type so the optimizer can inline
77
- // the 16- or 32-bit readUnicodeInt/readUnicodeInt32 as needed.
78
- template <typename F>
79
- void deserializeSets(
80
- const std::vector<uint16_t>& data,
81
- int& p,
82
- std::vector<misc::IntervalSet>& sets,
83
- F readUnicode) {
84
- int nsets = data[p++];
85
- for (int i = 0; i < nsets; i++) {
86
- int nintervals = data[p++];
87
- misc::IntervalSet set;
88
-
89
- bool containsEof = data[p++] != 0;
90
- if (containsEof) {
91
- set.add(-1);
92
- }
76
+ /**
77
+ * Analyze the {@link StarLoopEntryState} states in the specified ATN to set
78
+ * the {@link StarLoopEntryState#isPrecedenceDecision} field to the
79
+ * correct value.
80
+ *
81
+ * @param atn The ATN.
82
+ */
83
+ void markPrecedenceDecisions(const ATN &atn) {
84
+ for (ATNState *state : atn.states) {
85
+ if (!StarLoopEntryState::is(state)) {
86
+ continue;
87
+ }
93
88
 
94
- for (int j = 0; j < nintervals; j++) {
95
- auto a = readUnicode(data, p);
96
- auto b = readUnicode(data, p);
97
- set.add(a, b);
89
+ /* We analyze the ATN to determine if this ATN decision state is the
90
+ * decision for the closure block that determines whether a
91
+ * precedence rule should continue or complete.
92
+ */
93
+ if (atn.ruleToStartState[state->ruleIndex]->isLeftRecursiveRule) {
94
+ ATNState *maybeLoopEndState = state->transitions[state->transitions.size() - 1]->target;
95
+ if (LoopEndState::is(maybeLoopEndState)) {
96
+ if (maybeLoopEndState->epsilonOnlyTransitions && RuleStopState::is(maybeLoopEndState->transitions[0]->target)) {
97
+ downCast<StarLoopEntryState*>(state)->isPrecedenceDecision = true;
98
+ }
99
+ }
100
+ }
98
101
  }
99
- sets.push_back(set);
100
102
  }
101
- }
102
103
 
103
- }
104
+ Ref<const LexerAction> lexerActionFactory(LexerActionType type, int data1, int data2) {
105
+ switch (type) {
106
+ case LexerActionType::CHANNEL:
107
+ return std::make_shared<LexerChannelAction>(data1);
104
108
 
105
- ATNDeserializer::ATNDeserializer(): ATNDeserializer(ATNDeserializationOptions::getDefaultOptions()) {
106
- }
109
+ case LexerActionType::CUSTOM:
110
+ return std::make_shared<LexerCustomAction>(data1, data2);
107
111
 
108
- ATNDeserializer::ATNDeserializer(const ATNDeserializationOptions& dso): deserializationOptions(dso) {
109
- }
112
+ case LexerActionType::MODE:
113
+ return std::make_shared< LexerModeAction>(data1);
110
114
 
111
- ATNDeserializer::~ATNDeserializer() {
112
- }
115
+ case LexerActionType::MORE:
116
+ return LexerMoreAction::getInstance();
113
117
 
114
- /**
115
- * This value should never change. Updates following this version are
116
- * reflected as change in the unique ID SERIALIZED_UUID.
117
- */
118
- Guid ATNDeserializer::ADDED_PRECEDENCE_TRANSITIONS() {
119
- return Guid("1DA0C57D-6C06-438A-9B27-10BCB3CE0F61");
120
- }
118
+ case LexerActionType::POP_MODE:
119
+ return LexerPopModeAction::getInstance();
121
120
 
122
- Guid ATNDeserializer::ADDED_LEXER_ACTIONS() {
123
- return Guid("AADB8D7E-AEEF-4415-AD2B-8204D6CF042E");
124
- }
121
+ case LexerActionType::PUSH_MODE:
122
+ return std::make_shared<LexerPushModeAction>(data1);
125
123
 
126
- Guid ATNDeserializer::ADDED_UNICODE_SMP() {
127
- return Guid("59627784-3BE5-417A-B9EB-8131A7286089");
128
- }
124
+ case LexerActionType::SKIP:
125
+ return LexerSkipAction::getInstance();
129
126
 
130
- Guid ATNDeserializer::SERIALIZED_UUID() {
131
- return ADDED_UNICODE_SMP();
132
- }
127
+ case LexerActionType::TYPE:
128
+ return std::make_shared<LexerTypeAction>(data1);
133
129
 
134
- Guid ATNDeserializer::BASE_SERIALIZED_UUID() {
135
- return Guid("33761B2D-78BB-4A43-8B0B-4F5BEE8AACF3");
136
- }
130
+ default:
131
+ throw IllegalArgumentException("The specified lexer action type " + std::to_string(static_cast<size_t>(type)) +
132
+ " is not valid.");
133
+ }
134
+ }
137
135
 
138
- std::vector<Guid>& ATNDeserializer::SUPPORTED_UUIDS() {
139
- static std::vector<Guid> singleton = { BASE_SERIALIZED_UUID(), ADDED_PRECEDENCE_TRANSITIONS(), ADDED_LEXER_ACTIONS(), ADDED_UNICODE_SMP() };
140
- return singleton;
141
- }
136
+ ConstTransitionPtr edgeFactory(const ATN &atn, TransitionType type, size_t trg, size_t arg1, size_t arg2,
137
+ size_t arg3, const std::vector<misc::IntervalSet> &sets) {
138
+ ATNState *target = atn.states[trg];
139
+ switch (type) {
140
+ case TransitionType::EPSILON:
141
+ return std::make_unique<EpsilonTransition>(target);
142
+ case TransitionType::RANGE:
143
+ if (arg3 != 0) {
144
+ return std::make_unique<RangeTransition>(target, Token::EOF, arg2);
145
+ } else {
146
+ return std::make_unique<RangeTransition>(target, arg1, arg2);
147
+ }
148
+ case TransitionType::RULE:
149
+ return std::make_unique<RuleTransition>(downCast<RuleStartState*>(atn.states[arg1]), arg2, (int)arg3, target);
150
+ case TransitionType::PREDICATE:
151
+ return std::make_unique<PredicateTransition>(target, arg1, arg2, arg3 != 0);
152
+ case TransitionType::PRECEDENCE:
153
+ return std::make_unique<PrecedencePredicateTransition>(target, (int)arg1);
154
+ case TransitionType::ATOM:
155
+ if (arg3 != 0) {
156
+ return std::make_unique<AtomTransition>(target, Token::EOF);
157
+ } else {
158
+ return std::make_unique<AtomTransition>(target, arg1);
159
+ }
160
+ case TransitionType::ACTION:
161
+ return std::make_unique<ActionTransition>(target, arg1, arg2, arg3 != 0);
162
+ case TransitionType::SET:
163
+ return std::make_unique<SetTransition>(target, sets[arg1]);
164
+ case TransitionType::NOT_SET:
165
+ return std::make_unique<NotSetTransition>(target, sets[arg1]);
166
+ case TransitionType::WILDCARD:
167
+ return std::make_unique<WildcardTransition>(target);
168
+ }
142
169
 
143
- bool ATNDeserializer::isFeatureSupported(const Guid &feature, const Guid &actualUuid) {
144
- auto featureIterator = std::find(SUPPORTED_UUIDS().begin(), SUPPORTED_UUIDS().end(), feature);
145
- if (featureIterator == SUPPORTED_UUIDS().end()) {
146
- return false;
170
+ throw IllegalArgumentException("The specified transition type is not valid.");
147
171
  }
148
- auto actualIterator = std::find(SUPPORTED_UUIDS().begin(), SUPPORTED_UUIDS().end(), actualUuid);
149
- if (actualIterator == SUPPORTED_UUIDS().end()) {
150
- return false;
172
+
173
+ /* mem check: all created instances are freed in the d-tor of the ATN. */
174
+ ATNState* stateFactory(ATNStateType type, size_t ruleIndex) {
175
+ ATNState *s;
176
+ switch (type) {
177
+ case ATNStateType::INVALID:
178
+ return nullptr;
179
+ case ATNStateType::BASIC :
180
+ s = new BasicState();
181
+ break;
182
+ case ATNStateType::RULE_START :
183
+ s = new RuleStartState();
184
+ break;
185
+ case ATNStateType::BLOCK_START :
186
+ s = new BasicBlockStartState();
187
+ break;
188
+ case ATNStateType::PLUS_BLOCK_START :
189
+ s = new PlusBlockStartState();
190
+ break;
191
+ case ATNStateType::STAR_BLOCK_START :
192
+ s = new StarBlockStartState();
193
+ break;
194
+ case ATNStateType::TOKEN_START :
195
+ s = new TokensStartState();
196
+ break;
197
+ case ATNStateType::RULE_STOP :
198
+ s = new RuleStopState();
199
+ break;
200
+ case ATNStateType::BLOCK_END :
201
+ s = new BlockEndState();
202
+ break;
203
+ case ATNStateType::STAR_LOOP_BACK :
204
+ s = new StarLoopbackState();
205
+ break;
206
+ case ATNStateType::STAR_LOOP_ENTRY :
207
+ s = new StarLoopEntryState();
208
+ break;
209
+ case ATNStateType::PLUS_LOOP_BACK :
210
+ s = new PlusLoopbackState();
211
+ break;
212
+ case ATNStateType::LOOP_END :
213
+ s = new LoopEndState();
214
+ break;
215
+ default :
216
+ std::string message = "The specified state type " + std::to_string(static_cast<size_t>(type)) + " is not valid.";
217
+ throw IllegalArgumentException(message);
218
+ }
219
+ assert(s->getStateType() == type);
220
+ s->ruleIndex = ruleIndex;
221
+ return s;
151
222
  }
152
223
 
153
- return std::distance(featureIterator, actualIterator) >= 0;
154
- }
224
+ ssize_t readUnicodeInt32(SerializedATNView data, int& p) {
225
+ return static_cast<ssize_t>(data[p++]);
226
+ }
227
+
228
+ void deserializeSets(
229
+ SerializedATNView data,
230
+ int& p,
231
+ std::vector<misc::IntervalSet>& sets) {
232
+ size_t nsets = data[p++];
233
+ sets.reserve(sets.size() + nsets);
234
+ for (size_t i = 0; i < nsets; i++) {
235
+ size_t nintervals = data[p++];
236
+ misc::IntervalSet set;
237
+
238
+ bool containsEof = data[p++] != 0;
239
+ if (containsEof) {
240
+ set.add(-1);
241
+ }
155
242
 
156
- ATN ATNDeserializer::deserialize(const std::vector<uint16_t>& input) {
157
- // Don't adjust the first value since that's the version number.
158
- std::vector<uint16_t> data(input.size());
159
- data[0] = input[0];
160
- for (size_t i = 1; i < input.size(); ++i) {
161
- data[i] = input[i] - 2;
243
+ for (size_t j = 0; j < nintervals; j++) {
244
+ auto a = readUnicodeInt32(data, p);
245
+ auto b = readUnicodeInt32(data, p);
246
+ set.add(a, b);
247
+ }
248
+ sets.push_back(set);
249
+ }
162
250
  }
163
251
 
252
+ }
253
+
254
+ ATNDeserializer::ATNDeserializer() : ATNDeserializer(ATNDeserializationOptions::getDefaultOptions()) {}
255
+
256
+ ATNDeserializer::ATNDeserializer(ATNDeserializationOptions deserializationOptions) : _deserializationOptions(std::move(deserializationOptions)) {}
257
+
258
+ std::unique_ptr<ATN> ATNDeserializer::deserialize(SerializedATNView data) const {
164
259
  int p = 0;
165
260
  int version = data[p++];
166
261
  if (version != SERIALIZED_VERSION) {
@@ -169,60 +264,48 @@ ATN ATNDeserializer::deserialize(const std::vector<uint16_t>& input) {
169
264
  throw UnsupportedOperationException(reason);
170
265
  }
171
266
 
172
- Guid uuid = toUUID(data.data(), p);
173
- p += 8;
174
- auto uuidIterator = std::find(SUPPORTED_UUIDS().begin(), SUPPORTED_UUIDS().end(), uuid);
175
- if (uuidIterator == SUPPORTED_UUIDS().end()) {
176
- std::string reason = "Could not deserialize ATN with UUID " + uuid.toString() + " (expected " +
177
- SERIALIZED_UUID().toString() + " or a legacy UUID).";
178
-
179
- throw UnsupportedOperationException(reason);
180
- }
181
-
182
- bool supportsPrecedencePredicates = isFeatureSupported(ADDED_PRECEDENCE_TRANSITIONS(), uuid);
183
- bool supportsLexerActions = isFeatureSupported(ADDED_LEXER_ACTIONS(), uuid);
184
-
185
267
  ATNType grammarType = (ATNType)data[p++];
186
268
  size_t maxTokenType = data[p++];
187
- ATN atn(grammarType, maxTokenType);
269
+ auto atn = std::make_unique<ATN>(grammarType, maxTokenType);
188
270
 
189
271
  //
190
272
  // STATES
191
273
  //
192
- std::vector<std::pair<LoopEndState*, size_t>> loopBackStateNumbers;
193
- std::vector<std::pair<BlockStartState*, size_t>> endStateNumbers;
194
- size_t nstates = data[p++];
195
- for (size_t i = 0; i < nstates; i++) {
196
- size_t stype = data[p++];
197
- // ignore bad type of states
198
- if (stype == ATNState::ATN_INVALID_TYPE) {
199
- atn.addState(nullptr);
200
- continue;
201
- }
274
+ {
275
+ std::vector<std::pair<LoopEndState*, size_t>> loopBackStateNumbers;
276
+ std::vector<std::pair<BlockStartState*, size_t>> endStateNumbers;
277
+ size_t nstates = data[p++];
278
+ atn->states.reserve(nstates);
279
+ loopBackStateNumbers.reserve(nstates); // Reserve worst case size, its short lived.
280
+ endStateNumbers.reserve(nstates); // Reserve worst case size, its short lived.
281
+ for (size_t i = 0; i < nstates; i++) {
282
+ ATNStateType stype = static_cast<ATNStateType>(data[p++]);
283
+ // ignore bad type of states
284
+ if (stype == ATNStateType::INVALID) {
285
+ atn->addState(nullptr);
286
+ continue;
287
+ }
202
288
 
203
- size_t ruleIndex = data[p++];
204
- if (ruleIndex == 0xFFFF) {
205
- ruleIndex = INVALID_INDEX;
289
+ size_t ruleIndex = data[p++];
290
+ ATNState *s = stateFactory(stype, ruleIndex);
291
+ if (stype == ATNStateType::LOOP_END) { // special case
292
+ int loopBackStateNumber = data[p++];
293
+ loopBackStateNumbers.push_back({ downCast<LoopEndState*>(s), loopBackStateNumber });
294
+ } else if (BlockStartState::is(s)) {
295
+ int endStateNumber = data[p++];
296
+ endStateNumbers.push_back({ downCast<BlockStartState*>(s), endStateNumber });
297
+ }
298
+ atn->addState(s);
206
299
  }
207
300
 
208
- ATNState *s = stateFactory(stype, ruleIndex);
209
- if (stype == ATNState::LOOP_END) { // special case
210
- int loopBackStateNumber = data[p++];
211
- loopBackStateNumbers.push_back({ (LoopEndState*)s, loopBackStateNumber });
212
- } else if (is<BlockStartState*>(s)) {
213
- int endStateNumber = data[p++];
214
- endStateNumbers.push_back({ (BlockStartState*)s, endStateNumber });
301
+ // delay the assignment of loop back and end states until we know all the state instances have been initialized
302
+ for (auto &pair : loopBackStateNumbers) {
303
+ pair.first->loopBackState = atn->states[pair.second];
215
304
  }
216
- atn.addState(s);
217
- }
218
-
219
- // delay the assignment of loop back and end states until we know all the state instances have been initialized
220
- for (auto &pair : loopBackStateNumbers) {
221
- pair.first->loopBackState = atn.states[pair.second];
222
- }
223
305
 
224
- for (auto &pair : endStateNumbers) {
225
- pair.first->endState = (BlockEndState*)atn.states[pair.second];
306
+ for (auto &pair : endStateNumbers) {
307
+ pair.first->endState = downCast<BlockEndState*>(atn->states[pair.second]);
308
+ }
226
309
  }
227
310
 
228
311
  size_t numNonGreedyStates = data[p++];
@@ -230,118 +313,102 @@ ATN ATNDeserializer::deserialize(const std::vector<uint16_t>& input) {
230
313
  size_t stateNumber = data[p++];
231
314
  // The serialized ATN must be specifying the right states, so that the
232
315
  // cast below is correct.
233
- ((DecisionState *)atn.states[stateNumber])->nonGreedy = true;
316
+ downCast<DecisionState*>(atn->states[stateNumber])->nonGreedy = true;
234
317
  }
235
318
 
236
- if (supportsPrecedencePredicates) {
237
- size_t numPrecedenceStates = data[p++];
238
- for (size_t i = 0; i < numPrecedenceStates; i++) {
239
- size_t stateNumber = data[p++];
240
- ((RuleStartState *)atn.states[stateNumber])->isLeftRecursiveRule = true;
241
- }
319
+ size_t numPrecedenceStates = data[p++];
320
+ for (size_t i = 0; i < numPrecedenceStates; i++) {
321
+ size_t stateNumber = data[p++];
322
+ downCast<RuleStartState*>(atn->states[stateNumber])->isLeftRecursiveRule = true;
242
323
  }
243
324
 
244
325
  //
245
326
  // RULES
246
327
  //
247
328
  size_t nrules = data[p++];
329
+ atn->ruleToStartState.reserve(nrules);
248
330
  for (size_t i = 0; i < nrules; i++) {
249
331
  size_t s = data[p++];
250
332
  // Also here, the serialized atn must ensure to point to the correct class type.
251
- RuleStartState *startState = (RuleStartState*)atn.states[s];
252
- atn.ruleToStartState.push_back(startState);
253
- if (atn.grammarType == ATNType::LEXER) {
333
+ RuleStartState *startState = downCast<RuleStartState*>(atn->states[s]);
334
+ atn->ruleToStartState.push_back(startState);
335
+ if (atn->grammarType == ATNType::LEXER) {
254
336
  size_t tokenType = data[p++];
255
- if (tokenType == 0xFFFF) {
256
- tokenType = Token::EOF;
257
- }
258
-
259
- atn.ruleToTokenType.push_back(tokenType);
260
-
261
- if (!isFeatureSupported(ADDED_LEXER_ACTIONS(), uuid)) {
262
- // this piece of unused metadata was serialized prior to the
263
- // addition of LexerAction
264
- //int actionIndexIgnored = data[p++];
265
- p++;
266
- }
337
+ atn->ruleToTokenType.push_back(tokenType);
267
338
  }
268
339
  }
269
340
 
270
- atn.ruleToStopState.resize(nrules);
271
- for (ATNState *state : atn.states) {
272
- if (!is<RuleStopState*>(state)) {
341
+ atn->ruleToStopState.resize(nrules);
342
+ for (ATNState *state : atn->states) {
343
+ if (!RuleStopState::is(state)) {
273
344
  continue;
274
345
  }
275
346
 
276
- RuleStopState *stopState = static_cast<RuleStopState*>(state);
277
- atn.ruleToStopState[state->ruleIndex] = stopState;
278
- atn.ruleToStartState[state->ruleIndex]->stopState = stopState;
347
+ RuleStopState *stopState = downCast<RuleStopState*>(state);
348
+ atn->ruleToStopState[state->ruleIndex] = stopState;
349
+ atn->ruleToStartState[state->ruleIndex]->stopState = stopState;
279
350
  }
280
351
 
281
352
  //
282
353
  // MODES
283
354
  //
284
355
  size_t nmodes = data[p++];
356
+ atn->modeToStartState.reserve(nmodes);
285
357
  for (size_t i = 0; i < nmodes; i++) {
286
358
  size_t s = data[p++];
287
- atn.modeToStartState.push_back(static_cast<TokensStartState*>(atn.states[s]));
359
+ atn->modeToStartState.push_back(downCast<TokensStartState*>(atn->states[s]));
288
360
  }
289
361
 
290
362
  //
291
363
  // SETS
292
364
  //
293
- std::vector<misc::IntervalSet> sets;
294
-
295
- // First, deserialize sets with 16-bit arguments <= U+FFFF.
296
- deserializeSets(data, p, sets, readUnicodeInt);
297
-
298
- // Next, if the ATN was serialized with the Unicode SMP feature,
299
- // deserialize sets with 32-bit arguments <= U+10FFFF.
300
- if (isFeatureSupported(ADDED_UNICODE_SMP(), uuid)) {
301
- deserializeSets(data, p, sets, readUnicodeInt32);
302
- }
303
-
304
- //
305
- // EDGES
306
- //
307
- int nedges = data[p++];
308
- for (int i = 0; i < nedges; i++) {
309
- size_t src = data[p];
310
- size_t trg = data[p + 1];
311
- size_t ttype = data[p + 2];
312
- size_t arg1 = data[p + 3];
313
- size_t arg2 = data[p + 4];
314
- size_t arg3 = data[p + 5];
315
- Transition *trans = edgeFactory(atn, ttype, src, trg, arg1, arg2, arg3, sets);
316
- ATNState *srcState = atn.states[src];
317
- srcState->addTransition(trans);
318
- p += 6;
365
+ {
366
+ std::vector<misc::IntervalSet> sets;
367
+
368
+ deserializeSets(data, p, sets);
369
+ sets.shrink_to_fit();
370
+
371
+ //
372
+ // EDGES
373
+ //
374
+ int nedges = data[p++];
375
+ for (int i = 0; i < nedges; i++) {
376
+ size_t src = data[p];
377
+ size_t trg = data[p + 1];
378
+ TransitionType ttype = static_cast<TransitionType>(data[p + 2]);
379
+ size_t arg1 = data[p + 3];
380
+ size_t arg2 = data[p + 4];
381
+ size_t arg3 = data[p + 5];
382
+ ConstTransitionPtr trans = edgeFactory(*atn, ttype, trg, arg1, arg2, arg3, sets);
383
+ ATNState *srcState = atn->states[src];
384
+ srcState->addTransition(std::move(trans));
385
+ p += 6;
386
+ }
319
387
  }
320
-
321
388
  // edges for rule stop states can be derived, so they aren't serialized
322
- for (ATNState *state : atn.states) {
389
+ for (ATNState *state : atn->states) {
323
390
  for (size_t i = 0; i < state->transitions.size(); i++) {
324
- Transition *t = state->transitions[i];
325
- if (!is<RuleTransition*>(t)) {
391
+ const Transition *t = state->transitions[i].get();
392
+ if (!RuleTransition::is(t)) {
326
393
  continue;
327
394
  }
328
395
 
329
- RuleTransition *ruleTransition = static_cast<RuleTransition*>(t);
396
+ const RuleTransition *ruleTransition = downCast<const RuleTransition*>(t);
330
397
  size_t outermostPrecedenceReturn = INVALID_INDEX;
331
- if (atn.ruleToStartState[ruleTransition->target->ruleIndex]->isLeftRecursiveRule) {
398
+ if (atn->ruleToStartState[ruleTransition->target->ruleIndex]->isLeftRecursiveRule) {
332
399
  if (ruleTransition->precedence == 0) {
333
400
  outermostPrecedenceReturn = ruleTransition->target->ruleIndex;
334
401
  }
335
402
  }
336
403
 
337
- EpsilonTransition *returnTransition = new EpsilonTransition(ruleTransition->followState, outermostPrecedenceReturn); /* mem check: freed in ANTState d-tor */
338
- atn.ruleToStopState[ruleTransition->target->ruleIndex]->addTransition(returnTransition);
404
+ ConstTransitionPtr returnTransition = std::make_unique<EpsilonTransition>(ruleTransition->followState, outermostPrecedenceReturn);
405
+ atn->ruleToStopState[ruleTransition->target->ruleIndex]->addTransition(std::move(returnTransition));
339
406
  }
340
407
  }
341
408
 
342
- for (ATNState *state : atn.states) {
343
- if (is<BlockStartState *>(state)) {
344
- BlockStartState *startState = static_cast<BlockStartState *>(state);
409
+ for (ATNState *state : atn->states) {
410
+ if (BlockStartState::is(state)) {
411
+ BlockStartState *startState = downCast<BlockStartState*>(state);
345
412
 
346
413
  // we need to know the end state to set its start state
347
414
  if (startState->endState == nullptr) {
@@ -353,23 +420,23 @@ ATN ATNDeserializer::deserialize(const std::vector<uint16_t>& input) {
353
420
  throw IllegalStateException();
354
421
  }
355
422
 
356
- startState->endState->startState = static_cast<BlockStartState*>(state);
423
+ startState->endState->startState = downCast<BlockStartState*>(state);
357
424
  }
358
425
 
359
- if (is<PlusLoopbackState*>(state)) {
360
- PlusLoopbackState *loopbackState = static_cast<PlusLoopbackState *>(state);
426
+ if (PlusLoopbackState::is(state)) {
427
+ PlusLoopbackState *loopbackState = downCast<PlusLoopbackState*>(state);
361
428
  for (size_t i = 0; i < loopbackState->transitions.size(); i++) {
362
429
  ATNState *target = loopbackState->transitions[i]->target;
363
- if (is<PlusBlockStartState *>(target)) {
364
- (static_cast<PlusBlockStartState *>(target))->loopBackState = loopbackState;
430
+ if (PlusBlockStartState::is(target)) {
431
+ (downCast<PlusBlockStartState*>(target))->loopBackState = loopbackState;
365
432
  }
366
433
  }
367
- } else if (is<StarLoopbackState *>(state)) {
368
- StarLoopbackState *loopbackState = static_cast<StarLoopbackState *>(state);
434
+ } else if (StarLoopbackState::is(state)) {
435
+ StarLoopbackState *loopbackState = downCast<StarLoopbackState*>(state);
369
436
  for (size_t i = 0; i < loopbackState->transitions.size(); i++) {
370
437
  ATNState *target = loopbackState->transitions[i]->target;
371
- if (is<StarLoopEntryState *>(target)) {
372
- (static_cast<StarLoopEntryState*>(target))->loopBackState = loopbackState;
438
+ if (StarLoopEntryState::is(target)) {
439
+ downCast<StarLoopEntryState*>(target)->loopBackState = loopbackState;
373
440
  }
374
441
  }
375
442
  }
@@ -379,104 +446,76 @@ ATN ATNDeserializer::deserialize(const std::vector<uint16_t>& input) {
379
446
  // DECISIONS
380
447
  //
381
448
  size_t ndecisions = data[p++];
382
- for (size_t i = 1; i <= ndecisions; i++) {
449
+ atn->decisionToState.reserve(ndecisions);
450
+ for (size_t i = 0; i < ndecisions; i++) {
383
451
  size_t s = data[p++];
384
- DecisionState *decState = dynamic_cast<DecisionState*>(atn.states[s]);
452
+ DecisionState *decState = downCast<DecisionState*>(atn->states[s]);
385
453
  if (decState == nullptr)
386
454
  throw IllegalStateException();
387
455
 
388
- atn.decisionToState.push_back(decState);
389
- decState->decision = (int)i - 1;
456
+ atn->decisionToState.push_back(decState);
457
+ decState->decision = static_cast<int>(i);
390
458
  }
391
459
 
392
460
  //
393
461
  // LEXER ACTIONS
394
462
  //
395
- if (atn.grammarType == ATNType::LEXER) {
396
- if (supportsLexerActions) {
397
- atn.lexerActions.resize(data[p++]);
398
- for (size_t i = 0; i < atn.lexerActions.size(); i++) {
399
- LexerActionType actionType = (LexerActionType)data[p++];
400
- int data1 = data[p++];
401
- if (data1 == 0xFFFF) {
402
- data1 = -1;
403
- }
404
-
405
- int data2 = data[p++];
406
- if (data2 == 0xFFFF) {
407
- data2 = -1;
408
- }
409
-
410
- atn.lexerActions[i] = lexerActionFactory(actionType, data1, data2);
411
- }
412
- } else {
413
- // for compatibility with older serialized ATNs, convert the old
414
- // serialized action index for action transitions to the new
415
- // form, which is the index of a LexerCustomAction
416
- for (ATNState *state : atn.states) {
417
- for (size_t i = 0; i < state->transitions.size(); i++) {
418
- Transition *transition = state->transitions[i];
419
- if (!is<ActionTransition *>(transition)) {
420
- continue;
421
- }
422
-
423
- size_t ruleIndex = static_cast<ActionTransition *>(transition)->ruleIndex;
424
- size_t actionIndex = static_cast<ActionTransition *>(transition)->actionIndex;
425
- Ref<LexerCustomAction> lexerAction = std::make_shared<LexerCustomAction>(ruleIndex, actionIndex);
426
- state->transitions[i] = new ActionTransition(transition->target, ruleIndex, atn.lexerActions.size(), false); /* mem-check freed in ATNState d-tor */
427
- delete transition; // ml: no longer needed since we just replaced it.
428
- atn.lexerActions.push_back(lexerAction);
429
- }
430
- }
463
+ if (atn->grammarType == ATNType::LEXER) {
464
+ atn->lexerActions.resize(data[p++]);
465
+ for (size_t i = 0; i < atn->lexerActions.size(); i++) {
466
+ LexerActionType actionType = static_cast<LexerActionType>(data[p++]);
467
+ int data1 = data[p++];
468
+ int data2 = data[p++];
469
+ atn->lexerActions[i] = lexerActionFactory(actionType, data1, data2);
431
470
  }
432
471
  }
433
472
 
434
- markPrecedenceDecisions(atn);
473
+ markPrecedenceDecisions(*atn);
435
474
 
436
- if (deserializationOptions.isVerifyATN()) {
437
- verifyATN(atn);
475
+ if (_deserializationOptions.isVerifyATN()) {
476
+ verifyATN(*atn);
438
477
  }
439
478
 
440
- if (deserializationOptions.isGenerateRuleBypassTransitions() && atn.grammarType == ATNType::PARSER) {
441
- atn.ruleToTokenType.resize(atn.ruleToStartState.size());
442
- for (size_t i = 0; i < atn.ruleToStartState.size(); i++) {
443
- atn.ruleToTokenType[i] = int(atn.maxTokenType + i + 1);
479
+ if (_deserializationOptions.isGenerateRuleBypassTransitions() && atn->grammarType == ATNType::PARSER) {
480
+ atn->ruleToTokenType.resize(atn->ruleToStartState.size());
481
+ for (size_t i = 0; i < atn->ruleToStartState.size(); i++) {
482
+ atn->ruleToTokenType[i] = static_cast<int>(atn->maxTokenType + i + 1);
444
483
  }
445
484
 
446
- for (std::vector<RuleStartState*>::size_type i = 0; i < atn.ruleToStartState.size(); i++) {
485
+ for (std::vector<RuleStartState*>::size_type i = 0; i < atn->ruleToStartState.size(); i++) {
447
486
  BasicBlockStartState *bypassStart = new BasicBlockStartState(); /* mem check: freed in ATN d-tor */
448
- bypassStart->ruleIndex = (int)i;
449
- atn.addState(bypassStart);
487
+ bypassStart->ruleIndex = static_cast<int>(i);
488
+ atn->addState(bypassStart);
450
489
 
451
490
  BlockEndState *bypassStop = new BlockEndState(); /* mem check: freed in ATN d-tor */
452
- bypassStop->ruleIndex = (int)i;
453
- atn.addState(bypassStop);
491
+ bypassStop->ruleIndex = static_cast<int>(i);
492
+ atn->addState(bypassStop);
454
493
 
455
494
  bypassStart->endState = bypassStop;
456
- atn.defineDecisionState(bypassStart);
495
+ atn->defineDecisionState(bypassStart);
457
496
 
458
497
  bypassStop->startState = bypassStart;
459
498
 
460
499
  ATNState *endState;
461
- Transition *excludeTransition = nullptr;
462
- if (atn.ruleToStartState[i]->isLeftRecursiveRule) {
500
+ const Transition *excludeTransition = nullptr;
501
+ if (atn->ruleToStartState[i]->isLeftRecursiveRule) {
463
502
  // wrap from the beginning of the rule to the StarLoopEntryState
464
503
  endState = nullptr;
465
- for (ATNState *state : atn.states) {
504
+ for (ATNState *state : atn->states) {
466
505
  if (state->ruleIndex != i) {
467
506
  continue;
468
507
  }
469
508
 
470
- if (!is<StarLoopEntryState*>(state)) {
509
+ if (!StarLoopEntryState::is(state)) {
471
510
  continue;
472
511
  }
473
512
 
474
513
  ATNState *maybeLoopEndState = state->transitions[state->transitions.size() - 1]->target;
475
- if (!is<LoopEndState*>(maybeLoopEndState)) {
514
+ if (!LoopEndState::is(maybeLoopEndState)) {
476
515
  continue;
477
516
  }
478
517
 
479
- if (maybeLoopEndState->epsilonOnlyTransitions && is<RuleStopState*>(maybeLoopEndState->transitions[0]->target)) {
518
+ if (maybeLoopEndState->epsilonOnlyTransitions && RuleStopState::is(maybeLoopEndState->transitions[0]->target)) {
480
519
  endState = state;
481
520
  break;
482
521
  }
@@ -487,78 +526,50 @@ ATN ATNDeserializer::deserialize(const std::vector<uint16_t>& input) {
487
526
 
488
527
  }
489
528
 
490
- excludeTransition = (static_cast<StarLoopEntryState*>(endState))->loopBackState->transitions[0];
529
+ excludeTransition = (static_cast<StarLoopEntryState*>(endState))->loopBackState->transitions[0].get();
491
530
  } else {
492
- endState = atn.ruleToStopState[i];
531
+ endState = atn->ruleToStopState[i];
493
532
  }
494
533
 
495
534
  // all non-excluded transitions that currently target end state need to target blockEnd instead
496
- for (ATNState *state : atn.states) {
497
- for (Transition *transition : state->transitions) {
498
- if (transition == excludeTransition) {
535
+ for (ATNState *state : atn->states) {
536
+ for (auto &transition : state->transitions) {
537
+ if (transition.get() == excludeTransition) {
499
538
  continue;
500
539
  }
501
540
 
502
541
  if (transition->target == endState) {
503
- transition->target = bypassStop;
542
+ const_cast<Transition*>(transition.get())->target = bypassStop;
504
543
  }
505
544
  }
506
545
  }
507
546
 
508
547
  // all transitions leaving the rule start state need to leave blockStart instead
509
- while (atn.ruleToStartState[i]->transitions.size() > 0) {
510
- Transition *transition = atn.ruleToStartState[i]->removeTransition(atn.ruleToStartState[i]->transitions.size() - 1);
511
- bypassStart->addTransition(transition);
548
+ while (atn->ruleToStartState[i]->transitions.size() > 0) {
549
+ ConstTransitionPtr transition = atn->ruleToStartState[i]->removeTransition(atn->ruleToStartState[i]->transitions.size() - 1);
550
+ bypassStart->addTransition(std::move(transition));
512
551
  }
513
552
 
514
553
  // link the new states
515
- atn.ruleToStartState[i]->addTransition(new EpsilonTransition(bypassStart)); /* mem check: freed in ATNState d-tor */
516
- bypassStop->addTransition(new EpsilonTransition(endState)); /* mem check: freed in ATNState d-tor */
554
+ atn->ruleToStartState[i]->addTransition(std::make_unique<EpsilonTransition>(bypassStart));
555
+ bypassStop->addTransition(std::make_unique<EpsilonTransition>(endState));
517
556
 
518
557
  ATNState *matchState = new BasicState(); /* mem check: freed in ATN d-tor */
519
- atn.addState(matchState);
520
- matchState->addTransition(new AtomTransition(bypassStop, atn.ruleToTokenType[i])); /* mem check: freed in ATNState d-tor */
521
- bypassStart->addTransition(new EpsilonTransition(matchState)); /* mem check: freed in ATNState d-tor */
558
+ atn->addState(matchState);
559
+ matchState->addTransition(std::make_unique<AtomTransition>(bypassStop, atn->ruleToTokenType[i]));
560
+ bypassStart->addTransition(std::make_unique<EpsilonTransition>(matchState));
522
561
  }
523
562
 
524
- if (deserializationOptions.isVerifyATN()) {
563
+ if (_deserializationOptions.isVerifyATN()) {
525
564
  // reverify after modification
526
- verifyATN(atn);
565
+ verifyATN(*atn);
527
566
  }
528
567
  }
529
568
 
530
569
  return atn;
531
570
  }
532
571
 
533
- /**
534
- * Analyze the {@link StarLoopEntryState} states in the specified ATN to set
535
- * the {@link StarLoopEntryState#isPrecedenceDecision} field to the
536
- * correct value.
537
- *
538
- * @param atn The ATN.
539
- */
540
- void ATNDeserializer::markPrecedenceDecisions(const ATN &atn) {
541
- for (ATNState *state : atn.states) {
542
- if (!is<StarLoopEntryState *>(state)) {
543
- continue;
544
- }
545
-
546
- /* We analyze the ATN to determine if this ATN decision state is the
547
- * decision for the closure block that determines whether a
548
- * precedence rule should continue or complete.
549
- */
550
- if (atn.ruleToStartState[state->ruleIndex]->isLeftRecursiveRule) {
551
- ATNState *maybeLoopEndState = state->transitions[state->transitions.size() - 1]->target;
552
- if (is<LoopEndState *>(maybeLoopEndState)) {
553
- if (maybeLoopEndState->epsilonOnlyTransitions && is<RuleStopState *>(maybeLoopEndState->transitions[0]->target)) {
554
- static_cast<StarLoopEntryState *>(state)->isPrecedenceDecision = true;
555
- }
556
- }
557
- }
558
- }
559
- }
560
-
561
- void ATNDeserializer::verifyATN(const ATN &atn) {
572
+ void ATNDeserializer::verifyATN(const ATN &atn) const {
562
573
  // verify assumptions
563
574
  for (ATNState *state : atn.states) {
564
575
  if (state == nullptr) {
@@ -567,190 +578,52 @@ void ATNDeserializer::verifyATN(const ATN &atn) {
567
578
 
568
579
  checkCondition(state->epsilonOnlyTransitions || state->transitions.size() <= 1);
569
580
 
570
- if (is<PlusBlockStartState *>(state)) {
571
- checkCondition((static_cast<PlusBlockStartState *>(state))->loopBackState != nullptr);
581
+ if (PlusBlockStartState::is(state)) {
582
+ checkCondition((downCast<PlusBlockStartState*>(state))->loopBackState != nullptr);
572
583
  }
573
584
 
574
- if (is<StarLoopEntryState *>(state)) {
575
- StarLoopEntryState *starLoopEntryState = static_cast<StarLoopEntryState*>(state);
585
+ if (StarLoopEntryState::is(state)) {
586
+ StarLoopEntryState *starLoopEntryState = downCast<StarLoopEntryState*>(state);
576
587
  checkCondition(starLoopEntryState->loopBackState != nullptr);
577
588
  checkCondition(starLoopEntryState->transitions.size() == 2);
578
589
 
579
- if (is<StarBlockStartState *>(starLoopEntryState->transitions[0]->target)) {
580
- checkCondition(static_cast<LoopEndState *>(starLoopEntryState->transitions[1]->target) != nullptr);
590
+ if (StarBlockStartState::is(starLoopEntryState->transitions[0]->target)) {
591
+ checkCondition(downCast<LoopEndState*>(starLoopEntryState->transitions[1]->target) != nullptr);
581
592
  checkCondition(!starLoopEntryState->nonGreedy);
582
- } else if (is<LoopEndState *>(starLoopEntryState->transitions[0]->target)) {
583
- checkCondition(is<StarBlockStartState *>(starLoopEntryState->transitions[1]->target));
593
+ } else if (LoopEndState::is(starLoopEntryState->transitions[0]->target)) {
594
+ checkCondition(StarBlockStartState::is(starLoopEntryState->transitions[1]->target));
584
595
  checkCondition(starLoopEntryState->nonGreedy);
585
596
  } else {
586
597
  throw IllegalStateException();
587
-
588
598
  }
589
599
  }
590
600
 
591
- if (is<StarLoopbackState *>(state)) {
601
+ if (StarLoopbackState::is(state)) {
592
602
  checkCondition(state->transitions.size() == 1);
593
- checkCondition(is<StarLoopEntryState *>(state->transitions[0]->target));
603
+ checkCondition(StarLoopEntryState::is(state->transitions[0]->target));
594
604
  }
595
605
 
596
- if (is<LoopEndState *>(state)) {
597
- checkCondition((static_cast<LoopEndState *>(state))->loopBackState != nullptr);
606
+ if (LoopEndState::is(state)) {
607
+ checkCondition((downCast<LoopEndState*>(state))->loopBackState != nullptr);
598
608
  }
599
609
 
600
- if (is<RuleStartState *>(state)) {
601
- checkCondition((static_cast<RuleStartState *>(state))->stopState != nullptr);
610
+ if (RuleStartState::is(state)) {
611
+ checkCondition((downCast<RuleStartState*>(state))->stopState != nullptr);
602
612
  }
603
613
 
604
- if (is<BlockStartState *>(state)) {
605
- checkCondition((static_cast<BlockStartState *>(state))->endState != nullptr);
614
+ if (BlockStartState::is(state)) {
615
+ checkCondition((downCast<BlockStartState*>(state))->endState != nullptr);
606
616
  }
607
617
 
608
- if (is<BlockEndState *>(state)) {
609
- checkCondition((static_cast<BlockEndState *>(state))->startState != nullptr);
618
+ if (BlockEndState::is(state)) {
619
+ checkCondition((downCast<BlockEndState*>(state))->startState != nullptr);
610
620
  }
611
621
 
612
- if (is<DecisionState *>(state)) {
613
- DecisionState *decisionState = static_cast<DecisionState *>(state);
622
+ if (DecisionState::is(state)) {
623
+ DecisionState *decisionState = downCast<DecisionState*>(state);
614
624
  checkCondition(decisionState->transitions.size() <= 1 || decisionState->decision >= 0);
615
625
  } else {
616
- checkCondition(state->transitions.size() <= 1 || is<RuleStopState *>(state));
626
+ checkCondition(state->transitions.size() <= 1 || RuleStopState::is(state));
617
627
  }
618
628
  }
619
629
  }
620
-
621
- void ATNDeserializer::checkCondition(bool condition) {
622
- checkCondition(condition, "");
623
- }
624
-
625
- void ATNDeserializer::checkCondition(bool condition, const std::string &message) {
626
- if (!condition) {
627
- throw IllegalStateException(message);
628
- }
629
- }
630
-
631
- Guid ATNDeserializer::toUUID(const unsigned short *data, size_t offset) {
632
- return Guid((uint16_t *)data + offset, true);
633
- }
634
-
635
- /* mem check: all created instances are freed in the d-tor of the ATNState they are added to. */
636
- Transition *ATNDeserializer::edgeFactory(const ATN &atn, size_t type, size_t /*src*/, size_t trg, size_t arg1,
637
- size_t arg2, size_t arg3,
638
- const std::vector<misc::IntervalSet> &sets) {
639
-
640
- ATNState *target = atn.states[trg];
641
- switch (type) {
642
- case Transition::EPSILON:
643
- return new EpsilonTransition(target);
644
- case Transition::RANGE:
645
- if (arg3 != 0) {
646
- return new RangeTransition(target, Token::EOF, arg2);
647
- } else {
648
- return new RangeTransition(target, arg1, arg2);
649
- }
650
- case Transition::RULE:
651
- return new RuleTransition(static_cast<RuleStartState*>(atn.states[arg1]), arg2, (int)arg3, target);
652
- case Transition::PREDICATE:
653
- return new PredicateTransition(target, arg1, arg2, arg3 != 0);
654
- case Transition::PRECEDENCE:
655
- return new PrecedencePredicateTransition(target, (int)arg1);
656
- case Transition::ATOM:
657
- if (arg3 != 0) {
658
- return new AtomTransition(target, Token::EOF);
659
- } else {
660
- return new AtomTransition(target, arg1);
661
- }
662
- case Transition::ACTION:
663
- return new ActionTransition(target, arg1, arg2, arg3 != 0);
664
- case Transition::SET:
665
- return new SetTransition(target, sets[arg1]);
666
- case Transition::NOT_SET:
667
- return new NotSetTransition(target, sets[arg1]);
668
- case Transition::WILDCARD:
669
- return new WildcardTransition(target);
670
- }
671
-
672
- throw IllegalArgumentException("The specified transition type is not valid.");
673
- }
674
-
675
- /* mem check: all created instances are freed in the d-tor of the ATN. */
676
- ATNState* ATNDeserializer::stateFactory(size_t type, size_t ruleIndex) {
677
- ATNState *s;
678
- switch (type) {
679
- case ATNState::ATN_INVALID_TYPE:
680
- return nullptr;
681
- case ATNState::BASIC :
682
- s = new BasicState();
683
- break;
684
- case ATNState::RULE_START :
685
- s = new RuleStartState();
686
- break;
687
- case ATNState::BLOCK_START :
688
- s = new BasicBlockStartState();
689
- break;
690
- case ATNState::PLUS_BLOCK_START :
691
- s = new PlusBlockStartState();
692
- break;
693
- case ATNState::STAR_BLOCK_START :
694
- s = new StarBlockStartState();
695
- break;
696
- case ATNState::TOKEN_START :
697
- s = new TokensStartState();
698
- break;
699
- case ATNState::RULE_STOP :
700
- s = new RuleStopState();
701
- break;
702
- case ATNState::BLOCK_END :
703
- s = new BlockEndState();
704
- break;
705
- case ATNState::STAR_LOOP_BACK :
706
- s = new StarLoopbackState();
707
- break;
708
- case ATNState::STAR_LOOP_ENTRY :
709
- s = new StarLoopEntryState();
710
- break;
711
- case ATNState::PLUS_LOOP_BACK :
712
- s = new PlusLoopbackState();
713
- break;
714
- case ATNState::LOOP_END :
715
- s = new LoopEndState();
716
- break;
717
- default :
718
- std::string message = "The specified state type " + std::to_string(type) + " is not valid.";
719
- throw IllegalArgumentException(message);
720
- }
721
-
722
- s->ruleIndex = ruleIndex;
723
- return s;
724
- }
725
-
726
- Ref<LexerAction> ATNDeserializer::lexerActionFactory(LexerActionType type, int data1, int data2) {
727
- switch (type) {
728
- case LexerActionType::CHANNEL:
729
- return std::make_shared<LexerChannelAction>(data1);
730
-
731
- case LexerActionType::CUSTOM:
732
- return std::make_shared<LexerCustomAction>(data1, data2);
733
-
734
- case LexerActionType::MODE:
735
- return std::make_shared< LexerModeAction>(data1);
736
-
737
- case LexerActionType::MORE:
738
- return LexerMoreAction::getInstance();
739
-
740
- case LexerActionType::POP_MODE:
741
- return LexerPopModeAction::getInstance();
742
-
743
- case LexerActionType::PUSH_MODE:
744
- return std::make_shared<LexerPushModeAction>(data1);
745
-
746
- case LexerActionType::SKIP:
747
- return LexerSkipAction::getInstance();
748
-
749
- case LexerActionType::TYPE:
750
- return std::make_shared<LexerTypeAction>(data1);
751
-
752
- default:
753
- throw IllegalArgumentException("The specified lexer action type " + std::to_string(static_cast<size_t>(type)) +
754
- " is not valid.");
755
- }
756
- }