forked from jasder/antlr
Merge pull request #296 from sharwell/fix-295
Remove the SET_QUALIFIED_ATTR rule from ActionSplitter
This commit is contained in:
commit
28c240c54c
|
@ -195,15 +195,6 @@ public class ActionTranslator implements ActionSplitterListener {
|
|||
}
|
||||
}
|
||||
|
||||
/** $x.y = expr; */
|
||||
@Override
|
||||
public void setQualifiedAttr(String expr, Token x, Token y, Token rhs) {
|
||||
gen.g.tool.log("action-translator", "setQAttr "+x+"."+y+"="+rhs);
|
||||
// x has to be current rule; just set y attr
|
||||
List<ActionChunk> rhsChunks = translateActionChunk(factory,rf,rhs.getText(),node);
|
||||
chunks.add(new SetAttr(nodeContext,y.getText(), rhsChunks));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void qualifiedAttr(String expr, Token x, Token y) {
|
||||
gen.g.tool.log("action-translator", "qattr "+x+"."+y);
|
||||
|
|
|
@ -83,13 +83,6 @@ NONLOCAL_ATTR
|
|||
: '$' x=ID '::' y=ID {delegate.nonLocalAttr($text, $x, $y);}
|
||||
;
|
||||
|
||||
SET_QUALIFIED_ATTR
|
||||
: '$' x=ID '.' y=ID WS? '=' expr=ATTR_VALUE_EXPR ';'
|
||||
{
|
||||
delegate.setQualifiedAttr($text, $x, $y, $expr);
|
||||
}
|
||||
;
|
||||
|
||||
QUALIFIED_ATTR
|
||||
: '$' x=ID '.' y=ID {input.LA(1)!='('}? {delegate.qualifiedAttr($text, $x, $y);}
|
||||
;
|
||||
|
|
|
@ -34,7 +34,6 @@ import org.antlr.runtime.Token;
|
|||
|
||||
/** */
|
||||
public interface ActionSplitterListener {
|
||||
void setQualifiedAttr(String expr, Token x, Token y, Token rhs);
|
||||
void qualifiedAttr(String expr, Token x, Token y);
|
||||
void setAttr(String expr, Token x, Token rhs);
|
||||
void attr(String expr, Token x);
|
||||
|
|
|
@ -95,12 +95,6 @@ public class ActionSniffer extends BlankActionSplitterListener {
|
|||
processNested(rhs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setQualifiedAttr(String expr, Token x, Token y, Token rhs) {
|
||||
trackRef(x);
|
||||
processNested(rhs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNonLocalAttr(String expr, Token x, Token y, Token rhs) {
|
||||
processNested(rhs);
|
||||
|
|
|
@ -110,12 +110,6 @@ public class AttributeChecks implements ActionSplitterListener {
|
|||
|
||||
// LISTENER METHODS
|
||||
|
||||
@Override
|
||||
public void setQualifiedAttr(String expr, Token x, Token y, Token rhs) {
|
||||
qualifiedAttr(expr, x, y);
|
||||
new AttributeChecks(g, r, alt, node, rhs).examineAction();
|
||||
}
|
||||
|
||||
// $x.y
|
||||
@Override
|
||||
public void qualifiedAttr(String expr, Token x, Token y) {
|
||||
|
|
|
@ -34,10 +34,6 @@ import org.antlr.runtime.Token;
|
|||
import org.antlr.v4.parse.ActionSplitterListener;
|
||||
|
||||
public class BlankActionSplitterListener implements ActionSplitterListener {
|
||||
@Override
|
||||
public void setQualifiedAttr(String expr, Token x, Token y, Token rhs) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void qualifiedAttr(String expr, Token x, Token y) {
|
||||
}
|
||||
|
|
|
@ -81,8 +81,6 @@ public class UseDefAnalyzer {
|
|||
@Override
|
||||
public void setNonLocalAttr(String expr, Token x, Token y, Token rhs) { dependent[0] = true; }
|
||||
@Override
|
||||
public void setQualifiedAttr(String expr, Token x, Token y, Token rhs) { dependent[0] = true; }
|
||||
@Override
|
||||
public void attr(String expr, Token x) { dependent[0] = true; }
|
||||
};
|
||||
ActionSplitter splitter = new ActionSplitter(in, listener);
|
||||
|
|
|
@ -50,7 +50,7 @@ public class TestActionSplitter extends BaseTest {
|
|||
"$ID.text", "['$ID.text'<" + ActionSplitter.QUALIFIED_ATTR + ">]",
|
||||
"$ID", "['$ID'<" + ActionSplitter.ATTR + ">]",
|
||||
"$ID.getText()", "['$ID'<" + ActionSplitter.ATTR + ">, '.getText()'<" + ActionSplitter.TEXT + ">]",
|
||||
"$ID.text = \"test\";", "['$ID.text = \"test\";'<" + ActionSplitter.SET_QUALIFIED_ATTR + ">]",
|
||||
"$ID.text = \"test\";", "['$ID.text'<" + ActionSplitter.QUALIFIED_ATTR + ">, ' = \"test\";'<" + ActionSplitter.TEXT + ">]",
|
||||
"$a.line == $b.line", "['$a.line'<" + ActionSplitter.QUALIFIED_ATTR + ">, ' == '<" + ActionSplitter.TEXT + ">, '$b.line'<" + ActionSplitter.QUALIFIED_ATTR + ">]",
|
||||
"$r.tree", "['$r.tree'<" + ActionSplitter.QUALIFIED_ATTR + ">]",
|
||||
"foo $a::n bar", "['foo '<" + ActionSplitter.TEXT + ">, '$a::n'<" + ActionSplitter.NONLOCAL_ATTR + ">, ' bar'<" + ActionSplitter.TEXT + ">]",
|
||||
|
|
|
@ -143,8 +143,8 @@ public class TestActionTranslation extends BaseTest {
|
|||
}
|
||||
|
||||
@Test public void testReturnValues() throws Exception {
|
||||
String action = "$lab.e; $b.e;";
|
||||
String expected = "((AContext)_localctx).lab.e; ((AContext)_localctx).b.e;";
|
||||
String action = "$lab.e; $b.e; $y.e = \"\";";
|
||||
String expected = "((AContext)_localctx).lab.e; ((AContext)_localctx).b.e; _localctx.y.e = \"\";";
|
||||
testActions(attributeTemplate, "inline", action, expected);
|
||||
}
|
||||
|
||||
|
|
|
@ -77,6 +77,7 @@ public class TestAttributeChecks extends BaseTest {
|
|||
"$start", "",
|
||||
"$x = $y", "",
|
||||
"$y = $x", "",
|
||||
"$y.b = 3;", "",
|
||||
"$a.x = $a.y", "",
|
||||
"$lab.e", "",
|
||||
"$lab.text", "",
|
||||
|
@ -96,11 +97,11 @@ public class TestAttributeChecks extends BaseTest {
|
|||
"$q.y", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference 'q' in '$q.y'\n",
|
||||
"$q = 3", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference 'q' in '$q'\n",
|
||||
"$q = 3;", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference 'q' in '$q = 3;'\n",
|
||||
"$q.y = 3;", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference 'q' in '$q.y = 3;'\n",
|
||||
"$q.y = 3;", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference 'q' in '$q.y'\n",
|
||||
"$q = $blort;", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference 'q' in '$q = $blort;'\n" +
|
||||
"error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:9: unknown attribute reference 'blort' in '$blort'\n",
|
||||
"$a.ick", "error(" + ErrorType.UNKNOWN_RULE_ATTRIBUTE.code + "): A.g4:7:6: unknown attribute 'ick' for rule 'a' in '$a.ick'\n",
|
||||
"$a.ick = 3;", "error(" + ErrorType.UNKNOWN_RULE_ATTRIBUTE.code + "): A.g4:7:6: unknown attribute 'ick' for rule 'a' in '$a.ick = 3;'\n",
|
||||
"$a.ick = 3;", "error(" + ErrorType.UNKNOWN_RULE_ATTRIBUTE.code + "): A.g4:7:6: unknown attribute 'ick' for rule 'a' in '$a.ick'\n",
|
||||
"$b.d", "error(" + ErrorType.INVALID_RULE_PARAMETER_REF.code + "): A.g4:7:6: parameter 'd' of rule 'b' is not accessible in this scope: $b.d\n", // can't see rule ref's arg
|
||||
"$d.text", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference 'd' in '$d.text'\n", // valid rule, but no ref
|
||||
"$lab.d", "error(" + ErrorType.INVALID_RULE_PARAMETER_REF.code + "): A.g4:7:8: parameter 'd' of rule 'b' is not accessible in this scope: $lab.d\n",
|
||||
|
@ -125,11 +126,11 @@ public class TestAttributeChecks extends BaseTest {
|
|||
"$q.y", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:10:14: unknown attribute reference 'q' in '$q.y'\n",
|
||||
"$q = 3", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:10:14: unknown attribute reference 'q' in '$q'\n",
|
||||
"$q = 3;", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:10:14: unknown attribute reference 'q' in '$q = 3;'\n",
|
||||
"$q.y = 3;", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:10:14: unknown attribute reference 'q' in '$q.y = 3;'\n",
|
||||
"$q.y = 3;", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:10:14: unknown attribute reference 'q' in '$q.y'\n",
|
||||
"$q = $blort;", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:10:14: unknown attribute reference 'q' in '$q = $blort;'\n" +
|
||||
"error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:10:19: unknown attribute reference 'blort' in '$blort'\n",
|
||||
"$a.ick", "error(" + ErrorType.UNKNOWN_RULE_ATTRIBUTE.code + "): A.g4:10:16: unknown attribute 'ick' for rule 'a' in '$a.ick'\n",
|
||||
"$a.ick = 3;", "error(" + ErrorType.UNKNOWN_RULE_ATTRIBUTE.code + "): A.g4:10:16: unknown attribute 'ick' for rule 'a' in '$a.ick = 3;'\n",
|
||||
"$a.ick = 3;", "error(" + ErrorType.UNKNOWN_RULE_ATTRIBUTE.code + "): A.g4:10:16: unknown attribute 'ick' for rule 'a' in '$a.ick'\n",
|
||||
"$b.e", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:10:14: unknown attribute reference 'b' in '$b.e'\n", // can't see rule refs outside alts
|
||||
"$b.d", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:10:14: unknown attribute reference 'b' in '$b.d'\n",
|
||||
"$c.text", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:10:14: unknown attribute reference 'c' in '$c.text'\n",
|
||||
|
|
Loading…
Reference in New Issue