Class SymbolChecks
java.lang.Object
org.antlr.v4.semantics.SymbolChecks
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 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidcheckActionRedefinitions(List<GrammarAST> actions) protected voidcheckDeclarationRuleConflicts(Rule r, AttributeDict attributes, Set<String> ruleNames, ErrorType errorType) voidvoidcheckForLabelConflict(Rule r, GrammarAST labelID) voidcheckForLabelConflicts(Collection<Rule> rules) Make sure a label doesn't conflict with another symbol.voidprivate voidcheckForOverlap(Grammar g, Rule rule1, Rule rule2, List<String> firstTokenStringValues, List<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';voidcheckForQualifiedRuleIssues(Grammar g, List<GrammarAST> qualifiedRuleRefs) private voidcheckForTypeMismatch(Rule r, LabelElementPair prevLabelPair, LabelElementPair labelPair) voidAlgorithm steps: 1.private voidcheckLabelPairs(Rule r, Map<String, LabelElementPair> labelNameSpace, List<LabelElementPair> pairs) protected voidcheckLocalConflictingDeclarations(Rule r, AttributeDict attributes, AttributeDict referenceAttributes, ErrorType errorType) protected voidcheckReservedNames(Collection<Rule> rules) voidcheckRuleArgs(Grammar g, List<GrammarAST> rulerefs) private StringfindAltLabelName(org.antlr.runtime.tree.CommonTree label) getSingleTokenValues(Rule rule) voidprocess()
-
Field Details
-
g
Grammar g -
collector
SymbolCollector collector -
nameToRuleMap
-
tokenIDs
-
actionScopeToActionNames
-
errMgr
-
reservedNames
-
-
Constructor Details
-
SymbolChecks
-
-
Method Details
-
process
public void process() -
checkActionRedefinitions
-
checkForLabelConflicts
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, Map<String, LabelElementPair> labelNameSpace, List<LabelElementPair> pairs) -
findAltLabelName
-
checkForTypeMismatch
private void checkForTypeMismatch(Rule r, LabelElementPair prevLabelPair, LabelElementPair labelPair) -
checkForLabelConflict
-
checkForAttributeConflicts
-
checkDeclarationRuleConflicts
protected void checkDeclarationRuleConflicts(Rule r, AttributeDict attributes, Set<String> ruleNames, ErrorType errorType) -
checkLocalConflictingDeclarations
protected void checkLocalConflictingDeclarations(Rule r, AttributeDict attributes, AttributeDict referenceAttributes, ErrorType errorType) -
checkReservedNames
-
checkForModeConflicts
-
checkForUnreachableTokens
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
-
checkForOverlap
private void checkForOverlap(Grammar g, Rule rule1, Rule rule2, List<String> firstTokenStringValues, List<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
-
checkForQualifiedRuleIssues
-