Search in sources :

Example 16 with Unit

use of kotlin.Unit in project kotlin by JetBrains.

the class ExpressionCodegen method generateElvis.

private StackValue generateElvis(@NotNull final KtBinaryExpression expression) {
    KtExpression left = expression.getLeft();
    final Type exprType = expressionType(expression);
    final Type leftType = expressionType(left);
    final Label ifNull = new Label();
    assert left != null : "left expression in elvis should be not null: " + expression.getText();
    final StackValue value = generateExpressionWithNullFallback(left, ifNull);
    if (isPrimitive(leftType)) {
        return value;
    }
    return StackValue.operation(exprType, new Function1<InstructionAdapter, Unit>() {

        @Override
        public Unit invoke(InstructionAdapter v) {
            value.put(value.type, v);
            v.dup();
            v.ifnull(ifNull);
            StackValue.onStack(leftType).put(exprType, v);
            Label end = new Label();
            v.goTo(end);
            v.mark(ifNull);
            v.pop();
            gen(expression.getRight(), exprType);
            v.mark(end);
            return null;
        }
    });
}
Also used : IElementType(com.intellij.psi.tree.IElementType) Type(org.jetbrains.org.objectweb.asm.Type) KotlinType(org.jetbrains.kotlin.types.KotlinType) InstructionAdapter(org.jetbrains.org.objectweb.asm.commons.InstructionAdapter) Label(org.jetbrains.org.objectweb.asm.Label) Unit(kotlin.Unit)

Example 17 with Unit

use of kotlin.Unit in project kotlin by JetBrains.

the class ExpressionCodegen method genSamInterfaceValue.

@Nullable
private StackValue genSamInterfaceValue(@NotNull KtExpression probablyParenthesizedExpression, @NotNull final KtVisitor<StackValue, StackValue> visitor) {
    final KtExpression expression = KtPsiUtil.deparenthesize(probablyParenthesizedExpression);
    final SamType samType = bindingContext.get(SAM_VALUE, probablyParenthesizedExpression);
    if (samType == null || expression == null)
        return null;
    if (expression instanceof KtLambdaExpression) {
        return genClosure(((KtLambdaExpression) expression).getFunctionLiteral(), samType);
    }
    if (expression instanceof KtNamedFunction) {
        return genClosure((KtNamedFunction) expression, samType);
    }
    final Type asmType = state.getSamWrapperClasses().getSamWrapperClass(samType, expression.getContainingKtFile(), this);
    return StackValue.operation(asmType, new Function1<InstructionAdapter, Unit>() {

        @Override
        public Unit invoke(InstructionAdapter v) {
            v.anew(asmType);
            v.dup();
            Type functionType = typeMapper.mapType(samType.getKotlinFunctionType());
            expression.accept(visitor, StackValue.none()).put(functionType, v);
            Label ifNonNull = new Label();
            Label afterAll = new Label();
            v.dup();
            v.ifnonnull(ifNonNull);
            // if null: pop function value and wrapper objects, put null
            v.pop();
            v.pop2();
            v.aconst(null);
            v.goTo(afterAll);
            v.mark(ifNonNull);
            v.invokespecial(asmType.getInternalName(), "<init>", Type.getMethodDescriptor(Type.VOID_TYPE, functionType), false);
            v.mark(afterAll);
            return null;
        }
    });
}
Also used : IElementType(com.intellij.psi.tree.IElementType) Type(org.jetbrains.org.objectweb.asm.Type) KotlinType(org.jetbrains.kotlin.types.KotlinType) InstructionAdapter(org.jetbrains.org.objectweb.asm.commons.InstructionAdapter) Label(org.jetbrains.org.objectweb.asm.Label) Unit(kotlin.Unit) Nullable(org.jetbrains.annotations.Nullable)

Example 18 with Unit

use of kotlin.Unit in project kotlin by JetBrains.

the class MemberCodegen method generateKotlinClassMetadataAnnotation.

