From c53ff10d1a4dc814934560a97ade58ab117bd3cc Mon Sep 17 00:00:00 2001 From: Michael Hoffer Date: Thu, 13 Aug 2015 13:07:27 +0200 Subject: [PATCH] binaryOperatorinvocation can change the operator --- .../lang/model/BinaryOperatorInvocation.java | 12 ++++--- .../model/BinaryOperatorInvocationImpl.java | 31 ++++++++++++------- 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/VRL/VRL-Lang/src/main/java/eu/mihosoft/vrl/lang/model/BinaryOperatorInvocation.java b/VRL/VRL-Lang/src/main/java/eu/mihosoft/vrl/lang/model/BinaryOperatorInvocation.java index 43640150..b90a3d20 100644 --- a/VRL/VRL-Lang/src/main/java/eu/mihosoft/vrl/lang/model/BinaryOperatorInvocation.java +++ b/VRL/VRL-Lang/src/main/java/eu/mihosoft/vrl/lang/model/BinaryOperatorInvocation.java @@ -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(); } diff --git a/VRL/VRL-Lang/src/main/java/eu/mihosoft/vrl/lang/model/BinaryOperatorInvocationImpl.java b/VRL/VRL-Lang/src/main/java/eu/mihosoft/vrl/lang/model/BinaryOperatorInvocationImpl.java index 95609259..271a2e5f 100644 --- a/VRL/VRL-Lang/src/main/java/eu/mihosoft/vrl/lang/model/BinaryOperatorInvocationImpl.java +++ b/VRL/VRL-Lang/src/main/java/eu/mihosoft/vrl/lang/model/BinaryOperatorInvocationImpl.java @@ -13,7 +13,7 @@ */ 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) { @@ -21,34 +21,35 @@ public BinaryOperatorInvocationImpl(String id, Scope parent, IArgument leftArg, 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) { @@ -151,4 +152,10 @@ public boolean isArrayAccessOperator() { return arrayElementOperator(operator); } + @Override + public void setOperator(Operator op) { + this.operator = op; + validate(operator, getLeftArgument()); + } + }