Esempio n. 1
0
  @NotNull
  protected ExpressionCodegen createOrGetClInitCodegen() {
    DeclarationDescriptor descriptor = context.getContextDescriptor();
    assert state.getClassBuilderMode() == ClassBuilderMode.FULL
        : "<clinit> should not be generated for light classes. Descriptor: " + descriptor;
    if (clInit == null) {
      MethodVisitor mv = v.newMethod(null, ACC_STATIC, "<clinit>", "()V", null, null);
      mv.visitCode();
      SimpleFunctionDescriptorImpl clInit =
          SimpleFunctionDescriptorImpl.create(
              descriptor, Annotations.EMPTY, Name.special("<clinit>"), SYNTHESIZED);
      clInit.initialize(
          null,
          null,
          Collections.<TypeParameterDescriptor>emptyList(),
          Collections.<ValueParameterDescriptor>emptyList(),
          null,
          null,
          Visibilities.PRIVATE);

      this.clInit =
          new ExpressionCodegen(
              mv, new FrameMap(), Type.VOID_TYPE, context.intoFunction(clInit), state, this);
    }
    return clInit;
  }
Esempio n. 2
0
  private void done() {
    if (clInit != null) {
      clInit.v.visitInsn(RETURN);
      FunctionCodegen.endVisit(clInit.v, "static initializer", element);
    }

    v.done();
  }
Esempio n. 3
0
  protected void generatePropertyMetadataArrayFieldIfNeeded(@NotNull Type thisAsmType) {
    List<JetProperty> delegatedProperties = new ArrayList<JetProperty>();
    for (JetDeclaration declaration : ((JetDeclarationContainer) element).getDeclarations()) {
      if (declaration instanceof JetProperty) {
        JetProperty property = (JetProperty) declaration;
        if (property.getDelegate() != null) {
          delegatedProperties.add(property);
        }
      }
    }
    if (delegatedProperties.isEmpty()) return;

    v.newField(
        null,
        ACC_PRIVATE | ACC_STATIC | ACC_FINAL | ACC_SYNTHETIC,
        JvmAbi.PROPERTY_METADATA_ARRAY_NAME,
        "[" + PROPERTY_METADATA_TYPE,
        null,
        null);

    InstructionAdapter iv = createOrGetClInitCodegen().v;
    iv.iconst(delegatedProperties.size());
    iv.newarray(PROPERTY_METADATA_TYPE);

    for (int i = 0, size = delegatedProperties.size(); i < size; i++) {
      VariableDescriptor property =
          BindingContextUtils.getNotNull(bindingContext, VARIABLE, delegatedProperties.get(i));

      iv.dup();
      iv.iconst(i);
      iv.anew(PROPERTY_METADATA_IMPL_TYPE);
      iv.dup();
      iv.visitLdcInsn(property.getName().asString());
      iv.invokespecial(
          PROPERTY_METADATA_IMPL_TYPE.getInternalName(), "<init>", "(Ljava/lang/String;)V");
      iv.astore(PROPERTY_METADATA_IMPL_TYPE);
    }

    iv.putstatic(
        thisAsmType.getInternalName(),
        JvmAbi.PROPERTY_METADATA_ARRAY_NAME,
        "[" + PROPERTY_METADATA_TYPE);
  }