Skip to content

Commit

Permalink
binaryOperatorinvocation can change the operator
Browse files Browse the repository at this point in the history
  • Loading branch information
miho committed Aug 13, 2015
1 parent b967cd9 commit c53ff10
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,21 @@
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

package eu.mihosoft.vrl.lang.model;

/**
*
* @author miho
*/
public interface BinaryOperatorInvocation extends Invocation{
IArgument getLeftArgument();
public interface BinaryOperatorInvocation extends Invocation {

IArgument getLeftArgument();

IArgument getRightArgument();

Operator getOperator();


void setOperator(Operator op);

boolean isArrayAccessOperator();
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,42 +13,43 @@
*/
public class BinaryOperatorInvocationImpl extends InvocationImpl implements BinaryOperatorInvocation {

private final Operator operator;
private Operator operator;

public BinaryOperatorInvocationImpl(String id, Scope parent, IArgument leftArg, IArgument rightArg, Operator operator) {

super(parent, id, null, "op " + operator, Type.VOID, false, true, leftArg, rightArg);

this.operator = operator;

IType retType = Type.VOID;
validate(operator, leftArg);
}

if (assignmentOperator(operator)) {
private void validate(Operator operator1, IArgument leftArg) throws IllegalArgumentException {
IType retType = Type.VOID;
if (assignmentOperator(operator1)) {
if (leftArg.getArgType() != ArgumentType.VARIABLE) {
throw new IllegalArgumentException("Left Argument must be a variable!");
} else {
retType = leftArg.getVariable().get().getType();
}
} else if (booleanOperator(operator)) {
// if (leftArg.getArgType() == ArgumentType.VARIABLE
} else if (booleanOperator(operator1)) {
// if (leftArg.getArgType() == ArgumentType.VARIABLE
// && rightArg.getArgType() == ArgumentType.VARIABLE) {

// TODO: check that leftArg and rightArg == const or var or invocation
// TODO: check that leftArg and rightArg == const or var or invocation
retType = Type.BOOLEAN;
// }
} else if (basicArithmeticOperator(operator)) {
} else if (basicArithmeticOperator(operator1)) {
retType = Type.OBJECT;
} else if (arrayElementOperator(operator)) {
} else if (arrayElementOperator(operator1)) {
if (leftArg.getArgType() != ArgumentType.VARIABLE) {
throw new IllegalArgumentException("Left Argument must be a variable!");
} else {
retType = leftArg.getVariable().get().getType();
}
}

setReturnType(retType);

getNode().setTitle("op " + operator);
getNode().setTitle("op " + operator1);
}

public static boolean pureAssignmentOperator(Operator operator) {
Expand Down Expand Up @@ -151,4 +152,10 @@ public boolean isArrayAccessOperator() {
return arrayElementOperator(operator);
}

@Override
public void setOperator(Operator op) {
this.operator = op;
validate(operator, getLeftArgument());
}

}

0 comments on commit c53ff10

Please sign in to comment.