]> gitweb.ps.run Git - toc/blob - antlr4-cpp-runtime-4.9.2-source/runtime/src/atn/DecisionInfo.h
add antlr source code and ReadMe
[toc] / antlr4-cpp-runtime-4.9.2-source / runtime / src / atn / DecisionInfo.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/ContextSensitivityInfo.h"
9 #include "atn/AmbiguityInfo.h"
10 #include "atn/PredicateEvalInfo.h"
11 #include "atn/ErrorInfo.h"
12
13 namespace antlr4 {
14 namespace atn {
15
16   class LookaheadEventInfo;
17
18   /// <summary>
19   /// This class contains profiling gathered for a particular decision.
20   ///
21   /// <para>
22   /// Parsing performance in ANTLR 4 is heavily influenced by both static factors
23   /// (e.g. the form of the rules in the grammar) and dynamic factors (e.g. the
24   /// choice of input and the state of the DFA cache at the time profiling
25   /// operations are started). For best results, gather and use aggregate
26   /// statistics from a large sample of inputs representing the inputs expected in
27   /// production before using the results to make changes in the grammar.</para>
28   ///
29   /// @since 4.3
30   /// </summary>
31   class ANTLR4CPP_PUBLIC DecisionInfo {
32   public:
33     /// <summary>
34     /// The decision number, which is an index into <seealso cref="ATN#decisionToState"/>.
35     /// </summary>
36     const size_t decision;
37
38     /// <summary>
39     /// The total number of times <seealso cref="ParserATNSimulator#adaptivePredict"/> was
40     /// invoked for this decision.
41     /// </summary>
42     long long invocations = 0;
43
44     /// <summary>
45     /// The total time spent in <seealso cref="ParserATNSimulator#adaptivePredict"/> for
46     /// this decision, in nanoseconds.
47     ///
48     /// <para>
49     /// The value of this field contains the sum of differential results obtained
50     /// by <seealso cref="System#nanoTime()"/>, and is not adjusted to compensate for JIT
51     /// and/or garbage collection overhead. For best accuracy, use a modern JVM
52     /// implementation that provides precise results from
53     /// <seealso cref="System#nanoTime()"/>, and perform profiling in a separate process
54     /// which is warmed up by parsing the input prior to profiling. If desired,
55     /// call <seealso cref="ATNSimulator#clearDFA"/> to reset the DFA cache to its initial
56     /// state before starting the profiling measurement pass.</para>
57     /// </summary>
58     long long timeInPrediction = 0;
59
60     /// <summary>
61     /// The sum of the lookahead required for SLL prediction for this decision.
62     /// Note that SLL prediction is used before LL prediction for performance
63     /// reasons even when <seealso cref="PredictionMode#LL"/> or
64     /// <seealso cref="PredictionMode#LL_EXACT_AMBIG_DETECTION"/> is used.
65     /// </summary>
66     long long SLL_TotalLook = 0;
67
68     /// <summary>
69     /// Gets the minimum lookahead required for any single SLL prediction to
70     /// complete for this decision, by reaching a unique prediction, reaching an
71     /// SLL conflict state, or encountering a syntax error.
72     /// </summary>
73     long long SLL_MinLook = 0;
74
75     /// <summary>
76     /// Gets the maximum lookahead required for any single SLL prediction to
77     /// complete for this decision, by reaching a unique prediction, reaching an
78     /// SLL conflict state, or encountering a syntax error.
79     /// </summary>
80     long long SLL_MaxLook = 0;
81
82     /// Gets the <seealso cref="LookaheadEventInfo"/> associated with the event where the
83     /// <seealso cref="#SLL_MaxLook"/> value was set.
84     Ref<LookaheadEventInfo> SLL_MaxLookEvent;
85
86     /// <summary>
87     /// The sum of the lookahead required for LL prediction for this decision.
88     /// Note that LL prediction is only used when SLL prediction reaches a
89     /// conflict state.
90     /// </summary>
91     long long LL_TotalLook = 0;
92
93     /// <summary>
94     /// Gets the minimum lookahead required for any single LL prediction to
95     /// complete for this decision. An LL prediction completes when the algorithm
96     /// reaches a unique prediction, a conflict state (for
97     /// <seealso cref="PredictionMode#LL"/>, an ambiguity state (for
98     /// <seealso cref="PredictionMode#LL_EXACT_AMBIG_DETECTION"/>, or a syntax error.
99     /// </summary>
100     long long LL_MinLook = 0;
101
102     /// <summary>
103     /// Gets the maximum lookahead required for any single LL prediction to
104     /// complete for this decision. An LL prediction completes when the algorithm
105     /// reaches a unique prediction, a conflict state (for
106     /// <seealso cref="PredictionMode#LL"/>, an ambiguity state (for
107     /// <seealso cref="PredictionMode#LL_EXACT_AMBIG_DETECTION"/>, or a syntax error.
108     /// </summary>
109     long long LL_MaxLook = 0;
110
111     /// <summary>
112     /// Gets the <seealso cref="LookaheadEventInfo"/> associated with the event where the
113     /// <seealso cref="#LL_MaxLook"/> value was set.
114     /// </summary>
115     Ref<LookaheadEventInfo> LL_MaxLookEvent;
116
117     /// <summary>
118     /// A collection of <seealso cref="ContextSensitivityInfo"/> instances describing the
119     /// context sensitivities encountered during LL prediction for this decision.
120     /// </summary>
121     /// <seealso cref= ContextSensitivityInfo </seealso>
122     std::vector<ContextSensitivityInfo> contextSensitivities;
123
124     /// <summary>
125     /// A collection of <seealso cref="ErrorInfo"/> instances describing the parse errors
126     /// identified during calls to <seealso cref="ParserATNSimulator#adaptivePredict"/> for
127     /// this decision.
128     /// </summary>
129     /// <seealso cref= ErrorInfo </seealso>
130     std::vector<ErrorInfo> errors;
131
132     /// <summary>
133     /// A collection of <seealso cref="AmbiguityInfo"/> instances describing the
134     /// ambiguities encountered during LL prediction for this decision.
135     /// </summary>
136     /// <seealso cref= AmbiguityInfo </seealso>
137     std::vector<AmbiguityInfo> ambiguities;
138
139     /// <summary>
140     /// A collection of <seealso cref="PredicateEvalInfo"/> instances describing the
141     /// results of evaluating individual predicates during prediction for this
142     /// decision.
143     /// </summary>
144     /// <seealso cref= PredicateEvalInfo </seealso>
145     std::vector<PredicateEvalInfo> predicateEvals;
146
147     /// <summary>
148     /// The total number of ATN transitions required during SLL prediction for
149     /// this decision. An ATN transition is determined by the number of times the
150     /// DFA does not contain an edge that is required for prediction, resulting
151     /// in on-the-fly computation of that edge.
152     ///
153     /// <para>
154     /// If DFA caching of SLL transitions is employed by the implementation, ATN
155     /// computation may cache the computed edge for efficient lookup during
156     /// future parsing of this decision. Otherwise, the SLL parsing algorithm
157     /// will use ATN transitions exclusively.</para>
158     /// </summary>
159     /// <seealso cref= #SLL_ATNTransitions </seealso>
160     /// <seealso cref= ParserATNSimulator#computeTargetState </seealso>
161     /// <seealso cref= LexerATNSimulator#computeTargetState </seealso>
162     long long SLL_ATNTransitions = 0;
163
164     /// <summary>
165     /// The total number of DFA transitions required during SLL prediction for
166     /// this decision.
167     ///
168     /// <para>If the ATN simulator implementation does not use DFA caching for SLL
169     /// transitions, this value will be 0.</para>
170     /// </summary>
171     /// <seealso cref= ParserATNSimulator#getExistingTargetState </seealso>
172     /// <seealso cref= LexerATNSimulator#getExistingTargetState </seealso>
173     long long SLL_DFATransitions = 0;
174
175     /// <summary>
176     /// Gets the total number of times SLL prediction completed in a conflict
177     /// state, resulting in fallback to LL prediction.
178     ///
179     /// <para>Note that this value is not related to whether or not
180     /// <seealso cref="PredictionMode#SLL"/> may be used successfully with a particular
181     /// grammar. If the ambiguity resolution algorithm applied to the SLL
182     /// conflicts for this decision produce the same result as LL prediction for
183     /// this decision, <seealso cref="PredictionMode#SLL"/> would produce the same overall
184     /// parsing result as <seealso cref="PredictionMode#LL"/>.</para>
185     /// </summary>
186     long long LL_Fallback = 0;
187
188     /// <summary>
189     /// The total number of ATN transitions required during LL prediction for
190     /// this decision. An ATN transition is determined by the number of times the
191     /// DFA does not contain an edge that is required for prediction, resulting
192     /// in on-the-fly computation of that edge.
193     ///
194     /// <para>
195     /// If DFA caching of LL transitions is employed by the implementation, ATN
196     /// computation may cache the computed edge for efficient lookup during
197     /// future parsing of this decision. Otherwise, the LL parsing algorithm will
198     /// use ATN transitions exclusively.</para>
199     /// </summary>
200     /// <seealso cref= #LL_DFATransitions </seealso>
201     /// <seealso cref= ParserATNSimulator#computeTargetState </seealso>
202     /// <seealso cref= LexerATNSimulator#computeTargetState </seealso>
203     long long LL_ATNTransitions = 0;
204
205     /// <summary>
206     /// The total number of DFA transitions required during LL prediction for
207     /// this decision.
208     ///
209     /// <para>If the ATN simulator implementation does not use DFA caching for LL
210     /// transitions, this value will be 0.</para>
211     /// </summary>
212     /// <seealso cref= ParserATNSimulator#getExistingTargetState </seealso>
213     /// <seealso cref= LexerATNSimulator#getExistingTargetState </seealso>
214     long long LL_DFATransitions = 0;
215
216     /// <summary>
217     /// Constructs a new instance of the <seealso cref="DecisionInfo"/> class to contain
218     /// statistics for a particular decision.
219     /// </summary>
220     /// <param name="decision"> The decision number </param>
221     DecisionInfo(size_t decision);
222
223     std::string toString() const;
224   };
225
226 } // namespace atn
227 } // namespace antlr4