1 23 24 package org.objectweb.medor.expression.lib; 25 26 import org.objectweb.jorm.type.api.PType; 27 import org.objectweb.jorm.type.api.PTypeSpace; 28 import org.objectweb.medor.expression.api.BinaryLogicalOperator; 29 import org.objectweb.medor.expression.api.ExpressionException; 30 import org.objectweb.medor.expression.api.MalformedExpressionException; 31 import org.objectweb.medor.expression.api.Operand; 32 import org.objectweb.medor.expression.api.ParameterOperand; 33 import org.objectweb.medor.expression.api.TypingException; 34 import org.objectweb.medor.expression.api.Expression; 35 36 40 public abstract class BasicBinaryLogicalOperator 41 extends BasicBinaryOperator 42 implements BinaryLogicalOperator { 43 44 public BasicBinaryLogicalOperator() { 45 super(PTypeSpace.BOOLEAN); 46 } 47 48 public BasicBinaryLogicalOperator(Expression e0, Expression e1) { 49 super(PTypeSpace.BOOLEAN, e0, e1); 50 } 51 54 public org.objectweb.medor.expression.api.Operand evaluate(ParameterOperand[] pos, Object o) 55 throws ExpressionException { 56 try { 57 result.setValue( 58 evaluate( 59 expressions[0].evaluate(pos, o).getBoolean(), 60 expressions[1].evaluate(pos, o).getBoolean())); 61 } catch (NullPointerException e) { 62 throw new IllegalStateException ("Unevaluable Expression: Not compiled"); 63 } 64 return result; 65 } 66 67 70 public abstract boolean evaluate(boolean b1, boolean b2); 71 72 public Operand compileExpression() throws ExpressionException, MalformedExpressionException { 73 if ((expressions[0] != null) && (expressions[1] != null)) { 74 expressions[0].compileExpression(); 75 expressions[1].compileExpression(); 76 if (!(expressions[0].getType() == null || expressions[1].getType() == null)) { 77 if ((expressions[0].getType().getTypeCode() == PType.TYPECODE_BOOLEAN) 78 && 79 (expressions[1].getType().getTypeCode() == PType.TYPECODE_BOOLEAN)) { 80 result = new BasicVariableOperand(type); 81 verified = true; 82 } else 83 throw new TypingException("Attempt a boolean type"); } else 85 throw new MalformedExpressionException("null children value"); } else 87 throw new MalformedExpressionException("null children value"); return result; 89 } 90 } 91 | Popular Tags |