removed Rule depend from ATN

[git-p4: depot-paths = "//depot/code/antlr4/main/": change = 8778]
This commit is contained in:
parrt 2011-06-27 17:53:11 -08:00
parent ad98d17191
commit 4d04b21999
41 changed files with 74 additions and 67 deletions

View File

@ -27,8 +27,9 @@
*/
package org.antlr.v4.runtime;
import org.antlr.v4.misc.*;
import org.antlr.v4.misc.OrderedHashSet;
import org.antlr.v4.runtime.atn.*;
import org.antlr.v4.runtime.misc.IntervalSet;
import java.util.*;

View File

@ -27,7 +27,7 @@
*/
package org.antlr.v4.runtime;
import org.antlr.v4.misc.IntervalSet;
import org.antlr.v4.runtime.misc.IntervalSet;
import org.antlr.v4.runtime.tree.*;
/** The root of the ANTLR exception hierarchy.

View File

@ -1,8 +1,7 @@
package org.antlr.v4.runtime.atn;
import org.antlr.v4.misc.IntervalSet;
import org.antlr.v4.runtime.RuleContext;
import org.antlr.v4.tool.Rule;
import org.antlr.v4.runtime.misc.IntervalSet;
import java.util.*;
@ -21,8 +20,12 @@ public class ATN {
*/
public List<DecisionState> decisionToATNState = new ArrayList<DecisionState>();
public Map<Rule, RuleStartState> ruleToStartState = new LinkedHashMap<Rule, RuleStartState>();
public Map<Rule, RuleStopState> ruleToStopState = new LinkedHashMap<Rule, RuleStopState>();
public Map<Integer, RuleStartState> ruleToStartState = new LinkedHashMap<Integer, RuleStartState>();
public Map<Integer, RuleStopState> ruleToStopState = new LinkedHashMap<Integer, RuleStopState>();
// public RuleStartState[] ruleToStartState = new LinkedHashMap<Integer, RuleStartState>();
// public RuleStopState[] ruleToStopState = new LinkedHashMap<Integer, RuleStopState>();
public Map<String, TokensStartState> modeNameToStartState =
new LinkedHashMap<String, TokensStartState>();
@ -38,8 +41,6 @@ public class ATN {
int stateNumber = 0;
// TODO: for runtime all we need is states, decisionToATNState I think
/** Used for runtime deserialization of ATNs from strings */
public ATN() { }

View File

@ -1,8 +1,9 @@
package org.antlr.v4.runtime.atn;
import org.antlr.v4.misc.*;
import org.antlr.v4.misc.OrderedHashSet;
import org.antlr.v4.parse.ANTLRParser;
import org.antlr.v4.runtime.dfa.DFAState;
import org.antlr.v4.runtime.misc.IntervalSet;
import java.util.*;

View File

@ -1,6 +1,6 @@
package org.antlr.v4.runtime.atn;
import org.antlr.v4.misc.IntervalSet;
import org.antlr.v4.runtime.misc.IntervalSet;
import org.antlr.v4.tool.Grammar;
/** TODO: make all transitions sets? no, should remove set edges */

View File

@ -1,7 +1,7 @@
package org.antlr.v4.runtime.atn;
import org.antlr.v4.misc.IntervalSet;
import org.antlr.v4.runtime.RuleContext;
import org.antlr.v4.runtime.misc.IntervalSet;
import java.util.*;

View File

@ -1,6 +1,6 @@
package org.antlr.v4.runtime.atn;
import org.antlr.v4.misc.IntervalSet;
import org.antlr.v4.runtime.misc.IntervalSet;
import org.antlr.v4.tool.*;
public class NotSetTransition extends SetTransition {

View File

@ -1,6 +1,7 @@
package org.antlr.v4.runtime.atn;
import org.antlr.v4.misc.*;
import org.antlr.v4.misc.CharSupport;
import org.antlr.v4.runtime.misc.IntervalSet;
public class RangeTransition extends Transition {
public int from;

View File

@ -1,7 +1,7 @@
package org.antlr.v4.runtime.atn;
import org.antlr.v4.misc.IntervalSet;
import org.antlr.v4.runtime.Token;
import org.antlr.v4.runtime.misc.IntervalSet;
import org.antlr.v4.tool.*;
/** A transition containing a set of values */

View File

@ -1,6 +1,6 @@
package org.antlr.v4.runtime.atn;
import org.antlr.v4.misc.IntervalSet;
import org.antlr.v4.runtime.misc.IntervalSet;
import org.antlr.v4.tool.Grammar;
import java.util.*;

View File

@ -25,8 +25,9 @@
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.antlr.v4.misc;
package org.antlr.v4.runtime.misc;
import org.antlr.v4.misc.*;
import org.antlr.v4.runtime.Token;
import org.antlr.v4.tool.Grammar;

View File

@ -1,13 +1,9 @@
import org.antlr.v4.Tool;
import org.antlr.v4.automata.ParserATNFactory;
import org.antlr.v4.runtime.CommonToken;
import org.antlr.v4.runtime.Token;
import org.antlr.v4.runtime.TokenSource;
import org.antlr.v4.runtime.TokenStream;
import org.antlr.v4.runtime.*;
import org.antlr.v4.runtime.atn.ATN;
import org.antlr.v4.semantics.SemanticPipeline;
import org.antlr.v4.tool.DOTGenerator;
import org.antlr.v4.tool.Grammar;
import org.antlr.v4.tool.*;
import java.util.List;
@ -52,7 +48,7 @@ public class Test {
ATN atn = f.createATN();
DOTGenerator dot = new DOTGenerator(g);
System.out.println(dot.getDOT(atn.ruleToStartState.get(g.getRule("d"))));
System.out.println(dot.getDOT(atn.ruleToStartState.get(g.getRule("d").index)));
}
public static class IntTokenStream implements TokenStream {

View File

@ -410,7 +410,7 @@ public class Tool {
for (Grammar ig : grammars) {
for (Rule r : ig.rules.values()) {
try {
String dot = dotGenerator.getDOT(g.atn.ruleToStartState.get(r));
String dot = dotGenerator.getDOT(g.atn.ruleToStartState.get(r.index));
if (dot != null) {
writeDOTFile(g, r, dot);
}

View File

@ -1,7 +1,7 @@
package org.antlr.v4.analysis;
import org.antlr.v4.misc.IntervalSet;
import org.antlr.v4.runtime.atn.*;
import org.antlr.v4.runtime.misc.IntervalSet;
import org.antlr.v4.tool.Grammar;
import java.util.*;

View File

@ -1,7 +1,7 @@
package org.antlr.v4.automata;
import org.antlr.v4.misc.IntervalSet;
import org.antlr.v4.runtime.atn.*;
import org.antlr.v4.runtime.misc.IntervalSet;
import org.antlr.v4.tool.*;
import java.util.List;

View File

@ -2,6 +2,7 @@ package org.antlr.v4.automata;
import org.antlr.v4.misc.*;
import org.antlr.v4.runtime.atn.*;
import org.antlr.v4.runtime.misc.IntervalSet;
import org.antlr.v4.tool.*;
import java.util.*;

View File

@ -36,7 +36,7 @@ public class LexerATNFactory extends ParserATNFactory {
TokensStartState startState = atn.modeNameToStartState.get(modeName);
for (Rule r : rules) {
if ( !r.isFragment() ) {
RuleStartState s = atn.ruleToStartState.get(r);
RuleStartState s = atn.ruleToStartState.get(r.index);
epsilon(startState, s);
}
}

View File

@ -3,9 +3,10 @@ package org.antlr.v4.automata;
import org.antlr.runtime.*;
import org.antlr.runtime.tree.*;
import org.antlr.v4.misc.*;
import org.antlr.v4.misc.CharSupport;
import org.antlr.v4.parse.*;
import org.antlr.v4.runtime.atn.*;
import org.antlr.v4.runtime.misc.IntervalSet;
import org.antlr.v4.tool.*;
import java.lang.reflect.Constructor;
@ -56,9 +57,9 @@ public class ParserATNFactory implements ATNFactory {
/* start->ruleblock->end */
public Handle rule(GrammarAST ruleAST, String name, Handle blk) {
Rule r = g.getRule(name);
RuleStartState start = atn.ruleToStartState.get(r);
RuleStartState start = atn.ruleToStartState.get(r.index);
epsilon(start, blk.left);
RuleStopState stop = atn.ruleToStopState.get(r);
RuleStopState stop = atn.ruleToStopState.get(r.index);
epsilon(blk.right, stop);
Handle h = new Handle(start, stop);
// FASerializer ser = new FASerializer(g, h.left);
@ -140,7 +141,7 @@ public class ParserATNFactory implements ATNFactory {
public Handle _ruleRef(GrammarAST node) {
Rule r = g.getRule(node.getText());
RuleStartState start = atn.ruleToStartState.get(r);
RuleStartState start = atn.ruleToStartState.get(r.index);
ATNState left = newState(node);
ATNState right = newState(node);
RuleTransition call = new RuleTransition(r, start, right);
@ -152,7 +153,7 @@ public class ParserATNFactory implements ATNFactory {
public void addFollowLink(Rule r, ATNState right) {
// add follow edge from end of invoked rule
RuleStopState stop = atn.ruleToStopState.get(r);
RuleStopState stop = atn.ruleToStopState.get(r.index);
epsilon(stop, right);
}
@ -393,7 +394,6 @@ public class ParserATNFactory implements ATNFactory {
public Handle wildcard(GrammarAST node) {
ATNState left = newState(node);
ATNState right = newState(node);
int ttype = g.getTokenType(node.getText());
left.transition = new WildcardTransition(right);
right.incidentTransition = left.transition;
node.atnState = left;
@ -419,9 +419,9 @@ public class ParserATNFactory implements ATNFactory {
start.stopState = stop;
start.setRule(r);
stop.setRule(r);
atn.ruleToStartState.put(r, start);
atn.ruleToStartState.put(r.index, start);
atn.rules.add(start);
atn.ruleToStopState.put(r, stop);
atn.ruleToStopState.put(r.index, stop);
}
}
@ -437,7 +437,7 @@ public class ParserATNFactory implements ATNFactory {
int n = 0;
ATNState eofTarget = newState(null); // one unique EOF target for all rules
for (Rule r : g.rules.values()) {
ATNState stop = atn.ruleToStopState.get(r);
ATNState stop = atn.ruleToStopState.get(r.index);
if ( stop.getNumberOfTransitions()>0 ) continue;
n++;
Transition t = new AtomTransition(Token.EOF, eofTarget);

View File

@ -1,7 +1,7 @@
package org.antlr.v4.codegen;
import org.antlr.v4.codegen.model.*;
import org.antlr.v4.misc.IntervalSet;
import org.antlr.v4.runtime.misc.IntervalSet;
import org.antlr.v4.tool.*;
import java.util.*;

View File

@ -1,7 +1,7 @@
package org.antlr.v4.codegen;
import org.antlr.v4.codegen.model.*;
import org.antlr.v4.misc.IntervalSet;
import org.antlr.v4.runtime.misc.IntervalSet;
import org.antlr.v4.tool.*;
import java.util.*;

View File

@ -3,9 +3,9 @@ package org.antlr.v4.codegen;
import org.antlr.runtime.tree.CommonTreeNodeStream;
import org.antlr.v4.analysis.AnalysisPipeline;
import org.antlr.v4.codegen.model.*;
import org.antlr.v4.misc.IntervalSet;
import org.antlr.v4.parse.*;
import org.antlr.v4.runtime.atn.*;
import org.antlr.v4.runtime.misc.IntervalSet;
import org.antlr.v4.tool.*;
import java.util.List;

View File

@ -2,7 +2,8 @@ package org.antlr.v4.codegen.model;
import org.antlr.v4.codegen.OutputModelFactory;
import org.antlr.v4.codegen.model.decl.*;
import org.antlr.v4.misc.*;
import org.antlr.v4.misc.Utils;
import org.antlr.v4.runtime.misc.IntervalSet;
import org.antlr.v4.tool.GrammarAST;
import java.util.*;

View File

@ -1,8 +1,8 @@
package org.antlr.v4.codegen.model;
import org.antlr.v4.codegen.OutputModelFactory;
import org.antlr.v4.misc.IntervalSet;
import org.antlr.v4.runtime.atn.DecisionState;
import org.antlr.v4.runtime.misc.IntervalSet;
import org.antlr.v4.tool.GrammarAST;
import java.util.List;

View File

@ -1,7 +1,7 @@
package org.antlr.v4.codegen.model;
import org.antlr.v4.codegen.OutputModelFactory;
import org.antlr.v4.misc.IntervalSet;
import org.antlr.v4.runtime.misc.IntervalSet;
import org.antlr.v4.tool.GrammarAST;
import java.util.*;

View File

@ -1,8 +1,8 @@
package org.antlr.v4.codegen.model;
import org.antlr.v4.codegen.OutputModelFactory;
import org.antlr.v4.misc.IntervalSet;
import org.antlr.v4.runtime.atn.DecisionState;
import org.antlr.v4.runtime.misc.IntervalSet;
import org.antlr.v4.tool.GrammarAST;
import java.util.List;

View File

@ -1,8 +1,8 @@
package org.antlr.v4.codegen.model;
import org.antlr.v4.codegen.*;
import org.antlr.v4.misc.IntervalSet;
import org.antlr.v4.runtime.atn.PlusBlockStartState;
import org.antlr.v4.runtime.misc.IntervalSet;
import org.antlr.v4.tool.*;
import java.util.List;

View File

@ -1,8 +1,8 @@
package org.antlr.v4.codegen.model;
import org.antlr.v4.codegen.OutputModelFactory;
import org.antlr.v4.misc.IntervalSet;
import org.antlr.v4.runtime.atn.PlusBlockStartState;
import org.antlr.v4.runtime.misc.IntervalSet;
import org.antlr.v4.tool.GrammarAST;
import java.util.List;

View File

@ -1,8 +1,8 @@
package org.antlr.v4.codegen.model;
import org.antlr.v4.codegen.OutputModelFactory;
import org.antlr.v4.misc.IntervalSet;
import org.antlr.v4.runtime.atn.StarBlockStartState;
import org.antlr.v4.runtime.misc.IntervalSet;
import org.antlr.v4.tool.GrammarAST;
import java.util.List;

View File

@ -1,8 +1,8 @@
package org.antlr.v4.codegen.model;
import org.antlr.v4.codegen.OutputModelFactory;
import org.antlr.v4.misc.IntervalSet;
import org.antlr.v4.runtime.atn.StarBlockStartState;
import org.antlr.v4.runtime.misc.IntervalSet;
import org.antlr.v4.tool.GrammarAST;
import java.util.List;

View File

@ -77,7 +77,7 @@ public class RuleFunction extends OutputModelObject {
addLocalDecl(new KidsListDecl(factory, 0));
}
startState = factory.getGrammar().atn.ruleToStartState.get(r);
startState = factory.getGrammar().atn.ruleToStartState.get(r.index);
}
/** Add local var decl */

View File

@ -1,7 +1,7 @@
package org.antlr.v4.codegen.model;
import org.antlr.v4.codegen.OutputModelFactory;
import org.antlr.v4.misc.IntervalSet;
import org.antlr.v4.runtime.misc.IntervalSet;
import org.antlr.v4.tool.GrammarAST;
/** */

View File

@ -1,7 +1,7 @@
package org.antlr.v4.codegen.model;
import org.antlr.v4.codegen.OutputModelFactory;
import org.antlr.v4.misc.IntervalSet;
import org.antlr.v4.runtime.misc.IntervalSet;
import org.antlr.v4.tool.GrammarAST;
/** */

View File

@ -1,7 +1,7 @@
package org.antlr.v4.codegen.model;
import org.antlr.v4.codegen.OutputModelFactory;
import org.antlr.v4.misc.IntervalSet;
import org.antlr.v4.runtime.misc.IntervalSet;
import org.antlr.v4.tool.GrammarAST;
/** */

View File

@ -1,7 +1,7 @@
package org.antlr.v4.codegen.model;
import org.antlr.v4.codegen.OutputModelFactory;
import org.antlr.v4.misc.IntervalSet;
import org.antlr.v4.runtime.misc.IntervalSet;
import org.antlr.v4.tool.GrammarAST;
/** */

View File

@ -1,7 +1,7 @@
package org.antlr.v4.codegen.model;
import org.antlr.v4.codegen.OutputModelFactory;
import org.antlr.v4.misc.IntervalSet;
import org.antlr.v4.runtime.misc.IntervalSet;
import org.antlr.v4.tool.GrammarAST;
/** */

View File

@ -8,6 +8,7 @@ import org.antlr.v4.parse.*;
import org.antlr.v4.runtime.Token;
import org.antlr.v4.runtime.atn.ATN;
import org.antlr.v4.runtime.dfa.DFA;
import org.antlr.v4.runtime.misc.IntervalSet;
import java.util.*;

View File

@ -2,9 +2,9 @@ package org.antlr.v4.tool;
import org.antlr.runtime.*;
import org.antlr.runtime.tree.*;
import org.antlr.v4.misc.IntervalSet;
import org.antlr.v4.parse.ANTLRParser;
import org.antlr.v4.runtime.atn.ATNState;
import org.antlr.v4.runtime.misc.IntervalSet;
import java.util.*;

View File

@ -174,7 +174,7 @@ public abstract class BaseTest {
ErrorQueue equeue = new ErrorQueue();
Grammar g = new Grammar(gtext, equeue);
ATN atn = createATN(g);
ATNState s = atn.ruleToStartState.get(g.getRule(ruleName));
ATNState s = atn.ruleToStartState.get(g.getRule(ruleName).index);
if ( s==null ) {
System.err.println("no such rule: "+ruleName);
return null;

View File

@ -941,10 +941,10 @@ public class TestATNConstruction extends BaseTest {
ATN atn = f.createATN();
DOTGenerator dot = new DOTGenerator(g);
System.out.println(dot.getDOT(atn.ruleToStartState.get(g.getRule(ruleName))));
System.out.println(dot.getDOT(atn.ruleToStartState.get(g.getRule(ruleName).index)));
Rule r = g.getRule(ruleName);
ATNState startState = atn.ruleToStartState.get(r);
ATNState startState = atn.ruleToStartState.get(r.index);
ATNPrinter serializer = new ATNPrinter(g, startState);
String result = serializer.toString();

View File

@ -274,14 +274,15 @@ public class TestATNInterpreter extends BaseTest {
ParserInterpreter interp = new ParserInterpreter(atn);
TokenStream input = new IntTokenStream(types);
ATNState startState = atn.ruleToStartState.get(g.getRule("a"));
ATNState startState = atn.ruleToStartState.get(g.getRule("a").index);
if ( startState.transition(0).target instanceof BlockStartState ) {
startState = startState.transition(0).target;
}
DOTGenerator dot = new DOTGenerator(g);
System.out.println(dot.getDOT(atn.ruleToStartState.get(g.getRule("a"))));
System.out.println(dot.getDOT(atn.ruleToStartState.get(g.getRule("e"))));
System.out.println(dot.getDOT(atn.ruleToStartState.get(g.getRule("a").index)));
Rule r = g.getRule("e");
if ( r!=null ) System.out.println(dot.getDOT(atn.ruleToStartState.get(r.index)));
int result = interp.matchATN(input, startState);
assertEquals(expected, result);

View File

@ -269,9 +269,9 @@ public class TestATNParserPrediction extends BaseTest {
ParserATNFactory f = new ParserATNFactory(g);
ATN atn = f.createATN();
RuleStartState aStart = atn.ruleToStartState.get(g.getRule("a"));
RuleStartState bStart = atn.ruleToStartState.get(g.getRule("b"));
RuleStartState eStart = atn.ruleToStartState.get(g.getRule("e"));
RuleStartState aStart = atn.ruleToStartState.get(g.getRule("a").index);
RuleStartState bStart = atn.ruleToStartState.get(g.getRule("b").index);
RuleStartState eStart = atn.ruleToStartState.get(g.getRule("e").index);
ATNState a_e_invoke = aStart.transition(0).target; //
ATNState b_e_invoke = bStart.transition(0).target; //
RuleContext a_ctx = new RuleContext(null, -1, a_e_invoke.stateNumber);
@ -491,9 +491,11 @@ public class TestATNParserPrediction extends BaseTest {
ATN atn = f.createATN();
DOTGenerator dot = new DOTGenerator(g);
System.out.println(dot.getDOT(atn.ruleToStartState.get(g.getRule("a"))));
System.out.println(dot.getDOT(atn.ruleToStartState.get(g.getRule("b"))));
System.out.println(dot.getDOT(atn.ruleToStartState.get(g.getRule("e"))));
System.out.println(dot.getDOT(atn.ruleToStartState.get(g.getRule("a").index)));
Rule r = g.getRule("b");
if ( r!=null) System.out.println(dot.getDOT(atn.ruleToStartState.get(r.index)));
r = g.getRule("e");
if ( r!=null) System.out.println(dot.getDOT(atn.ruleToStartState.get(r.index)));
// Check ATN prediction
ParserInterpreter interp = new ParserInterpreter(atn);