@Override
  public Expression<K> applyInternal(And<K> input) {

    for (Expression<K> expr : input.expressions) {
      if (expr instanceof Literal) {
        Literal l = (Literal) expr;

        if (l.getValue()) {
          return copyWithoutTrue(input);
        } else {
          return Literal.getFalse();
        }
      }

      //  succeed immediately if require something or its opposite
      if (expr instanceof Not) {
        Expression<K> notChild = ((Not<K>) expr).getE();
        for (Expression<K> child : input.expressions) {
          if (child.equals(notChild)) {
            return Literal.getFalse();
          }
        }
      }
    }

    return input;
  }
 @Override
 public boolean equals(Object obj) {
   if (this == obj) return true;
   if (obj == null) return false;
   if (getClass() != obj.getClass()) return false;
   OperationExpression other = (OperationExpression) obj;
   if (lhs == null) {
     if (other.lhs != null) return false;
   } else if (!lhs.equals(other.lhs)) return false;
   if (op == null) {
     if (other.op != null) return false;
   } else if (!op.equals(other.op)) return false;
   if (rhs == null) {
     if (other.rhs != null) return false;
   } else if (!rhs.equals(other.rhs)) return false;
   return true;
 }
 @Override
 public void substitute(Expression oldExp, Expression newExp) {
   if (exp.equals(oldExp)) {
     exp = newExp;
   } else {
     exp.substitute(oldExp, newExp);
   }
 }
Esempio n. 4
0
  @Override
  public boolean equals(Object o) {
    if (this == o) return true;
    if (o == null || getClass() != o.getClass()) return false;

    UnaryOperation that = (UnaryOperation) o;

    if (!operand.equals(that.operand)) return false;
    return operator == that.operator;
  }
Esempio n. 5
0
 @Override
 Expression<T> simplifyTwo(Expression<T> left, Expression<T> right, T type) {
   if (left instanceof Const && right instanceof Const) return new Const<T>(evaluate());
   else if (left.equals(right)) return new Multiply<T>(new Const<T>(type.parse("2")), left);
   else if ((left instanceof UnaryMin && ((UnaryMin<T>) left).a.equals(right))
       || (right instanceof UnaryMin && ((UnaryMin<T>) right).a.equals(left))) {
     return new Const<T>(type.parse("0"));
   }
   return null;
 }
  @Override
  public void substitute(Expression oldExp, Expression newExp) {
    if (target != null && target.equals(oldExp)) {
      target = newExp;
    }

    if (target != null) {
      target.substitute(oldExp, newExp);
    }

    for (int i = 0; i < arguments.size(); i++) {
      Expression e = arguments.get(i);

      if (e.equals(oldExp)) {
        arguments.set(i, newExp);
      }

      arguments.get(i).substitute(oldExp, newExp);
    }
  }
  /** Inline */
  public Statement inline(Environment env, Context ctx) {
    ctx = new Context(ctx, this);
    cond = cond.inlineValue(env, ctx);

    // The compiler currently needs to perform inlining on both
    // branches of the if statement -- even if `cond' is a constant
    // true or false.  Why?  The compiler will later try to compile
    // all classes that it has seen; this includes classes that
    // appear in dead code.  If we don't inline the dead branch here
    // then the compiler will never perform inlining on any local
    // classes appearing on the dead code.  When the compiler tries
    // to compile an un-inlined local class with uplevel references,
    // it dies.  (bug 4059492)
    //
    // A better solution to this would be to walk the dead branch and
    // mark any local classes appearing therein as unneeded.  Then the
    // compilation phase could skip these classes.
    if (ifTrue != null) {
      ifTrue = ifTrue.inline(env, ctx);
    }
    if (ifFalse != null) {
      ifFalse = ifFalse.inline(env, ctx);
    }
    if (cond.equals(true)) {
      return eliminate(env, ifTrue);
    }
    if (cond.equals(false)) {
      return eliminate(env, ifFalse);
    }
    if ((ifTrue == null) && (ifFalse == null)) {
      return eliminate(env, new ExpressionStatement(where, cond).inline(env, ctx));
    }
    if (ifTrue == null) {
      cond = new NotExpression(cond.where, cond).inlineValue(env, ctx);
      return eliminate(env, new IfStatement(where, cond, ifFalse, null));
    }
    return this;
  }
