org.antlr.v4.runtime.atn.ParseInfo Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of antlr4-runtime Show documentation
Show all versions of antlr4-runtime Show documentation
The ANTLR 4 Runtime (Optimized)
/*
* Copyright (c) 2012 The ANTLR Project. All rights reserved.
* Use of this file is governed by the BSD-3-Clause license that
* can be found in the LICENSE.txt file in the project root.
*/
package org.antlr.v4.runtime.atn;
import org.antlr.v4.runtime.dfa.DFA;
import org.antlr.v4.runtime.misc.NotNull;
import java.util.ArrayList;
import java.util.List;
/**
* This class provides access to specific and aggregate statistics gathered
* during profiling of a parser.
*
* @since 4.3
*/
public class ParseInfo {
protected final ProfilingATNSimulator atnSimulator;
public ParseInfo(@NotNull ProfilingATNSimulator atnSimulator) {
this.atnSimulator = atnSimulator;
}
/**
* Gets an array of {@link DecisionInfo} instances containing the profiling
* information gathered for each decision in the ATN.
*
* @return An array of {@link DecisionInfo} instances, indexed by decision
* number.
*/
@NotNull
public DecisionInfo[] getDecisionInfo() {
return atnSimulator.getDecisionInfo();
}
/**
* Gets the decision numbers for decisions that required one or more
* full-context predictions during parsing. These are decisions for which
* {@link DecisionInfo#LL_Fallback} is non-zero.
*
* @return A list of decision numbers which required one or more
* full-context predictions during parsing.
*/
@NotNull
public List getLLDecisions() {
DecisionInfo[] decisions = atnSimulator.getDecisionInfo();
List LL = new ArrayList();
for (int i=0; i0 ) LL.add(i);
}
return LL;
}
/**
* Gets the total time spent during prediction across all decisions made
* during parsing. This value is the sum of
* {@link DecisionInfo#timeInPrediction} for all decisions.
*/
public long getTotalTimeInPrediction() {
DecisionInfo[] decisions = atnSimulator.getDecisionInfo();
long t = 0;
for (int i=0; i
* This value is the sum of {@link #getTotalSLLATNLookaheadOps} and
* {@link #getTotalLLATNLookaheadOps}.
*/
public long getTotalATNLookaheadOps() {
DecisionInfo[] decisions = atnSimulator.getDecisionInfo();
long k = 0;
for (int i = 0; i < decisions.length; i++) {
k += decisions[i].SLL_ATNTransitions;
k += decisions[i].LL_ATNTransitions;
}
return k;
}
/**
* Gets the total number of DFA states stored in the DFA cache for all
* decisions in the ATN.
*/
public int getDFASize() {
int n = 0;
DFA[] decisionToDFA = atnSimulator.atn.decisionToDFA;
for (int i = 0; i < decisionToDFA.length; i++) {
n += getDFASize(i);
}
return n;
}
/**
* Gets the total number of DFA states stored in the DFA cache for a
* particular decision.
*/
public int getDFASize(int decision) {
DFA decisionToDFA = atnSimulator.atn.decisionToDFA[decision];
return decisionToDFA.states.size();
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy