Search in sources :

Example 61 with Type

use of org.jetbrains.org.objectweb.asm.Type in project kotlin by JetBrains.

the class StackValue method enumEntry.

@NotNull
public static Field enumEntry(@NotNull ClassDescriptor descriptor, @NotNull KotlinTypeMapper typeMapper) {
    DeclarationDescriptor enumClass = descriptor.getContainingDeclaration();
    assert DescriptorUtils.isEnumClass(enumClass) : "Enum entry should be declared in enum class: " + descriptor;
    Type type = typeMapper.mapType((ClassDescriptor) enumClass);
    return field(type, type, descriptor.getName().asString(), true, none(), descriptor);
}
Also used : KotlinType(org.jetbrains.kotlin.types.KotlinType) IElementType(com.intellij.psi.tree.IElementType) PrimitiveType(org.jetbrains.kotlin.builtins.PrimitiveType) Type(org.jetbrains.org.objectweb.asm.Type) NotNull(org.jetbrains.annotations.NotNull)

Example 62 with Type

use of org.jetbrains.org.objectweb.asm.Type in project kotlin by JetBrains.

the class StackValue method receiver.

public static StackValue receiver(ResolvedCall<?> resolvedCall, StackValue receiver, ExpressionCodegen codegen, @Nullable Callable callableMethod) {
    ReceiverValue callDispatchReceiver = resolvedCall.getDispatchReceiver();
    CallableDescriptor descriptor = resolvedCall.getResultingDescriptor();
    if (descriptor instanceof SyntheticFieldDescriptor) {
        callDispatchReceiver = ((SyntheticFieldDescriptor) descriptor).getDispatchReceiverForBackend();
    }
    ReceiverValue callExtensionReceiver = resolvedCall.getExtensionReceiver();
    if (callDispatchReceiver != null || callExtensionReceiver != null || isLocalFunCall(callableMethod) || isCallToMemberObjectImportedByName(resolvedCall)) {
        ReceiverParameterDescriptor dispatchReceiverParameter = descriptor.getDispatchReceiverParameter();
        ReceiverParameterDescriptor extensionReceiverParameter = descriptor.getExtensionReceiverParameter();
        if (descriptor instanceof SyntheticFieldDescriptor) {
            dispatchReceiverParameter = ((SyntheticFieldDescriptor) descriptor).getDispatchReceiverParameterForBackend();
        }
        boolean hasExtensionReceiver = callExtensionReceiver != null;
        StackValue dispatchReceiver = platformStaticCallIfPresent(genReceiver(hasExtensionReceiver ? none() : receiver, codegen, resolvedCall, callableMethod, callDispatchReceiver, false), descriptor);
        StackValue extensionReceiver = genReceiver(receiver, codegen, resolvedCall, callableMethod, callExtensionReceiver, true);
        Type type = CallReceiver.calcType(resolvedCall, dispatchReceiverParameter, extensionReceiverParameter, codegen.typeMapper, callableMethod, codegen.getState());
        assert type != null : "Could not map receiver type for " + resolvedCall;
        return new CallReceiver(dispatchReceiver, extensionReceiver, type);
    }
    return receiver;
}
Also used : SyntheticFieldDescriptor(org.jetbrains.kotlin.descriptors.impl.SyntheticFieldDescriptor) KotlinType(org.jetbrains.kotlin.types.KotlinType) IElementType(com.intellij.psi.tree.IElementType) PrimitiveType(org.jetbrains.kotlin.builtins.PrimitiveType) Type(org.jetbrains.org.objectweb.asm.Type) ImportedFromObjectCallableDescriptor(org.jetbrains.kotlin.resolve.ImportedFromObjectCallableDescriptor) ReceiverValue(org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue)

Example 63 with Type

use of org.jetbrains.org.objectweb.asm.Type in project kotlin by JetBrains.

the class JvmSerializerExtension method serializeProperty.

@Override
public void serializeProperty(@NotNull PropertyDescriptor descriptor, @NotNull ProtoBuf.Property.Builder proto) {
    SignatureSerializer signatureSerializer = new SignatureSerializer();
    PropertyGetterDescriptor getter = descriptor.getGetter();
    PropertySetterDescriptor setter = descriptor.getSetter();
    Method getterMethod = getter == null ? null : bindings.get(METHOD_FOR_FUNCTION, getter);
    Method setterMethod = setter == null ? null : bindings.get(METHOD_FOR_FUNCTION, setter);
    Pair<Type, String> field = bindings.get(FIELD_FOR_PROPERTY, descriptor);
    Method syntheticMethod = bindings.get(SYNTHETIC_METHOD_FOR_PROPERTY, descriptor);
    JvmProtoBuf.JvmPropertySignature signature = signatureSerializer.propertySignature(descriptor, field != null ? field.second : null, field != null ? field.first.getDescriptor() : null, syntheticMethod != null ? signatureSerializer.methodSignature(null, syntheticMethod) : null, getterMethod != null ? signatureSerializer.methodSignature(null, getterMethod) : null, setterMethod != null ? signatureSerializer.methodSignature(null, setterMethod) : null);
    proto.setExtension(JvmProtoBuf.propertySignature, signature);
}
Also used : JvmProtoBuf(org.jetbrains.kotlin.serialization.jvm.JvmProtoBuf) KotlinType(org.jetbrains.kotlin.types.KotlinType) FlexibleType(org.jetbrains.kotlin.types.FlexibleType) Type(org.jetbrains.org.objectweb.asm.Type) Method(org.jetbrains.org.objectweb.asm.commons.Method)

