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.
8 #include "atn/ContextSensitivityInfo.h"
9 #include "atn/AmbiguityInfo.h"
10 #include "atn/PredicateEvalInfo.h"
11 #include "atn/ErrorInfo.h"
16 class LookaheadEventInfo;
19 /// This class contains profiling gathered for a particular decision.
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>
31 class ANTLR4CPP_PUBLIC DecisionInfo {
34 /// The decision number, which is an index into <seealso cref="ATN#decisionToState"/>.
36 const size_t decision;
39 /// The total number of times <seealso cref="ParserATNSimulator#adaptivePredict"/> was
40 /// invoked for this decision.
42 long long invocations = 0;
45 /// The total time spent in <seealso cref="ParserATNSimulator#adaptivePredict"/> for
46 /// this decision, in nanoseconds.
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>
58 long long timeInPrediction = 0;
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.
66 long long SLL_TotalLook = 0;
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.
73 long long SLL_MinLook = 0;
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.
80 long long SLL_MaxLook = 0;
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;
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
91 long long LL_TotalLook = 0;
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.
100 long long LL_MinLook = 0;
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.
109 long long LL_MaxLook = 0;
112 /// Gets the <seealso cref="LookaheadEventInfo"/> associated with the event where the
113 /// <seealso cref="#LL_MaxLook"/> value was set.
115 Ref<LookaheadEventInfo> LL_MaxLookEvent;
118 /// A collection of <seealso cref="ContextSensitivityInfo"/> instances describing the
119 /// context sensitivities encountered during LL prediction for this decision.
121 /// <seealso cref= ContextSensitivityInfo </seealso>
122 std::vector<ContextSensitivityInfo> contextSensitivities;
125 /// A collection of <seealso cref="ErrorInfo"/> instances describing the parse errors
126 /// identified during calls to <seealso cref="ParserATNSimulator#adaptivePredict"/> for
129 /// <seealso cref= ErrorInfo </seealso>
130 std::vector<ErrorInfo> errors;
133 /// A collection of <seealso cref="AmbiguityInfo"/> instances describing the
134 /// ambiguities encountered during LL prediction for this decision.
136 /// <seealso cref= AmbiguityInfo </seealso>
137 std::vector<AmbiguityInfo> ambiguities;
140 /// A collection of <seealso cref="PredicateEvalInfo"/> instances describing the
141 /// results of evaluating individual predicates during prediction for this
144 /// <seealso cref= PredicateEvalInfo </seealso>
145 std::vector<PredicateEvalInfo> predicateEvals;
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.
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>
159 /// <seealso cref= #SLL_ATNTransitions </seealso>
160 /// <seealso cref= ParserATNSimulator#computeTargetState </seealso>
161 /// <seealso cref= LexerATNSimulator#computeTargetState </seealso>
162 long long SLL_ATNTransitions = 0;
165 /// The total number of DFA transitions required during SLL prediction for
168 /// <para>If the ATN simulator implementation does not use DFA caching for SLL
169 /// transitions, this value will be 0.</para>
171 /// <seealso cref= ParserATNSimulator#getExistingTargetState </seealso>
172 /// <seealso cref= LexerATNSimulator#getExistingTargetState </seealso>
173 long long SLL_DFATransitions = 0;
176 /// Gets the total number of times SLL prediction completed in a conflict
177 /// state, resulting in fallback to LL prediction.
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>
186 long long LL_Fallback = 0;
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.
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>
200 /// <seealso cref= #LL_DFATransitions </seealso>
201 /// <seealso cref= ParserATNSimulator#computeTargetState </seealso>
202 /// <seealso cref= LexerATNSimulator#computeTargetState </seealso>
203 long long LL_ATNTransitions = 0;
206 /// The total number of DFA transitions required during LL prediction for
209 /// <para>If the ATN simulator implementation does not use DFA caching for LL
210 /// transitions, this value will be 0.</para>
212 /// <seealso cref= ParserATNSimulator#getExistingTargetState </seealso>
213 /// <seealso cref= LexerATNSimulator#getExistingTargetState </seealso>
214 long long LL_DFATransitions = 0;
217 /// Constructs a new instance of the <seealso cref="DecisionInfo"/> class to contain
218 /// statistics for a particular decision.
220 /// <param name="decision"> The decision number </param>
221 DecisionInfo(size_t decision);
223 std::string toString() const;
227 } // namespace antlr4