Skip to content

Commit

Permalink
Fix for #1580: retain dynamic selector expression
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed May 13, 2024
1 parent 16313b5 commit 776e02f
Show file tree
Hide file tree
Showing 8 changed files with 187 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2836,7 +2836,11 @@ public Expression visitNamePart(final NamePartContext ctx) {
} else if (asBoolean(ctx.stringLiteral())) {
return configureAST(this.visitStringLiteral(ctx.stringLiteral()), ctx);
} else if (asBoolean(ctx.dynamicMemberName())) {
/* GRECLIPSE edit
return configureAST(this.visitDynamicMemberName(ctx.dynamicMemberName()), ctx);
*/
return this.visitDynamicMemberName(ctx.dynamicMemberName());
// GRECLIPSE end
} else if (asBoolean(ctx.keywords())) {
return configureAST(new ConstantExpression(ctx.keywords().getText()), ctx);
}
Expand All @@ -2847,7 +2851,11 @@ public Expression visitNamePart(final NamePartContext ctx) {
@Override
public Expression visitDynamicMemberName(final DynamicMemberNameContext ctx) {
if (asBoolean(ctx.parExpression())) {
/* GRECLIPSE edit
return configureAST(this.visitParExpression(ctx.parExpression()), ctx);
*/
return this.visitParExpression(ctx.parExpression());
// GRECLIPSE end
} else if (asBoolean(ctx.gstring())) {
return configureAST(this.visitGstring(ctx.gstring()), ctx);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2267,12 +2267,14 @@ protected Expression expression(AST node, boolean convertToConstant) {
// method doesn't know we want a ConstantExpression instead of a
// VariableExpression
VariableExpression ve = (VariableExpression) expression;
/* GRECLIPSE edit
if (!ve.isThisExpression() && !ve.isSuperExpression()) {
expression = new ConstantExpression(ve.getName());
// GRECLIPSE add
configureAST(expression, node);
// GRECLIPSE end
}
*/
expression = new ConstantExpression(ve.getName());
expression.setSourcePosition(ve);
// GRECLIPSE end
}
/* GRECLIPSE edit -- each case of expressionSwitch does this already
configureAST(expression, node);
Expand All @@ -2284,7 +2286,7 @@ protected Expression expressionSwitch(AST node) {
switch (node.getType()) {
case EXPR:
Expression expression = expression(node.getFirstChild());
// GRECLIPSE add -- enclosing parentheses
// GRECLIPSE add -- command expression or enclosing parentheses
int offset = locations.findOffset(node.getLine(), node.getColumn());
if (offset < expression.getStart()) {
if (expression instanceof ArrayExpression ||
Expand Down Expand Up @@ -3023,7 +3025,11 @@ protected Expression dotExpression(AST node) {
if (identifierNode != null) {
Expression leftExpression = expression(leftNode);
if (isType(SELECT_SLOT, identifierNode)) {
/* GRECLIPSE edit
Expression field = expression(identifierNode.getFirstChild(), true);
*/
Expression field = expression(identifierNode.getFirstChild(), !isType(DYNAMIC_MEMBER, identifierNode.getFirstChild()));
// GRECLIPSE end
AttributeExpression attributeExpression = new AttributeExpression(leftExpression, field, node.getType() != DOT);
if (node.getType() == SPREAD_DOT) {
attributeExpression.setSpreadSafe(true);
Expand All @@ -3042,6 +3048,7 @@ protected Expression dotExpression(AST node) {
configureAST(propertyExpression, node);
return chomp(propertyExpression);
}
/* GRECLIPSE edit
Expression property = expression(identifierNode, true);
Expand All @@ -3052,7 +3059,9 @@ protected Expression dotExpression(AST node) {
property = new ConstantExpression(ve.getName());
property.setSourcePosition(ve);
}

*/
Expression property = expression(identifierNode, !isType(DYNAMIC_MEMBER, identifierNode));
// GRECLIPSE end
PropertyExpression propertyExpression = new PropertyExpression(leftExpression, property, node.getType() != DOT);
if (node.getType() == SPREAD_DOT) {
propertyExpression.setSpreadSafe(true);
Expand Down Expand Up @@ -3126,7 +3135,11 @@ protected Expression methodCallExpression(AST methodCallNode) {
} else if (isPrimitiveTypeLiteral(selector)) {
throw new ASTRuntimeException(selector, "Primitive type literal: " + selector.getText() + " cannot be used as a method name");
} else if (isType(SELECT_SLOT, selector)) {
/* GRECLIPSE edit
Expression field = expression(selector.getFirstChild(), true);
*/
Expression field = expression(selector.getFirstChild(), !isType(DYNAMIC_MEMBER, selector.getFirstChild()));
// GRECLIPSE end
AttributeExpression attributeExpression = new AttributeExpression(objectExpression, field, node.getType() != DOT);
configureAST(attributeExpression, node);
Expression arguments = arguments(elist);
Expand All @@ -3136,7 +3149,11 @@ protected Expression methodCallExpression(AST methodCallNode) {
return expression;
} else if (!implicitThis || isType(DYNAMIC_MEMBER, selector) || isType(IDENT, selector) ||
isType(STRING_CONSTRUCTOR, selector) || isType(STRING_LITERAL, selector)) {
/* GRECLIPSE edit
name = expression(selector, true);
*/
name = expression(selector, !isType(DYNAMIC_MEMBER, selector));
// GRECLIPSE end
} else {
implicitThis = false;
name = new ConstantExpression("call");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3300,7 +3300,11 @@ public Expression visitNamePart(final NamePartContext ctx) {
} else if (asBoolean(ctx.stringLiteral())) {
return configureAST(this.visitStringLiteral(ctx.stringLiteral()), ctx);
} else if (asBoolean(ctx.dynamicMemberName())) {
/* GRECLIPSE edit
return configureAST(this.visitDynamicMemberName(ctx.dynamicMemberName()), ctx);
*/
return this.visitDynamicMemberName(ctx.dynamicMemberName());
// GRECLIPSE end
} else if (asBoolean(ctx.keywords())) {
return configureAST(new ConstantExpression(ctx.keywords().getText()), ctx);
}
Expand All @@ -3311,7 +3315,11 @@ public Expression visitNamePart(final NamePartContext ctx) {
@Override
public Expression visitDynamicMemberName(final DynamicMemberNameContext ctx) {
if (asBoolean(ctx.parExpression())) {
/* GRECLIPSE edit
return configureAST(this.visitParExpression(ctx.parExpression()), ctx);
*/
return this.visitParExpression(ctx.parExpression());
// GRECLIPSE end
} else if (asBoolean(ctx.gstring())) {
return configureAST(this.visitGstring(ctx.gstring()), ctx);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2267,12 +2267,14 @@ protected Expression expression(AST node, boolean convertToConstant) {
// method doesn't know we want a ConstantExpression instead of a
// VariableExpression
VariableExpression ve = (VariableExpression) expression;
/* GRECLIPSE edit
if (!ve.isThisExpression() && !ve.isSuperExpression()) {
expression = new ConstantExpression(ve.getName());
// GRECLIPSE add
configureAST(expression, node);
// GRECLIPSE end
}
*/
expression = new ConstantExpression(ve.getName());
expression.setSourcePosition(ve);
// GRECLIPSE end
}
/* GRECLIPSE edit -- each case of expressionSwitch does this already
configureAST(expression, node);
Expand All @@ -2284,7 +2286,7 @@ protected Expression expressionSwitch(AST node) {
switch (node.getType()) {
case EXPR:
Expression expression = expression(node.getFirstChild());
// GRECLIPSE add -- enclosing parentheses
// GRECLIPSE add -- command expression or enclosing parentheses
int offset = locations.findOffset(node.getLine(), node.getColumn());
if (offset < expression.getStart()) {
if (expression instanceof ArrayExpression ||
Expand Down Expand Up @@ -3023,7 +3025,11 @@ protected Expression dotExpression(AST node) {
if (identifierNode != null) {
Expression leftExpression = expression(leftNode);
if (isType(SELECT_SLOT, identifierNode)) {
/* GRECLIPSE edit
Expression field = expression(identifierNode.getFirstChild(), true);
*/
Expression field = expression(identifierNode.getFirstChild(), !isType(DYNAMIC_MEMBER, identifierNode.getFirstChild()));
// GRECLIPSE end
AttributeExpression attributeExpression = new AttributeExpression(leftExpression, field, node.getType() != DOT);
if (node.getType() == SPREAD_DOT) {
attributeExpression.setSpreadSafe(true);
Expand All @@ -3042,6 +3048,7 @@ protected Expression dotExpression(AST node) {
configureAST(propertyExpression, node);
return chomp(propertyExpression);
}
/* GRECLIPSE edit
Expression property = expression(identifierNode, true);
Expand All @@ -3052,7 +3059,9 @@ protected Expression dotExpression(AST node) {
property = new ConstantExpression(ve.getName());
property.setSourcePosition(ve);
}

*/
Expression property = expression(identifierNode, !isType(DYNAMIC_MEMBER, identifierNode));
// GRECLIPSE end
PropertyExpression propertyExpression = new PropertyExpression(leftExpression, property, node.getType() != DOT);
if (node.getType() == SPREAD_DOT) {
propertyExpression.setSpreadSafe(true);
Expand Down Expand Up @@ -3126,7 +3135,11 @@ protected Expression methodCallExpression(AST methodCallNode) {
} else if (isPrimitiveTypeLiteral(selector)) {
throw new ASTRuntimeException(selector, "Primitive type literal: " + selector.getText() + " cannot be used as a method name");
} else if (isType(SELECT_SLOT, selector)) {
/* GRECLIPSE edit
Expression field = expression(selector.getFirstChild(), true);
*/
Expression field = expression(selector.getFirstChild(), !isType(DYNAMIC_MEMBER, selector.getFirstChild()));
// GRECLIPSE end
AttributeExpression attributeExpression = new AttributeExpression(objectExpression, field, node.getType() != DOT);
configureAST(attributeExpression, node);
Expression arguments = arguments(elist);
Expand All @@ -3136,7 +3149,11 @@ protected Expression methodCallExpression(AST methodCallNode) {
return expression;
} else if (!implicitThis || isType(DYNAMIC_MEMBER, selector) || isType(IDENT, selector) ||
isType(STRING_CONSTRUCTOR, selector) || isType(STRING_LITERAL, selector)) {
/* GRECLIPSE edit
name = expression(selector, true);
*/
name = expression(selector, !isType(DYNAMIC_MEMBER, selector));
// GRECLIPSE end
} else {
implicitThis = false;
name = new ConstantExpression("call");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3242,7 +3242,11 @@ public Expression visitNamePart(final NamePartContext ctx) {
} else if (asBoolean(ctx.stringLiteral())) {
return configureAST(this.visitStringLiteral(ctx.stringLiteral()), ctx);
} else if (asBoolean(ctx.dynamicMemberName())) {
/* GRECLIPSE edit
return configureAST(this.visitDynamicMemberName(ctx.dynamicMemberName()), ctx);
*/
return this.visitDynamicMemberName(ctx.dynamicMemberName());
// GRECLIPSE end
} else if (asBoolean(ctx.keywords())) {
return configureAST(new ConstantExpression(ctx.keywords().getText()), ctx);
}
Expand All @@ -3253,7 +3257,11 @@ public Expression visitNamePart(final NamePartContext ctx) {
@Override
public Expression visitDynamicMemberName(final DynamicMemberNameContext ctx) {
if (asBoolean(ctx.parExpression())) {
/* GRECLIPSE edit
return configureAST(this.visitParExpression(ctx.parExpression()), ctx);
*/
return this.visitParExpression(ctx.parExpression());
// GRECLIPSE end
} else if (asBoolean(ctx.gstring())) {
return configureAST(this.visitGstring(ctx.gstring()), ctx);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2269,12 +2269,14 @@ protected Expression expression(AST node, boolean convertToConstant) {
// method doesn't know we want a ConstantExpression instead of a
// VariableExpression
VariableExpression ve = (VariableExpression) expression;
/* GRECLIPSE add
if (!ve.isThisExpression() && !ve.isSuperExpression()) {
expression = new ConstantExpression(ve.getName());
// GRECLIPSE add
configureAST(expression, node);
// GRECLIPSE end
}
*/
expression = new ConstantExpression(ve.getName());
expression.setSourcePosition(ve);
// GRECLIPSE end
}
/* GRECLIPSE edit -- each case of expressionSwitch does this already
configureAST(expression, node);
Expand All @@ -2286,7 +2288,7 @@ protected Expression expressionSwitch(AST node) {
switch (node.getType()) {
case EXPR:
Expression expression = expression(node.getFirstChild());
// GRECLIPSE add -- enclosing parentheses
// GRECLIPSE add -- command expression or enclosing parentheses
int offset = locations.findOffset(node.getLine(), node.getColumn());
if (offset < expression.getStart()) {
if (expression instanceof ArrayExpression ||
Expand Down Expand Up @@ -3025,7 +3027,11 @@ protected Expression dotExpression(AST node) {
if (identifierNode != null) {
Expression leftExpression = expression(leftNode);
if (isType(SELECT_SLOT, identifierNode)) {
/* GRECLIPSE edit
Expression field = expression(identifierNode.getFirstChild(), true);
*/
Expression field = expression(identifierNode.getFirstChild(), !isType(DYNAMIC_MEMBER, identifierNode.getFirstChild()));
// GRECLIPSE end
AttributeExpression attributeExpression = new AttributeExpression(leftExpression, field, node.getType() != DOT);
if (node.getType() == SPREAD_DOT) {
attributeExpression.setSpreadSafe(true);
Expand All @@ -3044,6 +3050,7 @@ protected Expression dotExpression(AST node) {
configureAST(propertyExpression, node);
return chomp(propertyExpression);
}
/* GRECLIPSE edit
Expression property = expression(identifierNode, true);
Expand All @@ -3054,7 +3061,9 @@ protected Expression dotExpression(AST node) {
property = new ConstantExpression(ve.getName());
property.setSourcePosition(ve);
}

*/
Expression property = expression(identifierNode, !isType(DYNAMIC_MEMBER, identifierNode));
// GRECLIPSE end
PropertyExpression propertyExpression = new PropertyExpression(leftExpression, property, node.getType() != DOT);
if (node.getType() == SPREAD_DOT) {
propertyExpression.setSpreadSafe(true);
Expand Down Expand Up @@ -3128,7 +3137,11 @@ protected Expression methodCallExpression(AST methodCallNode) {
} else if (isPrimitiveTypeLiteral(selector)) {
throw new ASTRuntimeException(selector, "Primitive type literal: " + selector.getText() + " cannot be used as a method name");
} else if (isType(SELECT_SLOT, selector)) {
/* GRECLIPSE edit
Expression field = expression(selector.getFirstChild(), true);
*/
Expression field = expression(selector.getFirstChild(), !isType(DYNAMIC_MEMBER, selector.getFirstChild()));
// GRECLIPSE end
AttributeExpression attributeExpression = new AttributeExpression(objectExpression, field, node.getType() != DOT);
configureAST(attributeExpression, node);
Expression arguments = arguments(elist);
Expand All @@ -3138,7 +3151,11 @@ protected Expression methodCallExpression(AST methodCallNode) {
return expression;
} else if (!implicitThis || isType(DYNAMIC_MEMBER, selector) || isType(IDENT, selector) ||
isType(STRING_CONSTRUCTOR, selector) || isType(STRING_LITERAL, selector)) {
/* GRECLIPSE edit
name = expression(selector, true);
*/
name = expression(selector, !isType(DYNAMIC_MEMBER, selector));
// GRECLIPSE end
} else {
implicitThis = false;
name = new ConstantExpression("call");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2009-2023 the original author or authors.
* Copyright 2009-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -177,7 +177,8 @@ private static void handleSingleAssignment(final Expression lhs, final VariableS

} else if (lhs instanceof PropertyExpression) {
PropertyExpression exp = (PropertyExpression) lhs;
handleSingleAssignment(exp.getProperty(), scope, rhsType);
if (!(exp.getProperty() instanceof VariableExpression))
handleSingleAssignment(exp.getProperty(), scope, rhsType);
}/* else {
System.err.println("AssignmentStorer.storeAssignment: LHS is " + lhs.getClass().getSimpleName());
}*/
Expand Down
Loading

0 comments on commit 776e02f

Please sign in to comment.