Package org.antlr.v4.semantics
Class SymbolChecks
- java.lang.Object
-
- org.antlr.v4.semantics.SymbolChecks
-
public class SymbolChecks extends java.lang.Object
Check for symbol problems; no side-effects. Inefficient to walk rules and such multiple times, but I like isolating all error checking outside of code that actually defines symbols etc... Side-effect: strip away redef'd rules.
-
-
Field Summary
Fields Modifier and Type Field Description (package private) java.util.Map<java.lang.String,java.util.Set<java.lang.String>>
actionScopeToActionNames
(package private) SymbolCollector
collector
ErrorManager
errMgr
(package private) Grammar
g
(package private) java.util.Map<java.lang.String,Rule>
nameToRuleMap
protected java.util.Set<java.lang.String>
reservedNames
(package private) java.util.Set<java.lang.String>
tokenIDs
-
Constructor Summary
Constructors Constructor Description SymbolChecks(Grammar g, SymbolCollector collector)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
checkActionRedefinitions(java.util.List<GrammarAST> actions)
protected void
checkDeclarationRuleConflicts(Rule r, AttributeDict attributes, java.util.Set<java.lang.String> ruleNames, ErrorType errorType)
void
checkForAttributeConflicts(Rule r)
void
checkForLabelConflict(Rule r, GrammarAST labelID)
void
checkForLabelConflicts(java.util.Collection<Rule> rules)
Make sure a label doesn't conflict with another symbol.void
checkForModeConflicts(Grammar g)
private void
checkForOverlap(Grammar g, Rule rule1, Rule rule2, java.util.List<java.lang.String> firstTokenStringValues, java.util.List<java.lang.String> secondTokenStringValues)
For same rule compare values from next index: TOKEN_WITH_SAME_VALUES: 'asdf' | 'asdf'; For different rules compare from start value: TOKEN1: 'asdf'; TOKEN2: 'asdf';void
checkForQualifiedRuleIssues(Grammar g, java.util.List<GrammarAST> qualifiedRuleRefs)
private void
checkForTypeMismatch(Rule r, LabelElementPair prevLabelPair, LabelElementPair labelPair)
void
checkForUnreachableTokens(Grammar g)
Algorithm steps: 1.private void
checkLabelPairs(Rule r, java.util.Map<java.lang.String,LabelElementPair> labelNameSpace, java.util.List<LabelElementPair> pairs)
protected void
checkLocalConflictingDeclarations(Rule r, AttributeDict attributes, AttributeDict referenceAttributes, ErrorType errorType)
protected void
checkReservedNames(java.util.Collection<Rule> rules)
void
checkRuleArgs(Grammar g, java.util.List<GrammarAST> rulerefs)
private java.lang.String
findAltLabelName(org.antlr.runtime.tree.CommonTree label)
private java.util.List<java.lang.String>
getSingleTokenValues(Rule rule)
{@return} list of simple string literals for rule {@param rule}void
process()
-
-
-
Field Detail
-
g
Grammar g
-
collector
SymbolCollector collector
-
nameToRuleMap
java.util.Map<java.lang.String,Rule> nameToRuleMap
-
tokenIDs
java.util.Set<java.lang.String> tokenIDs
-
actionScopeToActionNames
java.util.Map<java.lang.String,java.util.Set<java.lang.String>> actionScopeToActionNames
-
errMgr
public ErrorManager errMgr
-
reservedNames
protected final java.util.Set<java.lang.String> reservedNames
-
-
Constructor Detail
-
SymbolChecks
public SymbolChecks(Grammar g, SymbolCollector collector)
-
-
Method Detail
-
process
public void process()
-
checkActionRedefinitions
public void checkActionRedefinitions(java.util.List<GrammarAST> actions)
-
checkForLabelConflicts
public void checkForLabelConflicts(java.util.Collection<Rule> rules)
Make sure a label doesn't conflict with another symbol. Labels must not conflict with: rules, tokens, scope names, return values, parameters, and rule-scope dynamic attributes defined in surrounding rule. Also they must have same type for repeated defs.
-
checkLabelPairs
private void checkLabelPairs(Rule r, java.util.Map<java.lang.String,LabelElementPair> labelNameSpace, java.util.List<LabelElementPair> pairs)
-
findAltLabelName
private java.lang.String findAltLabelName(org.antlr.runtime.tree.CommonTree label)
-
checkForTypeMismatch
private void checkForTypeMismatch(Rule r, LabelElementPair prevLabelPair, LabelElementPair labelPair)
-
checkForLabelConflict
public void checkForLabelConflict(Rule r, GrammarAST labelID)
-
checkForAttributeConflicts
public void checkForAttributeConflicts(Rule r)
-
checkDeclarationRuleConflicts
protected void checkDeclarationRuleConflicts(Rule r, AttributeDict attributes, java.util.Set<java.lang.String> ruleNames, ErrorType errorType)
-
checkLocalConflictingDeclarations
protected void checkLocalConflictingDeclarations(Rule r, AttributeDict attributes, AttributeDict referenceAttributes, ErrorType errorType)
-
checkReservedNames
protected void checkReservedNames(java.util.Collection<Rule> rules)
-
checkForModeConflicts
public void checkForModeConflicts(Grammar g)
-
checkForUnreachableTokens
public void checkForUnreachableTokens(Grammar g)
Algorithm steps: 1. Collect all simple string literals (i.e. 'asdf', 'as' 'df', but not [a-z]+, 'a'..'z') for all lexer rules in each mode except of autogenerated tokens (getSingleTokenValues
) 2. Compare every string literal with each other (checkForOverlap
) and throw TOKEN_UNREACHABLE warning if the same string found. Complexity: O(m * n^2 / 2), approximately equals to O(n^2) where m - number of modes, n - average number of lexer rules per mode. See also testUnreachableTokens unit test for details.
-
getSingleTokenValues
private java.util.List<java.lang.String> getSingleTokenValues(Rule rule)
{@return} list of simple string literals for rule {@param rule}
-
checkForOverlap
private void checkForOverlap(Grammar g, Rule rule1, Rule rule2, java.util.List<java.lang.String> firstTokenStringValues, java.util.List<java.lang.String> secondTokenStringValues)
For same rule compare values from next index: TOKEN_WITH_SAME_VALUES: 'asdf' | 'asdf'; For different rules compare from start value: TOKEN1: 'asdf'; TOKEN2: 'asdf';
-
checkRuleArgs
public void checkRuleArgs(Grammar g, java.util.List<GrammarAST> rulerefs)
-
checkForQualifiedRuleIssues
public void checkForQualifiedRuleIssues(Grammar g, java.util.List<GrammarAST> qualifiedRuleRefs)
-
-