]> gitweb.ps.run Git - toc/blob - antlr4-cpp-runtime-4.9.2-source/runtime/src/atn/ProfilingATNSimulator.h
add antlr source code and ReadMe
[toc] / antlr4-cpp-runtime-4.9.2-source / runtime / src / atn / ProfilingATNSimulator.h
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 #pragma once
7
8 #include "atn/ParserATNSimulator.h"
9 #include "atn/DecisionInfo.h"
10
11 namespace antlr4 {
12 namespace atn {
13
14   class ANTLR4CPP_PUBLIC ProfilingATNSimulator : public ParserATNSimulator {
15   public:
16     ProfilingATNSimulator(Parser *parser);
17
18     virtual size_t adaptivePredict(TokenStream *input, size_t decision, ParserRuleContext *outerContext) override;
19
20     virtual std::vector<DecisionInfo> getDecisionInfo() const;
21     virtual dfa::DFAState* getCurrentState() const;
22
23   protected:
24     std::vector<DecisionInfo> _decisions;
25
26     int _sllStopIndex = 0;
27     int _llStopIndex = 0;
28
29     size_t _currentDecision = 0;
30     dfa::DFAState *_currentState;
31
32     /// <summary>
33     /// At the point of LL failover, we record how SLL would resolve the conflict so that
34     ///  we can determine whether or not a decision / input pair is context-sensitive.
35     ///  If LL gives a different result than SLL's predicted alternative, we have a
36     ///  context sensitivity for sure. The converse is not necessarily true, however.
37     ///  It's possible that after conflict resolution chooses minimum alternatives,
38     ///  SLL could get the same answer as LL. Regardless of whether or not the result indicates
39     ///  an ambiguity, it is not treated as a context sensitivity because LL prediction
40     ///  was not required in order to produce a correct prediction for this decision and input sequence.
41     ///  It may in fact still be a context sensitivity but we don't know by looking at the
42     ///  minimum alternatives for the current input.
43     /// </summary>
44     size_t conflictingAltResolvedBySLL = 0;
45
46     virtual dfa::DFAState* getExistingTargetState(dfa::DFAState *previousD, size_t t) override;
47     virtual dfa::DFAState* computeTargetState(dfa::DFA &dfa, dfa::DFAState *previousD, size_t t) override;
48     virtual std::unique_ptr<ATNConfigSet> computeReachSet(ATNConfigSet *closure, size_t t, bool fullCtx) override;
49     virtual bool evalSemanticContext(Ref<SemanticContext> const& pred, ParserRuleContext *parserCallStack,
50                                      size_t alt, bool fullCtx) override;
51     virtual void reportAttemptingFullContext(dfa::DFA &dfa, const antlrcpp::BitSet &conflictingAlts, ATNConfigSet *configs,
52                                              size_t startIndex, size_t stopIndex) override;
53     virtual void reportContextSensitivity(dfa::DFA &dfa, size_t prediction, ATNConfigSet *configs,
54                                           size_t startIndex, size_t stopIndex) override;
55     virtual void reportAmbiguity(dfa::DFA &dfa, dfa::DFAState *D, size_t startIndex, size_t stopIndex, bool exact,
56                                  const antlrcpp::BitSet &ambigAlts, ATNConfigSet *configs) override;
57   };
58
59 } // namespace atn
60 } // namespace antlr4