コード例 #1
0
 private List<Instruction> transformGetterInvocation(InvokeInstruction insn, String property) {
   if (insn.getReceiver() == null) {
     return Collections.emptyList();
   }
   ValueType type = insn.getMethod().getDescriptor().getResultType();
   List<Instruction> instructions = new ArrayList<>();
   if (type instanceof ValueType.Primitive) {
     switch (((ValueType.Primitive) type).getKind()) {
       case BOOLEAN:
         getAndCastProperty(insn, property, instructions, boolean.class);
         return instructions;
       case BYTE:
         getAndCastProperty(insn, property, instructions, byte.class);
         return instructions;
       case SHORT:
         getAndCastProperty(insn, property, instructions, short.class);
         return instructions;
       case INTEGER:
         getAndCastProperty(insn, property, instructions, int.class);
         return instructions;
       case FLOAT:
         getAndCastProperty(insn, property, instructions, float.class);
         return instructions;
       case DOUBLE:
         getAndCastProperty(insn, property, instructions, double.class);
         return instructions;
       case CHARACTER:
       case LONG:
         break;
     }
   } else if (type instanceof ValueType.Object) {
     switch (((ValueType.Object) type).getClassName()) {
       case "java.lang.String":
         {
           Variable resultVar = insn.getProgram().createVariable();
           getProperty(insn, property, instructions, resultVar);
           InvokeInstruction castInvoke = new InvokeInstruction();
           castInvoke.setType(InvocationType.SPECIAL);
           castInvoke.setMethod(
               new MethodReference(
                   ResourceAccessor.class, "castToString", Object.class, String.class));
           castInvoke.getArguments().add(resultVar);
           castInvoke.setReceiver(insn.getReceiver());
           instructions.add(castInvoke);
           return instructions;
         }
       default:
         {
           Variable resultVar = insn.getProgram().createVariable();
           getProperty(insn, property, instructions, resultVar);
           CastInstruction castInsn = new CastInstruction();
           castInsn.setReceiver(insn.getReceiver());
           castInsn.setTargetType(type);
           castInsn.setValue(resultVar);
           instructions.add(castInsn);
           return instructions;
         }
     }
   }
   return null;
 }
コード例 #2
0
ファイル: StatementGenerator.java プロジェクト: sba1/teavm
 @Override
 public void visit(CastInstruction insn) {
   assign(Expr.var(insn.getValue().getIndex()), insn.getReceiver());
 }