void codeStore(Environment env, Context ctx, Assembler asm) {
   switch (type.getTypeCode()) {
     case TC_BOOLEAN:
     case TC_BYTE:
       asm.add(where, opc_bastore);
       break;
     case TC_CHAR:
       asm.add(where, opc_castore);
       break;
     case TC_SHORT:
       asm.add(where, opc_sastore);
       break;
     default:
       asm.add(where, opc_iastore + type.getTypeCodeOffset());
   }
 }
Example #2
0
  /** Code */
  void code(Environment env, Context ctx, Assembler asm, boolean valNeeded) {

    // Handle cases in which a '+=' or '-=' operator can be optimized using
    // the 'iinc' instruction.  See also 'IncDecExpression.codeIncDec'.
    // The 'iinc' instruction cannot be used if an access method call is required.
    int val = getIncrement();
    if (val != NOINC && updater == null) {
      int v = ((LocalMember) ((IdentifierExpression) left).field).number;
      int[] operands = {v, val};
      asm.add(where, opc_iinc, operands);
      if (valNeeded) {
        left.codeValue(env, ctx, asm);
      }
      return;
    }

    if (updater == null) {
      // Field is directly accessible.
      int depth = left.codeLValue(env, ctx, asm);
      codeDup(env, ctx, asm, depth, 0);
      left.codeLoad(env, ctx, asm);
      codeConversion(env, ctx, asm, left.type, itype);
      right.codeValue(env, ctx, asm);
      codeOperation(env, ctx, asm);
      codeConversion(env, ctx, asm, itype, type);
      if (valNeeded) {
        codeDup(env, ctx, asm, type.stackSize(), depth);
      }
      left.codeStore(env, ctx, asm);
    } else {
      // Must use access methods.
      updater.startUpdate(env, ctx, asm, false);
      codeConversion(env, ctx, asm, left.type, itype);
      right.codeValue(env, ctx, asm);
      codeOperation(env, ctx, asm);
      codeConversion(env, ctx, asm, itype, type);
      updater.finishUpdate(env, ctx, asm, valNeeded);
    }
  }