ATN fields grammarType and maxTokenType are now final
This commit is contained in:
parent
8b6c994694
commit
f6ad977e0d
|
@ -64,9 +64,9 @@ public class ATN {
|
|||
/**
|
||||
* The type of the ATN.
|
||||
*/
|
||||
public ATNType grammarType;
|
||||
public final ATNType grammarType;
|
||||
|
||||
public int maxTokenType;
|
||||
public final int maxTokenType;
|
||||
|
||||
// runtime for lexer only
|
||||
public int[] ruleToTokenType;
|
||||
|
@ -76,7 +76,10 @@ public class ATN {
|
|||
public final List<TokensStartState> modeToStartState = new ArrayList<TokensStartState>();
|
||||
|
||||
/** Used for runtime deserialization of ATNs from strings */
|
||||
public ATN() { }
|
||||
public ATN(@NotNull ATNType grammarType, int maxTokenType) {
|
||||
this.grammarType = grammarType;
|
||||
this.maxTokenType = maxTokenType;
|
||||
}
|
||||
|
||||
/** Compute the set of valid tokens that can occur starting in s.
|
||||
* If ctx is null, the set of tokens will not include what can follow
|
||||
|
|
|
@ -118,7 +118,6 @@ public abstract class ATNSimulator {
|
|||
data[i] = (char)(data[i] - 2);
|
||||
}
|
||||
|
||||
ATN atn = new ATN();
|
||||
List<IntervalSet> sets = new ArrayList<IntervalSet>();
|
||||
int p = 0;
|
||||
int version = toInt(data[p++]);
|
||||
|
@ -134,8 +133,9 @@ public abstract class ATNSimulator {
|
|||
throw new UnsupportedOperationException(new InvalidClassException(ATN.class.getName(), reason));
|
||||
}
|
||||
|
||||
atn.grammarType = ATNType.values()[toInt(data[p++])];
|
||||
atn.maxTokenType = toInt(data[p++]);
|
||||
ATNType grammarType = ATNType.values()[toInt(data[p++])];
|
||||
int maxTokenType = toInt(data[p++]);
|
||||
ATN atn = new ATN(grammarType, maxTokenType);
|
||||
|
||||
//
|
||||
// STATES
|
||||
|
|
|
@ -41,6 +41,7 @@ import org.antlr.v4.parse.ATNBuilder;
|
|||
import org.antlr.v4.parse.GrammarASTAdaptor;
|
||||
import org.antlr.v4.runtime.atn.ATN;
|
||||
import org.antlr.v4.runtime.atn.ATNState;
|
||||
import org.antlr.v4.runtime.atn.ATNType;
|
||||
import org.antlr.v4.runtime.atn.ActionTransition;
|
||||
import org.antlr.v4.runtime.atn.AtomTransition;
|
||||
import org.antlr.v4.runtime.atn.BasicBlockStartState;
|
||||
|
@ -73,6 +74,7 @@ import org.antlr.v4.tool.ErrorManager;
|
|||
import org.antlr.v4.tool.ErrorType;
|
||||
import org.antlr.v4.tool.Grammar;
|
||||
import org.antlr.v4.tool.LeftRecursiveRule;
|
||||
import org.antlr.v4.tool.LexerGrammar;
|
||||
import org.antlr.v4.tool.Rule;
|
||||
import org.antlr.v4.tool.ast.ActionAST;
|
||||
import org.antlr.v4.tool.ast.AltAST;
|
||||
|
@ -112,13 +114,16 @@ public class ParserATNFactory implements ATNFactory {
|
|||
}
|
||||
|
||||
this.g = g;
|
||||
this.atn = new ATN();
|
||||
|
||||
ATNType atnType = g instanceof LexerGrammar ? ATNType.LEXER : ATNType.PARSER;
|
||||
int maxTokenType = g.getMaxTokenType();
|
||||
this.atn = new ATN(atnType, maxTokenType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ATN createATN() {
|
||||
_createATN(g.rules.values());
|
||||
atn.maxTokenType = g.getMaxTokenType();
|
||||
assert atn.maxTokenType == g.getMaxTokenType();
|
||||
addRuleFollowLinks();
|
||||
addEOFTransitionToStartRules();
|
||||
ATNOptimizer.optimize(g, atn);
|
||||
|
|
Loading…
Reference in New Issue