Ejemplo n.º 1
0
      @Override
      public StackValue innerValue(
          DeclarationDescriptor d,
          LocalLookup localLookup,
          GenerationState state,
          MutableClosure closure,
          Type classType) {
        VariableDescriptor vd = (VariableDescriptor) d;

        boolean idx = localLookup != null && localLookup.lookupLocal(vd);
        if (!idx) return null;

        Type sharedVarType = state.getTypeMapper().getSharedVarType(vd);
        Type localType = state.getTypeMapper().mapType(vd);
        Type type = sharedVarType != null ? sharedVarType : localType;

        String fieldName = "$" + vd.getName();
        StackValue innerValue =
            sharedVarType != null
                ? StackValue.fieldForSharedVar(localType, classType, fieldName)
                : StackValue.field(type, classType, fieldName, false);

        closure.recordField(fieldName, type);
        closure.captureVariable(new EnclosedValueDescriptor(fieldName, d, innerValue, type));

        return innerValue;
      }
Ejemplo n.º 2
0
  public static void genNotNullAssertionsForParameters(
      @NotNull InstructionAdapter v,
      @NotNull GenerationState state,
      @NotNull FunctionDescriptor descriptor,
      @NotNull FrameMap frameMap) {
    if (!state.isGenerateNotNullParamAssertions()) return;

    // Private method is not accessible from other classes, no assertions needed
    if (getVisibilityAccessFlag(descriptor) == ACC_PRIVATE) return;

    for (ValueParameterDescriptor parameter : descriptor.getValueParameters()) {
      JetType type = parameter.getReturnType();
      if (type == null || isNullableType(type)) continue;

      int index = frameMap.getIndex(parameter);
      Type asmType = state.getTypeMapper().mapReturnType(type);
      if (asmType.getSort() == Type.OBJECT || asmType.getSort() == Type.ARRAY) {
        v.load(index, asmType);
        v.visitLdcInsn(descriptor.getName().asString());
        v.invokestatic(
            "jet/runtime/Intrinsics",
            "checkParameterIsNotNull",
            "(Ljava/lang/Object;Ljava/lang/String;)V");
      }
    }
  }
Ejemplo n.º 3
0
 @Override
 public StackValue generate(
     ExpressionCodegen codegen,
     InstructionAdapter v,
     @NotNull Type expectedType,
     PsiElement element,
     List<JetExpression> arguments,
     StackValue receiver,
     @NotNull GenerationState state) {
   final CallableMethod callableMethod =
       state.getTypeMapper().mapToCallableMethod(method, false, OwnerKind.IMPLEMENTATION);
   codegen.invokeMethodWithArguments(callableMethod, (JetCallExpression) element, receiver);
   return StackValue.onStack(callableMethod.getSignature().getAsmMethod().getReturnType());
 }
Ejemplo n.º 4
0
 @Override
 public final void generateBody(
     @NotNull MethodVisitor mv,
     @NotNull JvmMethodSignature signature,
     @NotNull MethodContext context,
     @Nullable MemberCodegen<?> parentCodegen) {
   ExpressionCodegen codegen =
       new ExpressionCodegen(
           mv,
           getFrameMap(state.getTypeMapper(), context),
           signature.getReturnType(),
           context,
           state,
           parentCodegen);
   doGenerateBody(codegen, signature);
 }
Ejemplo n.º 5
0
      @Override
      public StackValue innerValue(
          DeclarationDescriptor d,
          LocalLookup enclosingLocalLookup,
          GenerationState state,
          MutableClosure closure,
          Type classType) {
        if (closure.getEnclosingReceiverDescriptor() != d) return null;

        JetType receiverType = ((CallableDescriptor) d).getReceiverParameter().getType();
        Type type = state.getTypeMapper().mapType(receiverType);
        StackValue innerValue = StackValue.field(type, classType, CAPTURED_RECEIVER_FIELD, false);
        closure.setCaptureReceiver();

        return innerValue;
      }
Ejemplo n.º 6
0
  private static void genNotNullAssertion(
      @NotNull InstructionAdapter v,
      @NotNull GenerationState state,
      @NotNull CallableDescriptor descriptor,
      @NotNull String assertMethodToCall) {
    if (!state.isGenerateNotNullAssertions()) return;

    if (!isDeclaredInJava(descriptor, state.getBindingContext())) return;

    JetType type = descriptor.getReturnType();
    if (type == null || isNullableType(type)) return;

    Type asmType = state.getTypeMapper().mapReturnType(type);
    if (asmType.getSort() == Type.OBJECT || asmType.getSort() == Type.ARRAY) {
      v.dup();
      v.visitLdcInsn(descriptor.getContainingDeclaration().getName().asString());
      v.visitLdcInsn(descriptor.getName().asString());
      v.invokestatic(
          "jet/runtime/Intrinsics",
          assertMethodToCall,
          "(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/String;)V");
    }
  }