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.
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"
12 #include "atn/ATNSimulator.h"
14 using namespace antlr4;
15 using namespace antlr4::dfa;
16 using namespace antlr4::atn;
18 const Ref<DFAState> ATNSimulator::ERROR = std::make_shared<DFAState>(INT32_MAX);
19 antlrcpp::SingleWriteMultipleReadLock ATNSimulator::_stateLock;
20 antlrcpp::SingleWriteMultipleReadLock ATNSimulator::_edgeLock;
22 ATNSimulator::ATNSimulator(const ATN &atn, PredictionContextCache &sharedContextCache)
23 : atn(atn), _sharedContextCache(sharedContextCache) {
26 ATNSimulator::~ATNSimulator() {
29 void ATNSimulator::clearDFA() {
30 throw UnsupportedOperationException("This ATN simulator does not support clearing the DFA.");
33 PredictionContextCache& ATNSimulator::getSharedContextCache() {
34 return _sharedContextCache;
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);
43 ATN ATNSimulator::deserialize(const std::vector<uint16_t> &data) {
44 ATNDeserializer deserializer;
45 return deserializer.deserialize(data);
48 void ATNSimulator::checkCondition(bool condition) {
49 ATNDeserializer::checkCondition(condition);
52 void ATNSimulator::checkCondition(bool condition, const std::string &message) {
53 ATNDeserializer::checkCondition(condition, message);
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);
61 ATNState *ATNSimulator::stateFactory(int type, int ruleIndex) {
62 return ATNDeserializer::stateFactory(type, ruleIndex);