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
@@ -3,7 +3,11 @@
3
3
  * can be found in the LICENSE.txt file in the project root.
4
4
  */
5
5
 
6
+ #include <functional>
7
+ #include <unordered_set>
8
+
6
9
  #include "misc/MurmurHash.h"
10
+ #include "support/Casts.h"
7
11
  #include "support/CPPUtils.h"
8
12
  #include "support/Arrays.h"
9
13
 
@@ -13,41 +17,109 @@ using namespace antlr4;
13
17
  using namespace antlr4::atn;
14
18
  using namespace antlrcpp;
15
19
 
16
- //------------------ Predicate -----------------------------------------------------------------------------------------
20
+ namespace {
17
21
 
18
- SemanticContext::Predicate::Predicate() : Predicate(INVALID_INDEX, INVALID_INDEX, false) {
19
- }
22
+ struct SemanticContextHasher final {
23
+ size_t operator()(const SemanticContext *semanticContext) const {
24
+ return semanticContext->hashCode();
25
+ }
26
+ };
27
+
28
+ struct SemanticContextComparer final {
29
+ bool operator()(const SemanticContext *lhs, const SemanticContext *rhs) const {
30
+ return *lhs == *rhs;
31
+ }
32
+ };
33
+
34
+ template <typename Comparer>
35
+ void insertSemanticContext(const Ref<const SemanticContext> &semanticContext,
36
+ std::unordered_set<const SemanticContext*, SemanticContextHasher, SemanticContextComparer> &operandSet,
37
+ std::vector<Ref<const SemanticContext>> &operandList,
38
+ Ref<const SemanticContext::PrecedencePredicate> &precedencePredicate,
39
+ Comparer comparer) {
40
+ if (semanticContext != nullptr) {
41
+ if (semanticContext->getContextType() == SemanticContextType::PRECEDENCE) {
42
+ if (precedencePredicate == nullptr || comparer(downCast<const SemanticContext::PrecedencePredicate*>(semanticContext.get())->precedence, precedencePredicate->precedence)) {
43
+ precedencePredicate = std::static_pointer_cast<const SemanticContext::PrecedencePredicate>(semanticContext);
44
+ }
45
+ } else {
46
+ auto [existing, inserted] = operandSet.insert(semanticContext.get());
47
+ if (inserted) {
48
+ operandList.push_back(semanticContext);
49
+ }
50
+ }
51
+ }
52
+ }
53
+
54
+ template <typename Comparer>
55
+ void insertSemanticContext(Ref<const SemanticContext> &&semanticContext,
56
+ std::unordered_set<const SemanticContext*, SemanticContextHasher, SemanticContextComparer> &operandSet,
57
+ std::vector<Ref<const SemanticContext>> &operandList,
58
+ Ref<const SemanticContext::PrecedencePredicate> &precedencePredicate,
59
+ Comparer comparer) {
60
+ if (semanticContext != nullptr) {
61
+ if (semanticContext->getContextType() == SemanticContextType::PRECEDENCE) {
62
+ if (precedencePredicate == nullptr || comparer(downCast<const SemanticContext::PrecedencePredicate*>(semanticContext.get())->precedence, precedencePredicate->precedence)) {
63
+ precedencePredicate = std::static_pointer_cast<const SemanticContext::PrecedencePredicate>(std::move(semanticContext));
64
+ }
65
+ } else {
66
+ auto [existing, inserted] = operandSet.insert(semanticContext.get());
67
+ if (inserted) {
68
+ operandList.push_back(std::move(semanticContext));
69
+ }
70
+ }
71
+ }
72
+ }
73
+
74
+ size_t predictOperandCapacity(const Ref<const SemanticContext> &x) {
75
+ switch (x->getContextType()) {
76
+ case SemanticContextType::AND:
77
+ return downCast<const SemanticContext::AND&>(*x).getOperands().size();
78
+ case SemanticContextType::OR:
79
+ return downCast<const SemanticContext::OR&>(*x).getOperands().size();
80
+ default:
81
+ return 1;
82
+ }
83
+ }
84
+
85
+ size_t predictOperandCapacity(const Ref<const SemanticContext> &a, const Ref<const SemanticContext> &b) {
86
+ return predictOperandCapacity(a) + predictOperandCapacity(b);
87
+ }
20
88
 
21
- SemanticContext::Predicate::Predicate(size_t ruleIndex, size_t predIndex, bool isCtxDependent)
22
- : ruleIndex(ruleIndex), predIndex(predIndex), isCtxDependent(isCtxDependent) {
23
89
  }
24
90
 
91
+ //------------------ Predicate -----------------------------------------------------------------------------------------
25
92
 
26
- bool SemanticContext::Predicate::eval(Recognizer *parser, RuleContext *parserCallStack) {
93
+ SemanticContext::Predicate::Predicate(size_t ruleIndex, size_t predIndex, bool isCtxDependent)
94
+ : SemanticContext(SemanticContextType::PREDICATE), ruleIndex(ruleIndex), predIndex(predIndex), isCtxDependent(isCtxDependent) {}
95
+
96
+ bool SemanticContext::Predicate::eval(Recognizer *parser, RuleContext *parserCallStack) const {
27
97
  RuleContext *localctx = nullptr;
28
- if (isCtxDependent)
98
+ if (isCtxDependent) {
29
99
  localctx = parserCallStack;
100
+ }
30
101
  return parser->sempred(localctx, ruleIndex, predIndex);
31
102
  }
32
103
 
33
104
  size_t SemanticContext::Predicate::hashCode() const {
34
105
  size_t hashCode = misc::MurmurHash::initialize();
106
+ hashCode = misc::MurmurHash::update(hashCode, static_cast<size_t>(getContextType()));
35
107
  hashCode = misc::MurmurHash::update(hashCode, ruleIndex);
36
108
  hashCode = misc::MurmurHash::update(hashCode, predIndex);
37
109
  hashCode = misc::MurmurHash::update(hashCode, isCtxDependent ? 1 : 0);
38
- hashCode = misc::MurmurHash::finish(hashCode, 3);
110
+ hashCode = misc::MurmurHash::finish(hashCode, 4);
39
111
  return hashCode;
40
112
  }
41
113
 
42
- bool SemanticContext::Predicate::operator == (const SemanticContext &other) const {
43
- if (this == &other)
114
+ bool SemanticContext::Predicate::equals(const SemanticContext &other) const {
115
+ if (this == &other) {
44
116
  return true;
45
-
46
- const Predicate *p = dynamic_cast<const Predicate*>(&other);
47
- if (p == nullptr)
117
+ }
118
+ if (getContextType() != other.getContextType()) {
48
119
  return false;
49
-
50
- return ruleIndex == p->ruleIndex && predIndex == p->predIndex && isCtxDependent == p->isCtxDependent;
120
+ }
121
+ const Predicate &p = downCast<const Predicate&>(other);
122
+ return ruleIndex == p.ruleIndex && predIndex == p.predIndex && isCtxDependent == p.isCtxDependent;
51
123
  }
52
124
 
53
125
  std::string SemanticContext::Predicate::toString() const {
@@ -56,45 +128,36 @@ std::string SemanticContext::Predicate::toString() const {
56
128
 
57
129
  //------------------ PrecedencePredicate -------------------------------------------------------------------------------
58
130
 
59
- SemanticContext::PrecedencePredicate::PrecedencePredicate() : precedence(0) {
60
- }
131
+ SemanticContext::PrecedencePredicate::PrecedencePredicate(int precedence) : SemanticContext(SemanticContextType::PRECEDENCE), precedence(precedence) {}
61
132
 
62
- SemanticContext::PrecedencePredicate::PrecedencePredicate(int precedence) : precedence(precedence) {
63
- }
64
-
65
- bool SemanticContext::PrecedencePredicate::eval(Recognizer *parser, RuleContext *parserCallStack) {
133
+ bool SemanticContext::PrecedencePredicate::eval(Recognizer *parser, RuleContext *parserCallStack) const {
66
134
  return parser->precpred(parserCallStack, precedence);
67
135
  }
68
136
 
69
- Ref<SemanticContext> SemanticContext::PrecedencePredicate::evalPrecedence(Recognizer *parser,
70
- RuleContext *parserCallStack) {
137
+ Ref<const SemanticContext> SemanticContext::PrecedencePredicate::evalPrecedence(Recognizer *parser,
138
+ RuleContext *parserCallStack) const {
71
139
  if (parser->precpred(parserCallStack, precedence)) {
72
140
  return SemanticContext::NONE;
73
141
  }
74
- else {
75
- return nullptr;
76
- }
77
- }
78
-
79
- int SemanticContext::PrecedencePredicate::compareTo(PrecedencePredicate *o) {
80
- return precedence - o->precedence;
142
+ return nullptr;
81
143
  }
82
144
 
83
145
  size_t SemanticContext::PrecedencePredicate::hashCode() const {
84
- size_t hashCode = 1;
85
- hashCode = 31 * hashCode + static_cast<size_t>(precedence);
86
- return hashCode;
146
+ size_t hashCode = misc::MurmurHash::initialize();
147
+ hashCode = misc::MurmurHash::update(hashCode, static_cast<size_t>(getContextType()));
148
+ hashCode = misc::MurmurHash::update(hashCode, static_cast<size_t>(precedence));
149
+ return misc::MurmurHash::finish(hashCode, 2);
87
150
  }
88
151
 
89
- bool SemanticContext::PrecedencePredicate::operator == (const SemanticContext &other) const {
90
- if (this == &other)
152
+ bool SemanticContext::PrecedencePredicate::equals(const SemanticContext &other) const {
153
+ if (this == &other) {
91
154
  return true;
92
-
93
- const PrecedencePredicate *predicate = dynamic_cast<const PrecedencePredicate *>(&other);
94
- if (predicate == nullptr)
155
+ }
156
+ if (getContextType() != other.getContextType()) {
95
157
  return false;
96
-
97
- return precedence == predicate->precedence;
158
+ }
159
+ const PrecedencePredicate &predicate = downCast<const PrecedencePredicate&>(other);
160
+ return precedence == predicate.precedence;
98
161
  }
99
162
 
100
163
  std::string SemanticContext::PrecedencePredicate::toString() const {
@@ -103,61 +166,60 @@ std::string SemanticContext::PrecedencePredicate::toString() const {
103
166
 
104
167
  //------------------ AND -----------------------------------------------------------------------------------------------
105
168
 
106
- SemanticContext::AND::AND(Ref<SemanticContext> const& a, Ref<SemanticContext> const& b) {
107
- Set operands;
169
+ SemanticContext::AND::AND(Ref<const SemanticContext> a, Ref<const SemanticContext> b) : Operator(SemanticContextType::AND) {
170
+ std::unordered_set<const SemanticContext*, SemanticContextHasher, SemanticContextComparer> operands;
171
+ Ref<const SemanticContext::PrecedencePredicate> precedencePredicate;
108
172
 
109
- if (is<AND>(a)) {
110
- for (auto operand : std::dynamic_pointer_cast<AND>(a)->opnds) {
111
- operands.insert(operand);
173
+ _opnds.reserve(predictOperandCapacity(a, b) + 1);
174
+
175
+ if (a->getContextType() == SemanticContextType::AND) {
176
+ for (const auto &operand : downCast<const AND*>(a.get())->getOperands()) {
177
+ insertSemanticContext(operand, operands, _opnds, precedencePredicate, std::less<int>{});
112
178
  }
113
179
  } else {
114
- operands.insert(a);
180
+ insertSemanticContext(std::move(a), operands, _opnds, precedencePredicate, std::less<int>{});
115
181
  }
116
182
 
117
- if (is<AND>(b)) {
118
- for (auto operand : std::dynamic_pointer_cast<AND>(b)->opnds) {
119
- operands.insert(operand);
183
+ if (b->getContextType() == SemanticContextType::AND) {
184
+ for (const auto &operand : downCast<const AND*>(b.get())->getOperands()) {
185
+ insertSemanticContext(operand, operands, _opnds, precedencePredicate, std::less<int>{});
120
186
  }
121
187
  } else {
122
- operands.insert(b);
188
+ insertSemanticContext(std::move(b), operands, _opnds, precedencePredicate, std::less<int>{});
123
189
  }
124
190
 
125
- std::vector<Ref<PrecedencePredicate>> precedencePredicates = filterPrecedencePredicates(operands);
126
-
127
- if (!precedencePredicates.empty()) {
191
+ if (precedencePredicate != nullptr) {
128
192
  // interested in the transition with the lowest precedence
129
- auto predicate = [](Ref<PrecedencePredicate> const& a, Ref<PrecedencePredicate> const& b) {
130
- return a->precedence < b->precedence;
131
- };
132
-
133
- auto reduced = std::min_element(precedencePredicates.begin(), precedencePredicates.end(), predicate);
134
- operands.insert(*reduced);
193
+ auto [existing, inserted] = operands.insert(precedencePredicate.get());
194
+ if (inserted) {
195
+ _opnds.push_back(std::move(precedencePredicate));
196
+ }
135
197
  }
136
-
137
- std::copy(operands.begin(), operands.end(), std::back_inserter(opnds));
138
198
  }
139
199
 
140
- std::vector<Ref<SemanticContext>> SemanticContext::AND::getOperands() const {
141
- return opnds;
200
+ const std::vector<Ref<const SemanticContext>>& SemanticContext::AND::getOperands() const {
201
+ return _opnds;
142
202
  }
143
203
 
144
- bool SemanticContext::AND::operator == (const SemanticContext &other) const {
145
- if (this == &other)
204
+ bool SemanticContext::AND::equals(const SemanticContext &other) const {
205
+ if (this == &other) {
146
206
  return true;
147
-
148
- const AND *context = dynamic_cast<const AND *>(&other);
149
- if (context == nullptr)
207
+ }
208
+ if (getContextType() != other.getContextType()) {
150
209
  return false;
151
-
152
- return Arrays::equals(opnds, context->opnds);
210
+ }
211
+ const AND &context = downCast<const AND&>(other);
212
+ return Arrays::equals(getOperands(), context.getOperands());
153
213
  }
154
214
 
155
215
  size_t SemanticContext::AND::hashCode() const {
156
- return misc::MurmurHash::hashCode(opnds, typeid(AND).hash_code());
216
+ size_t hash = misc::MurmurHash::initialize();
217
+ hash = misc::MurmurHash::update(hash, static_cast<size_t>(getContextType()));
218
+ return misc::MurmurHash::hashCode(getOperands(), hash);
157
219
  }
158
220
 
159
- bool SemanticContext::AND::eval(Recognizer *parser, RuleContext *parserCallStack) {
160
- for (auto opnd : opnds) {
221
+ bool SemanticContext::AND::eval(Recognizer *parser, RuleContext *parserCallStack) const {
222
+ for (const auto &opnd : getOperands()) {
161
223
  if (!opnd->eval(parser, parserCallStack)) {
162
224
  return false;
163
225
  }
@@ -165,18 +227,19 @@ bool SemanticContext::AND::eval(Recognizer *parser, RuleContext *parserCallStack
165
227
  return true;
166
228
  }
167
229
 
168
- Ref<SemanticContext> SemanticContext::AND::evalPrecedence(Recognizer *parser, RuleContext *parserCallStack) {
230
+ Ref<const SemanticContext> SemanticContext::AND::evalPrecedence(Recognizer *parser, RuleContext *parserCallStack) const {
169
231
  bool differs = false;
170
- std::vector<Ref<SemanticContext>> operands;
171
- for (auto context : opnds) {
172
- Ref<SemanticContext> evaluated = context->evalPrecedence(parser, parserCallStack);
232
+ std::vector<Ref<const SemanticContext>> operands;
233
+ for (const auto &context : getOperands()) {
234
+ auto evaluated = context->evalPrecedence(parser, parserCallStack);
173
235
  differs |= (evaluated != context);
174
236
  if (evaluated == nullptr) {
175
237
  // The AND context is false if any element is false.
176
238
  return nullptr;
177
- } else if (evaluated != NONE) {
239
+ }
240
+ if (evaluated != NONE) {
178
241
  // Reduce the result by skipping true elements.
179
- operands.push_back(evaluated);
242
+ operands.push_back(std::move(evaluated));
180
243
  }
181
244
  }
182
245
 
@@ -189,9 +252,9 @@ Ref<SemanticContext> SemanticContext::AND::evalPrecedence(Recognizer *parser, Ru
189
252
  return NONE;
190
253
  }
191
254
 
192
- Ref<SemanticContext> result = operands[0];
255
+ Ref<const SemanticContext> result = std::move(operands[0]);
193
256
  for (size_t i = 1; i < operands.size(); ++i) {
194
- result = SemanticContext::And(result, operands[i]);
257
+ result = SemanticContext::And(std::move(result), std::move(operands[i]));
195
258
  }
196
259
 
197
260
  return result;
@@ -199,7 +262,7 @@ Ref<SemanticContext> SemanticContext::AND::evalPrecedence(Recognizer *parser, Ru
199
262
 
200
263
  std::string SemanticContext::AND::toString() const {
201
264
  std::string tmp;
202
- for (auto var : opnds) {
265
+ for (const auto &var : getOperands()) {
203
266
  tmp += var->toString() + " && ";
204
267
  }
205
268
  return tmp;
@@ -207,59 +270,60 @@ std::string SemanticContext::AND::toString() const {
207
270
 
208
271
  //------------------ OR ------------------------------------------------------------------------------------------------
209
272
 
210
- SemanticContext::OR::OR(Ref<SemanticContext> const& a, Ref<SemanticContext> const& b) {
211
- Set operands;
273
+ SemanticContext::OR::OR(Ref<const SemanticContext> a, Ref<const SemanticContext> b) : Operator(SemanticContextType::OR) {
274
+ std::unordered_set<const SemanticContext*, SemanticContextHasher, SemanticContextComparer> operands;
275
+ Ref<const SemanticContext::PrecedencePredicate> precedencePredicate;
276
+
277
+ _opnds.reserve(predictOperandCapacity(a, b) + 1);
212
278
 
213
- if (is<OR>(a)) {
214
- for (auto operand : std::dynamic_pointer_cast<OR>(a)->opnds) {
215
- operands.insert(operand);
279
+ if (a->getContextType() == SemanticContextType::OR) {
280
+ for (const auto &operand : downCast<const OR*>(a.get())->getOperands()) {
281
+ insertSemanticContext(operand, operands, _opnds, precedencePredicate, std::greater<int>{});
216
282
  }
217
283
  } else {
218
- operands.insert(a);
284
+ insertSemanticContext(std::move(a), operands, _opnds, precedencePredicate, std::greater<int>{});
219
285
  }
220
286
 
221
- if (is<OR>(b)) {
222
- for (auto operand : std::dynamic_pointer_cast<OR>(b)->opnds) {
223
- operands.insert(operand);
287
+ if (b->getContextType() == SemanticContextType::OR) {
288
+ for (const auto &operand : downCast<const OR*>(b.get())->getOperands()) {
289
+ insertSemanticContext(operand, operands, _opnds, precedencePredicate, std::greater<int>{});
224
290
  }
225
291
  } else {
226
- operands.insert(b);
292
+ insertSemanticContext(std::move(b), operands, _opnds, precedencePredicate, std::greater<int>{});
227
293
  }
228
294
 
229
- std::vector<Ref<PrecedencePredicate>> precedencePredicates = filterPrecedencePredicates(operands);
230
- if (!precedencePredicates.empty()) {
295
+ if (precedencePredicate != nullptr) {
231
296
  // interested in the transition with the highest precedence
232
- auto predicate = [](Ref<PrecedencePredicate> const& a, Ref<PrecedencePredicate> const& b) {
233
- return a->precedence < b->precedence;
234
- };
235
- auto reduced = std::max_element(precedencePredicates.begin(), precedencePredicates.end(), predicate);
236
- operands.insert(*reduced);
297
+ auto [existing, inserted] = operands.insert(precedencePredicate.get());
298
+ if (inserted) {
299
+ _opnds.push_back(std::move(precedencePredicate));
300
+ }
237
301
  }
238
-
239
- std::copy(operands.begin(), operands.end(), std::back_inserter(opnds));
240
302
  }
241
303
 
242
- std::vector<Ref<SemanticContext>> SemanticContext::OR::getOperands() const {
243
- return opnds;
304
+ const std::vector<Ref<const SemanticContext>>& SemanticContext::OR::getOperands() const {
305
+ return _opnds;
244
306
  }
245
307
 
246
- bool SemanticContext::OR::operator == (const SemanticContext &other) const {
247
- if (this == &other)
308
+ bool SemanticContext::OR::equals(const SemanticContext &other) const {
309
+ if (this == &other) {
248
310
  return true;
249
-
250
- const OR *context = dynamic_cast<const OR *>(&other);
251
- if (context == nullptr)
311
+ }
312
+ if (getContextType() != other.getContextType()) {
252
313
  return false;
253
-
254
- return Arrays::equals(opnds, context->opnds);
314
+ }
315
+ const OR &context = downCast<const OR&>(other);
316
+ return Arrays::equals(getOperands(), context.getOperands());
255
317
  }
256
318
 
257
319
  size_t SemanticContext::OR::hashCode() const {
258
- return misc::MurmurHash::hashCode(opnds, typeid(OR).hash_code());
320
+ size_t hash = misc::MurmurHash::initialize();
321
+ hash = misc::MurmurHash::update(hash, static_cast<size_t>(getContextType()));
322
+ return misc::MurmurHash::hashCode(getOperands(), hash);
259
323
  }
260
324
 
261
- bool SemanticContext::OR::eval(Recognizer *parser, RuleContext *parserCallStack) {
262
- for (auto opnd : opnds) {
325
+ bool SemanticContext::OR::eval(Recognizer *parser, RuleContext *parserCallStack) const {
326
+ for (const auto &opnd : getOperands()) {
263
327
  if (opnd->eval(parser, parserCallStack)) {
264
328
  return true;
265
329
  }
@@ -267,18 +331,19 @@ bool SemanticContext::OR::eval(Recognizer *parser, RuleContext *parserCallStack)
267
331
  return false;
268
332
  }
269
333
 
270
- Ref<SemanticContext> SemanticContext::OR::evalPrecedence(Recognizer *parser, RuleContext *parserCallStack) {
334
+ Ref<const SemanticContext> SemanticContext::OR::evalPrecedence(Recognizer *parser, RuleContext *parserCallStack) const {
271
335
  bool differs = false;
272
- std::vector<Ref<SemanticContext>> operands;
273
- for (auto context : opnds) {
274
- Ref<SemanticContext> evaluated = context->evalPrecedence(parser, parserCallStack);
336
+ std::vector<Ref<const SemanticContext>> operands;
337
+ for (const auto &context : getOperands()) {
338
+ auto evaluated = context->evalPrecedence(parser, parserCallStack);
275
339
  differs |= (evaluated != context);
276
340
  if (evaluated == NONE) {
277
341
  // The OR context is true if any element is true.
278
342
  return NONE;
279
- } else if (evaluated != nullptr) {
343
+ }
344
+ if (evaluated != nullptr) {
280
345
  // Reduce the result by skipping false elements.
281
- operands.push_back(evaluated);
346
+ operands.push_back(std::move(evaluated));
282
347
  }
283
348
  }
284
349
 
@@ -291,9 +356,9 @@ Ref<SemanticContext> SemanticContext::OR::evalPrecedence(Recognizer *parser, Rul
291
356
  return nullptr;
292
357
  }
293
358
 
294
- Ref<SemanticContext> result = operands[0];
359
+ Ref<const SemanticContext> result = std::move(operands[0]);
295
360
  for (size_t i = 1; i < operands.size(); ++i) {
296
- result = SemanticContext::Or(result, operands[i]);
361
+ result = SemanticContext::Or(std::move(result), std::move(operands[i]));
297
362
  }
298
363
 
299
364
  return result;
@@ -301,7 +366,7 @@ Ref<SemanticContext> SemanticContext::OR::evalPrecedence(Recognizer *parser, Rul
301
366
 
302
367
  std::string SemanticContext::OR::toString() const {
303
368
  std::string tmp;
304
- for(auto var : opnds) {
369
+ for(const auto &var : getOperands()) {
305
370
  tmp += var->toString() + " || ";
306
371
  }
307
372
  return tmp;
@@ -309,20 +374,13 @@ std::string SemanticContext::OR::toString() const {
309
374
 
310
375
  //------------------ SemanticContext -----------------------------------------------------------------------------------
311
376
 
312
- const Ref<SemanticContext> SemanticContext::NONE = std::make_shared<Predicate>(INVALID_INDEX, INVALID_INDEX, false);
313
-
314
- SemanticContext::~SemanticContext() {
315
- }
377
+ const Ref<const SemanticContext> SemanticContext::NONE = std::make_shared<Predicate>(INVALID_INDEX, INVALID_INDEX, false);
316
378
 
317
- bool SemanticContext::operator != (const SemanticContext &other) const {
318
- return !(*this == other);
319
- }
320
-
321
- Ref<SemanticContext> SemanticContext::evalPrecedence(Recognizer * /*parser*/, RuleContext * /*parserCallStack*/) {
379
+ Ref<const SemanticContext> SemanticContext::evalPrecedence(Recognizer * /*parser*/, RuleContext * /*parserCallStack*/) const {
322
380
  return shared_from_this();
323
381
  }
324
382
 
325
- Ref<SemanticContext> SemanticContext::And(Ref<SemanticContext> const& a, Ref<SemanticContext> const& b) {
383
+ Ref<const SemanticContext> SemanticContext::And(Ref<const SemanticContext> a, Ref<const SemanticContext> b) {
326
384
  if (!a || a == NONE) {
327
385
  return b;
328
386
  }
@@ -331,15 +389,15 @@ Ref<SemanticContext> SemanticContext::And(Ref<SemanticContext> const& a, Ref<Sem
331
389
  return a;
332
390
  }
333
391
 
334
- Ref<AND> result = std::make_shared<AND>(a, b);
335
- if (result->opnds.size() == 1) {
336
- return result->opnds[0];
392
+ Ref<AND> result = std::make_shared<AND>(std::move(a), std::move(b));
393
+ if (result->getOperands().size() == 1) {
394
+ return result->getOperands()[0];
337
395
  }
338
396
 
339
397
  return result;
340
398
  }
341
399
 
342
- Ref<SemanticContext> SemanticContext::Or(Ref<SemanticContext> const& a, Ref<SemanticContext> const& b) {
400
+ Ref<const SemanticContext> SemanticContext::Or(Ref<const SemanticContext> a, Ref<const SemanticContext> b) {
343
401
  if (!a) {
344
402
  return b;
345
403
  }
@@ -351,27 +409,10 @@ Ref<SemanticContext> SemanticContext::Or(Ref<SemanticContext> const& a, Ref<Sema
351
409
  return NONE;
352
410
  }
353
411
 
354
- Ref<OR> result = std::make_shared<OR>(a, b);
355
- if (result->opnds.size() == 1) {
356
- return result->opnds[0];
412
+ Ref<OR> result = std::make_shared<OR>(std::move(a), std::move(b));
413
+ if (result->getOperands().size() == 1) {
414
+ return result->getOperands()[0];
357
415
  }
358
416
 
359
417
  return result;
360
418
  }
361
-
362
- std::vector<Ref<SemanticContext::PrecedencePredicate>> SemanticContext::filterPrecedencePredicates(const Set &collection) {
363
- std::vector<Ref<SemanticContext::PrecedencePredicate>> result;
364
- for (auto context : collection) {
365
- if (antlrcpp::is<PrecedencePredicate>(context)) {
366
- result.push_back(std::dynamic_pointer_cast<PrecedencePredicate>(context));
367
- }
368
- }
369
-
370
- return result;
371
- }
372
-
373
-
374
- //------------------ Operator -----------------------------------------------------------------------------------------
375
-
376
- SemanticContext::Operator::~Operator() {
377
- }