From 6c23a9604647077c4eb63eab121900f3ece254c5 Mon Sep 17 00:00:00 2001 From: Sam Harwell Date: Thu, 3 Jan 2013 02:41:02 -0600 Subject: [PATCH] Always update ATNConfigSet.hasSemanticContext and ATNConfigSet.dipsIntoOuterContext when adding configurations to the set; remove unnecessary manual updates --- .../src/org/antlr/v4/runtime/atn/ATNConfigSet.java | 14 +++++++++++--- .../antlr/v4/runtime/atn/ParserATNSimulator.java | 7 ------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/runtime/Java/src/org/antlr/v4/runtime/atn/ATNConfigSet.java b/runtime/Java/src/org/antlr/v4/runtime/atn/ATNConfigSet.java index 513880af8..344c6ecac 100755 --- a/runtime/Java/src/org/antlr/v4/runtime/atn/ATNConfigSet.java +++ b/runtime/Java/src/org/antlr/v4/runtime/atn/ATNConfigSet.java @@ -33,6 +33,8 @@ package org.antlr.v4.runtime.atn; import org.antlr.v4.runtime.misc.AbstractEqualityComparator; import org.antlr.v4.runtime.misc.Array2DHashSet; import org.antlr.v4.runtime.misc.DoubleKeyMap; +import org.antlr.v4.runtime.misc.NotNull; +import org.antlr.v4.runtime.misc.Nullable; import java.util.ArrayList; import java.util.BitSet; @@ -317,22 +319,28 @@ public class ATNConfigSet implements Set { } @Override - public boolean add(ATNConfig config) { + public boolean add(@NotNull ATNConfig config) { return add(config, null); } /** Adding a new config means merging contexts with existing configs for * (s, i, pi, _) * We use (s,i,pi) as key + *

+ * This method updates {@link #dipsIntoOuterContext} and + * {@link #hasSemanticContext} when necessary. */ public boolean add( - ATNConfig config, - DoubleKeyMap mergeCache) + @NotNull ATNConfig config, + @Nullable DoubleKeyMap mergeCache) { if ( readonly ) throw new IllegalStateException("This set is readonly"); if ( config.semanticContext!=SemanticContext.NONE ) { hasSemanticContext = true; } + if (config.reachesIntoOuterContext > 0) { + dipsIntoOuterContext = true; + } ATNConfig existing = configLookup.getOrAdd(config); if ( existing==config ) { // we added this new one configs.add(config); // track order here diff --git a/runtime/Java/src/org/antlr/v4/runtime/atn/ParserATNSimulator.java b/runtime/Java/src/org/antlr/v4/runtime/atn/ParserATNSimulator.java index 33bde36c2..a191975ee 100755 --- a/runtime/Java/src/org/antlr/v4/runtime/atn/ParserATNSimulator.java +++ b/runtime/Java/src/org/antlr/v4/runtime/atn/ParserATNSimulator.java @@ -968,7 +968,6 @@ public class ParserATNSimulator extends ATNSimulator { if (skippedStopStates != null && !PredictionMode.hasConfigAtRuleStopState(reach)) { for (ATNConfig c : skippedStopStates) { - assert c.reachesIntoOuterContext == 0 && c.semanticContext == SemanticContext.NONE; reach.add(c, mergeCache); } } @@ -1232,12 +1231,6 @@ public class ParserATNSimulator extends ATNSimulator { // optimization if ( !p.onlyHasEpsilonTransitions() ) { configs.add(config, mergeCache); - if ( config.semanticContext!= SemanticContext.NONE ) { - configs.hasSemanticContext = true; - } - if ( config.reachesIntoOuterContext>0 ) { - configs.dipsIntoOuterContext = true; - } // if ( debug ) System.out.println("added config "+configs); }