Code clean and simplification
This commit is contained in:
@@ -1350,7 +1350,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
Type[] argumentTypes = superCallable.getAsmMethod().getArgumentTypes();
|
Type[] argumentTypes = superCallable.getAsmMethod().getArgumentTypes();
|
||||||
ResolvedCall resolvedCall = bindingContext.get(BindingContext.RESOLVED_CALL, superCall.getCalleeExpression());
|
ResolvedCall resolvedCall = bindingContext.get(BindingContext.RESOLVED_CALL, superCall.getCalleeExpression());
|
||||||
assert resolvedCall != null;
|
assert resolvedCall != null;
|
||||||
pushMethodArguments(resolvedCall, Arrays.asList(argumentTypes), null);
|
pushMethodArguments(resolvedCall, Arrays.asList(argumentTypes), defaulCallGenerator);
|
||||||
}
|
}
|
||||||
|
|
||||||
v.invokespecial(type.getInternalName(), "<init>", constructor.getAsmMethod().getDescriptor());
|
v.invokespecial(type.getInternalName(), "<init>", constructor.getAsmMethod().getDescriptor());
|
||||||
@@ -1984,7 +1984,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public StackValue invokeFunction(
|
public StackValue invokeFunction(
|
||||||
@NotNull Call call,
|
Call call,
|
||||||
StackValue receiver,
|
StackValue receiver,
|
||||||
ResolvedCall<? extends CallableDescriptor> resolvedCall
|
ResolvedCall<? extends CallableDescriptor> resolvedCall
|
||||||
) {
|
) {
|
||||||
@@ -2307,11 +2307,11 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int pushMethodArguments(@NotNull ResolvedCall resolvedCall, List<Type> valueParameterTypes, CallGenerator callGenerator) {
|
public int pushMethodArguments(@NotNull ResolvedCall resolvedCall, List<Type> valueParameterTypes, @NotNull CallGenerator callGenerator) {
|
||||||
return pushMethodArguments(resolvedCall, valueParameterTypes, false, callGenerator);
|
return pushMethodArguments(resolvedCall, valueParameterTypes, false, callGenerator);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int pushMethodArguments(@NotNull ResolvedCall resolvedCall, List<Type> valueParameterTypes, boolean skipLast, CallGenerator callGenerator) {
|
private int pushMethodArguments(@NotNull ResolvedCall resolvedCall, List<Type> valueParameterTypes, boolean skipLast, @NotNull CallGenerator callGenerator) {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
List<ResolvedValueArgument> valueArguments = resolvedCall.getValueArgumentsByIndex();
|
List<ResolvedValueArgument> valueArguments = resolvedCall.getValueArgumentsByIndex();
|
||||||
CallableDescriptor fd = resolvedCall.getResultingDescriptor();
|
CallableDescriptor fd = resolvedCall.getResultingDescriptor();
|
||||||
@@ -2321,7 +2321,6 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
throw new IllegalStateException();
|
throw new IllegalStateException();
|
||||||
}
|
}
|
||||||
|
|
||||||
callGenerator = callGenerator != null ? callGenerator : defaulCallGenerator;
|
|
||||||
int mask = 0;
|
int mask = 0;
|
||||||
|
|
||||||
for (Iterator<ValueParameterDescriptor> iterator = valueParameters.iterator(); iterator.hasNext(); ) {
|
for (Iterator<ValueParameterDescriptor> iterator = valueParameters.iterator(); iterator.hasNext(); ) {
|
||||||
@@ -3409,7 +3408,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
if (callable instanceof CallableMethod) {
|
if (callable instanceof CallableMethod) {
|
||||||
genThisAndReceiverFromResolvedCall(receiver, resolvedCall, (CallableMethod) callable);
|
genThisAndReceiverFromResolvedCall(receiver, resolvedCall, (CallableMethod) callable);
|
||||||
boolean skipLast = !isGetter;
|
boolean skipLast = !isGetter;
|
||||||
pushMethodArguments(resolvedCall, ((CallableMethod) callable).getValueParameterTypes(), skipLast, null);
|
pushMethodArguments(resolvedCall, ((CallableMethod) callable).getValueParameterTypes(), skipLast, defaulCallGenerator);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
gen(array, arrayType); // intrinsic method
|
gen(array, arrayType); // intrinsic method
|
||||||
|
|||||||
@@ -180,7 +180,11 @@ public abstract class CodegenContext<T extends DeclarationDescriptor> {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public MethodContext intoFunction(FunctionDescriptor descriptor) {
|
public MethodContext intoFunction(FunctionDescriptor descriptor) {
|
||||||
return new MethodContext(descriptor, getContextKind(), this, null);
|
return new MethodContext(descriptor, getContextKind(), this, null, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MethodContext intoInlinedLambda(FunctionDescriptor descriptor) {
|
||||||
|
return new MethodContext(descriptor, getContextKind(), this, null, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ public class ConstructorContext extends MethodContext {
|
|||||||
@NotNull CodegenContext parent,
|
@NotNull CodegenContext parent,
|
||||||
@Nullable MutableClosure closure
|
@Nullable MutableClosure closure
|
||||||
) {
|
) {
|
||||||
super(contextDescriptor, kind, parent, closure);
|
super(contextDescriptor, kind, parent, closure, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -30,26 +30,20 @@ public class MethodContext extends CodegenContext<CallableMemberDescriptor> {
|
|||||||
|
|
||||||
private Label methodStartLabel;
|
private Label methodStartLabel;
|
||||||
|
|
||||||
private boolean isInlineClosure;
|
private final boolean isInliningLambda;
|
||||||
|
|
||||||
public MethodContext(
|
|
||||||
@NotNull FunctionDescriptor contextType,
|
|
||||||
@NotNull OwnerKind contextKind,
|
|
||||||
@NotNull CodegenContext parentContext
|
|
||||||
) {
|
|
||||||
this(contextType, contextKind, parentContext, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected MethodContext(
|
protected MethodContext(
|
||||||
@NotNull FunctionDescriptor contextDescriptor,
|
@NotNull FunctionDescriptor contextDescriptor,
|
||||||
@NotNull OwnerKind contextKind,
|
@NotNull OwnerKind contextKind,
|
||||||
@NotNull CodegenContext parentContext,
|
@NotNull CodegenContext parentContext,
|
||||||
@Nullable MutableClosure closure
|
@Nullable MutableClosure closure,
|
||||||
|
boolean isInliningLambda
|
||||||
) {
|
) {
|
||||||
super(contextDescriptor instanceof PropertyAccessorDescriptor
|
super(contextDescriptor instanceof PropertyAccessorDescriptor
|
||||||
? ((PropertyAccessorDescriptor) contextDescriptor).getCorrespondingProperty()
|
? ((PropertyAccessorDescriptor) contextDescriptor).getCorrespondingProperty()
|
||||||
: contextDescriptor, contextKind, parentContext, closure,
|
: contextDescriptor, contextKind, parentContext, closure,
|
||||||
parentContext.hasThisDescriptor() ? parentContext.getThisDescriptor() : null, null);
|
parentContext.hasThisDescriptor() ? parentContext.getThisDescriptor() : null, null);
|
||||||
|
this.isInliningLambda = isInliningLambda;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -96,16 +90,12 @@ public class MethodContext extends CodegenContext<CallableMemberDescriptor> {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setInlineClosure(boolean isInlineClosure) {
|
public boolean isInliningLambda() {
|
||||||
this.isInlineClosure = isInlineClosure;
|
return isInliningLambda;
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isInlineClosure() {
|
|
||||||
return isInlineClosure;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isSpecialStackValue(StackValue stackValue) {
|
public boolean isSpecialStackValue(StackValue stackValue) {
|
||||||
if (isInlineClosure && stackValue instanceof StackValue.Composed) {
|
if (isInliningLambda && stackValue instanceof StackValue.Composed) {
|
||||||
StackValue prefix = ((StackValue.Composed) stackValue).prefix;
|
StackValue prefix = ((StackValue.Composed) stackValue).prefix;
|
||||||
StackValue suffix = ((StackValue.Composed) stackValue).suffix;
|
StackValue suffix = ((StackValue.Composed) stackValue).suffix;
|
||||||
if (prefix instanceof StackValue.Local && ((StackValue.Local) prefix).index == 0) {
|
if (prefix instanceof StackValue.Local && ((StackValue.Local) prefix).index == 0) {
|
||||||
|
|||||||
@@ -213,18 +213,17 @@ public class InlineCodegen implements ParentCodegenAware, CallGenerator {
|
|||||||
|
|
||||||
private void generateClosuresBodies() {
|
private void generateClosuresBodies() {
|
||||||
for (LambdaInfo info : expressionMap.values()) {
|
for (LambdaInfo info : expressionMap.values()) {
|
||||||
info.setNode(generateClosureBody(info));
|
info.setNode(generateLambdaBody(info));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private MethodNode generateClosureBody(LambdaInfo info) {
|
private MethodNode generateLambdaBody(LambdaInfo info) {
|
||||||
JetFunctionLiteral declaration = info.getFunctionLiteral();
|
JetFunctionLiteral declaration = info.getFunctionLiteral();
|
||||||
FunctionDescriptor descriptor = info.getFunctionDescriptor();
|
FunctionDescriptor descriptor = info.getFunctionDescriptor();
|
||||||
|
|
||||||
MethodContext parentContext = codegen.getContext();
|
MethodContext parentContext = codegen.getContext();
|
||||||
|
|
||||||
MethodContext context = parentContext.intoClosure(descriptor, codegen, typeMapper).intoFunction(descriptor);
|
MethodContext context = parentContext.intoClosure(descriptor, codegen, typeMapper).intoInlinedLambda(descriptor);
|
||||||
context.setInlineClosure(true);
|
|
||||||
|
|
||||||
JvmMethodSignature jvmMethodSignature = typeMapper.mapSignature(descriptor);
|
JvmMethodSignature jvmMethodSignature = typeMapper.mapSignature(descriptor);
|
||||||
Method asmMethod = jvmMethodSignature.getAsmMethod();
|
Method asmMethod = jvmMethodSignature.getAsmMethod();
|
||||||
@@ -294,7 +293,7 @@ public class InlineCodegen implements ParentCodegenAware, CallGenerator {
|
|||||||
|
|
||||||
if (stackValue instanceof StackValue.Composed) {
|
if (stackValue instanceof StackValue.Composed) {
|
||||||
//see: Method.isSpecialStackValue: go through aload 0
|
//see: Method.isSpecialStackValue: go through aload 0
|
||||||
if (codegen.getContext().isInlineClosure() && codegen.getContext().getContextDescriptor() instanceof AnonymousFunctionDescriptor) {
|
if (codegen.getContext().isInliningLambda() && codegen.getContext().getContextDescriptor() instanceof AnonymousFunctionDescriptor) {
|
||||||
if (descriptor != null && !InlineUtil.hasNoinlineAnnotation(descriptor)) {
|
if (descriptor != null && !InlineUtil.hasNoinlineAnnotation(descriptor)) {
|
||||||
//TODO: check type of context
|
//TODO: check type of context
|
||||||
return false;
|
return false;
|
||||||
@@ -425,11 +424,11 @@ public class InlineCodegen implements ParentCodegenAware, CallGenerator {
|
|||||||
return parent.intoFunction((FunctionDescriptor) descriptor);
|
return parent.intoFunction((FunctionDescriptor) descriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new IllegalStateException("Coudn't build context for " + descriptorName(descriptor));
|
throw new IllegalStateException("Couldn't build context for " + descriptorName(descriptor));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isStaticMethod(FunctionDescriptor functionDescriptor, MethodContext context) {
|
private static boolean isStaticMethod(FunctionDescriptor functionDescriptor, MethodContext context) {
|
||||||
return (getMethodAsmFlags(functionDescriptor, context.getContextKind()) & Opcodes.ACC_STATIC) == Opcodes.ACC_STATIC;
|
return (getMethodAsmFlags(functionDescriptor, context.getContextKind()) & Opcodes.ACC_STATIC) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ public class StupidSync extends IntrinsicMethod {
|
|||||||
|
|
||||||
assert resolvedCall != null : "Resolved call for " + element.getText() + " should be not null";
|
assert resolvedCall != null : "Resolved call for " + element.getText() + " should be not null";
|
||||||
|
|
||||||
codegen.pushMethodArguments(resolvedCall, Arrays.asList(OBJECT_TYPE, FUNCTION0_TYPE), null);
|
codegen.pushMethodArguments(resolvedCall, Arrays.asList(OBJECT_TYPE, FUNCTION0_TYPE), codegen.defaulCallGenerator);
|
||||||
v.invokestatic("kotlin/jvm/internal/Intrinsics", "stupidSync", Type.getMethodDescriptor(OBJECT_TYPE, OBJECT_TYPE, FUNCTION0_TYPE));
|
v.invokestatic("kotlin/jvm/internal/Intrinsics", "stupidSync", Type.getMethodDescriptor(OBJECT_TYPE, OBJECT_TYPE, FUNCTION0_TYPE));
|
||||||
return OBJECT_TYPE;
|
return OBJECT_TYPE;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,11 +37,6 @@ public class InlineUtil {
|
|||||||
|
|
||||||
public static boolean DEFAULT_INLINE_FLAG_FOR_STUB = false; /*always false*/
|
public static boolean DEFAULT_INLINE_FLAG_FOR_STUB = false; /*always false*/
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public static InlineStrategy getInlineType(@NotNull Annotated annotated) {
|
|
||||||
return getInlineType(annotated.getAnnotations());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean hasNoinlineAnnotation(@NotNull CallableDescriptor valueParameterDescriptor) {
|
public static boolean hasNoinlineAnnotation(@NotNull CallableDescriptor valueParameterDescriptor) {
|
||||||
KotlinBuiltIns builtIns = KotlinBuiltIns.getInstance();
|
KotlinBuiltIns builtIns = KotlinBuiltIns.getInstance();
|
||||||
return KotlinBuiltIns.containsAnnotation(valueParameterDescriptor, builtIns.getNoinlineClassAnnotation());
|
return KotlinBuiltIns.containsAnnotation(valueParameterDescriptor, builtIns.getNoinlineClassAnnotation());
|
||||||
@@ -62,6 +57,7 @@ public class InlineUtil {
|
|||||||
else {
|
else {
|
||||||
assert argument instanceof EnumValue : "Inline annotation parameter should be inline entry but was: " + argument + "!";
|
assert argument instanceof EnumValue : "Inline annotation parameter should be inline entry but was: " + argument + "!";
|
||||||
ClassDescriptor value = ((EnumValue) argument).getValue();
|
ClassDescriptor value = ((EnumValue) argument).getValue();
|
||||||
|
assert value != null : "Value for enum value should be not null " + argument;
|
||||||
String name = value.getName().asString();
|
String name = value.getName().asString();
|
||||||
return name.equals(InlineStrategy.IN_PLACE.name()) ? InlineStrategy.IN_PLACE : InlineStrategy.AS_FUNCTION;
|
return name.equals(InlineStrategy.IN_PLACE.name()) ? InlineStrategy.IN_PLACE : InlineStrategy.AS_FUNCTION;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user