[ClavaAst] Improves MSPropertyRefExpr.isOnLeftSideOfAssign()
@@ -23,12 +23,12 @@ import pt.up.fe.specs.clava.ClavaNode;
import pt.up.fe.specs.clava.ast.decl.MSPropertyDecl;
import pt.up.fe.specs.clava.ast.expr.enums.BinaryOperatorKind;
import pt.up.fe.specs.clava.ast.extra.TranslationUnit;
-import pt.up.fe.specs.clava.ast.stmt.Stmt;
/**
* A member reference to an MSPropertyDecl.
*
- * This expression always has pseudo-object type, and therefore it is typically not encountered in a fully-type checked expression except within the syntactic form of a PseudoObjectExpr.
+ * This expression always has pseudo-object type, and therefore it is typically not encountered in a fully-type checked
+ * expression except within the syntactic form of a PseudoObjectExpr.
*
* @author jbispo
*
@@ -40,7 +40,6 @@ public class MSPropertyRefExpr extends Expr {
public static final DataKey<Boolean> IS_IMPLICIT_ACCESS = KeyFactory.bool("isImplicitAccess");
public static final DataKey<Boolean> IS_ARROW = KeyFactory.bool("isArrow");
-
public MSPropertyRefExpr(DataStore data, Collection<? extends ClavaNode> children) {
super(data, children);
}
@@ -51,6 +50,29 @@ public class MSPropertyRefExpr extends Expr {
}
public boolean isOnLeftSideOfAssign() {
+ // Check if immediate parent is a binary operator expression, and if node is on the left side
+
+ var parent = getParent();
+
+ if (parent == null) {
+ return false;
+ }
+
+ // If not a BinaryOperator, ignore
+ if (!(parent instanceof BinaryOperator)) {
+ return false;
+ }
+
+ var op = parent.get(BinaryOperator.OP);
+
+ // Ignore ops that are not assignment
+ if (op != BinaryOperatorKind.Assign) {
+ return false;
+ }
+
+ // Found assignment, check on which side of the assignment is this node
+ return ((BinaryOperator) parent).getLhs() == this;
+ /*
ClavaNode currentNode = this;
// Go back until a statement is found, or there is no parent
@@ -80,6 +102,7 @@ public class MSPropertyRefExpr extends Expr {
}
return false;
+ */
}
@Override
@@ -89,7 +112,8 @@ public class MSPropertyRefExpr extends Expr {
// If there is an assignment and is on the left side of the assignment, is a setter. Otherwise, getter
var isOnLeftSide = isOnLeftSideOfAssign();
- var propertyString = isOnLeftSide ? property.get(MSPropertyDecl.SETTER_NAME) : property.get(MSPropertyDecl.GETTER_NAME);
+ var propertyString = isOnLeftSide ? property.get(MSPropertyDecl.SETTER_NAME)
+ : property.get(MSPropertyDecl.GETTER_NAME);
if (propertyString.isEmpty()) {
String expected = isOnLeftSide ? "setter" : "getter";
