Exemplo n.º 1
0
  /** Check expression type */
  public Vset checkValue(Environment env, Context ctx, Vset vset, Hashtable exp) {
    vset = right.checkValue(env, ctx, vset, exp);
    if (index == null) {
      env.error(where, "array.index.required");
      return vset;
    }
    vset = index.checkValue(env, ctx, vset, exp);
    index = convert(env, ctx, Type.tInt, index);

    if (!right.type.isType(TC_ARRAY)) {
      if (!right.type.isType(TC_ERROR)) {
        env.error(where, "not.array", right.type);
      }
      return vset;
    }

    type = right.type.getElementType();
    return vset;
  }
Exemplo n.º 2
0
  public Vset checkAmbigName(
      Environment env, Context ctx, Vset vset, Hashtable exp, UnaryExpression loc) {
    if (index == null) {
      vset = right.checkAmbigName(env, ctx, vset, exp, this);
      if (right.type == Type.tPackage) {
        FieldExpression.reportFailedPackagePrefix(env, right);
        return vset;
      }

      // Nope.  Is this field expression a type?
      if (right instanceof TypeExpression) {
        Type atype = Type.tArray(right.type);
        loc.right = new TypeExpression(where, atype);
        return vset;
      }

      env.error(where, "array.index.required");
      return vset;
    }
    return super.checkAmbigName(env, ctx, vset, exp, loc);
  }
Exemplo n.º 3
0
  /** Select the type */
  final void selectType(Environment env, Context ctx, int tm) {
    Type rtype = null; // special conversion type for RHS
    switch (op) {
      case ASGADD:
        if (left.type == Type.tString) {
          if (right.type == Type.tVoid) {
            // The type of the right hand side can be
            // anything except void.  Fix for 4119864.
            env.error(where, "incompatible.type", opNames[op], Type.tVoid, Type.tString);
            type = Type.tError;
          } else {
            type = itype = Type.tString;
          }
          return;
        }
        /* Fall through */
      case ASGDIV:
      case ASGMUL:
      case ASGSUB:
      case ASGREM:
        if ((tm & TM_DOUBLE) != 0) {
          itype = Type.tDouble;
        } else if ((tm & TM_FLOAT) != 0) {
          itype = Type.tFloat;
        } else if ((tm & TM_LONG) != 0) {
          itype = Type.tLong;
        } else {
          itype = Type.tInt;
        }
        break;

      case ASGBITAND:
      case ASGBITOR:
      case ASGBITXOR:
        if ((tm & TM_BOOLEAN) != 0) {
          itype = Type.tBoolean;
        } else if ((tm & TM_LONG) != 0) {
          itype = Type.tLong;
        } else {
          itype = Type.tInt;
        }
        break;

      case ASGLSHIFT:
      case ASGRSHIFT:
      case ASGURSHIFT:
        rtype = Type.tInt;

        // Fix for bug 4134459.
        // We allow any integral type (even long) to
        // be the right hand side of a shift operation.
        if (right.type.inMask(TM_INTEGER)) {
          right = new ConvertExpression(where, Type.tInt, right);
        }
        // The intermediate type of the expression is the
        // type of the left hand side after undergoing
        // unary (not binary) type promotion.  We ignore
        // tm -- it contains information about both left
        // and right hand sides -- and we compute the
        // type only from the type of the lhs.
        if (left.type == Type.tLong) {
          itype = Type.tLong;
        } else {
          itype = Type.tInt;
        }

        break;

      default:
        throw new CompilerError("Bad assignOp type: " + op);
    }
    if (rtype == null) {
      rtype = itype;
    }
    right = convert(env, ctx, rtype, right);
    // The result is always the type of the left operand.

    type = left.type;
  }
Exemplo n.º 4
0
 Type toType(Environment env, Type t) {
   if (index != null) {
     env.error(index.where, "array.dim.in.type");
   }
   return Type.tArray(t);
 }