Remove useless parameter of FunctionCodegen.generateMethod

JvmMethodSignature can now be perfectly obtained by JetTypeMapper.mapSignature
This commit is contained in:
Alexander Udalov
2015-02-10 19:49:30 +03:00
parent e7a744b315
commit f4d4fc042b
6 changed files with 34 additions and 50 deletions
@@ -35,7 +35,6 @@ import org.jetbrains.kotlin.name.Name;
import org.jetbrains.kotlin.psi.JetElement; import org.jetbrains.kotlin.psi.JetElement;
import org.jetbrains.kotlin.resolve.BindingContext; import org.jetbrains.kotlin.resolve.BindingContext;
import org.jetbrains.kotlin.resolve.DescriptorUtils; import org.jetbrains.kotlin.resolve.DescriptorUtils;
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature;
import org.jetbrains.kotlin.types.JetType; import org.jetbrains.kotlin.types.JetType;
import org.jetbrains.org.objectweb.asm.MethodVisitor; import org.jetbrains.org.objectweb.asm.MethodVisitor;
import org.jetbrains.org.objectweb.asm.Type; import org.jetbrains.org.objectweb.asm.Type;
@@ -161,10 +160,12 @@ public class ClosureCodegen extends MemberCodegen<JetElement> {
erasedInterfaceFunction = samType.getAbstractMethod().getOriginal(); erasedInterfaceFunction = samType.getAbstractMethod().getOriginal();
} }
JvmMethodSignature jvmMethodSignature = typeMapper.mapSignature(funDescriptor); generateBridge(
generateBridge(typeMapper.mapSignature(erasedInterfaceFunction).getAsmMethod(), jvmMethodSignature.getAsmMethod()); typeMapper.mapSignature(erasedInterfaceFunction).getAsmMethod(),
typeMapper.mapSignature(funDescriptor).getAsmMethod()
);
functionCodegen.generateMethod(OtherOrigin(element, funDescriptor), jvmMethodSignature, funDescriptor, strategy); functionCodegen.generateMethod(OtherOrigin(element, funDescriptor), funDescriptor, strategy);
//TODO: rewrite cause ugly hack //TODO: rewrite cause ugly hack
if (samType != null) { if (samType != null) {
@@ -110,8 +110,7 @@ public class FunctionCodegen {
JvmMethodSignature method = typeMapper.mapSignature(functionDescriptor, kind); JvmMethodSignature method = typeMapper.mapSignature(functionDescriptor, kind);
if (kind != OwnerKind.TRAIT_IMPL || function.hasBody()) { if (kind != OwnerKind.TRAIT_IMPL || function.hasBody()) {
generateMethod(OtherOrigin(function, functionDescriptor), generateMethod(OtherOrigin(function, functionDescriptor), functionDescriptor,
method, functionDescriptor,
new FunctionGenerationStrategy.FunctionDefault(state, functionDescriptor, function)); new FunctionGenerationStrategy.FunctionDefault(state, functionDescriptor, function));
} }
@@ -121,24 +120,23 @@ public class FunctionCodegen {
public void generateMethod( public void generateMethod(
@NotNull JvmDeclarationOrigin origin, @NotNull JvmDeclarationOrigin origin,
@NotNull JvmMethodSignature jvmSignature, @NotNull FunctionDescriptor descriptor,
@NotNull FunctionDescriptor functionDescriptor,
@NotNull FunctionGenerationStrategy strategy @NotNull FunctionGenerationStrategy strategy
) { ) {
generateMethod(origin, jvmSignature, functionDescriptor, owner.intoFunction(functionDescriptor), strategy); generateMethod(origin, descriptor, owner.intoFunction(descriptor), strategy);
} }
public void generateMethod( public void generateMethod(
@NotNull JvmDeclarationOrigin origin, @NotNull JvmDeclarationOrigin origin,
@NotNull JvmMethodSignature jvmSignature,
@NotNull FunctionDescriptor functionDescriptor, @NotNull FunctionDescriptor functionDescriptor,
@NotNull MethodContext methodContext, @NotNull MethodContext methodContext,
@NotNull FunctionGenerationStrategy strategy @NotNull FunctionGenerationStrategy strategy
) { ) {
OwnerKind methodContextKind = methodContext.getContextKind(); OwnerKind contextKind = methodContext.getContextKind();
JvmMethodSignature jvmSignature = typeMapper.mapSignature(functionDescriptor, contextKind);
Method asmMethod = jvmSignature.getAsmMethod(); Method asmMethod = jvmSignature.getAsmMethod();
int flags = getMethodAsmFlags(functionDescriptor, methodContextKind); int flags = getMethodAsmFlags(functionDescriptor, contextKind);
boolean isNative = NativeDeclarationsPackage.hasNativeAnnotation(functionDescriptor); boolean isNative = NativeDeclarationsPackage.hasNativeAnnotation(functionDescriptor);
if (isNative && owner instanceof PackageContext && !(owner instanceof PackageFacadeContext)) { if (isNative && owner instanceof PackageContext && !(owner instanceof PackageFacadeContext)) {
@@ -176,7 +174,7 @@ public class FunctionCodegen {
parentBodyCodegen.addAdditionalTask(new PlatformStaticGenerator(functionDescriptor, origin, state)); parentBodyCodegen.addAdditionalTask(new PlatformStaticGenerator(functionDescriptor, origin, state));
} }
if (state.getClassBuilderMode() == ClassBuilderMode.LIGHT_CLASSES || isAbstractMethod(functionDescriptor, methodContextKind)) { if (state.getClassBuilderMode() == ClassBuilderMode.LIGHT_CLASSES || isAbstractMethod(functionDescriptor, contextKind)) {
generateLocalVariableTable( generateLocalVariableTable(
mv, mv,
jvmSignature, jvmSignature,
@@ -184,7 +182,7 @@ public class FunctionCodegen {
getThisTypeForFunction(functionDescriptor, methodContext, typeMapper), getThisTypeForFunction(functionDescriptor, methodContext, typeMapper),
new Label(), new Label(),
new Label(), new Label(),
methodContextKind contextKind
); );
mv.visitEnd(); mv.visitEnd();
@@ -851,10 +849,8 @@ public class FunctionCodegen {
final ClassDescriptor toClass, final ClassDescriptor toClass,
final StackValue field final StackValue field
) { ) {
final JvmMethodSignature jvmDelegateMethodSignature = typeMapper.mapSignature(delegateFunction);
final JvmMethodSignature jvmDelegateToMethodSignature = typeMapper.mapSignature(delegatedTo);
generateMethod( generateMethod(
OtherOrigin(delegateFunction), jvmDelegateMethodSignature, delegateFunction, OtherOrigin(delegateFunction), delegateFunction,
new FunctionGenerationStrategy() { new FunctionGenerationStrategy() {
@Override @Override
public void generateBody( public void generateBody(
@@ -864,8 +860,8 @@ public class FunctionCodegen {
@NotNull MethodContext context, @NotNull MethodContext context,
@NotNull MemberCodegen<?> parentCodegen @NotNull MemberCodegen<?> parentCodegen
) { ) {
Method delegateToMethod = jvmDelegateToMethodSignature.getAsmMethod(); Method delegateToMethod = typeMapper.mapSignature(delegatedTo).getAsmMethod();
Method delegateMethod = jvmDelegateMethodSignature.getAsmMethod(); Method delegateMethod = typeMapper.mapSignature(delegateFunction).getAsmMethod();
Type[] argTypes = delegateMethod.getArgumentTypes(); Type[] argTypes = delegateMethod.getArgumentTypes();
Type[] originalArgTypes = delegateToMethod.getArgumentTypes(); Type[] originalArgTypes = delegateToMethod.getArgumentTypes();
@@ -893,7 +889,8 @@ public class FunctionCodegen {
TypesPackage.getApproximationTo( TypesPackage.getApproximationTo(
delegatedTo.getReturnType(), delegatedTo.getReturnType(),
delegateFunction.getReturnType(), delegateFunction.getReturnType(),
new Approximation.DataFlowExtras.OnlyMessage(delegatedTo.getName() + "(...)")) new Approximation.DataFlowExtras.OnlyMessage(delegatedTo.getName() + "(...)")
)
); );
stackValue.put(delegateMethod.getReturnType(), iv); stackValue.put(delegateMethod.getReturnType(), iv);
@@ -681,7 +681,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
@Override @Override
public void generateComponentFunction(@NotNull FunctionDescriptor function, @NotNull final ValueParameterDescriptor parameter) { public void generateComponentFunction(@NotNull FunctionDescriptor function, @NotNull final ValueParameterDescriptor parameter) {
PsiElement originalElement = DescriptorToSourceUtils.descriptorToDeclaration(parameter); PsiElement originalElement = DescriptorToSourceUtils.descriptorToDeclaration(parameter);
functionCodegen.generateMethod(OtherOrigin(originalElement, function), typeMapper.mapSignature(function), function, new FunctionGenerationStrategy() { functionCodegen.generateMethod(OtherOrigin(originalElement, function), function, new FunctionGenerationStrategy() {
@Override @Override
public void generateBody( public void generateBody(
@NotNull MethodVisitor mv, @NotNull MethodVisitor mv,
@@ -706,11 +706,9 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
@Override @Override
public void generateCopyFunction(@NotNull final FunctionDescriptor function, @NotNull List<JetParameter> constructorParameters) { public void generateCopyFunction(@NotNull final FunctionDescriptor function, @NotNull List<JetParameter> constructorParameters) {
JvmMethodSignature methodSignature = typeMapper.mapSignature(function);
final Type thisDescriptorType = typeMapper.mapType(descriptor); final Type thisDescriptorType = typeMapper.mapType(descriptor);
functionCodegen.generateMethod(OtherOrigin(myClass, function), methodSignature, function, new FunctionGenerationStrategy() { functionCodegen.generateMethod(OtherOrigin(myClass, function), function, new FunctionGenerationStrategy() {
@Override @Override
public void generateBody( public void generateBody(
@NotNull MethodVisitor mv, @NotNull MethodVisitor mv,
@@ -755,7 +753,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
}); });
functionCodegen.generateDefaultIfNeeded( functionCodegen.generateDefaultIfNeeded(
context.intoFunction(function), methodSignature, function, OwnerKind.IMPLEMENTATION, context.intoFunction(function), typeMapper.mapSignature(function), function, OwnerKind.IMPLEMENTATION,
new DefaultParameterValueLoader() { new DefaultParameterValueLoader() {
@Override @Override
public StackValue genValue(ValueParameterDescriptor valueParameter, ExpressionCodegen codegen) { public StackValue genValue(ValueParameterDescriptor valueParameter, ExpressionCodegen codegen) {
@@ -834,7 +832,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
FunctionDescriptor bridge = (FunctionDescriptor) entry.getValue(); FunctionDescriptor bridge = (FunctionDescriptor) entry.getValue();
final FunctionDescriptor original = (FunctionDescriptor) entry.getKey(); final FunctionDescriptor original = (FunctionDescriptor) entry.getKey();
functionCodegen.generateMethod( functionCodegen.generateMethod(
Synthetic(null, original), typeMapper.mapSignature(bridge), bridge, Synthetic(null, original), bridge,
new FunctionGenerationStrategy.CodegenBased<FunctionDescriptor>(state, bridge) { new FunctionGenerationStrategy.CodegenBased<FunctionDescriptor>(state, bridge) {
@Override @Override
public void doGenerateBody(@NotNull ExpressionCodegen codegen, @NotNull JvmMethodSignature signature) { public void doGenerateBody(@NotNull ExpressionCodegen codegen, @NotNull JvmMethodSignature signature) {
@@ -889,9 +887,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
PropertyGetterDescriptor getter = bridge.getGetter(); PropertyGetterDescriptor getter = bridge.getGetter();
assert getter != null; assert getter != null;
functionCodegen.generateMethod(Synthetic(null, original.getGetter() != null ? original.getGetter() : original), functionCodegen.generateMethod(Synthetic(null, original.getGetter() != null ? original.getGetter() : original),
typeMapper.mapSignature(getter), getter, new PropertyAccessorStrategy(getter));
getter,
new PropertyAccessorStrategy(getter));
if (bridge.isVar()) { if (bridge.isVar()) {
@@ -899,9 +895,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
assert setter != null; assert setter != null;
functionCodegen.generateMethod(Synthetic(null, original.getSetter() != null ? original.getSetter() : original), functionCodegen.generateMethod(Synthetic(null, original.getSetter() != null ? original.getSetter() : original),
typeMapper.mapSignature(setter), setter, new PropertyAccessorStrategy(setter));
setter,
new PropertyAccessorStrategy(setter));
} }
} }
else { else {
@@ -1053,9 +1047,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
lookupConstructorExpressionsInClosureIfPresent(constructorContext); lookupConstructorExpressionsInClosureIfPresent(constructorContext);
} }
JvmMethodSignature signature = typeMapper.mapSignature(constructorDescriptor); functionCodegen.generateMethod(OtherOrigin(myClass, constructorDescriptor), constructorDescriptor, constructorContext,
functionCodegen.generateMethod(OtherOrigin(myClass, constructorDescriptor), signature, constructorDescriptor, constructorContext,
new FunctionGenerationStrategy.CodegenBased<ConstructorDescriptor>(state, constructorDescriptor) { new FunctionGenerationStrategy.CodegenBased<ConstructorDescriptor>(state, constructorDescriptor) {
@Override @Override
public void doGenerateBody(@NotNull ExpressionCodegen codegen, @NotNull JvmMethodSignature signature) { public void doGenerateBody(@NotNull ExpressionCodegen codegen, @NotNull JvmMethodSignature signature) {
@@ -1064,8 +1056,8 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
} }
); );
functionCodegen.generateDefaultIfNeeded(constructorContext, signature, constructorDescriptor, OwnerKind.IMPLEMENTATION, functionCodegen.generateDefaultIfNeeded(constructorContext, typeMapper.mapSignature(constructorDescriptor), constructorDescriptor,
DefaultParameterValueLoader.DEFAULT, null); OwnerKind.IMPLEMENTATION, DefaultParameterValueLoader.DEFAULT, null);
CallableMethod callableMethod = typeMapper.mapToCallableMethod(constructorDescriptor); CallableMethod callableMethod = typeMapper.mapToCallableMethod(constructorDescriptor);
FunctionCodegen.generateConstructorWithoutParametersIfNeeded(state, callableMethod, constructorDescriptor, v, myClass); FunctionCodegen.generateConstructorWithoutParametersIfNeeded(state, callableMethod, constructorDescriptor, v, myClass);
@@ -1348,7 +1340,6 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
private void generateDelegationToTraitImpl(@NotNull final FunctionDescriptor traitFun, @NotNull FunctionDescriptor inheritedFun) { private void generateDelegationToTraitImpl(@NotNull final FunctionDescriptor traitFun, @NotNull FunctionDescriptor inheritedFun) {
functionCodegen.generateMethod( functionCodegen.generateMethod(
DelegationToTraitImpl(descriptorToDeclaration(traitFun), traitFun), DelegationToTraitImpl(descriptorToDeclaration(traitFun), traitFun),
typeMapper.mapSignature(inheritedFun),
inheritedFun, inheritedFun,
new FunctionGenerationStrategy.CodegenBased<FunctionDescriptor>(state, inheritedFun) { new FunctionGenerationStrategy.CodegenBased<FunctionDescriptor>(state, inheritedFun) {
@Override @Override
@@ -174,8 +174,7 @@ public class PackageCodegen {
if (member instanceof DeserializedSimpleFunctionDescriptor) { if (member instanceof DeserializedSimpleFunctionDescriptor) {
DeserializedSimpleFunctionDescriptor function = (DeserializedSimpleFunctionDescriptor) member; DeserializedSimpleFunctionDescriptor function = (DeserializedSimpleFunctionDescriptor) member;
JvmMethodSignature signature = state.getTypeMapper().mapSignature(function, OwnerKind.PACKAGE); memberCodegen.functionCodegen.generateMethod(OtherOrigin(function), function,
memberCodegen.functionCodegen.generateMethod(OtherOrigin(function), signature, function,
new FunctionGenerationStrategy() { new FunctionGenerationStrategy() {
@Override @Override
public void generateBody( public void generateBody(
@@ -191,9 +190,9 @@ public class PackageCodegen {
); );
memberCodegen.functionCodegen.generateDefaultIfNeeded( memberCodegen.functionCodegen.generateDefaultIfNeeded(
context.intoFunction(function), signature, function, OwnerKind.PACKAGE, context.intoFunction(function), state.getTypeMapper().mapSignature(function, OwnerKind.PACKAGE),
DefaultParameterValueLoader.DEFAULT, null); function, OwnerKind.PACKAGE, DefaultParameterValueLoader.DEFAULT, null
);
} }
else if (member instanceof DeserializedPropertyDescriptor) { else if (member instanceof DeserializedPropertyDescriptor) {
memberCodegen.propertyCodegen.generateInPackageFacade((DeserializedPropertyDescriptor) member); memberCodegen.propertyCodegen.generateInPackageFacade((DeserializedPropertyDescriptor) member);
@@ -40,13 +40,10 @@ class PlatformStaticGenerator(
override fun invoke(codegen: ImplementationBodyCodegen, classBuilder: ClassBuilder) { override fun invoke(codegen: ImplementationBodyCodegen, classBuilder: ClassBuilder) {
val staticFunctionDescriptor = createStaticFunctionDescriptor(descriptor) val staticFunctionDescriptor = createStaticFunctionDescriptor(descriptor)
val jvmMethodSignature = state.getTypeMapper().mapSignature(staticFunctionDescriptor)
codegen.functionCodegen.generateMethod( codegen.functionCodegen.generateMethod(
Synthetic(declarationOrigin.element, staticFunctionDescriptor), Synthetic(declarationOrigin.element, staticFunctionDescriptor),
jvmMethodSignature,
staticFunctionDescriptor, staticFunctionDescriptor,
object: FunctionGenerationStrategy() { object : FunctionGenerationStrategy() {
override fun generateBody( override fun generateBody(
mv: MethodVisitor, mv: MethodVisitor,
frameMap: FrameMap, frameMap: FrameMap,
@@ -86,7 +83,7 @@ class PlatformStaticGenerator(
val copies = CodegenUtil.copyFunctions( val copies = CodegenUtil.copyFunctions(
memberDescriptor, memberDescriptor,
memberDescriptor, memberDescriptor,
descriptor.getContainingDeclaration()?.getContainingDeclaration(), descriptor.getContainingDeclaration().getContainingDeclaration(),
descriptor.getModality(), descriptor.getModality(),
descriptor.getVisibility(), descriptor.getVisibility(),
CallableMemberDescriptor.Kind.SYNTHESIZED, CallableMemberDescriptor.Kind.SYNTHESIZED,
@@ -341,8 +341,7 @@ public class PropertyCodegen {
strategy = new FunctionGenerationStrategy.FunctionDefault(state, accessorDescriptor, accessor); strategy = new FunctionGenerationStrategy.FunctionDefault(state, accessorDescriptor, accessor);
} }
JvmMethodSignature signature = typeMapper.mapSignature(accessorDescriptor, kind); functionCodegen.generateMethod(OtherOrigin(accessor != null ? accessor : p, accessorDescriptor), accessorDescriptor, strategy);
functionCodegen.generateMethod(OtherOrigin(accessor != null ? accessor : p, accessorDescriptor), signature, accessorDescriptor, strategy);
} }
public static int indexOfDelegatedProperty(@NotNull JetProperty property) { public static int indexOfDelegatedProperty(@NotNull JetProperty property) {