From 611728a3806d6a8c9fe44a538d34b448784986c1 Mon Sep 17 00:00:00 2001 From: Sam Harwell Date: Mon, 20 Feb 2012 18:51:26 -0600 Subject: [PATCH] Update testPerformance to show information about DFA states in the lexer --- .../v4/runtime/atn/LexerATNSimulator.java | 2 +- .../org/antlr/v4/test/TestPerformance.java | 25 ++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/runtime/Java/src/org/antlr/v4/runtime/atn/LexerATNSimulator.java b/runtime/Java/src/org/antlr/v4/runtime/atn/LexerATNSimulator.java index 3000c99b5..8aef0e84d 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/atn/LexerATNSimulator.java +++ b/runtime/Java/src/org/antlr/v4/runtime/atn/LexerATNSimulator.java @@ -114,7 +114,7 @@ public class LexerATNSimulator extends ATNSimulator { protected int charPositionInLine = 0; @NotNull - protected DFA[] dfa; + public final DFA[] dfa; protected int mode = Lexer.DEFAULT_MODE; /** Used during DFA/ATN exec to record the most recent accept configuration info */ diff --git a/tool/test/org/antlr/v4/test/TestPerformance.java b/tool/test/org/antlr/v4/test/TestPerformance.java index 92a6e5a87..a41543415 100644 --- a/tool/test/org/antlr/v4/test/TestPerformance.java +++ b/tool/test/org/antlr/v4/test/TestPerformance.java @@ -284,6 +284,29 @@ public class TestPerformance extends BaseTest { tokenCount, System.currentTimeMillis() - startTime); + final LexerATNSimulator lexerInterpreter = sharedLexer.getInterpreter(); + final DFA[] modeToDFA = lexerInterpreter.dfa; + if (SHOW_DFA_STATE_STATS) { + int states = 0; + int configs = 0; + Set uniqueConfigs = new HashSet(); + + for (int i = 0; i < modeToDFA.length; i++) { + DFA dfa = modeToDFA[i]; + if (dfa == null || dfa.states == null) { + continue; + } + + states += dfa.states.size(); + for (DFAState state : dfa.states.values()) { + configs += state.configset.size(); + uniqueConfigs.addAll(state.configset); + } + } + + System.out.format("There are %d lexer DFAState instances, %d configs (%d unique).\n", states, configs, uniqueConfigs.size()); + } + if (RUN_PARSER) { // make sure the individual DFAState objects actually have unique ATNConfig arrays final ParserATNSimulator interpreter = sharedParser.getInterpreter(); @@ -307,7 +330,7 @@ public class TestPerformance extends BaseTest { } } - System.out.format("There are %d DFAState instances, %d configs (%d unique).\n", states, configs, uniqueConfigs.size()); + System.out.format("There are %d parser DFAState instances, %d configs (%d unique).\n", states, configs, uniqueConfigs.size()); } int localDfaCount = 0;