public void gen(@NotNull KtNamedFunction function) { SimpleFunctionDescriptor functionDescriptor = bindingContext.get(BindingContext.FUNCTION, function); assert functionDescriptor != null : "No descriptor for function " + function.getText() + "\n" + "in " + function.getContainingFile().getVirtualFile(); if (owner.getContextKind() != OwnerKind.DEFAULT_IMPLS || function.hasBody()) { generateMethod( JvmDeclarationOriginKt.OtherOrigin(function, functionDescriptor), functionDescriptor, new FunctionGenerationStrategy.FunctionDefault(state, functionDescriptor, function)); } generateDefaultIfNeeded( owner.intoFunction(functionDescriptor), functionDescriptor, owner.getContextKind(), DefaultParameterValueLoader.DEFAULT, function); generateOverloadsWithDefaultValues(function, functionDescriptor, functionDescriptor); }
public void genDelegate( @NotNull final FunctionDescriptor delegateFunction, final FunctionDescriptor delegatedTo, final ClassDescriptor toClass, final StackValue field) { generateMethod( JvmDeclarationOriginKt.Delegation( DescriptorToSourceUtils.descriptorToDeclaration(delegatedTo), delegateFunction), delegateFunction, new FunctionGenerationStrategy() { @Override public void generateBody( @NotNull MethodVisitor mv, @NotNull FrameMap frameMap, @NotNull JvmMethodSignature signature, @NotNull MethodContext context, @NotNull MemberCodegen<?> parentCodegen) { Method delegateToMethod = typeMapper.mapToCallableMethod(delegatedTo, /* superCall = */ false).getAsmMethod(); Method delegateMethod = typeMapper.mapSignature(delegateFunction).getAsmMethod(); Type[] argTypes = delegateMethod.getArgumentTypes(); Type[] originalArgTypes = delegateToMethod.getArgumentTypes(); InstructionAdapter iv = new InstructionAdapter(mv); iv.load(0, OBJECT_TYPE); field.put(field.type, iv); for (int i = 0, reg = 1; i < argTypes.length; i++) { StackValue.local(reg, argTypes[i]).put(originalArgTypes[i], iv); //noinspection AssignmentToForLoopParameter reg += argTypes[i].getSize(); } String internalName = typeMapper.mapType(toClass).getInternalName(); if (toClass.getKind() == ClassKind.INTERFACE) { iv.invokeinterface( internalName, delegateToMethod.getName(), delegateToMethod.getDescriptor()); } else { iv.invokevirtual( internalName, delegateToMethod.getName(), delegateToMethod.getDescriptor()); } StackValue stackValue = AsmUtil.genNotNullAssertions( state, StackValue.onStack(delegateToMethod.getReturnType()), RuntimeAssertionInfo.create( delegateFunction.getReturnType(), delegatedTo.getReturnType(), new RuntimeAssertionInfo.DataFlowExtras.OnlyMessage( delegatedTo.getName() + "(...)"))); stackValue.put(delegateMethod.getReturnType(), iv); iv.areturn(delegateMethod.getReturnType()); } }); }
public void generateMethod( @NotNull JvmDeclarationOrigin origin, @NotNull FunctionDescriptor descriptor, @NotNull FunctionGenerationStrategy strategy) { generateMethod(origin, descriptor, owner.intoFunction(descriptor), strategy); }