Esempio n. 1
0
 public void storeVar(BytecodeVariable variable) {
   MethodVisitor mv = controller.getMethodVisitor();
   int idx = variable.getIndex();
   ClassNode type = variable.getType();
   // value is on stack
   if (variable.isHolder()) {
     doGroovyCast(type);
     box();
     mv.visitVarInsn(ALOAD, idx);
     mv.visitTypeInsn(CHECKCAST, "groovy/lang/Reference");
     mv.visitInsn(SWAP);
     mv.visitMethodInsn(
         INVOKEVIRTUAL, "groovy/lang/Reference", "set", "(Ljava/lang/Object;)V", false);
   } else {
     doGroovyCast(type);
     if (type == ClassHelper.double_TYPE) {
       mv.visitVarInsn(DSTORE, idx);
     } else if (type == ClassHelper.float_TYPE) {
       mv.visitVarInsn(FSTORE, idx);
     } else if (type == ClassHelper.long_TYPE) {
       mv.visitVarInsn(LSTORE, idx);
     } else if (type == ClassHelper.boolean_TYPE
         || type == ClassHelper.char_TYPE
         || type == ClassHelper.byte_TYPE
         || type == ClassHelper.int_TYPE
         || type == ClassHelper.short_TYPE) {
       mv.visitVarInsn(ISTORE, idx);
     } else {
       mv.visitVarInsn(ASTORE, idx);
     }
   }
   // remove RHS value from operand stack
   remove(1);
 }
Esempio n. 2
0
  public void loadOrStoreVariable(BytecodeVariable variable, boolean useReferenceDirectly) {
    CompileStack compileStack = controller.getCompileStack();

    if (compileStack.isLHS()) {
      storeVar(variable);
    } else {
      MethodVisitor mv = controller.getMethodVisitor();
      int idx = variable.getIndex();
      ClassNode type = variable.getType();

      if (variable.isHolder()) {
        mv.visitVarInsn(ALOAD, idx);
        if (!useReferenceDirectly) {
          mv.visitMethodInsn(
              INVOKEVIRTUAL, "groovy/lang/Reference", "get", "()Ljava/lang/Object;", false);
          BytecodeHelper.doCast(mv, type);
          push(type);
        } else {
          push(ClassHelper.REFERENCE_TYPE);
        }
      } else {
        load(type, idx);
      }
    }
  }