got more tests in; about to refactor resolving.

[git-p4: depot-paths = "//depot/code/antlr4/main/": change = 6697]
This commit is contained in:
parrt 2010-02-16 10:32:51 -08:00
parent 29c602c202
commit 9c8e4380fc
2 changed files with 39 additions and 10 deletions

View File

@ -103,6 +103,9 @@ public class AttributeChecks implements ActionSplitterListener {
public void attr(String expr, Token x) { // arg, retval, predefined, token ref, rule ref, current rule public void attr(String expr, Token x) { // arg, retval, predefined, token ref, rule ref, current rule
if ( node.resolver.resolveToAttribute(x.getText(), node)==null ) { if ( node.resolver.resolveToAttribute(x.getText(), node)==null ) {
if ( node.resolver.resolveToScope(x.getText(), node)!=null ) {
return; // $S for scope S is ok
}
if ( node.resolver.resolveToRule(x.getText(), node)!=null ) { // or in rule and is rule ref if ( node.resolver.resolveToRule(x.getText(), node)!=null ) { // or in rule and is rule ref
ErrorManager.grammarError(ErrorType.ISOLATED_RULE_SCOPE, ErrorManager.grammarError(ErrorType.ISOLATED_RULE_SCOPE,
g.fileName, x, x.getText(), expr); g.fileName, x, x.getText(), expr);
@ -137,21 +140,25 @@ public class AttributeChecks implements ActionSplitterListener {
public void setDynamicNegativeIndexedScopeAttr(String expr, Token x, Token y, public void setDynamicNegativeIndexedScopeAttr(String expr, Token x, Token y,
Token index, Token rhs) { Token index, Token rhs) {
setDynamicScopeAttr(expr, x, y, rhs); setDynamicScopeAttr(expr, x, y, rhs);
new AttributeChecks(g, r, alt, node, index).examineAction();
} }
public void dynamicNegativeIndexedScopeAttr(String expr, Token x, Token y, public void dynamicNegativeIndexedScopeAttr(String expr, Token x, Token y,
Token index) { Token index) {
dynamicScopeAttr(expr, x, y); dynamicScopeAttr(expr, x, y);
new AttributeChecks(g, r, alt, node, index).examineAction();
} }
public void setDynamicAbsoluteIndexedScopeAttr(String expr, Token x, Token y, public void setDynamicAbsoluteIndexedScopeAttr(String expr, Token x, Token y,
Token index, Token rhs) { Token index, Token rhs) {
setDynamicScopeAttr(expr, x, y, rhs); setDynamicScopeAttr(expr, x, y, rhs);
new AttributeChecks(g, r, alt, node, index).examineAction();
} }
public void dynamicAbsoluteIndexedScopeAttr(String expr, Token x, Token y, public void dynamicAbsoluteIndexedScopeAttr(String expr, Token x, Token y,
Token index) { Token index) {
dynamicScopeAttr(expr, x, y); dynamicScopeAttr(expr, x, y);
new AttributeChecks(g, r, alt, node, index).examineAction();
} }
public void unknownSyntax(String text) { public void unknownSyntax(String text) {

View File

@ -14,6 +14,7 @@ public class TestAttributeChecks extends BaseTest {
" : lab=b[34] {\n" + " : lab=b[34] {\n" +
" <inline>\n" + " <inline>\n" +
" }\n" + " }\n" +
" c\n" +
" ;\n" + " ;\n" +
" finally {<finally>}\n" + " finally {<finally>}\n" +
"b[int d] returns [int e]\n" + "b[int d] returns [int e]\n" +
@ -46,29 +47,33 @@ public class TestAttributeChecks extends BaseTest {
}; };
String[] initChecks = { String[] initChecks = {
"$a", "error(33): A.g:4:8: missing attribute access on rule reference a in $a", "$a", "", // a has scope
"$c", "error(29): A.g:4:8: unknown attribute reference c in $c",
"$a.q", "error(31): A.g:4:10: unknown attribute rule q in $a.q", "$a.q", "error(31): A.g:4:10: unknown attribute rule q in $a.q",
}; };
String[] inlineChecks = { String[] inlineChecks = {
"$q", "error(29): A.g:6:4: unknown attribute reference q in $q", "$a", "",
"$b", "", // b has scope
"$lab", "",
"$c", "error(29): A.g:6:4: unknown attribute reference c in $c", // no scope
"$q", "error(29): A.g:6:4: unknown attribute reference q in $q",
"$q.y", "error(29): A.g:6:4: unknown attribute reference q in $q.y", "$q.y", "error(29): A.g:6:4: unknown attribute reference q in $q.y",
"$q = 3", "error(29): A.g:6:4: unknown attribute reference q in $q", "$q = 3", "error(29): A.g:6:4: unknown attribute reference q in $q",
"$q = 3;", "error(29): A.g:6:4: unknown attribute reference q in $q = 3;", "$q = 3;", "error(29): A.g:6:4: unknown attribute reference q in $q = 3;",
"$q.y = 3;", "error(29): A.g:6:4: unknown attribute reference q in $q.y = 3;", "$q.y = 3;", "error(29): A.g:6:4: unknown attribute reference q in $q.y = 3;",
"$q = $blort;", "error(29): A.g:6:4: unknown attribute reference q in $q = $blort;\n" + "$q = $blort;", "error(29): A.g:6:4: unknown attribute reference q in $q = $blort;\n" +
"error(29): A.g:6:9: unknown attribute reference blort in $blort", "error(29): A.g:6:9: unknown attribute reference blort in $blort",
"$a", "error(33): A.g:6:4: missing attribute access on rule reference a in $a",
"$a.ick", "error(31): A.g:6:6: unknown attribute rule ick in $a.ick", "$a.ick", "error(31): A.g:6:6: unknown attribute rule ick in $a.ick",
"$a.ick = 3;", "error(31): A.g:6:6: unknown attribute rule ick in $a.ick = 3;", "$a.ick = 3;", "error(31): A.g:6:6: unknown attribute rule ick in $a.ick = 3;",
"$b", "error(33): A.g:6:4: missing attribute access on rule reference b in $b",
"$b.d", "error(30): A.g:6:6: cannot access rule d's parameter: $b.d", // can't see rule ref's arg "$b.d", "error(30): A.g:6:6: cannot access rule d's parameter: $b.d", // can't see rule ref's arg
"$c.text", "error(29): A.g:6:4: unknown attribute reference c in $c.text", // valid rule, but no ref "$c.text", "error(29): A.g:6:4: unknown attribute reference c in $c.text", // valid rule, but no ref
"$lab", "error(33): A.g:6:4: missing attribute access on rule reference lab in $lab",
"$lab.d", "error(31): A.g:6:8: unknown attribute rule d in $lab.d", "$lab.d", "error(31): A.g:6:8: unknown attribute rule d in $lab.d",
}; };
String[] finallyChecks = { String[] finallyChecks = {
"$lab", "",
"$a", "",
"$q", "error(29): A.g:8:14: unknown attribute reference q in $q", "$q", "error(29): A.g:8:14: unknown attribute reference q in $q",
"$q.y", "error(29): A.g:8:14: unknown attribute reference q in $q.y", "$q.y", "error(29): A.g:8:14: unknown attribute reference q in $q.y",
"$q = 3", "error(29): A.g:8:14: unknown attribute reference q in $q", "$q = 3", "error(29): A.g:8:14: unknown attribute reference q in $q",
@ -76,13 +81,11 @@ public class TestAttributeChecks extends BaseTest {
"$q.y = 3;", "error(29): A.g:8:14: unknown attribute reference q in $q.y = 3;", "$q.y = 3;", "error(29): A.g:8:14: unknown attribute reference q in $q.y = 3;",
"$q = $blort;", "error(29): A.g:8:14: unknown attribute reference q in $q = $blort;\n" + "$q = $blort;", "error(29): A.g:8:14: unknown attribute reference q in $q = $blort;\n" +
"error(29): A.g:8:19: unknown attribute reference blort in $blort", "error(29): A.g:8:19: unknown attribute reference blort in $blort",
"$a", "error(33): A.g:8:14: missing attribute access on rule reference a in $a",
"$a.ick", "error(31): A.g:8:16: unknown attribute rule ick in $a.ick", "$a.ick", "error(31): A.g:8:16: unknown attribute rule ick in $a.ick",
"$a.ick = 3;", "error(31): A.g:8:16: unknown attribute rule ick in $a.ick = 3;", "$a.ick = 3;", "error(31): A.g:8:16: unknown attribute rule ick in $a.ick = 3;",
"$b", "error(29): A.g:8:14: unknown attribute reference b in $b", "$b", "error(29): A.g:8:14: unknown attribute reference b in $b",
"$b.d", "error(29): A.g:8:14: unknown attribute reference b in $b.d", "$b.d", "error(29): A.g:8:14: unknown attribute reference b in $b.d",
"$c.text", "error(29): A.g:8:14: unknown attribute reference c in $c.text", "$c.text", "error(29): A.g:8:14: unknown attribute reference c in $c.text",
"$lab", "error(33): A.g:8:14: missing attribute access on rule reference lab in $lab",
"$lab.d", "error(31): A.g:8:18: unknown attribute rule d in $lab.d", "$lab.d", "error(31): A.g:8:18: unknown attribute rule d in $lab.d",
}; };
@ -103,11 +106,30 @@ public class TestAttributeChecks extends BaseTest {
}; };
String[] dynInlineChecks = { String[] dynInlineChecks = {
"$b::f", "", "$b::f", "",
"$S::j", "error(55): A.g:9:13: unknown dynamically-scoped attribute for scope S: j in $S::j", "$S", "",
"$S::j = 3;", "error(55): A.g:9:13: unknown dynamically-scoped attribute for scope S: j in $S::j = 3;",
"$S::j", "error(55): A.g:9:13: unknown dynamically-scoped attribute for scope S: j in $S::j",
"$S::j = 3;", "error(55): A.g:9:13: unknown dynamically-scoped attribute for scope S: j in $S::j = 3;",
"$S::j = $S::k;", "error(55): A.g:9:13: unknown dynamically-scoped attribute for scope S: j in $S::j = $S::k;\n" + "$S::j = $S::k;", "error(55): A.g:9:13: unknown dynamically-scoped attribute for scope S: j in $S::j = $S::k;\n" +
"error(55): A.g:9:21: unknown dynamically-scoped attribute for scope S: k in $S::k", "error(55): A.g:9:21: unknown dynamically-scoped attribute for scope S: k in $S::k",
"$Q[-1]::y", "error(54): A.g:9:10: unknown dynamic scope: Q in $Q[-1]::y",
"$Q[-i]::y", "error(54): A.g:9:10: unknown dynamic scope: Q in $Q[-i]::y",
"$Q[i]::y", "error(54): A.g:9:10: unknown dynamic scope: Q in $Q[i]::y",
"$Q[0]::y", "error(54): A.g:9:10: unknown dynamic scope: Q in $Q[0]::y",
"$Q[-1]::y = 23;", "error(54): A.g:9:10: unknown dynamic scope: Q in $Q[-1]::y = 23;",
"$Q[-i]::y = 23;", "error(54): A.g:9:10: unknown dynamic scope: Q in $Q[-i]::y = 23;",
"$Q[i]::y = 23;", "error(54): A.g:9:10: unknown dynamic scope: Q in $Q[i]::y = 23;",
"$Q[0]::y = 23;", "error(54): A.g:9:10: unknown dynamic scope: Q in $Q[0]::y = 23;",
"$S[-1]::y", "error(55): A.g:9:17: unknown dynamically-scoped attribute for scope S: y in $S[-1]::y",
"$S[-i]::y", "error(55): A.g:9:17: unknown dynamically-scoped attribute for scope S: y in $S[-i]::y",
"$S[i]::y", "error(55): A.g:9:16: unknown dynamically-scoped attribute for scope S: y in $S[i]::y",
"$S[0]::y", "error(55): A.g:9:16: unknown dynamically-scoped attribute for scope S: y in $S[0]::y",
"$S[-1]::y = 23;", "error(55): A.g:9:17: unknown dynamically-scoped attribute for scope S: y in $S[-1]::y = 23;",
"$S[-i]::y = 23;", "error(55): A.g:9:17: unknown dynamically-scoped attribute for scope S: y in $S[-i]::y = 23;",
"$S[i]::y = 23;", "error(55): A.g:9:16: unknown dynamically-scoped attribute for scope S: y in $S[i]::y = 23;",
"$S[0]::y = 23;", "error(55): A.g:9:16: unknown dynamically-scoped attribute for scope S: y in $S[0]::y = 23;",
"$S[$S::y]::i", "error(55): A.g:9:16: unknown dynamically-scoped attribute for scope S: y in $S::y"
}; };
String[] dynFinallyChecks = { String[] dynFinallyChecks = {