use of org.jetbrains.org.objectweb.asm.Type in project kotlin by JetBrains.
the class ExpressionCodegen method generateObjectLiteral.
@NotNull
public ObjectLiteralResult generateObjectLiteral(@NotNull KtObjectLiteralExpression literal) {
KtObjectDeclaration objectDeclaration = literal.getObjectDeclaration();
ClassDescriptor classDescriptor = bindingContext.get(CLASS, objectDeclaration);
assert classDescriptor != null;
Type asmType = asmTypeForAnonymousClass(bindingContext, objectDeclaration);
ClassBuilder classBuilder = state.getFactory().newVisitor(JvmDeclarationOriginKt.OtherOrigin(objectDeclaration, classDescriptor), asmType, literal.getContainingFile());
ClassContext objectContext = context.intoAnonymousClass(classDescriptor, this, OwnerKind.IMPLEMENTATION);
MemberCodegen literalCodegen = new ImplementationBodyCodegen(objectDeclaration, objectContext, classBuilder, state, getParentCodegen(), /* isLocal = */
true);
literalCodegen.generate();
addReifiedParametersFromSignature(literalCodegen, classDescriptor);
propagateChildReifiedTypeParametersUsages(literalCodegen.getReifiedTypeParametersUsages());
return new ObjectLiteralResult(literalCodegen.getReifiedTypeParametersUsages().wereUsedReifiedParameters(), classDescriptor);
}
use of org.jetbrains.org.objectweb.asm.Type in project kotlin by JetBrains.
the class ExpressionCodegen method visitBinaryWithTypeRHSExpression.
@Override
public StackValue visitBinaryWithTypeRHSExpression(@NotNull KtBinaryExpressionWithTypeRHS expression, StackValue receiver) {
KtExpression left = expression.getLeft();
final IElementType opToken = expression.getOperationReference().getReferencedNameElementType();
final KotlinType rightType = bindingContext.get(TYPE, expression.getRight());
assert rightType != null;
final StackValue value = genQualified(receiver, left);
return StackValue.operation(boxType(asmType(rightType)), new Function1<InstructionAdapter, Unit>() {
@Override
public Unit invoke(InstructionAdapter v) {
value.put(boxType(value.type), v);
if (value.type == Type.VOID_TYPE) {
StackValue.putUnitInstance(v);
}
boolean safeAs = opToken == KtTokens.AS_SAFE;
Type type = boxType(asmType(rightType));
if (TypeUtils.isReifiedTypeParameter(rightType)) {
putReifiedOperationMarkerIfTypeIsReifiedParameter(rightType, safeAs ? ReifiedTypeInliner.OperationKind.SAFE_AS : ReifiedTypeInliner.OperationKind.AS);
v.checkcast(type);
return Unit.INSTANCE;
}
CodegenUtilKt.generateAsCast(v, rightType, type, safeAs);
return Unit.INSTANCE;
}
});
}
use of org.jetbrains.org.objectweb.asm.Type in project kotlin by JetBrains.
the class ExpressionCodegen method generateThisOrOuter.
@NotNull
public StackValue generateThisOrOuter(@NotNull ClassDescriptor calleeContainingClass, boolean isSuper, boolean forceOuter) {
boolean isSingleton = calleeContainingClass.getKind().isSingleton();
if (isSingleton) {
if (calleeContainingClass.equals(context.getThisDescriptor()) && !CodegenUtilKt.isJvmStaticInObjectOrClass(context.getFunctionDescriptor())) {
return StackValue.local(0, typeMapper.mapType(calleeContainingClass));
} else if (isEnumEntry(calleeContainingClass)) {
return StackValue.enumEntry(calleeContainingClass, typeMapper);
} else {
return StackValue.singleton(calleeContainingClass, typeMapper);
}
}
CodegenContext cur = context;
Type type = asmType(calleeContainingClass.getDefaultType());
StackValue result = StackValue.local(0, type);
boolean inStartConstructorContext = cur instanceof ConstructorContext;
while (cur != null) {
ClassDescriptor thisDescriptor = cur.getThisDescriptor();
if (!isSuper && thisDescriptor == calleeContainingClass) {
return result;
}
if (!forceOuter && isSuper && DescriptorUtils.isSubclass(thisDescriptor, calleeContainingClass)) {
return castToRequiredTypeOfInterfaceIfNeeded(result, thisDescriptor, calleeContainingClass);
}
forceOuter = false;
//for constructor super call we should access to outer instance through parameter in locals, in other cases through field for captured outer
if (inStartConstructorContext) {
result = cur.getOuterExpression(result, false);
cur = getNotNullParentContextForMethod(cur);
inStartConstructorContext = false;
} else {
cur = getNotNullParentContextForMethod(cur);
result = cur.getOuterExpression(result, false);
}
cur = cur.getParentContext();
}
throw new UnsupportedOperationException();
}
use of org.jetbrains.org.objectweb.asm.Type 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;
}
});
}
use of org.jetbrains.org.objectweb.asm.Type in project kotlin by JetBrains.
the class ExpressionCodegen method addLeaveTaskToRemoveLocalVariableFromFrameMap.
private void addLeaveTaskToRemoveLocalVariableFromFrameMap(@NotNull KtVariableDeclaration statement, final Label blockEnd, @NotNull List<Function<StackValue, Void>> leaveTasks) {
final VariableDescriptor variableDescriptor = getVariableDescriptorNotNull(statement);
// They always will have special name
if (variableDescriptor.getName().isSpecial())
return;
final Type type = getVariableType(variableDescriptor);
final Label scopeStart = new Label();
v.mark(scopeStart);
leaveTasks.add(new Function<StackValue, Void>() {
@Override
public Void fun(StackValue answer) {
if (isDelegatedLocalVariable(variableDescriptor)) {
myFrameMap.leave(getDelegatedLocalVariableMetadata(variableDescriptor, bindingContext));
}
int index = myFrameMap.leave(variableDescriptor);
if (isSharedVarType(type)) {
v.aconst(null);
v.store(index, OBJECT_TYPE);
}
v.visitLocalVariable(variableDescriptor.getName().asString(), type.getDescriptor(), null, scopeStart, blockEnd, index);
return null;
}
});
}
Aggregations