use of org.jetbrains.org.objectweb.asm.Type in project kotlin by JetBrains.
the class ExpressionCodegen method addLeaveTaskToRemoveNamedFunctionFromFrameMap.
private void addLeaveTaskToRemoveNamedFunctionFromFrameMap(@NotNull final KtNamedFunction statement, final Label blockEnd, @NotNull List<Function<StackValue, Void>> leaveTasks) {
final FunctionDescriptor functionDescriptor = (FunctionDescriptor) bindingContext.get(DECLARATION_TO_DESCRIPTOR, statement);
assert functionDescriptor != null;
final Type type = asmTypeForAnonymousClass(bindingContext, functionDescriptor);
final Label scopeStart = new Label();
v.mark(scopeStart);
leaveTasks.add(new Function<StackValue, Void>() {
@Override
public Void fun(StackValue answer) {
int index = myFrameMap.leave(functionDescriptor);
assert !functionDescriptor.getName().isSpecial() : "Local variable should be generated only for function with name: " + statement.getText();
v.visitLocalVariable(functionDescriptor.getName().asString() + "$", type.getDescriptor(), null, scopeStart, blockEnd, index);
return null;
}
});
}
use of org.jetbrains.org.objectweb.asm.Type in project kotlin by JetBrains.
the class ExpressionCodegen method generateExpressionWithNullFallback.
private StackValue generateExpressionWithNullFallback(@NotNull KtExpression expression, @NotNull Label ifnull) {
KtExpression deparenthesized = KtPsiUtil.deparenthesize(expression);
assert deparenthesized != null : "Unexpected empty expression";
expression = deparenthesized;
Type type = expressionType(expression);
if (expression instanceof KtSafeQualifiedExpression && !isPrimitive(type)) {
return StackValue.coercion(generateSafeQualifiedExpression((KtSafeQualifiedExpression) expression, ifnull), type);
} else {
return genLazy(expression, type);
}
}
use of org.jetbrains.org.objectweb.asm.Type in project kotlin by JetBrains.
the class ImplementationBodyCodegen method initializeEnumConstant.
private void initializeEnumConstant(@NotNull List<KtEnumEntry> enumEntries, int ordinal) {
ExpressionCodegen codegen = createOrGetClInitCodegen();
InstructionAdapter iv = codegen.v;
KtEnumEntry enumEntry = enumEntries.get(ordinal);
iv.dup();
iv.iconst(ordinal);
ClassDescriptor classDescriptor = getNotNull(bindingContext, BindingContext.CLASS, enumEntry);
Type implClass = typeMapper.mapClass(classDescriptor);
iv.anew(implClass);
iv.dup();
iv.aconst(enumEntry.getName());
iv.iconst(ordinal);
List<KtSuperTypeListEntry> delegationSpecifiers = enumEntry.getSuperTypeListEntries();
ResolvedCall<?> defaultArgumentsConstructorCall = CallUtilKt.getResolvedCall(enumEntry, bindingContext);
boolean enumEntryHasSubclass = CodegenBinding.enumEntryNeedSubclass(bindingContext, classDescriptor);
if (delegationSpecifiers.size() == 1 && !enumEntryNeedSubclass(bindingContext, enumEntry)) {
ResolvedCall<?> resolvedCall = CallUtilKt.getResolvedCallWithAssert(delegationSpecifiers.get(0), bindingContext);
CallableMethod method = typeMapper.mapToCallableMethod((ConstructorDescriptor) resolvedCall.getResultingDescriptor(), false);
codegen.invokeMethodWithArguments(method, resolvedCall, StackValue.none());
} else if (defaultArgumentsConstructorCall != null && !enumEntryHasSubclass) {
codegen.invokeFunction(defaultArgumentsConstructorCall, StackValue.none()).put(Type.VOID_TYPE, iv);
} else {
iv.invokespecial(implClass.getInternalName(), "<init>", "(Ljava/lang/String;I)V", false);
}
iv.dup();
iv.putstatic(classAsmType.getInternalName(), enumEntry.getName(), classAsmType.getDescriptor());
iv.astore(OBJECT_TYPE);
}
use of org.jetbrains.org.objectweb.asm.Type in project kotlin by JetBrains.
the class FunctionReferenceGenerationStrategy method computeAndSaveArguments.
private void computeAndSaveArguments(@NotNull List<? extends ValueArgument> fakeArguments, @NotNull ExpressionCodegen codegen) {
int receivers = (referencedFunction.getDispatchReceiverParameter() != null ? 1 : 0) + (referencedFunction.getExtensionReceiverParameter() != null ? 1 : 0) - (receiverType != null ? 1 : 0);
if (receivers < 0 && referencedFunction instanceof ConstructorDescriptor && isObject(referencedFunction.getContainingDeclaration().getContainingDeclaration())) {
//reference to object nested class
//TODO: seems problem should be fixed on frontend side (note that object instance are captured by generated class)
receivers = 0;
}
List<ValueParameterDescriptor> parameters = CollectionsKt.drop(functionDescriptor.getValueParameters(), receivers);
for (int i = 0; i < parameters.size(); i++) {
ValueParameterDescriptor parameter = parameters.get(i);
ValueArgument fakeArgument = fakeArguments.get(i);
Type type = state.getTypeMapper().mapType(parameter);
int localIndex = codegen.myFrameMap.getIndex(parameter);
codegen.tempVariables.put(fakeArgument.getArgumentExpression(), StackValue.local(localIndex, type));
}
}
use of org.jetbrains.org.objectweb.asm.Type in project kotlin by JetBrains.
the class ExpressionCodegen method visitClassOrObject.
private StackValue visitClassOrObject(KtClassOrObject declaration) {
ClassDescriptor descriptor = bindingContext.get(CLASS, declaration);
assert descriptor != null;
Type asmType = asmTypeForAnonymousClass(bindingContext, declaration);
ClassBuilder classBuilder = state.getFactory().newVisitor(JvmDeclarationOriginKt.OtherOrigin(declaration, descriptor), asmType, declaration.getContainingFile());
ClassContext objectContext = context.intoAnonymousClass(descriptor, this, OwnerKind.IMPLEMENTATION);
new ImplementationBodyCodegen(declaration, objectContext, classBuilder, state, getParentCodegen(), /* isLocal = */
true).generate();
if (declaration instanceof KtClass && ((KtClass) declaration).isInterface()) {
Type traitImplType = state.getTypeMapper().mapDefaultImpls(descriptor);
ClassBuilder traitImplBuilder = state.getFactory().newVisitor(JvmDeclarationOriginKt.DefaultImpls(declaration, descriptor), traitImplType, declaration.getContainingFile());
ClassContext traitImplContext = context.intoAnonymousClass(descriptor, this, OwnerKind.DEFAULT_IMPLS);
new InterfaceImplBodyCodegen(declaration, traitImplContext, traitImplBuilder, state, parentCodegen).generate();
}
return StackValue.none();
}
Aggregations