From 067b6b60f6277b3d2ede071f92ec4044396d08b4 Mon Sep 17 00:00:00 2001 From: parrt Date: Wed, 31 Mar 2010 17:06:35 -0800 Subject: [PATCH] don't pass configs down through closures [git-p4: depot-paths = "//depot/code/antlr4/main/": change = 6782] --- .../v4/analysis/PredictionDFAFactory.java | 52 ++++++++----------- 1 file changed, 23 insertions(+), 29 deletions(-) diff --git a/tool/src/org/antlr/v4/analysis/PredictionDFAFactory.java b/tool/src/org/antlr/v4/analysis/PredictionDFAFactory.java index c37ceca33..79d8e29d5 100644 --- a/tool/src/org/antlr/v4/analysis/PredictionDFAFactory.java +++ b/tool/src/org/antlr/v4/analysis/PredictionDFAFactory.java @@ -275,10 +275,10 @@ public class PredictionDFAFactory { // TODO: can we avoid this separate list by directly filling d.nfaConfigs? // OH: concurrent modification. dup initialconfigs? works for lexers, try here to save configs param List configs = new ArrayList(); - for (NFAConfig c : d.nfaConfigs) { - closure(c, collectPredicates, configs); + configs.addAll(d.nfaConfigs); + for (NFAConfig c : configs) { + closure(d, c, collectPredicates); } - d.nfaConfigs.addAll(configs); // Add new NFA configs to DFA state d closureBusy.clear(); @@ -303,41 +303,36 @@ public class PredictionDFAFactory { * always detect the conflict later when checking for context suffixes... * I check for left-recursive stuff and terminate before analysis to * avoid need to do this more expensive computation. - * - * This - * - * TODO: remove altNum if we don't reorder for loopback nodes - * TODO: pass in a config? */ - public void closure(NFAConfig c, boolean collectPredicates, List configs) { + public void closure(DFAState d, NFAConfig c, boolean collectPredicates) { //NFAConfig proposedNFAConfig = new NFAConfig(s, altNum, context, semanticContext); if ( closureBusy.contains(c) ) return; closureBusy.add(c); // p itself is always in closure - configs.add(c); + d.nfaConfigs.add(c); if ( c.state instanceof RuleStopState ) { - ruleStopStateClosure(c, collectPredicates, configs); + ruleStopStateClosure(d, c, collectPredicates); } else { - commonClosure(c, collectPredicates, configs); + commonClosure(d, c, collectPredicates); } } // if we have context info and we're at rule stop state, do // local follow for invokingRule and global follow for other links - void ruleStopStateClosure(NFAConfig c, boolean collectPredicates, List configs) { + void ruleStopStateClosure(DFAState d, NFAConfig c, boolean collectPredicates) { if ( !c.context.recursed ) { System.out.println("dynamic FOLLOW of "+c.state+" context="+c.context); - if ( !c.context.isEmpty() ) { - NFAContext newContext = c.context.parent; // "pop" invoking state - closure(new NFAConfig(c, c.context.returnState, newContext), - collectPredicates, configs); + if ( c.context.isEmpty() ) { + commonClosure(d, c, collectPredicates); // do global FOLLOW } else { - commonClosure(c, collectPredicates, configs); // do global FOLLOW + NFAContext newContext = c.context.parent; // "pop" invoking state + closure(d, new NFAConfig(c, c.context.returnState, newContext), + collectPredicates); } return; } @@ -359,15 +354,15 @@ public class PredictionDFAFactory { // else follow link to context state only if ( t.target.rule != invokingRule ) { //System.out.println("OFF TO "+t.target); - closure(new NFAConfig(c, t.target), collectPredicates, configs); + closure(d, new NFAConfig(c, t.target), collectPredicates); } else { // t.target is in invoking rule; only follow context's link if ( t.target == c.context.returnState ) { //System.out.println("OFF TO CALL SITE "+t.target); // go only to specific call site; pop context NFAContext newContext = c.context.parent; // "pop" invoking state - closure(new NFAConfig(c, t.target, newContext), - collectPredicates, configs); + closure(d, new NFAConfig(c, t.target, newContext), + collectPredicates); } } } @@ -375,14 +370,13 @@ public class PredictionDFAFactory { } - void commonClosure(NFAConfig c, boolean collectPredicates, List configs) { + void commonClosure(DFAState d, NFAConfig c, boolean collectPredicates) { int n = c.state.getNumberOfTransitions(); for (int i=0; i