From af59f354818d0242e2c5fcc332a6c454d604d0eb Mon Sep 17 00:00:00 2001 From: Sam Harwell Date: Mon, 13 May 2013 20:27:18 -0500 Subject: [PATCH] Count full context transitions in statistics --- tool/test/org/antlr/v4/test/TestPerformance.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tool/test/org/antlr/v4/test/TestPerformance.java b/tool/test/org/antlr/v4/test/TestPerformance.java index 02074f72b..70b7e6d6f 100644 --- a/tool/test/org/antlr/v4/test/TestPerformance.java +++ b/tool/test/org/antlr/v4/test/TestPerformance.java @@ -1260,6 +1260,7 @@ public class TestPerformance extends BaseTest { public final int parserDFASize; public final long parserTotalTransitions; public final long parserComputedTransitions; + public final long parserFullContextTransitions; public FileParseResult(String sourceName, int checksum, @Nullable ParseTree parseTree, int tokenCount, long startTime, Lexer lexer, Parser parser) { this.sourceName = sourceName; @@ -1298,9 +1299,11 @@ public class TestPerformance extends BaseTest { if (interpreter instanceof StatisticsParserATNSimulator) { parserTotalTransitions = ((StatisticsParserATNSimulator)interpreter).totalTransitions; parserComputedTransitions = ((StatisticsParserATNSimulator)interpreter).computedTransitions; + parserFullContextTransitions = ((StatisticsParserATNSimulator)interpreter).fullContextTransitions; } else { parserTotalTransitions = 0; parserComputedTransitions = 0; + parserFullContextTransitions = 0; } int dfaSize = 0; @@ -1315,6 +1318,7 @@ public class TestPerformance extends BaseTest { parserDFASize = 0; parserTotalTransitions = 0; parserComputedTransitions = 0; + parserFullContextTransitions = 0; } } } @@ -1349,6 +1353,7 @@ public class TestPerformance extends BaseTest { public long totalTransitions; public long computedTransitions; + public long fullContextTransitions; public StatisticsParserATNSimulator(ATN atn, DFA[] decisionToDFA, PredictionContextCache sharedContextCache) { super(atn, decisionToDFA, sharedContextCache); @@ -1369,6 +1374,17 @@ public class TestPerformance extends BaseTest { computedTransitions++; return super.computeTargetState(dfa, previousD, t); } + + @Override + protected ATNConfigSet computeReachSet(ATNConfigSet closure, int t, boolean fullCtx) { + if (fullCtx) { + totalTransitions++; + computedTransitions++; + fullContextTransitions++; + } + + return super.computeReachSet(closure, t, fullCtx); + } } private static class DescriptiveErrorListener extends BaseErrorListener {