expressir 1.2.3 → 1.2.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (328) hide show
  1. checksums.yaml +4 -4
  2. data/.cross_rubies +0 -6
  3. data/.github/workflows/rake.yml +223 -31
  4. data/.gitignore +7 -1
  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 +11 -9
  16. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/CMakeLists.txt +44 -9
  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 +19 -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 +51 -35
  26. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/antlrcpp.xcodeproj/xcshareddata/xcschemes/antlr4.xcscheme +1 -1
  27. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/antlrcpp.xcodeproj/xcshareddata/xcschemes/antlr4_ios.xcscheme +1 -5
  28. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/antlrcpp.xcodeproj/xcshareddata/xcschemes/antlr4_static.xcscheme +1 -5
  29. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/ANTLRFileStream.cpp +1 -12
  30. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/ANTLRFileStream.h +9 -6
  31. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/ANTLRInputStream.cpp +43 -18
  32. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/ANTLRInputStream.h +16 -6
  33. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/CommonToken.cpp +2 -4
  34. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/CommonTokenFactory.cpp +1 -1
  35. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/CommonTokenFactory.h +1 -1
  36. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/DefaultErrorStrategy.cpp +16 -13
  37. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/Exceptions.cpp +2 -2
  38. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/Exceptions.h +2 -2
  39. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/FailedPredicateException.cpp +5 -4
  40. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/FailedPredicateException.h +1 -1
  41. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/IntStream.h +1 -1
  42. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/Lexer.cpp +2 -3
  43. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/Lexer.h +9 -9
  44. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/LexerInterpreter.cpp +0 -15
  45. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/LexerInterpreter.h +1 -7
  46. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/ListTokenSource.cpp +2 -2
  47. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/ListTokenSource.h +2 -2
  48. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/Parser.cpp +51 -31
  49. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/Parser.h +1 -7
  50. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/ParserInterpreter.cpp +27 -39
  51. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/ParserInterpreter.h +1 -7
  52. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/ParserRuleContext.cpp +20 -23
  53. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/ParserRuleContext.h +21 -21
  54. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/ProxyErrorListener.cpp +4 -4
  55. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/RecognitionException.cpp +0 -1
  56. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/Recognizer.cpp +16 -27
  57. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/Recognizer.h +12 -17
  58. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/RuleContext.cpp +4 -3
  59. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/RuleContext.h +5 -1
  60. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/RuntimeMetaData.cpp +2 -1
  61. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/Token.h +7 -7
  62. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/TokenSource.h +1 -1
  63. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/TokenStreamRewriter.cpp +6 -6
  64. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/TokenStreamRewriter.h +4 -2
  65. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/UnbufferedCharStream.cpp +15 -18
  66. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/UnbufferedCharStream.h +12 -18
  67. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/Version.h +42 -0
  68. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/Vocabulary.cpp +13 -53
  69. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/Vocabulary.h +11 -27
  70. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/antlr4-common.h +19 -58
  71. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/antlr4-runtime.h +7 -5
  72. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATN.cpp +6 -57
  73. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATN.h +35 -15
  74. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNConfig.cpp +29 -36
  75. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNConfig.h +36 -27
  76. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNConfigSet.cpp +58 -54
  77. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNConfigSet.h +77 -31
  78. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNDeserializationOptions.cpp +22 -32
  79. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNDeserializationOptions.h +22 -24
  80. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNDeserializer.cpp +335 -464
  81. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNDeserializer.h +9 -62
  82. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNSimulator.cpp +9 -39
  83. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNSimulator.h +6 -22
  84. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNState.cpp +10 -26
  85. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNState.h +42 -36
  86. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNStateType.cpp +33 -0
  87. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNStateType.h +36 -0
  88. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ActionTransition.cpp +2 -6
  89. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ActionTransition.h +4 -2
  90. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ArrayPredictionContext.cpp +49 -22
  91. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ArrayPredictionContext.h +20 -12
  92. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/AtomTransition.cpp +1 -5
  93. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/AtomTransition.h +5 -2
  94. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/BasicBlockStartState.h +4 -2
  95. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/BasicState.h +4 -2
  96. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/BlockEndState.h +5 -3
  97. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/BlockStartState.h +10 -1
  98. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/DecisionInfo.h +1 -1
  99. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/DecisionState.cpp +0 -5
  100. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/DecisionState.h +12 -8
  101. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/EpsilonTransition.cpp +2 -6
  102. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/EpsilonTransition.h +6 -3
  103. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LL1Analyzer.cpp +139 -108
  104. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LL1Analyzer.h +10 -43
  105. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerATNConfig.cpp +16 -33
  106. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerATNConfig.h +12 -12
  107. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerATNSimulator.cpp +69 -82
  108. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerATNSimulator.h +17 -28
  109. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerAction.cpp +12 -6
  110. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerAction.h +45 -11
  111. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerActionExecutor.cpp +48 -44
  112. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerActionExecutor.h +31 -18
  113. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerActionType.h +3 -1
  114. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerChannelAction.cpp +14 -26
  115. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerChannelAction.h +12 -16
  116. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerCustomAction.cpp +15 -32
  117. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerCustomAction.h +12 -24
  118. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerIndexedCustomAction.cpp +23 -29
  119. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerIndexedCustomAction.h +13 -19
  120. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerModeAction.cpp +13 -26
  121. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerModeAction.h +12 -16
  122. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerMoreAction.cpp +6 -17
  123. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerMoreAction.h +12 -16
  124. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerPopModeAction.cpp +6 -17
  125. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerPopModeAction.h +12 -16
  126. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerPushModeAction.cpp +13 -26
  127. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerPushModeAction.h +12 -16
  128. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerSkipAction.cpp +6 -17
  129. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerSkipAction.h +11 -15
  130. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerTypeAction.cpp +13 -26
  131. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LexerTypeAction.h +13 -17
  132. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LoopEndState.h +5 -1
  133. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/NotSetTransition.cpp +1 -6
  134. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/NotSetTransition.h +4 -2
  135. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/OrderedATNConfigSet.cpp +6 -2
  136. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/OrderedATNConfigSet.h +8 -3
  137. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ParserATNSimulator.cpp +169 -152
  138. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ParserATNSimulator.h +26 -19
  139. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ParserATNSimulatorOptions.h +50 -0
  140. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PlusBlockStartState.h +5 -1
  141. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PlusLoopbackState.h +5 -2
  142. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PrecedencePredicateTransition.cpp +2 -11
  143. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PrecedencePredicateTransition.h +15 -9
  144. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredicateEvalInfo.cpp +2 -2
  145. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredicateEvalInfo.h +2 -2
  146. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredicateTransition.cpp +4 -14
  147. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredicateTransition.h +22 -11
  148. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredictionContext.cpp +255 -338
  149. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredictionContext.h +87 -116
  150. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredictionContextCache.cpp +56 -0
  151. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredictionContextCache.h +64 -0
  152. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredictionContextMergeCache.cpp +167 -0
  153. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredictionContextMergeCache.h +101 -0
  154. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredictionContextMergeCacheOptions.h +71 -0
  155. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredictionContextType.h +21 -0
  156. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredictionMode.cpp +18 -17
  157. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PredictionMode.h +1 -1
  158. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ProfilingATNSimulator.cpp +2 -2
  159. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ProfilingATNSimulator.h +2 -2
  160. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/RangeTransition.cpp +1 -5
  161. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/RangeTransition.h +4 -2
  162. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/RuleStartState.h +4 -3
  163. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/RuleStopState.h +4 -2
  164. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/RuleTransition.cpp +1 -5
  165. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/RuleTransition.h +5 -3
  166. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/SemanticContext.cpp +197 -156
  167. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/SemanticContext.h +92 -81
  168. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/SemanticContextType.h +23 -0
  169. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/SerializedATNView.h +101 -0
  170. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/SetTransition.cpp +2 -6
  171. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/SetTransition.h +11 -3
  172. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/SingletonPredictionContext.cpp +39 -34
  173. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/SingletonPredictionContext.h +17 -10
  174. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/StarBlockStartState.h +5 -2
  175. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/StarLoopEntryState.h +4 -2
  176. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/StarLoopbackState.cpp +6 -6
  177. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/StarLoopbackState.h +6 -2
  178. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/TokensStartState.h +5 -2
  179. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/Transition.cpp +1 -9
  180. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/Transition.h +11 -22
  181. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/TransitionType.cpp +27 -0
  182. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/TransitionType.h +33 -0
  183. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/WildcardTransition.cpp +1 -5
  184. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/WildcardTransition.h +4 -2
  185. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/dfa/DFA.cpp +11 -23
  186. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/dfa/DFA.h +20 -15
  187. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/dfa/DFASerializer.cpp +2 -9
  188. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/dfa/DFASerializer.h +4 -4
  189. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/dfa/DFAState.cpp +9 -50
  190. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/dfa/DFAState.h +57 -48
  191. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/dfa/LexerDFASerializer.cpp +1 -4
  192. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/dfa/LexerDFASerializer.h +3 -4
  193. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/InterpreterDataReader.cpp +2 -2
  194. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/InterpreterDataReader.h +3 -1
  195. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/Interval.cpp +1 -29
  196. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/Interval.h +10 -10
  197. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/IntervalSet.cpp +15 -28
  198. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/IntervalSet.h +1 -9
  199. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/MurmurHash.cpp +54 -68
  200. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/misc/MurmurHash.h +35 -9
  201. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/Any.cpp +0 -5
  202. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/Any.h +1 -155
  203. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/Arrays.cpp +2 -2
  204. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/Arrays.h +39 -0
  205. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/BitSet.h +1 -1
  206. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/CPPUtils.cpp +13 -54
  207. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/CPPUtils.h +16 -29
  208. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/Casts.h +34 -0
  209. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/Declarations.h +0 -2
  210. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/StringUtils.cpp +25 -23
  211. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/StringUtils.h +2 -40
  212. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/Unicode.h +28 -0
  213. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/Utf8.cpp +242 -0
  214. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/Utf8.h +54 -0
  215. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/AbstractParseTreeVisitor.h +13 -12
  216. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ErrorNode.h +7 -2
  217. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ErrorNodeImpl.cpp +36 -5
  218. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ErrorNodeImpl.h +14 -4
  219. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/IterativeParseTreeWalker.cpp +14 -19
  220. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ParseTree.cpp +0 -3
  221. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ParseTree.h +14 -5
  222. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ParseTreeType.h +22 -0
  223. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ParseTreeVisitor.h +4 -4
  224. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ParseTreeWalker.cpp +8 -9
  225. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ParseTreeWalker.h +30 -6
  226. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/TerminalNode.h +10 -2
  227. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/TerminalNodeImpl.cpp +2 -5
  228. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/TerminalNodeImpl.h +4 -5
  229. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/Trees.cpp +1 -1
  230. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/pattern/ParseTreePattern.cpp +1 -1
  231. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/pattern/ParseTreePatternMatcher.cpp +1 -2
  232. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPath.cpp +1 -1
  233. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathLexer.cpp +128 -119
  234. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathLexer.h +18 -27
  235. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathRuleElement.cpp +1 -1
  236. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/xpath/XPathTokenElement.cpp +1 -1
  237. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/tests/Utf8Test.cpp +110 -0
  238. data/ext/express-parser/antlrgen/Express.interp +1 -1
  239. data/ext/express-parser/antlrgen/ExpressBaseListener.cpp +1 -1
  240. data/ext/express-parser/antlrgen/ExpressBaseListener.h +1 -1
  241. data/ext/express-parser/antlrgen/ExpressBaseVisitor.cpp +1 -1
  242. data/ext/express-parser/antlrgen/ExpressBaseVisitor.h +200 -200
  243. data/ext/express-parser/antlrgen/ExpressLexer.cpp +645 -1129
  244. data/ext/express-parser/antlrgen/ExpressLexer.h +20 -27
  245. data/ext/express-parser/antlrgen/ExpressLexer.interp +1 -1
  246. data/ext/express-parser/antlrgen/ExpressListener.cpp +1 -1
  247. data/ext/express-parser/antlrgen/ExpressListener.h +1 -1
  248. data/ext/express-parser/antlrgen/ExpressParser.cpp +1754 -1447
  249. data/ext/express-parser/antlrgen/ExpressParser.h +219 -223
  250. data/ext/express-parser/antlrgen/ExpressVisitor.cpp +1 -1
  251. data/ext/express-parser/antlrgen/ExpressVisitor.h +200 -200
  252. data/ext/express-parser/express_parser.cpp +165 -101
  253. data/ext/express-parser/extconf.rb +14 -14
  254. data/lib/expressir/config.rb +1 -1
  255. data/lib/expressir/express/parser.rb +17 -15
  256. data/lib/expressir/express/visitor.rb +7 -3
  257. data/lib/expressir/model.rb +78 -78
  258. data/lib/expressir/version.rb +1 -1
  259. data/rakelib/antlr4-native.rake +161 -0
  260. data/rakelib/cross-ruby.rake +213 -162
  261. data/spec/acceptance/version_spec.rb +17 -2
  262. data/spec/expressir/express/cache_spec.rb +23 -5
  263. data/spec/expressir/express/formatter_spec.rb +54 -8
  264. data/spec/expressir/express/parser_spec.rb +47 -11
  265. data/spec/expressir/model/model_element_spec.rb +198 -146
  266. data/spec/spec_helper.rb +7 -0
  267. metadata +79 -91
  268. data/demo.rb +0 -18
  269. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNSerializer.cpp +0 -621
  270. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/ATNSerializer.h +0 -61
  271. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/AbstractPredicateTransition.cpp +0 -14
  272. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/AbstractPredicateTransition.h +0 -24
  273. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/BasicBlockStartState.cpp +0 -12
  274. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/BasicState.cpp +0 -12
  275. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/BlockEndState.cpp +0 -15
  276. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/BlockStartState.cpp +0 -9
  277. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/EmptyPredictionContext.cpp +0 -35
  278. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/EmptyPredictionContext.h +0 -27
  279. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/LoopEndState.cpp +0 -12
  280. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/Makefile +0 -67
  281. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PlusBlockStartState.cpp +0 -12
  282. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/PlusLoopbackState.cpp +0 -12
  283. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/RuleStartState.cpp +0 -16
  284. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/RuleStopState.cpp +0 -12
  285. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/StarBlockStartState.cpp +0 -12
  286. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/StarLoopEntryState.cpp +0 -15
  287. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/atn/TokensStartState.cpp +0 -12
  288. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/guid.cpp +0 -303
  289. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/support/guid.h +0 -112
  290. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/ErrorNode.cpp +0 -9
  291. data/ext/express-parser/antlr4-upstream/runtime/Cpp/runtime/src/tree/TerminalNode.cpp +0 -9
  292. data/original/examples/ap233/ap233e1_arm_lf_stepmod-2010-11-12.exp +0 -9589
  293. data/original/examples/ap233/ap233e1_arm_lf_stepmod-2010-11-12.owl +0 -36619
  294. data/original/examples/ap233/ap233e1_arm_lf_stepmod-2010-11-12.xml +0 -13294
  295. data/original/examples/employment/eclipse/.project +0 -17
  296. data/original/examples/employment/eclipse/Export/Employment.png +0 -0
  297. data/original/examples/employment/eclipse/Express/employment_schema.exp +0 -33
  298. data/original/examples/employment/eclipse/Express/employment_schema.xmi +0 -77
  299. data/original/examples/employment/eclipse/Express/employment_schema.xml +0 -93
  300. data/original/examples/employment/eclipse/Models/Employment.uml +0 -4
  301. data/original/examples/employment/eclipse/Models/Employment.umldi +0 -240
  302. data/original/examples/employment/eclipse/readme.txt +0 -7
  303. data/original/examples/employment/employment_schema.exp +0 -33
  304. data/original/examples/employment/employment_schema.rb +0 -232
  305. data/original/examples/employment/employment_schema.xml +0 -93
  306. data/original/examples/employment/employment_schema___module.rb +0 -46
  307. data/original/examples/employment/employment_schema___p28attr.rb +0 -126
  308. data/original/examples/employment/employment_schema___p28inst.rb +0 -26
  309. data/original/examples/employment/example_employment_data.xml +0 -1
  310. data/original/examples/employment/example_employment_data_copy.xml +0 -1
  311. data/original/examples/employment/example_employment_reader.rb +0 -30
  312. data/original/examples/employment/example_employment_writer.rb +0 -51
  313. data/original/examples/plcs/ap239e1_arm_lf_dexlib_2010-01-06.exp +0 -3710
  314. data/original/examples/plcs/ap239e1_arm_lf_dexlib_2010-01-06.owl +0 -35880
  315. data/original/examples/plcs/ap239e1_arm_lf_dexlib_2010-01-06.xmi +0 -15357
  316. data/original/examples/plcs/ap239e1_arm_lf_dexlib_2010-01-06.xml +0 -9468
  317. data/original/examples/plcs/ap239e2_arm_lf_stepmod-2010-01-25.exp +0 -8404
  318. data/original/examples/plcs/ap239e2_arm_lf_stepmod-2010-01-25.owl +0 -43147
  319. data/original/examples/plcs/ap239e2_arm_lf_stepmod-2010-01-25.xmi +0 -18341
  320. data/original/examples/plcs/ap239e2_arm_lf_stepmod-2010-01-25.xml +0 -11632
  321. data/original/exp2ruby.rb +0 -525
  322. data/original/expsm.rb +0 -34
  323. data/original/mapping_owl.rb +0 -1018
  324. data/original/mapping_sysml.rb +0 -2281
  325. data/original/mapping_uml2.rb +0 -599
  326. data/original/mapping_uml2_eclipse.rb +0 -433
  327. data/original/reeper.rb +0 -134
  328. data/spec/expressr_spec.rb +0 -5
