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
|
@Override
|
||||||
public void qualifiedAttr(String expr, Token x, Token y) {
|
public void qualifiedAttr(String expr, Token x, Token y) {
|
||||||
gen.g.tool.log("action-translator", "qattr "+x+"."+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);}
|
: '$' 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
|
QUALIFIED_ATTR
|
||||||
: '$' x=ID '.' y=ID {input.LA(1)!='('}? {delegate.qualifiedAttr($text, $x, $y);}
|
: '$' x=ID '.' y=ID {input.LA(1)!='('}? {delegate.qualifiedAttr($text, $x, $y);}
|
||||||
;
|
;
|
||||||
|
|
|
@ -34,7 +34,6 @@ import org.antlr.runtime.Token;
|
||||||
|
|
||||||
/** */
|
/** */
|
||||||
public interface ActionSplitterListener {
|
public interface ActionSplitterListener {
|
||||||
void setQualifiedAttr(String expr, Token x, Token y, Token rhs);
|
|
||||||
void qualifiedAttr(String expr, Token x, Token y);
|
void qualifiedAttr(String expr, Token x, Token y);
|
||||||
void setAttr(String expr, Token x, Token rhs);
|
void setAttr(String expr, Token x, Token rhs);
|
||||||
void attr(String expr, Token x);
|
void attr(String expr, Token x);
|
||||||
|
|
|
@ -95,12 +95,6 @@ public class ActionSniffer extends BlankActionSplitterListener {
|
||||||
processNested(rhs);
|
processNested(rhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setQualifiedAttr(String expr, Token x, Token y, Token rhs) {
|
|
||||||
trackRef(x);
|
|
||||||
processNested(rhs);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setNonLocalAttr(String expr, Token x, Token y, Token rhs) {
|
public void setNonLocalAttr(String expr, Token x, Token y, Token rhs) {
|
||||||
processNested(rhs);
|
processNested(rhs);
|
||||||
|
|
|
@ -110,12 +110,6 @@ public class AttributeChecks implements ActionSplitterListener {
|
||||||
|
|
||||||
// LISTENER METHODS
|
// 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
|
// $x.y
|
||||||
@Override
|
@Override
|
||||||
public void qualifiedAttr(String expr, Token x, Token y) {
|
public void qualifiedAttr(String expr, Token x, Token y) {
|
||||||
|
|
|
@ -34,10 +34,6 @@ import org.antlr.runtime.Token;
|
||||||
import org.antlr.v4.parse.ActionSplitterListener;
|
import org.antlr.v4.parse.ActionSplitterListener;
|
||||||
|
|
||||||
public class BlankActionSplitterListener implements ActionSplitterListener {
|
public class BlankActionSplitterListener implements ActionSplitterListener {
|
||||||
@Override
|
|
||||||
public void setQualifiedAttr(String expr, Token x, Token y, Token rhs) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void qualifiedAttr(String expr, Token x, Token y) {
|
public void qualifiedAttr(String expr, Token x, Token y) {
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,8 +81,6 @@ public class UseDefAnalyzer {
|
||||||
@Override
|
@Override
|
||||||
public void setNonLocalAttr(String expr, Token x, Token y, Token rhs) { dependent[0] = true; }
|
public void setNonLocalAttr(String expr, Token x, Token y, Token rhs) { dependent[0] = true; }
|
||||||
@Override
|
@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; }
|
public void attr(String expr, Token x) { dependent[0] = true; }
|
||||||
};
|
};
|
||||||
ActionSplitter splitter = new ActionSplitter(in, listener);
|
ActionSplitter splitter = new ActionSplitter(in, listener);
|
||||||
|
|
|
@ -50,7 +50,7 @@ public class TestActionSplitter extends BaseTest {
|
||||||
"$ID.text", "['$ID.text'<" + ActionSplitter.QUALIFIED_ATTR + ">]",
|
"$ID.text", "['$ID.text'<" + ActionSplitter.QUALIFIED_ATTR + ">]",
|
||||||
"$ID", "['$ID'<" + ActionSplitter.ATTR + ">]",
|
"$ID", "['$ID'<" + ActionSplitter.ATTR + ">]",
|
||||||
"$ID.getText()", "['$ID'<" + ActionSplitter.ATTR + ">, '.getText()'<" + ActionSplitter.TEXT + ">]",
|
"$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 + ">]",
|
"$a.line == $b.line", "['$a.line'<" + ActionSplitter.QUALIFIED_ATTR + ">, ' == '<" + ActionSplitter.TEXT + ">, '$b.line'<" + ActionSplitter.QUALIFIED_ATTR + ">]",
|
||||||
"$r.tree", "['$r.tree'<" + 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 + ">]",
|
"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 {
|
@Test public void testReturnValues() throws Exception {
|
||||||
String action = "$lab.e; $b.e;";
|
String action = "$lab.e; $b.e; $y.e = \"\";";
|
||||||
String expected = "((AContext)_localctx).lab.e; ((AContext)_localctx).b.e;";
|
String expected = "((AContext)_localctx).lab.e; ((AContext)_localctx).b.e; _localctx.y.e = \"\";";
|
||||||
testActions(attributeTemplate, "inline", action, expected);
|
testActions(attributeTemplate, "inline", action, expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -77,6 +77,7 @@ public class TestAttributeChecks extends BaseTest {
|
||||||
"$start", "",
|
"$start", "",
|
||||||
"$x = $y", "",
|
"$x = $y", "",
|
||||||
"$y = $x", "",
|
"$y = $x", "",
|
||||||
|
"$y.b = 3;", "",
|
||||||
"$a.x = $a.y", "",
|
"$a.x = $a.y", "",
|
||||||
"$lab.e", "",
|
"$lab.e", "",
|
||||||
"$lab.text", "",
|
"$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.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'\n",
|
||||||
"$q = 3;", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference 'q' in '$q = 3;'\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" +
|
"$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",
|
"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", "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
|
"$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
|
"$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",
|
"$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.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'\n",
|
||||||
"$q = 3;", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:10:14: unknown attribute reference 'q' in '$q = 3;'\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" +
|
"$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",
|
"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", "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.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",
|
"$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",
|
"$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