Example 64 with Type

use of org.jetbrains.org.objectweb.asm.Type in project kotlin by JetBrains.

the class JvmSignatureWriter method makeJvmMethodSignature.

@NotNull
public JvmMethodGenericSignature makeJvmMethodSignature(@NotNull String name) {
    List<Type> types = new ArrayList<Type>(kotlinParameterTypes.size());
    for (JvmMethodParameterSignature parameter : kotlinParameterTypes) {
        types.add(parameter.getAsmType());
    }
    Method asmMethod = new Method(name, jvmReturnType, types.toArray(new Type[types.size()]));
    return new JvmMethodGenericSignature(asmMethod, kotlinParameterTypes, makeJavaGenericSignature());
}
Also used : Type(org.jetbrains.org.objectweb.asm.Type) JvmMethodParameterSignature(org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodParameterSignature) ArrayList(java.util.ArrayList) JvmMethodGenericSignature(org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodGenericSignature) Method(org.jetbrains.org.objectweb.asm.commons.Method) NotNull(org.jetbrains.annotations.NotNull)

Example 65 with Type

use of org.jetbrains.org.objectweb.asm.Type in project kotlin by JetBrains.

the class CodegenContext method lookupInContext.

public StackValue lookupInContext(DeclarationDescriptor d, @Nullable StackValue result, GenerationState state, boolean ignoreNoOuter) {
    StackValue myOuter = null;
    if (closure != null) {
        EnclosedValueDescriptor answer = closure.getCaptureVariables().get(d);
        if (answer != null) {
            return StackValue.changeReceiverForFieldAndSharedVar(answer.getInnerValue(), result);
        }
        for (LocalLookup.LocalLookupCase aCase : LocalLookup.LocalLookupCase.values()) {
            if (aCase.isCase(d)) {
                Type classType = state.getTypeMapper().mapType(getThisDescriptor());
                StackValue.StackValueWithSimpleReceiver innerValue = aCase.innerValue(d, enclosingLocalLookup, state, closure, classType);
                if (innerValue == null) {
                    break;
                } else {
                    return StackValue.changeReceiverForFieldAndSharedVar(innerValue, result);
                }
            }
        }
        myOuter = getOuterExpression(result, ignoreNoOuter, false);
        result = myOuter;
    }
    StackValue resultValue;
    if (myOuter != null && getEnclosingClass() == d) {
        resultValue = result;
    } else {
        resultValue = parentContext != null ? parentContext.lookupInContext(d, result, state, ignoreNoOuter) : null;
    }
    if (myOuter != null && resultValue != null && !isStaticField(resultValue)) {
        closure.setCaptureThis();
    }
    return resultValue;
}
Also used : KotlinType(org.jetbrains.kotlin.types.KotlinType) Type(org.jetbrains.org.objectweb.asm.Type)

Aggregations

Type (org.jetbrains.org.objectweb.asm.Type)104 KotlinType (org.jetbrains.kotlin.types.KotlinType)66 IElementType (com.intellij.psi.tree.IElementType)45 NotNull (org.jetbrains.annotations.NotNull)23 InstructionAdapter (org.jetbrains.org.objectweb.asm.commons.InstructionAdapter)16 Label (org.jetbrains.org.objectweb.asm.Label)12 Type.getObjectType (org.jetbrains.org.objectweb.asm.Type.getObjectType)10 Method (org.jetbrains.org.objectweb.asm.commons.Method)9 Unit (kotlin.Unit)8 LocalVariableDescriptor (org.jetbrains.kotlin.descriptors.impl.LocalVariableDescriptor)7 ArrayList (java.util.ArrayList)5 JavaClassDescriptor (org.jetbrains.kotlin.load.java.descriptors.JavaClassDescriptor)5 MethodVisitor (org.jetbrains.org.objectweb.asm.MethodVisitor)5 PrimitiveType (org.jetbrains.kotlin.builtins.PrimitiveType)4 ValueParameterDescriptor (org.jetbrains.kotlin.descriptors.ValueParameterDescriptor)4 List (java.util.List)3 Nullable (org.jetbrains.annotations.Nullable)3 ScriptDescriptor (org.jetbrains.kotlin.descriptors.ScriptDescriptor)3 InOut (com.intellij.codeInspection.bytecodeAnalysis.Direction.InOut)2 FunctionClassDescriptor (org.jetbrains.kotlin.builtins.functions.FunctionClassDescriptor)2