@@ -15,26 +15,31 @@
15
15
  using namespace antlr4::atn;
16
16
  using namespace antlrcpp;
17
17
 
18
- ATNConfigSet::ATNConfigSet(bool fullCtx) : fullCtx(fullCtx) {
19
- InitializeInstanceFields();
20
- }
18
+ namespace {
21
19
 
22
- ATNConfigSet::ATNConfigSet(const Ref<ATNConfigSet> &old) : ATNConfigSet(old->fullCtx) {
23
- addAll(old);
24
- uniqueAlt = old->uniqueAlt;
25
- conflictingAlts = old->conflictingAlts;
26
- hasSemanticContext = old->hasSemanticContext;
27
- dipsIntoOuterContext = old->dipsIntoOuterContext;
28
20
  }
29
21
 
30
- ATNConfigSet::~ATNConfigSet() {
22
+ ATNConfigSet::ATNConfigSet() : ATNConfigSet(true) {}
23
+
24
+ ATNConfigSet::ATNConfigSet(const ATNConfigSet &other)
25
+ : fullCtx(other.fullCtx), _configLookup(other._configLookup.bucket_count(), ATNConfigHasher{this}, ATNConfigComparer{this}) {
26
+ addAll(other);
27
+ uniqueAlt = other.uniqueAlt;
28
+ conflictingAlts = other.conflictingAlts;
29
+ hasSemanticContext = other.hasSemanticContext;
30
+ dipsIntoOuterContext = other.dipsIntoOuterContext;
31
31
  }
32
32
 
33
+ ATNConfigSet::ATNConfigSet(bool fullCtx)
34
+ : fullCtx(fullCtx), _configLookup(0, ATNConfigHasher{this}, ATNConfigComparer{this}) {}
35
+
33
36
  bool ATNConfigSet::add(const Ref<ATNConfig> &config) {
34
37
  return add(config, nullptr);
35
38
  }
36
39
 
37
40
  bool ATNConfigSet::add(const Ref<ATNConfig> &config, PredictionContextMergeCache *mergeCache) {
41
+ assert(config);
42
+
38
43
  if (_readonly) {
39
44
  throw IllegalStateException("This set is readonly");
40
45
  }
@@ -45,10 +50,9 @@ bool ATNConfigSet::add(const Ref<ATNConfig> &config, PredictionContextMergeCache
45
50
  dipsIntoOuterContext = true;
46
51
  }
47
52
 
48
- size_t hash = getHash(config.get());
49
- ATNConfig *existing = _configLookup[hash];
50
- if (existing == nullptr) {
51
- _configLookup[hash] = config.get();
53
+ auto existing = _configLookup.find(config.get());
54
+ if (existing == _configLookup.end()) {
55
+ _configLookup.insert(config.get());
52
56
  _cachedHashCode = 0;
53
57
  configs.push_back(config); // track order here
54
58
 
@@ -57,32 +61,33 @@ bool ATNConfigSet::add(const Ref<ATNConfig> &config, PredictionContextMergeCache
57
61
 
58
62
  // a previous (s,i,pi,_), merge with it and save result
59
63
  bool rootIsWildcard = !fullCtx;
60
- Ref<PredictionContext> merged = PredictionContext::merge(existing->context, config->context, rootIsWildcard, mergeCache);
64
+ Ref<const PredictionContext> merged = PredictionContext::merge((*existing)->context, config->context, rootIsWildcard, mergeCache);
61
65
  // no need to check for existing.context, config.context in cache
62
66
  // since only way to create new graphs is "call rule" and here. We
63
67
  // cache at both places.
64
- existing->reachesIntoOuterContext = std::max(existing->reachesIntoOuterContext, config->reachesIntoOuterContext);
68
+ (*existing)->reachesIntoOuterContext = std::max((*existing)->reachesIntoOuterContext, config->reachesIntoOuterContext);
65
69
 
66
70
  // make sure to preserve the precedence filter suppression during the merge
67
71
  if (config->isPrecedenceFilterSuppressed()) {
68
- existing->setPrecedenceFilterSuppressed(true);
72
+ (*existing)->setPrecedenceFilterSuppressed(true);
69
73
  }
70
74
 
71
- existing->context = merged; // replace context; no need to alt mapping
75
+ (*existing)->context = std::move(merged); // replace context; no need to alt mapping
72
76
 
73
77
  return true;
74
78
  }
75
79
 
76
- bool ATNConfigSet::addAll(const Ref<ATNConfigSet> &other) {
77
- for (auto &c : other->configs) {
80
+ bool ATNConfigSet::addAll(const ATNConfigSet &other) {
81
+ for (const auto &c : other.configs) {
78
82
  add(c);
79
83
  }
80
84
  return false;
81
85
  }
82
86
 
83
- std::vector<ATNState*> ATNConfigSet::getStates() {
87
+ std::vector<ATNState*> ATNConfigSet::getStates() const {
84
88
  std::vector<ATNState*> states;
85
- for (auto c : configs) {
89
+ states.reserve(configs.size());
90
+ for (const auto &c : configs) {
86
91
  states.push_back(c->state);
87
92
  }
88
93
  return states;
@@ -97,17 +102,18 @@ std::vector<ATNState*> ATNConfigSet::getStates() {
97
102
  * @since 4.3
98
103
  */
99
104
 
100
- BitSet ATNConfigSet::getAlts() {
105
+ BitSet ATNConfigSet::getAlts() const {
101
106
  BitSet alts;
102
- for (ATNConfig config : configs) {
103
- alts.set(config.alt);
107
+ for (const auto &config : configs) {
108
+ alts.set(config->alt);
104
109
  }
105
110
  return alts;
106
111
  }
107
112
 
108
- std::vector<Ref<SemanticContext>> ATNConfigSet::getPredicates() {
109
- std::vector<Ref<SemanticContext>> preds;
110
- for (auto c : configs) {
113
+ std::vector<Ref<const SemanticContext>> ATNConfigSet::getPredicates() const {
114
+ std::vector<Ref<const SemanticContext>> preds;
115
+ preds.reserve(configs.size());
116
+ for (const auto &c : configs) {
111
117
  if (c->semanticContext != SemanticContext::NONE) {
112
118
  preds.push_back(c->semanticContext);
113
119
  }
@@ -115,23 +121,25 @@ std::vector<Ref<SemanticContext>> ATNConfigSet::getPredicates() {
115
121
  return preds;
116
122
  }
117
123
 
118
- Ref<ATNConfig> ATNConfigSet::get(size_t i) const {
124
+ const Ref<ATNConfig>& ATNConfigSet::get(size_t i) const {
119
125
  return configs[i];
120
126
  }
121
127
 
122
128
  void ATNConfigSet::optimizeConfigs(ATNSimulator *interpreter) {
129
+ assert(interpreter);
130
+
123
131
  if (_readonly) {
124
132
  throw IllegalStateException("This set is readonly");
125
133
  }
126
134
  if (_configLookup.empty())
127
135
  return;
128
136
 
129
- for (auto &config : configs) {
137
+ for (const auto &config : configs) {
130
138
  config->context = interpreter->getCachedContext(config->context);
131
139
  }
132
140
  }
133
141
 
134
- bool ATNConfigSet::operator == (const ATNConfigSet &other) {
142
+ bool ATNConfigSet::equals(const ATNConfigSet &other) const {
135
143
  if (&other == this) {
136
144
  return true;
137
145
  }
@@ -147,22 +155,23 @@ bool ATNConfigSet::operator == (const ATNConfigSet &other) {
147
155
  return Arrays::equals(configs, other.configs);
148
156
  }
149
157
 
150
- size_t ATNConfigSet::hashCode() {
151
- if (!isReadonly() || _cachedHashCode == 0) {
152
- _cachedHashCode = 1;
153
- for (auto &i : configs) {
154
- _cachedHashCode = 31 * _cachedHashCode + i->hashCode(); // Same as Java's list hashCode impl.
158
+ size_t ATNConfigSet::hashCode() const {
159
+ size_t cachedHashCode = _cachedHashCode.load(std::memory_order_relaxed);
160
+ if (!isReadonly() || cachedHashCode == 0) {
161
+ cachedHashCode = 1;
162
+ for (const auto &i : configs) {
163
+ cachedHashCode = 31 * cachedHashCode + i->hashCode(); // Same as Java's list hashCode impl.
155
164
  }
165
+ _cachedHashCode.store(cachedHashCode, std::memory_order_relaxed);
156
166
  }
157
-
158
- return _cachedHashCode;
167
+ return cachedHashCode;
159
168
  }
160
169
 
161
- size_t ATNConfigSet::size() {
170
+ size_t ATNConfigSet::size() const {
162
171
  return configs.size();
163
172
  }
164
173
 
165
- bool ATNConfigSet::isEmpty() {
174
+ bool ATNConfigSet::isEmpty() const {
166
175
  return configs.empty();
167
176
  }
168
177
 
@@ -175,16 +184,16 @@ void ATNConfigSet::clear() {
175
184
  _configLookup.clear();
176
185
  }
177
186
 
178
- bool ATNConfigSet::isReadonly() {
187
+ bool ATNConfigSet::isReadonly() const {
179
188
  return _readonly;
180
189
  }
181
190
 
182
191
  void ATNConfigSet::setReadonly(bool readonly) {
183
192
  _readonly = readonly;
184
- _configLookup.clear();
193
+ LookupContainer(0, ATNConfigHasher{this}, ATNConfigComparer{this}).swap(_configLookup);
185
194
  }
186
195
 
187
- std::string ATNConfigSet::toString() {
196
+ std::string ATNConfigSet::toString() const {
188
197
  std::stringstream ss;
189
198
  ss << "[";
190
199
  for (size_t i = 0; i < configs.size(); i++) {
@@ -210,19 +219,14 @@ std::string ATNConfigSet::toString() {
210
219
  return ss.str();
211
220
  }
212
221
 
213
- size_t ATNConfigSet::getHash(ATNConfig *c) {
222
+ size_t ATNConfigSet::hashCode(const ATNConfig &other) const {
214
223
  size_t hashCode = 7;
215
- hashCode = 31 * hashCode + c->state->stateNumber;
216
- hashCode = 31 * hashCode + c->alt;
217
- hashCode = 31 * hashCode + c->semanticContext->hashCode();
224
+ hashCode = 31 * hashCode + other.state->stateNumber;
225
+ hashCode = 31 * hashCode + other.alt;
226
+ hashCode = 31 * hashCode + other.semanticContext->hashCode();
218
227
  return hashCode;
219
228
  }
220
229
 
221
- void ATNConfigSet::InitializeInstanceFields() {
222
- uniqueAlt = 0;
223
- hasSemanticContext = false;
224
- dipsIntoOuterContext = false;
225
-
226
- _readonly = false;
227
- _cachedHashCode = 0;
230
+ bool ATNConfigSet::equals(const ATNConfig &lhs, const ATNConfig &rhs) const {
231
+ return lhs.state->stateNumber == rhs.state->stateNumber && lhs.alt == rhs.alt && *lhs.semanticContext == *rhs.semanticContext;
228
232
  }
@@ -5,8 +5,11 @@
5
5
 
6
6
  #pragma once
7
7
 
8
+ #include <cassert>
9
+
8
10
  #include "support/BitSet.h"
9
11
  #include "atn/PredictionContext.h"
12
+ #include "atn/ATNConfig.h"
10
13
 
11
14
  namespace antlr4 {
12
15
  namespace atn {
@@ -20,7 +23,7 @@ namespace atn {
20
23
 
21
24
  // TODO: these fields make me pretty uncomfortable but nice to pack up info together, saves recomputation
22
25
  // TODO: can we track conflicts as they are added to save scanning configs later?
23
- size_t uniqueAlt;
26
+ size_t uniqueAlt = 0;
24
27
 
25
28
  /** Currently this is only used when we detect SLL conflict; this does
26
29
  * not necessarily represent the ambiguous alternatives. In fact,
@@ -31,20 +34,25 @@ namespace atn {
31
34
 
32
35
  // Used in parser and lexer. In lexer, it indicates we hit a pred
33
36
  // while computing a closure operation. Don't make a DFA state from this.
34
- bool hasSemanticContext;
35
- bool dipsIntoOuterContext;
37
+ bool hasSemanticContext = false;
38
+ bool dipsIntoOuterContext = false;
36
39
 
37
40
  /// Indicates that this configuration set is part of a full context
38
41
  /// LL prediction. It will be used to determine how to merge $. With SLL
39
42
  /// it's a wildcard whereas it is not for LL context merge.
40
- const bool fullCtx;
43
+ const bool fullCtx = true;
44
+
45
+ ATNConfigSet();
46
+
47
+ ATNConfigSet(const ATNConfigSet &other);
41
48
 
42
- ATNConfigSet(bool fullCtx = true);
43
- ATNConfigSet(const Ref<ATNConfigSet> &old);
49
+ ATNConfigSet(ATNConfigSet&&) = delete;
44
50
 
45
- virtual ~ATNConfigSet();
51
+ explicit ATNConfigSet(bool fullCtx);
46
52
 
47
- virtual bool add(const Ref<ATNConfig> &config);
53
+ virtual ~ATNConfigSet() = default;
54
+
55
+ bool add(const Ref<ATNConfig> &config);
48
56
 
49
57
  /// <summary>
50
58
  /// Adding a new config means merging contexts with existing configs for
@@ -56,9 +64,11 @@ namespace atn {
56
64
  /// This method updates <seealso cref="#dipsIntoOuterContext"/> and
57
65
  /// <seealso cref="#hasSemanticContext"/> when necessary.
58
66
  /// </summary>
59
- virtual bool add(const Ref<ATNConfig> &config, PredictionContextMergeCache *mergeCache);
67
+ bool add(const Ref<ATNConfig> &config, PredictionContextMergeCache *mergeCache);
68
+
69
+ bool addAll(const ATNConfigSet &other);
60
70
 
61
- virtual std::vector<ATNState *> getStates();
71
+ std::vector<ATNState*> getStates() const;
62
72
 
63
73
  /**
64
74
  * Gets the complete set of represented alternatives for the configuration
@@ -68,43 +78,79 @@ namespace atn {
68
78
  *
69
79
  * @since 4.3
70
80
  */
71
- antlrcpp::BitSet getAlts();
72
- virtual std::vector<Ref<SemanticContext>> getPredicates();
81
+ antlrcpp::BitSet getAlts() const;
82
+ std::vector<Ref<const SemanticContext>> getPredicates() const;
83
+
84
+ const Ref<ATNConfig>& get(size_t i) const;
73
85
 
74
- virtual Ref<ATNConfig> get(size_t i) const;
86
+ void optimizeConfigs(ATNSimulator *interpreter);
75
87
 
76
- virtual void optimizeConfigs(ATNSimulator *interpreter);
88
+ size_t size() const;
89
+ bool isEmpty() const;
90
+ void clear();
91
+ bool isReadonly() const;
92
+ void setReadonly(bool readonly);
93
+
94
+ virtual size_t hashCode() const;
95
+
96
+ virtual bool equals(const ATNConfigSet &other) const;
97
+
98
+ virtual std::string toString() const;
99
+
100
+ private:
101
+ struct ATNConfigHasher final {
102
+ const ATNConfigSet* atnConfigSet;
77
103
 
78
- bool addAll(const Ref<ATNConfigSet> &other);
104
+ size_t operator()(const ATNConfig *other) const {
105
+ assert(other != nullptr);
106
+ return atnConfigSet->hashCode(*other);
107
+ }
108
+ };
79
109
 
80
- bool operator == (const ATNConfigSet &other);
81
- virtual size_t hashCode();
82
- virtual size_t size();
83
- virtual bool isEmpty();
84
- virtual void clear();
85
- virtual bool isReadonly();
86
- virtual void setReadonly(bool readonly);
87
- virtual std::string toString();
110
+ struct ATNConfigComparer final {
111
+ const ATNConfigSet* atnConfigSet;
112
+
113
+ bool operator()(const ATNConfig *lhs, const ATNConfig *rhs) const {
114
+ assert(lhs != nullptr);
115
+ assert(rhs != nullptr);
116
+ return atnConfigSet->equals(*lhs, *rhs);
117
+ }
118
+ };
119
+
120
+ mutable std::atomic<size_t> _cachedHashCode = 0;
88
121
 
89
- protected:
90
122
  /// Indicates that the set of configurations is read-only. Do not
91
123
  /// allow any code to manipulate the set; DFA states will point at
92
124
  /// the sets and they must not change. This does not protect the other
93
125
  /// fields; in particular, conflictingAlts is set after
94
126
  /// we've made this readonly.
95
- bool _readonly;
127
+ bool _readonly = false;
96
128
 
97
- virtual size_t getHash(ATNConfig *c); // Hash differs depending on set type.
129
+ virtual size_t hashCode(const ATNConfig &atnConfig) const;
98
130
 
99
- private:
100
- size_t _cachedHashCode;
131
+ virtual bool equals(const ATNConfig &lhs, const ATNConfig &rhs) const;
132
+
133
+ using LookupContainer = std::unordered_set<ATNConfig*, ATNConfigHasher, ATNConfigComparer>;
101
134
 
102
135
  /// All configs but hashed by (s, i, _, pi) not including context. Wiped out
103
136
  /// when we go readonly as this set becomes a DFA state.
104
- std::unordered_map<size_t, ATNConfig *> _configLookup;
105
-
106
- void InitializeInstanceFields();
137
+ LookupContainer _configLookup;
107
138
  };
108
139
 
140
+ inline bool operator==(const ATNConfigSet &lhs, const ATNConfigSet &rhs) { return lhs.equals(rhs); }
141
+
142
+ inline bool operator!=(const ATNConfigSet &lhs, const ATNConfigSet &rhs) { return !operator==(lhs, rhs); }
143
+
109
144
  } // namespace atn
110
145
  } // namespace antlr4
146
+
147
+ namespace std {
148
+
149
+ template <>
150
+ struct hash<::antlr4::atn::ATNConfigSet> {
151
+ size_t operator()(const ::antlr4::atn::ATNConfigSet &atnConfigSet) const {
152
+ return atnConfigSet.hashCode();
153
+ }
154
+ };
155
+
156
+ } // namespace std
@@ -4,61 +4,51 @@
4
4
  */
5
5
 
6
6
  #include "atn/ATNDeserializationOptions.h"
7
+ #include "Exceptions.h"
7
8
 
9
+ #include <memory>
10
+ #include <mutex>
11
+
12
+ using namespace antlr4;
8
13
  using namespace antlr4::atn;
9
14
 
10
- ATNDeserializationOptions ATNDeserializationOptions::defaultOptions;
15
+ namespace {
11
16
 
12
- ATNDeserializationOptions::ATNDeserializationOptions() {
13
- InitializeInstanceFields();
14
- }
17
+ std::once_flag defaultATNDeserializationOptionsOnceFlag;
18
+ std::unique_ptr<ATNDeserializationOptions> defaultATNDeserializationOptions;
15
19
 
16
- ATNDeserializationOptions::ATNDeserializationOptions(ATNDeserializationOptions *options) : ATNDeserializationOptions() {
17
- this->verifyATN = options->verifyATN;
18
- this->generateRuleBypassTransitions = options->generateRuleBypassTransitions;
20
+ void initializeDefaultATNDeserializationOptions() {
21
+ defaultATNDeserializationOptions.reset(new ATNDeserializationOptions());
19
22
  }
20
23
 
21
- ATNDeserializationOptions::~ATNDeserializationOptions() {
22
24
  }
23
25
 
24
- const ATNDeserializationOptions& ATNDeserializationOptions::getDefaultOptions() {
25
- return defaultOptions;
26
- }
26
+ ATNDeserializationOptions::ATNDeserializationOptions(ATNDeserializationOptions *options)
27
+ : _readOnly(false), _verifyATN(options->_verifyATN),
28
+ _generateRuleBypassTransitions(options->_generateRuleBypassTransitions) {}
27
29
 
28
- bool ATNDeserializationOptions::isReadOnly() {
29
- return readOnly;
30
+ const ATNDeserializationOptions& ATNDeserializationOptions::getDefaultOptions() {
31
+ std::call_once(defaultATNDeserializationOptionsOnceFlag,
32
+ initializeDefaultATNDeserializationOptions);
33
+ return *defaultATNDeserializationOptions;
30
34
  }
31
35
 
32
36
  void ATNDeserializationOptions::makeReadOnly() {
33
- readOnly = true;
34
- }
35
-
36
- bool ATNDeserializationOptions::isVerifyATN() {
37
- return verifyATN;
37
+ _readOnly = true;
38
38
  }
39
39
 
40
40
  void ATNDeserializationOptions::setVerifyATN(bool verify) {
41
41
  throwIfReadOnly();
42
- verifyATN = verify;
43
- }
44
-
45
- bool ATNDeserializationOptions::isGenerateRuleBypassTransitions() {
46
- return generateRuleBypassTransitions;
42
+ _verifyATN = verify;
47
43
  }
48
44
 
49
45
  void ATNDeserializationOptions::setGenerateRuleBypassTransitions(bool generate) {
50
46
  throwIfReadOnly();
51
- generateRuleBypassTransitions = generate;
47
+ _generateRuleBypassTransitions = generate;
52
48
  }
53
49
 
54
- void ATNDeserializationOptions::throwIfReadOnly() {
50
+ void ATNDeserializationOptions::throwIfReadOnly() const {
55
51
  if (isReadOnly()) {
56
- throw "The object is read only.";
52
+ throw IllegalStateException("ATNDeserializationOptions is read only.");
57
53
  }
58
54
  }
59
-
60
- void ATNDeserializationOptions::InitializeInstanceFields() {
61
- readOnly = false;
62
- verifyATN = true;
63
- generateRuleBypassTransitions = false;
64
- }
@@ -10,41 +10,39 @@
10
10
  namespace antlr4 {
11
11
  namespace atn {
12
12
 
13
- class ANTLR4CPP_PUBLIC ATNDeserializationOptions {
14
- private:
15
- static ATNDeserializationOptions defaultOptions;
13
+ class ANTLR4CPP_PUBLIC ATNDeserializationOptions final {
14
+ public:
15
+ ATNDeserializationOptions()
16
+ : _readOnly(false), _verifyATN(true), _generateRuleBypassTransitions(false) {}
16
17
 
17
- bool readOnly;
18
- bool verifyATN;
19
- bool generateRuleBypassTransitions;
18
+ // TODO: Is this useful? If so we should mark it as explicit, otherwise remove it.
19
+ ATNDeserializationOptions(ATNDeserializationOptions *options);
20
20
 
21
- public:
22
- ATNDeserializationOptions();
23
- ATNDeserializationOptions(ATNDeserializationOptions *options);
24
- ATNDeserializationOptions(ATNDeserializationOptions const&) = default;
25
- virtual ~ATNDeserializationOptions();
26
- ATNDeserializationOptions& operator=(ATNDeserializationOptions const&) = default;
21
+ ATNDeserializationOptions(const ATNDeserializationOptions&) = default;
27
22
 
28
- static const ATNDeserializationOptions& getDefaultOptions();
23
+ ATNDeserializationOptions& operator=(const ATNDeserializationOptions&) = default;
29
24
 
30
- bool isReadOnly();
25
+ static const ATNDeserializationOptions& getDefaultOptions();
31
26
 
32
- void makeReadOnly();
27
+ bool isReadOnly() const { return _readOnly; }
33
28
 
34
- bool isVerifyATN();
29
+ void makeReadOnly();
35
30
 
36
- void setVerifyATN(bool verify);
31
+ bool isVerifyATN() const { return _verifyATN; }
37
32
 
38
- bool isGenerateRuleBypassTransitions();
33
+ void setVerifyATN(bool verify);
39
34
 
40
- void setGenerateRuleBypassTransitions(bool generate);
35
+ bool isGenerateRuleBypassTransitions() const { return _generateRuleBypassTransitions; }
41
36
 
42
- protected:
43
- virtual void throwIfReadOnly();
37
+ void setGenerateRuleBypassTransitions(bool generate);
44
38
 
45
- private:
46
- void InitializeInstanceFields();
47
- };
39
+ private:
40
+ void throwIfReadOnly() const;
41
+
42
+ bool _readOnly;
43
+ bool _verifyATN;
44
+ bool _generateRuleBypassTransitions;
45
+ };
48
46
 
49
47
  } // namespace atn
50
48
  } // namespace antlr4