Example #1
0
  /**
   * Create a representation of a range from min to max.
   *
   * @param min is the lower bound
   * @param max is the upper bound
   */
  public static Bound create(Expression min, Expression max) {
    if (max == null) {
      if (min == null) return noBound;
      max = LiteralMap.put(0x7ffffff, Machine.currentMachine.getIntegerCalcType());
    }

    if (bounds != null) {
      int n = bounds.size();
      for (int i = 0; i < n; i++) {
        Bound ta = bounds.elementAt(i);

        if (!min.equivalent(ta.min)) continue;

        if (!max.equivalent(ta.max)) continue;

        return ta;
      }
    }
    Bound a = new Bound(min, max);
    return a;
  }
Example #2
0
  /**
   * Return the integer value minimum value for the bound.
   *
   * @throws scale.common.InvalidException if the minimum value for the bound is not statically
   *     known
   */
  public final long getConstMin() throws scale.common.InvalidException {
    if ((flags & INTMIN) != 0) return minValue;

    if ((flags & MINCALC) != 0)
      throw new scale.common.InvalidException(
          "The number of elements is not known at compile time.");

    flags |= MINCALC;

    minValue = scale.common.Lattice.convertToLongValue(min.getConstantValue());
    flags |= INTMIN;
    return minValue;
  }
Example #3
0
  /** Return true if the types are equivalent. */
  public boolean equivalent(Node tc) {
    if (!(tc instanceof Bound)) return false;

    Bound t2 = (Bound) tc;
    if (this == t2) return true;

    if ((min == t2.min) && (max == t2.max)) return true;

    if ((min == null) || (t2.min == null) || (max == null) || (t2.max == null)) return false;

    Literal b1 =
        scale.common.Lattice.equal(
            min.getCoreType(), min.getConstantValue(), t2.min.getConstantValue());
    Literal b2 =
        scale.common.Lattice.equal(
            max.getCoreType(), max.getConstantValue(), t2.max.getConstantValue());
    try {
      if (!scale.common.Lattice.convertToBooleanValue(b1)) return false;
      if (!scale.common.Lattice.convertToBooleanValue(b2)) return false;
    } catch (scale.common.InvalidException e) {
      return false;
    }
    return true;
  }