Search in sources :

Example 91 with Type

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

the class ExpressionCodegen method visitPrefixExpression.

@Override
public StackValue visitPrefixExpression(@NotNull KtPrefixExpression expression, @NotNull StackValue receiver) {
    ConstantValue<?> compileTimeConstant = getPrimitiveOrStringCompileTimeConstant(expression, bindingContext, state.getShouldInlineConstVals());
    if (compileTimeConstant != null) {
        return StackValue.constant(compileTimeConstant.getValue(), expressionType(expression));
    }
    DeclarationDescriptor originalOperation = bindingContext.get(REFERENCE_TARGET, expression.getOperationReference());
    ResolvedCall<?> resolvedCall = CallUtilKt.getResolvedCallWithAssert(expression, bindingContext);
    CallableDescriptor op = resolvedCall.getResultingDescriptor();
    assert op instanceof FunctionDescriptor || originalOperation == null : String.valueOf(op);
    String operationName = originalOperation == null ? "" : originalOperation.getName().asString();
    if (!(operationName.equals("inc") || operationName.equals("dec"))) {
        return invokeFunction(resolvedCall, receiver);
    }
    int increment = operationName.equals("inc") ? 1 : -1;
    Type type = expressionType(expression.getBaseExpression());
    StackValue value = gen(expression.getBaseExpression());
    return StackValue.preIncrement(type, value, increment, resolvedCall, this);
}
Also used : IElementType(com.intellij.psi.tree.IElementType) Type(org.jetbrains.org.objectweb.asm.Type) KotlinType(org.jetbrains.kotlin.types.KotlinType)

Example 92 with Type

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

the class ExpressionCodegen method initializeLocalVariable.

private void initializeLocalVariable(@NotNull KtVariableDeclaration variableDeclaration, @NotNull StackValue initializer) {
    LocalVariableDescriptor variableDescriptor = (LocalVariableDescriptor) getVariableDescriptorNotNull(variableDeclaration);
    if (KtPsiUtil.isScriptDeclaration(variableDeclaration)) {
        return;
    }
    int index = lookupLocalIndex(variableDescriptor);
    if (index < 0) {
        throw new IllegalStateException("Local variable not found for " + variableDescriptor);
    }
    Type sharedVarType = typeMapper.getSharedVarType(variableDescriptor);
    Type varType = getVariableTypeNoSharing(variableDescriptor);
    StackValue storeTo = sharedVarType == null ? StackValue.local(index, varType) : StackValue.shared(index, varType);
    storeTo.putReceiver(v, false);
    initializer.put(initializer.type, v);
    markLineNumber(variableDeclaration, false);
    Type resultType = initializer.type;
    if (isDelegatedLocalVariable(variableDescriptor)) {
        StackValue metadataValue = getVariableMetadataValue(variableDescriptor);
        initializePropertyMetadata((KtProperty) variableDeclaration, variableDescriptor, metadataValue);
        ResolvedCall<FunctionDescriptor> provideDelegateResolvedCall = bindingContext.get(PROVIDE_DELEGATE_RESOLVED_CALL, variableDescriptor);
        if (provideDelegateResolvedCall != null) {
            resultType = generateProvideDelegateCallForLocalVariable(initializer, metadataValue, provideDelegateResolvedCall);
        }
    }
    storeTo.storeSelector(resultType, v);
}
Also used : LocalVariableDescriptor(org.jetbrains.kotlin.descriptors.impl.LocalVariableDescriptor) IElementType(com.intellij.psi.tree.IElementType) Type(org.jetbrains.org.objectweb.asm.Type) KotlinType(org.jetbrains.kotlin.types.KotlinType)

Example 93 with Type

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

the class ExpressionCodegen method generateScriptReceiver.

@NotNull
private StackValue generateScriptReceiver(@NotNull ScriptDescriptor receiver) {
    CodegenContext cur = context;
    StackValue result = StackValue.LOCAL_0;
    boolean inStartConstructorContext = cur instanceof ConstructorContext;
    while (cur != null) {
        if (!inStartConstructorContext) {
            cur = getNotNullParentContextForMethod(cur);
        }
        if (cur instanceof ScriptContext) {
            ScriptContext scriptContext = (ScriptContext) cur;
            if (scriptContext.getScriptDescriptor() == receiver) {
                //TODO lazy
                return result;
            }
            Type currentScriptType = typeMapper.mapType(scriptContext.getScriptDescriptor());
            Type classType = typeMapper.mapType(receiver);
            String fieldName = scriptContext.getScriptFieldName(receiver);
            return StackValue.field(classType, currentScriptType, fieldName, false, result, receiver);
        }
        result = cur.getOuterExpression(result, false);
        if (inStartConstructorContext) {
            cur = getNotNullParentContextForMethod(cur);
            inStartConstructorContext = false;
        }
        cur = cur.getParentContext();
    }
    throw new UnsupportedOperationException();
}
Also used : IElementType(com.intellij.psi.tree.IElementType) Type(org.jetbrains.org.objectweb.asm.Type) KotlinType(org.jetbrains.kotlin.types.KotlinType) NotNull(org.jetbrains.annotations.NotNull)

Example 94 with Type

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

the class ExpressionCodegen method stackValueForLocal.

private StackValue stackValueForLocal(DeclarationDescriptor descriptor, int index) {
    if (descriptor instanceof VariableDescriptor) {
        VariableDescriptor variableDescriptor = (VariableDescriptor) descriptor;
        Type sharedVarType = typeMapper.getSharedVarType(descriptor);
        Type varType = getVariableTypeNoSharing(variableDescriptor);
        if (sharedVarType != null) {
            return StackValue.shared(index, varType);
        } else {
            return adjustVariableValue(StackValue.local(index, varType), variableDescriptor);
        }
    } else {
        return StackValue.local(index, OBJECT_TYPE);
    }
}
Also used : IElementType(com.intellij.psi.tree.IElementType) Type(org.jetbrains.org.objectweb.asm.Type) KotlinType(org.jetbrains.kotlin.types.KotlinType) LocalVariableDescriptor(org.jetbrains.kotlin.descriptors.impl.LocalVariableDescriptor)

Example 95 with Type

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

the class ExpressionCodegen method generate754EqualsForNullableTypesViaIntrinsic.

private void generate754EqualsForNullableTypesViaIntrinsic(@NotNull InstructionAdapter v, @NotNull IElementType opToken, @Nullable StackValue pregeneratedLeft, @Nullable KtExpression left, @NotNull TypeAndNullability left754Type, @Nullable KtExpression right, @NotNull TypeAndNullability right754Type) {
    Type leftType = left754Type.isNullable ? AsmUtil.boxType(left754Type.type) : left754Type.type;
    if (pregeneratedLeft != null) {
        StackValue.coercion(pregeneratedLeft, leftType).put(leftType, v);
    } else {
        gen(left, leftType);
    }
    Type rightType = right754Type.isNullable ? AsmUtil.boxType(right754Type.type) : right754Type.type;
    gen(right, rightType);
    AsmUtil.genIEEE754EqualForNullableTypesCall(v, leftType, rightType);
    if (opToken == KtTokens.EXCLEQ) {
        genInvertBoolean(v);
    }
}
Also used : IElementType(com.intellij.psi.tree.IElementType) Type(org.jetbrains.org.objectweb.asm.Type) KotlinType(org.jetbrains.kotlin.types.KotlinType)

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