From 9187116055f5e5fff9f3d5f51039135d3444babe Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Wed, 10 Apr 2013 15:24:39 +0400 Subject: [PATCH] Refactor componentN() function generation Adopt to the new FunctionGenerationStrategy --- .../jet/codegen/FunctionCodegen.java | 2 +- .../codegen/ImplementationBodyCodegen.java | 41 ++++++++++--------- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/FunctionCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/FunctionCodegen.java index 2e44915976c..e0d480f5bdb 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/FunctionCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/FunctionCodegen.java @@ -324,7 +324,7 @@ public class FunctionCodegen extends GenerationStateAware { iv.areturn(asmMethod.getReturnType()); } - public static void genJetAnnotations( + private static void genJetAnnotations( @NotNull GenerationState state, @NotNull FunctionDescriptor functionDescriptor, @Nullable JvmMethodSignature jvmSignature, diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java index 28f38f1ce10..aa56723536c 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java @@ -671,29 +671,32 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { } } - private void generateComponentFunction(@NotNull FunctionDescriptor function, @NotNull ValueParameterDescriptor parameter) { + private void generateComponentFunction(@NotNull FunctionDescriptor function, @NotNull final ValueParameterDescriptor parameter) { JetType returnType = function.getReturnType(); assert returnType != null : "Return type of component function should not be null: " + function; - Type componentType = typeMapper.mapReturnType(returnType); + final Type componentType = typeMapper.mapReturnType(returnType); - String desc = "()" + componentType.getDescriptor(); - MethodVisitor mv = v.newMethod(myClass, - AsmUtil.getMethodAsmFlags(function, OwnerKind.IMPLEMENTATION), - function.getName().getName(), - desc, - null, null); + JvmMethodSignature signature = typeMapper.mapSignature(function.getName(), function); - FunctionCodegen.genJetAnnotations(state, function, null, null, mv); - - mv.visitCode(); - InstructionAdapter iv = new InstructionAdapter(mv); - if (!componentType.equals(Type.VOID_TYPE)) { - iv.load(0, classAsmType); - iv.invokevirtual(classAsmType.getInternalName(), PropertyCodegen.getterName(parameter.getName()), desc); - } - iv.areturn(componentType); - - FunctionCodegen.endVisit(mv, function.getName().getName(), myClass); + FunctionCodegen fc = new FunctionCodegen(context, v, state); + fc.generateMethod(myClass, signature, true, null, function, new FunctionGenerationStrategy() { + @Override + public void generateBody( + @NotNull MethodVisitor mv, + @NotNull JvmMethodSignature signature, + @NotNull MethodContext context, + @NotNull Collection localVariableNames, + @NotNull FrameMap frameMap + ) { + InstructionAdapter iv = new InstructionAdapter(mv); + if (!componentType.equals(Type.VOID_TYPE)) { + iv.load(0, classAsmType); + String desc = "()" + componentType.getDescriptor(); + iv.invokevirtual(classAsmType.getInternalName(), PropertyCodegen.getterName(parameter.getName()), desc); + } + iv.areturn(componentType); + } + }); } private void generateCopyFunction(@NotNull final FunctionDescriptor function) {