protected void generateKotlinClassMetadataAnnotation(@NotNull ClassDescriptor descriptor, boolean isScript) {
    final DescriptorSerializer serializer = DescriptorSerializer.create(descriptor, new JvmSerializerExtension(v.getSerializationBindings(), state));
    final ProtoBuf.Class classProto = serializer.classProto(descriptor).build();
    int flags = isScript ? JvmAnnotationNames.METADATA_SCRIPT_FLAG : 0;
    WriteAnnotationUtilKt.writeKotlinMetadata(v, state, KotlinClassHeader.Kind.CLASS, flags, new Function1<AnnotationVisitor, Unit>() {

        @Override
        public Unit invoke(AnnotationVisitor av) {
            writeAnnotationData(av, serializer, classProto);
            return Unit.INSTANCE;
        }
    });
}
Also used : JvmSerializerExtension(org.jetbrains.kotlin.codegen.serialization.JvmSerializerExtension) DescriptorSerializer(org.jetbrains.kotlin.serialization.DescriptorSerializer) Unit(kotlin.Unit) ProtoBuf(org.jetbrains.kotlin.serialization.ProtoBuf)

Example 19 with Unit

use of kotlin.Unit in project kotlin by JetBrains.

the class TypeUnifierTest method makeType.

private TypeProjection makeType(String typeStr) {
    LexicalScope withX = new LexicalScopeImpl(builtinsImportingScope, module, false, null, LexicalScopeKind.SYNTHETIC, LocalRedeclarationChecker.DO_NOTHING.INSTANCE, new Function1<LexicalScopeImpl.InitializeHandler, Unit>() {

        @Override
        public Unit invoke(LexicalScopeImpl.InitializeHandler handler) {
            handler.addClassifierDescriptor(x);
            handler.addClassifierDescriptor(y);
            return Unit.INSTANCE;
        }
    });
    KtTypeProjection projection = KtPsiFactoryKt.KtPsiFactory(getProject()).createTypeArguments("<" + typeStr + ">").getArguments().get(0);
    KtTypeReference typeReference = projection.getTypeReference();
    assert typeReference != null;
    KotlinType type = typeResolver.resolveType(withX, typeReference, KotlinTestUtils.DUMMY_TRACE, true);
    return new TypeProjectionImpl(getProjectionKind(typeStr, projection), type);
}
Also used : KtTypeProjection(org.jetbrains.kotlin.psi.KtTypeProjection) KtTypeReference(org.jetbrains.kotlin.psi.KtTypeReference) Unit(kotlin.Unit)

Aggregations

Unit (kotlin.Unit)19 KotlinType (org.jetbrains.kotlin.types.KotlinType)10 InstructionAdapter (org.jetbrains.org.objectweb.asm.commons.InstructionAdapter)10 IElementType (com.intellij.psi.tree.IElementType)9 Type (org.jetbrains.org.objectweb.asm.Type)8 Label (org.jetbrains.org.objectweb.asm.Label)6 File (java.io.File)3 JvmSerializerExtension (org.jetbrains.kotlin.codegen.serialization.JvmSerializerExtension)3 KtFile (org.jetbrains.kotlin.psi.KtFile)3 DescriptorSerializer (org.jetbrains.kotlin.serialization.DescriptorSerializer)3 ProtoBuf (org.jetbrains.kotlin.serialization.ProtoBuf)3 Method (org.jetbrains.org.objectweb.asm.commons.Method)3 ArrayList (java.util.ArrayList)2 NotNull (org.jetbrains.annotations.NotNull)2 Nullable (org.jetbrains.annotations.Nullable)2 AnnotationVisitor (org.jetbrains.org.objectweb.asm.AnnotationVisitor)2 IntentMessage (ai.snips.hermes.IntentMessage)1 SessionEndedMessage (ai.snips.hermes.SessionEndedMessage)1 SessionQueuedMessage (ai.snips.hermes.SessionQueuedMessage)1 SessionStartedMessage (ai.snips.hermes.SessionStartedMessage)1