Esempio n. 8
0
  @Override
  public boolean equals(Object o) {
    if (this == o) return true;
    if (o == null || getClass() != o.getClass()) return false;

    ExpressionCall that = (ExpressionCall) o;

    if (arguments != null ? !arguments.equals(that.arguments) : that.arguments != null)
      return false;
    if (methodName != null ? !methodName.equals(that.methodName) : that.methodName != null)
      return false;
    if (owner != null ? !owner.equals(that.owner) : that.owner != null) return false;

    return true;
  }
Esempio n. 9
0
 @Override
 public boolean equals(Object obj) {
   if (this == obj) {
     return true;
   }
   if (obj == null) {
     return false;
   }
   if (getClass() != obj.getClass()) {
     return false;
   }
   Parenthesized other = (Parenthesized) obj;
   if (expression.equals(other.expression) == false) {
     return false;
   }
   return true;
 }
Esempio n. 10
0
  @Override
  public boolean equals(Object o) {
    if (this == o) {
      return true;
    }
    if (o == null || getClass() != o.getClass()) {
      return false;
    }

    NegativeExpression that = (NegativeExpression) o;

    if (!value.equals(that.value)) {
      return false;
    }

    return true;
  }
Esempio n. 11
0
  @Override
  public boolean equals(Object o) {
    if (this == o) {
      return true;
    }
    if (o == null || getClass() != o.getClass()) {
      return false;
    }
    if (!super.equals(o)) {
      return false;
    }

    LabelStatement that = (LabelStatement) o;

    if (defaultValue != null
        ? !defaultValue.equals(that.defaultValue)
        : that.defaultValue != null) {
      return false;
    }

    return true;
  }
 @Override
 public boolean equals(Object obj) {
   if (this == obj) {
     return true;
   }
   if (obj == null) {
     return false;
   }
   if (getClass() != obj.getClass()) {
     return false;
   }
   PostfixIncrementExpression other = (PostfixIncrementExpression) obj;
   if (expression == null) {
     if (other.expression != null) {
       return false;
     }
   } else if (!expression.equals(other.expression)) {
     return false;
   }
   if (increment != other.increment) {
     return false;
   }
   return true;
 }
 /** Is this expression the same as another expression? */
 public boolean equals(Object other) {
   if (other instanceof BinaryExpression) {
     BinaryExpression b = (BinaryExpression) other;
     if (operator == b.operator) {
       if (operand0.equals(b.operand0) && operand1.equals(b.operand1)) {
         return true;
       }
       if (isCommutative(operator) && operand0.equals(b.operand1) && operand1.equals(b.operand0)) {
         return true;
       }
       if (isAssociative(operator)
           && pairwiseEqual(
               flattenExpression(new ArrayList(4)), b.flattenExpression(new ArrayList(4)))) {
         return true;
       }
     }
     if (isInverse(operator, b.operator)
         && operand0.equals(b.operand1)
         && operand1.equals(b.operand0)) {
       return true;
     }
   }
   return false;
 }
Esempio n. 14
0
 /**
  * Indicates whether some other object is "equal to" this one.
  *
  * @return <code>true</code> iff this object is the same as the argument.
  */
 public boolean equals(Object o) {
   if (!(o instanceof FieldAccess)) return false;
   FieldAccess f = (FieldAccess) o;
   return object.equals(f.object) && name.equals(f.name);
 }
Esempio n. 15
0
 @Override
 public boolean equals(Object obj) {
   if (!getClass().equals(obj.getClass())) return false;
   ReadFieldExpression o = (ReadFieldExpression) obj;
   return field.equals(o.field) && base.equals(o.base);
 }