From 36acb139b7b8af91a972d577fecf2453911b6c9b Mon Sep 17 00:00:00 2001 From: Sam Harwell Date: Fri, 28 Jun 2013 10:28:55 -0500 Subject: [PATCH] Remove the SET_QUALIFIED_ATTR rule from ActionSplitter since it provides no additional functionality (fixes #295) --- tool/src/org/antlr/v4/codegen/ActionTranslator.java | 9 --------- tool/src/org/antlr/v4/parse/ActionSplitter.g | 7 ------- tool/src/org/antlr/v4/parse/ActionSplitterListener.java | 1 - tool/src/org/antlr/v4/semantics/ActionSniffer.java | 6 ------ tool/src/org/antlr/v4/semantics/AttributeChecks.java | 6 ------ .../antlr/v4/semantics/BlankActionSplitterListener.java | 4 ---- tool/src/org/antlr/v4/semantics/UseDefAnalyzer.java | 2 -- tool/test/org/antlr/v4/test/TestActionSplitter.java | 2 +- tool/test/org/antlr/v4/test/TestActionTranslation.java | 4 ++-- tool/test/org/antlr/v4/test/TestAttributeChecks.java | 9 +++++---- 10 files changed, 8 insertions(+), 42 deletions(-) diff --git a/tool/src/org/antlr/v4/codegen/ActionTranslator.java b/tool/src/org/antlr/v4/codegen/ActionTranslator.java index 4e374607c..6647bc40b 100644 --- a/tool/src/org/antlr/v4/codegen/ActionTranslator.java +++ b/tool/src/org/antlr/v4/codegen/ActionTranslator.java @@ -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 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); diff --git a/tool/src/org/antlr/v4/parse/ActionSplitter.g b/tool/src/org/antlr/v4/parse/ActionSplitter.g index 99ed437f5..5feeb955d 100644 --- a/tool/src/org/antlr/v4/parse/ActionSplitter.g +++ b/tool/src/org/antlr/v4/parse/ActionSplitter.g @@ -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);} ; diff --git a/tool/src/org/antlr/v4/parse/ActionSplitterListener.java b/tool/src/org/antlr/v4/parse/ActionSplitterListener.java index 6f9dd2151..0e793b717 100644 --- a/tool/src/org/antlr/v4/parse/ActionSplitterListener.java +++ b/tool/src/org/antlr/v4/parse/ActionSplitterListener.java @@ -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); diff --git a/tool/src/org/antlr/v4/semantics/ActionSniffer.java b/tool/src/org/antlr/v4/semantics/ActionSniffer.java index 1331ebb3b..2d48e25e6 100644 --- a/tool/src/org/antlr/v4/semantics/ActionSniffer.java +++ b/tool/src/org/antlr/v4/semantics/ActionSniffer.java @@ -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); diff --git a/tool/src/org/antlr/v4/semantics/AttributeChecks.java b/tool/src/org/antlr/v4/semantics/AttributeChecks.java index 805e04b9d..f70218535 100644 --- a/tool/src/org/antlr/v4/semantics/AttributeChecks.java +++ b/tool/src/org/antlr/v4/semantics/AttributeChecks.java @@ -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) { diff --git a/tool/src/org/antlr/v4/semantics/BlankActionSplitterListener.java b/tool/src/org/antlr/v4/semantics/BlankActionSplitterListener.java index a00bdf8c0..e919890c1 100644 --- a/tool/src/org/antlr/v4/semantics/BlankActionSplitterListener.java +++ b/tool/src/org/antlr/v4/semantics/BlankActionSplitterListener.java @@ -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) { } diff --git a/tool/src/org/antlr/v4/semantics/UseDefAnalyzer.java b/tool/src/org/antlr/v4/semantics/UseDefAnalyzer.java index eb4f0e64d..ac788e144 100644 --- a/tool/src/org/antlr/v4/semantics/UseDefAnalyzer.java +++ b/tool/src/org/antlr/v4/semantics/UseDefAnalyzer.java @@ -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); diff --git a/tool/test/org/antlr/v4/test/TestActionSplitter.java b/tool/test/org/antlr/v4/test/TestActionSplitter.java index 530be6966..af8c11f87 100644 --- a/tool/test/org/antlr/v4/test/TestActionSplitter.java +++ b/tool/test/org/antlr/v4/test/TestActionSplitter.java @@ -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 + ">]", diff --git a/tool/test/org/antlr/v4/test/TestActionTranslation.java b/tool/test/org/antlr/v4/test/TestActionTranslation.java index 03a5d063f..85b4c345d 100644 --- a/tool/test/org/antlr/v4/test/TestActionTranslation.java +++ b/tool/test/org/antlr/v4/test/TestActionTranslation.java @@ -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); } diff --git a/tool/test/org/antlr/v4/test/TestAttributeChecks.java b/tool/test/org/antlr/v4/test/TestAttributeChecks.java index 73466ed44..652beb065 100644 --- a/tool/test/org/antlr/v4/test/TestAttributeChecks.java +++ b/tool/test/org/antlr/v4/test/TestAttributeChecks.java @@ -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",