diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/ClosureCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/ClosureCodegen.java index cc793e9939f..17fe59b164b 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/ClosureCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/ClosureCodegen.java @@ -25,7 +25,7 @@ import org.jetbrains.asm4.MethodVisitor; import org.jetbrains.asm4.Type; import org.jetbrains.asm4.commons.InstructionAdapter; import org.jetbrains.asm4.commons.Method; -import org.jetbrains.jet.codegen.inline.Inliner; +import org.jetbrains.jet.codegen.inline.CallGenerator; import org.jetbrains.jet.codegen.binding.CalculatedClosure; import org.jetbrains.jet.codegen.context.CodegenContext; import org.jetbrains.jet.codegen.context.LocalLookup; @@ -154,7 +154,7 @@ public class ClosureCodegen extends ParentCodegenAwareImpl { v.anew(asmType); v.dup(); - codegen.pushClosureOnStack(closure, false, Inliner.NOT_INLINE); + codegen.pushClosureOnStack(closure, false, CallGenerator.NOT_INLINE); v.invokespecial(asmType.getInternalName(), "", constructor.getDescriptor()); } return StackValue.onStack(asmType); diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java index c79c9edd7e9..6c79eb72c6c 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java @@ -33,7 +33,7 @@ import org.jetbrains.asm4.Type; import org.jetbrains.asm4.commons.InstructionAdapter; import org.jetbrains.asm4.commons.Method; import org.jetbrains.jet.codegen.inline.InlineCodegen; -import org.jetbrains.jet.codegen.inline.Inliner; +import org.jetbrains.jet.codegen.inline.CallGenerator; import org.jetbrains.jet.codegen.inline.NameGenerator; import org.jetbrains.jet.codegen.binding.CalculatedClosure; import org.jetbrains.jet.codegen.binding.CodegenBinding; @@ -1334,7 +1334,7 @@ public class ExpressionCodegen extends JetVisitor implem v.anew(type); v.dup(); - pushClosureOnStack(closure, false, Inliner.NOT_INLINE); + pushClosureOnStack(closure, false, CallGenerator.NOT_INLINE); JetDelegatorToSuperCall superCall = closure.getSuperCall(); if (superCall != null) { @@ -1355,7 +1355,7 @@ public class ExpressionCodegen extends JetVisitor implem return StackValue.onStack(type); } - public void pushClosureOnStack(CalculatedClosure closure, boolean ignoreThisAndReceiver, Inliner inliner) { + public void pushClosureOnStack(CalculatedClosure closure, boolean ignoreThisAndReceiver, CallGenerator callGenerator) { if (closure != null) { int paramIndex = 0; if (!ignoreThisAndReceiver) { @@ -1364,20 +1364,20 @@ public class ExpressionCodegen extends JetVisitor implem StackValue thisOrOuter = generateThisOrOuter(captureThis, false); assert !isPrimitive(thisOrOuter.type) : "This or outer should be non primitive: " + thisOrOuter.type; - if (inliner.shouldPutValue(thisOrOuter.type, thisOrOuter, null)) { + if (callGenerator.shouldPutValue(thisOrOuter.type, thisOrOuter, null)) { thisOrOuter.put(thisOrOuter.type, v); } - inliner.putCapturedInLocal(thisOrOuter.type, thisOrOuter, null, paramIndex++); + callGenerator.putCapturedInLocal(thisOrOuter.type, thisOrOuter, null, paramIndex++); } JetType captureReceiver = closure.getCaptureReceiverType(); if (captureReceiver != null) { Type asmType = typeMapper.mapType(captureReceiver); StackValue.Local capturedReceiver = StackValue.local(context.isStatic() ? 0 : 1, asmType); - if (inliner.shouldPutValue(asmType, capturedReceiver, null)) { + if (callGenerator.shouldPutValue(asmType, capturedReceiver, null)) { capturedReceiver.put(asmType, v); } - inliner.putCapturedInLocal(asmType, capturedReceiver, null, paramIndex++); + callGenerator.putCapturedInLocal(asmType, capturedReceiver, null, paramIndex++); } } @@ -1387,10 +1387,10 @@ public class ExpressionCodegen extends JetVisitor implem sharedVarType = typeMapper.mapType((VariableDescriptor) entry.getKey()); } StackValue capturedVar = entry.getValue().getOuterValue(this); - if (inliner.shouldPutValue(sharedVarType, capturedVar, null)) { + if (callGenerator.shouldPutValue(sharedVarType, capturedVar, null)) { capturedVar.put(sharedVarType, v); } - inliner.putCapturedInLocal(sharedVarType, capturedVar, null, paramIndex++); + callGenerator.putCapturedInLocal(sharedVarType, capturedVar, null, paramIndex++); } } } @@ -2123,7 +2123,7 @@ public class ExpressionCodegen extends JetVisitor implem descriptor instanceof SimpleFunctionDescriptor && ((SimpleFunctionDescriptor) descriptor).getInlineStrategy().isInline(); - Inliner inliner = !isInline ? Inliner.NOT_INLINE : + CallGenerator callGenerator = !isInline ? CallGenerator.NOT_INLINE : new InlineCodegen(this, state, (SimpleFunctionDescriptor) unwrapFakeOverride( (CallableMemberDescriptor) descriptor.getOriginal()), call); @@ -2136,16 +2136,16 @@ public class ExpressionCodegen extends JetVisitor implem receiver.put(receiver.type, v); } - assert inliner == Inliner.NOT_INLINE || !hasDefaults(resolvedCall) && !tailRecursionCodegen.isTailRecursion(resolvedCall) : + assert callGenerator == CallGenerator.NOT_INLINE || !hasDefaultArguments(resolvedCall) && !tailRecursionCodegen.isTailRecursion(resolvedCall) : "Method with defaults or tail recursive couldn't be inlined " + descriptor; - pushArgumentsAndInvoke(resolvedCall, callableMethod, inliner); + pushArgumentsAndInvoke(resolvedCall, callableMethod, callGenerator); } - private void pushArgumentsAndInvoke(@NotNull ResolvedCall resolvedCall, @NotNull CallableMethod callable, @NotNull Inliner inliner) { - inliner.putHiddenParams(); + private void pushArgumentsAndInvoke(@NotNull ResolvedCall resolvedCall, @NotNull CallableMethod callable, @NotNull CallGenerator callGenerator) { + callGenerator.putHiddenParams(); - int mask = pushMethodArguments(resolvedCall, callable.getValueParameterTypes(), inliner); + int mask = pushMethodArguments(resolvedCall, callable.getValueParameterTypes(), callGenerator); if (tailRecursionCodegen.isTailRecursion(resolvedCall)) { tailRecursionCodegen.generateTailRecursion(resolvedCall); @@ -2153,8 +2153,8 @@ public class ExpressionCodegen extends JetVisitor implem } if (mask == 0) { - if (inliner != Inliner.NOT_INLINE) { - inliner.inlineCall(callable, getParentCodegen().getBuilder().getVisitor()); + if (callGenerator != CallGenerator.NOT_INLINE) { + callGenerator.inlineCall(callable, getParentCodegen().getBuilder().getVisitor()); } else { callable.invokeWithNotNullAssertion(v, state, resolvedCall); } @@ -2163,7 +2163,7 @@ public class ExpressionCodegen extends JetVisitor implem callable.invokeDefaultWithNotNullAssertion(v, state, resolvedCall, mask); } - inliner.leaveTemps(); + callGenerator.leaveTemps(); } private void genThisAndReceiverFromResolvedCall( @@ -2325,11 +2325,11 @@ public class ExpressionCodegen extends JetVisitor implem return false; } - private int pushMethodArguments(@NotNull ResolvedCall resolvedCall, List valueParameterTypes, Inliner inliner) { - return pushMethodArguments(resolvedCall, valueParameterTypes, false, inliner); + private int pushMethodArguments(@NotNull ResolvedCall resolvedCall, List valueParameterTypes, CallGenerator callGenerator) { + return pushMethodArguments(resolvedCall, valueParameterTypes, false, callGenerator); } - private int pushMethodArguments(@NotNull ResolvedCall resolvedCall, List valueParameterTypes, boolean skipLast, Inliner inliner) { + private int pushMethodArguments(@NotNull ResolvedCall resolvedCall, List valueParameterTypes, boolean skipLast, CallGenerator callGenerator) { @SuppressWarnings("unchecked") List valueArguments = resolvedCall.getValueArgumentsByIndex(); CallableDescriptor fd = resolvedCall.getResultingDescriptor(); @@ -2339,7 +2339,7 @@ public class ExpressionCodegen extends JetVisitor implem throw new IllegalStateException(); } - inliner = inliner != null ? inliner : Inliner.NOT_INLINE; + callGenerator = callGenerator != null ? callGenerator : CallGenerator.NOT_INLINE; int mask = 0; for (Iterator iterator = valueParameters.iterator(); iterator.hasNext(); ) { @@ -2360,15 +2360,15 @@ public class ExpressionCodegen extends JetVisitor implem assert argumentExpression != null : valueArgument.asElement().getText(); //TODO deparenthisise - if (inliner.isInliningClosure(argumentExpression, valueParameter)) { - inliner.rememberClosure((JetFunctionLiteralExpression) argumentExpression, parameterType); + if (callGenerator.isInliningClosure(argumentExpression, valueParameter)) { + callGenerator.rememberClosure((JetFunctionLiteralExpression) argumentExpression, parameterType); putInLocal = false; } else { StackValue value = gen(argumentExpression); - if (inliner.shouldPutValue(parameterType, value, valueParameter)) { + if (callGenerator.shouldPutValue(parameterType, value, valueParameter)) { value.put(parameterType, v); } - valueIfPresent = value; + callGenerator.putInLocal(parameterType, value, valueParameter); } } else if (resolvedValueArgument instanceof DefaultValueArgument) { pushDefaultValueOnStack(parameterType, v); @@ -2383,13 +2383,13 @@ public class ExpressionCodegen extends JetVisitor implem } if (putInLocal) { - inliner.putInLocal(parameterType, valueIfPresent, valueParameter); + callGenerator.putInLocal(parameterType, valueIfPresent, valueParameter); } } return mask; } - private static boolean hasDefaults(@NotNull ResolvedCall resolvedCall) { + private static boolean hasDefaultArguments(@NotNull ResolvedCall resolvedCall) { List valueArguments = resolvedCall.getValueArgumentsByIndex(); CallableDescriptor fd = resolvedCall.getResultingDescriptor(); @@ -3023,7 +3023,7 @@ public class ExpressionCodegen extends JetVisitor implem receiver.put(receiver.type, v); } - pushArgumentsAndInvoke(resolvedCall, callable, Inliner.NOT_INLINE); + pushArgumentsAndInvoke(resolvedCall, callable, CallGenerator.NOT_INLINE); if (keepReturnValue) { value.store(callable.getReturnType(), v); @@ -3342,7 +3342,7 @@ public class ExpressionCodegen extends JetVisitor implem //Resolved call to local class constructor doesn't have resolvedCall.getThisObject() and resolvedCall.getReceiverArgument() //so we need generate closure on stack //See StackValue.receiver for more info - pushClosureOnStack(closure, resolvedCall.getThisObject().exists() || resolvedCall.getReceiverArgument().exists(), Inliner.NOT_INLINE); + pushClosureOnStack(closure, resolvedCall.getThisObject().exists() || resolvedCall.getReceiverArgument().exists(), CallGenerator.NOT_INLINE); ConstructorDescriptor originalOfSamAdapter = (ConstructorDescriptor) SamCodegenUtil.getOriginalIfSamAdapter(constructorDescriptor); CallableMethod method = typeMapper.mapToCallableMethod(originalOfSamAdapter == null ? constructorDescriptor : originalOfSamAdapter); diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/inline/Inliner.java b/compiler/backend/src/org/jetbrains/jet/codegen/inline/CallGenerator.java similarity index 97% rename from compiler/backend/src/org/jetbrains/jet/codegen/inline/Inliner.java rename to compiler/backend/src/org/jetbrains/jet/codegen/inline/CallGenerator.java index 64b60c3c215..faf9227daea 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/inline/Inliner.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/inline/CallGenerator.java @@ -24,9 +24,9 @@ import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor; import org.jetbrains.jet.lang.psi.JetExpression; import org.jetbrains.jet.lang.psi.JetFunctionLiteralExpression; -public interface Inliner { +public interface CallGenerator { - Inliner NOT_INLINE = new Inliner() { + CallGenerator NOT_INLINE = new CallGenerator() { @Override public void inlineCall( CallableMethod callableMethod, ClassVisitor visitor diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/inline/InlineCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/inline/InlineCodegen.java index f45536f52cd..183380150bf 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/inline/InlineCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/inline/InlineCodegen.java @@ -57,7 +57,7 @@ import static org.jetbrains.jet.codegen.AsmUtil.getMethodAsmFlags; import static org.jetbrains.jet.codegen.AsmUtil.isPrimitive; import static org.jetbrains.jet.codegen.binding.CodegenBinding.asmTypeForAnonymousClass; -public class InlineCodegen implements ParentCodegenAware, Inliner { +public class InlineCodegen implements ParentCodegenAware, CallGenerator { private final JetTypeMapper typeMapper;