]> gitweb.ps.run Git - toc/blob - antlr4-cpp-runtime-4.9.2-source/runtime/src/atn/ATNSimulator.cpp
add antlr source code and ReadMe
[toc] / antlr4-cpp-runtime-4.9.2-source / runtime / src / atn / ATNSimulator.cpp
1 /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.
2  * Use of this file is governed by the BSD 3-clause license that
3  * can be found in the LICENSE.txt file in the project root.
4  */
5
6 #include "atn/ATNType.h"
7 #include "atn/ATNConfigSet.h"
8 #include "dfa/DFAState.h"
9 #include "atn/ATNDeserializer.h"
10 #include "atn/EmptyPredictionContext.h"
11
12 #include "atn/ATNSimulator.h"
13
14 using namespace antlr4;
15 using namespace antlr4::dfa;
16 using namespace antlr4::atn;
17
18 const Ref<DFAState> ATNSimulator::ERROR = std::make_shared<DFAState>(INT32_MAX);
19 antlrcpp::SingleWriteMultipleReadLock ATNSimulator::_stateLock;
20 antlrcpp::SingleWriteMultipleReadLock ATNSimulator::_edgeLock;
21
22 ATNSimulator::ATNSimulator(const ATN &atn, PredictionContextCache &sharedContextCache)
23 : atn(atn), _sharedContextCache(sharedContextCache) {
24 }
25
26 ATNSimulator::~ATNSimulator() {
27 }
28
29 void ATNSimulator::clearDFA() {
30   throw UnsupportedOperationException("This ATN simulator does not support clearing the DFA.");
31 }
32
33 PredictionContextCache& ATNSimulator::getSharedContextCache() {
34   return _sharedContextCache;
35 }
36
37 Ref<PredictionContext> ATNSimulator::getCachedContext(Ref<PredictionContext> const& context) {
38   // This function must only be called with an active state lock, as we are going to change a shared structure.
39   std::map<Ref<PredictionContext>, Ref<PredictionContext>> visited;
40   return PredictionContext::getCachedContext(context, _sharedContextCache, visited);
41 }
42
43 ATN ATNSimulator::deserialize(const std::vector<uint16_t> &data) {
44   ATNDeserializer deserializer;
45   return deserializer.deserialize(data);
46 }
47
48 void ATNSimulator::checkCondition(bool condition) {
49   ATNDeserializer::checkCondition(condition);
50 }
51
52 void ATNSimulator::checkCondition(bool condition, const std::string &message) {
53   ATNDeserializer::checkCondition(condition, message);
54 }
55
56 Transition *ATNSimulator::edgeFactory(const ATN &atn, int type, int src, int trg, int arg1, int arg2, int arg3,
57                                       const std::vector<misc::IntervalSet> &sets) {
58   return ATNDeserializer::edgeFactory(atn, type, src, trg, arg1, arg2, arg3, sets);
59 }
60
61 ATNState *ATNSimulator::stateFactory(int type, int ruleIndex) {
62   return ATNDeserializer::stateFactory(type, ruleIndex);
63 }