Example #1
0
 public AsmField(AsmClass owner, int access, String name, String desc, Object value) {
   _owner = owner;
   _modifiers = access;
   _name = name;
   _annotations = Collections.emptyList();
   _type = AsmUtil.makeType(desc);
   _staticValue = value;
 }
 private void writePackageFacadeMethodAnnotationsIfNeeded(MethodVisitor mv) {
   if (owner instanceof PackageFacadeContext) {
     PackageFacadeContext packageFacadeContext = (PackageFacadeContext) owner;
     Type delegateToClassType = packageFacadeContext.getPublicFacadeType();
     if (delegateToClassType != null) {
       String className = delegateToClassType.getClassName();
       AnnotationVisitor av =
           mv.visitAnnotation(
               AsmUtil.asmDescByFqNameWithoutInnerClasses(
                   JvmAnnotationNames.KOTLIN_DELEGATED_METHOD),
               true);
       av.visit(JvmAnnotationNames.IMPLEMENTATION_CLASS_NAME_FIELD_NAME, className);
       av.visitEnd();
     }
   }
 }
Example #3
0
  public ClosureCodegen(
      @NotNull GenerationState state,
      @NotNull JetElement element,
      @Nullable SamType samType,
      @NotNull ClosureContext context,
      @NotNull KotlinSyntheticClass.Kind syntheticClassKind,
      @NotNull FunctionGenerationStrategy strategy,
      @NotNull MemberCodegen<?> parentCodegen,
      @NotNull ClassBuilder classBuilder) {
    super(state, parentCodegen, context, element, classBuilder);

    this.funDescriptor = context.getFunctionDescriptor();
    this.classDescriptor = context.getContextDescriptor();
    this.samType = samType;
    this.syntheticClassKind = syntheticClassKind;
    this.strategy = strategy;

    if (samType == null) {
      this.superInterfaceTypes = new ArrayList<JetType>();

      JetType superClassType = null;
      for (JetType supertype : classDescriptor.getTypeConstructor().getSupertypes()) {
        ClassifierDescriptor classifier = supertype.getConstructor().getDeclarationDescriptor();
        if (DescriptorUtils.isTrait(classifier)) {
          superInterfaceTypes.add(supertype);
        } else {
          assert superClassType == null
              : "Closure class can't have more than one superclass: " + funDescriptor;
          superClassType = supertype;
        }
      }
      assert superClassType != null : "Closure class should have a superclass: " + funDescriptor;

      this.superClassType = superClassType;
    } else {
      this.superInterfaceTypes = Collections.singletonList(samType.getType());
      this.superClassType = getBuiltIns(funDescriptor).getAnyType();
    }

    this.closure = bindingContext.get(CLOSURE, classDescriptor);
    assert closure != null : "Closure must be calculated for class: " + classDescriptor;

    this.asmType = typeMapper.mapClass(classDescriptor);

    visibilityFlag = AsmUtil.getVisibilityAccessFlagForAnonymous(classDescriptor);
  }
Example #4
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();
    }
  }
Example #5
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);
 }