Esempio n. 1
0
  private static void generateLocalVariableTable(
      @NotNull MethodVisitor mv,
      @NotNull JvmMethodSignature jvmMethodSignature,
      @NotNull FunctionDescriptor functionDescriptor,
      @Nullable Type thisType,
      @NotNull Label methodBegin,
      @NotNull Label methodEnd,
      @NotNull OwnerKind ownerKind) {
    Iterator<ValueParameterDescriptor> valueParameters =
        functionDescriptor.getValueParameters().iterator();
    List<JvmMethodParameterSignature> params = jvmMethodSignature.getValueParameters();
    int shift = 0;

    boolean isStatic = AsmUtil.isStaticMethod(ownerKind, functionDescriptor);
    if (!isStatic) {
      // add this
      if (thisType != null) {
        mv.visitLocalVariable(
            "this", thisType.getDescriptor(), null, methodBegin, methodEnd, shift);
      } else {
        // TODO: provide thisType for callable reference
      }
      shift++;
    }

    for (int i = 0; i < params.size(); i++) {
      JvmMethodParameterSignature param = params.get(i);
      JvmMethodParameterKind kind = param.getKind();
      String parameterName;

      if (kind == JvmMethodParameterKind.VALUE) {
        ValueParameterDescriptor parameter = valueParameters.next();
        parameterName = parameter.getName().asString();
      } else {
        String lowercaseKind = kind.name().toLowerCase();
        parameterName = needIndexForVar(kind) ? "$" + lowercaseKind + "$" + i : "$" + lowercaseKind;
      }

      Type type = param.getAsmType();
      mv.visitLocalVariable(
          parameterName, type.getDescriptor(), null, methodBegin, methodEnd, shift);
      shift += type.getSize();
    }
  }
Esempio n. 2
0
 private static void genDefaultSuperCallCheckIfNeeded(
     @NotNull InstructionAdapter iv, @NotNull Method defaultMethod) {
   String defaultMethodName = defaultMethod.getName();
   if ("<init>".equals(defaultMethodName)) {
     return;
   }
   Label end = new Label();
   int handleIndex =
       (Type.getArgumentsAndReturnSizes(defaultMethod.getDescriptor()) >> 2)
           - 2; /*-1 for this, and -1 for handle*/
   iv.load(handleIndex, OBJECT_TYPE);
   iv.ifnull(end);
   AsmUtil.genThrow(
       iv,
       "java/lang/UnsupportedOperationException",
       "Super calls with default arguments not supported in this target, function: "
           + StringsKt.substringBeforeLast(
               defaultMethodName, JvmAbi.DEFAULT_PARAMS_IMPL_SUFFIX, defaultMethodName));
   iv.visitLabel(end);
 }