Remove useless parameter of FunctionCodegen.generateDefault

JvmMethodSignature can now be perfectly obtained by JetTypeMapper.mapSignature
This commit is contained in:
Alexander Udalov
2015-02-10 20:05:30 +03:00
parent f4d4fc042b
commit 22e5efc7cd
5 changed files with 29 additions and 49 deletions
@@ -191,12 +191,9 @@ public class ClosureCodegen extends MemberCodegen<JetElement> {
genClosureFields(closure, v, typeMapper); genClosureFields(closure, v, typeMapper);
functionCodegen.generateDefaultIfNeeded(context.intoFunction(funDescriptor), functionCodegen.generateDefaultIfNeeded(
typeMapper.mapSignature(funDescriptor), context.intoFunction(funDescriptor), funDescriptor, context.getContextKind(), DefaultParameterValueLoader.DEFAULT, null
funDescriptor, );
context.getContextKind(),
DefaultParameterValueLoader.DEFAULT,
null);
} }
@Override @Override
@@ -106,15 +106,12 @@ public class FunctionCodegen {
assert functionDescriptor != null : "No descriptor for function " + function.getText() + "\n" + assert functionDescriptor != null : "No descriptor for function " + function.getText() + "\n" +
"in " + function.getContainingFile().getVirtualFile(); "in " + function.getContainingFile().getVirtualFile();
OwnerKind kind = owner.getContextKind(); if (owner.getContextKind() != OwnerKind.TRAIT_IMPL || function.hasBody()) {
JvmMethodSignature method = typeMapper.mapSignature(functionDescriptor, kind);
if (kind != OwnerKind.TRAIT_IMPL || function.hasBody()) {
generateMethod(OtherOrigin(function, functionDescriptor), functionDescriptor, generateMethod(OtherOrigin(function, functionDescriptor), functionDescriptor,
new FunctionGenerationStrategy.FunctionDefault(state, functionDescriptor, function)); new FunctionGenerationStrategy.FunctionDefault(state, functionDescriptor, function));
} }
generateDefaultIfNeeded(owner.intoFunction(functionDescriptor), method, functionDescriptor, kind, generateDefaultIfNeeded(owner.intoFunction(functionDescriptor), functionDescriptor, owner.getContextKind(),
DefaultParameterValueLoader.DEFAULT, function); DefaultParameterValueLoader.DEFAULT, function);
} }
@@ -593,7 +590,6 @@ public class FunctionCodegen {
void generateDefaultIfNeeded( void generateDefaultIfNeeded(
@NotNull MethodContext owner, @NotNull MethodContext owner,
@NotNull JvmMethodSignature signature,
@NotNull FunctionDescriptor functionDescriptor, @NotNull FunctionDescriptor functionDescriptor,
@NotNull OwnerKind kind, @NotNull OwnerKind kind,
@NotNull DefaultParameterValueLoader loadStrategy, @NotNull DefaultParameterValueLoader loadStrategy,
@@ -611,18 +607,19 @@ public class FunctionCodegen {
return; return;
} }
Method jvmSignature = signature.getAsmMethod(); int flags = getVisibilityAccessFlag(functionDescriptor) |
getDeprecatedAccessFlag(functionDescriptor) |
int flags = getVisibilityAccessFlag(functionDescriptor) | getDeprecatedAccessFlag(functionDescriptor); (functionDescriptor instanceof ConstructorDescriptor ? 0 : ACC_STATIC);
boolean isConstructor = "<init>".equals(jvmSignature.getName());
Method defaultMethod = typeMapper.mapDefaultMethod(functionDescriptor, kind, owner); Method defaultMethod = typeMapper.mapDefaultMethod(functionDescriptor, kind, owner);
MethodVisitor mv = v.newMethod(Synthetic(function, functionDescriptor), flags | (isConstructor ? 0 : ACC_STATIC), MethodVisitor mv = v.newMethod(
defaultMethod.getName(), Synthetic(function, functionDescriptor),
defaultMethod.getDescriptor(), null, flags,
getThrownExceptions(functionDescriptor, typeMapper)); defaultMethod.getName(),
defaultMethod.getDescriptor(), null,
getThrownExceptions(functionDescriptor, typeMapper)
);
if (state.getClassBuilderMode() == ClassBuilderMode.FULL) { if (state.getClassBuilderMode() == ClassBuilderMode.FULL) {
if (this.owner instanceof PackageFacadeContext) { if (this.owner instanceof PackageFacadeContext) {
@@ -631,36 +628,25 @@ public class FunctionCodegen {
endVisit(mv, "default method delegation", callableDescriptorToDeclaration(functionDescriptor)); endVisit(mv, "default method delegation", callableDescriptorToDeclaration(functionDescriptor));
} }
else { else {
generateDefaultImpl(owner, signature, functionDescriptor, isStaticMethod(kind, functionDescriptor), mv, loadStrategy, function); mv.visitCode();
generateDefaultImplBody(owner, functionDescriptor, mv, loadStrategy, function, memberCodegen);
endVisit(mv, "default method", callableDescriptorToDeclaration(functionDescriptor));
} }
} }
} }
private void generateDefaultImpl(
@NotNull MethodContext methodContext,
@NotNull JvmMethodSignature signature,
@NotNull FunctionDescriptor functionDescriptor,
boolean isStatic,
@NotNull MethodVisitor mv,
@NotNull DefaultParameterValueLoader loadStrategy,
@Nullable JetNamedFunction function
) {
mv.visitCode();
generateDefaultImplBody(methodContext, signature, functionDescriptor, isStatic, mv, loadStrategy, function, memberCodegen, state);
endVisit(mv, "default method", callableDescriptorToDeclaration(functionDescriptor));
}
public static void generateDefaultImplBody( public static void generateDefaultImplBody(
@NotNull MethodContext methodContext, @NotNull MethodContext methodContext,
@NotNull JvmMethodSignature signature,
@NotNull FunctionDescriptor functionDescriptor, @NotNull FunctionDescriptor functionDescriptor,
boolean isStatic,
@NotNull MethodVisitor mv, @NotNull MethodVisitor mv,
@NotNull DefaultParameterValueLoader loadStrategy, @NotNull DefaultParameterValueLoader loadStrategy,
@Nullable JetNamedFunction function, @Nullable JetNamedFunction function,
@NotNull MemberCodegen<?> parentCodegen, @NotNull MemberCodegen<?> parentCodegen
@NotNull GenerationState state
) { ) {
GenerationState state = parentCodegen.state;
JvmMethodSignature signature = state.getTypeMapper().mapSignature(functionDescriptor, methodContext.getContextKind());
boolean isStatic = isStaticMethod(methodContext.getContextKind(), functionDescriptor);
FrameMap frameMap = createFrameMap(state, functionDescriptor, signature, isStatic); FrameMap frameMap = createFrameMap(state, functionDescriptor, signature, isStatic);
ExpressionCodegen codegen = new ExpressionCodegen(mv, frameMap, signature.getReturnType(), methodContext, state, parentCodegen); ExpressionCodegen codegen = new ExpressionCodegen(mv, frameMap, signature.getReturnType(), methodContext, state, parentCodegen);
@@ -753,7 +753,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
}); });
functionCodegen.generateDefaultIfNeeded( functionCodegen.generateDefaultIfNeeded(
context.intoFunction(function), typeMapper.mapSignature(function), function, OwnerKind.IMPLEMENTATION, context.intoFunction(function), function, OwnerKind.IMPLEMENTATION,
new DefaultParameterValueLoader() { new DefaultParameterValueLoader() {
@Override @Override
public StackValue genValue(ValueParameterDescriptor valueParameter, ExpressionCodegen codegen) { public StackValue genValue(ValueParameterDescriptor valueParameter, ExpressionCodegen codegen) {
@@ -1056,8 +1056,8 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
} }
); );
functionCodegen.generateDefaultIfNeeded(constructorContext, typeMapper.mapSignature(constructorDescriptor), constructorDescriptor, functionCodegen.generateDefaultIfNeeded(constructorContext, constructorDescriptor, OwnerKind.IMPLEMENTATION,
OwnerKind.IMPLEMENTATION, DefaultParameterValueLoader.DEFAULT, null); 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);
@@ -190,8 +190,7 @@ public class PackageCodegen {
); );
memberCodegen.functionCodegen.generateDefaultIfNeeded( memberCodegen.functionCodegen.generateDefaultIfNeeded(
context.intoFunction(function), state.getTypeMapper().mapSignature(function, OwnerKind.PACKAGE), context.intoFunction(function), function, OwnerKind.PACKAGE, DefaultParameterValueLoader.DEFAULT, null
function, OwnerKind.PACKAGE, DefaultParameterValueLoader.DEFAULT, null
); );
} }
else if (member instanceof DeserializedPropertyDescriptor) { else if (member instanceof DeserializedPropertyDescriptor) {
@@ -187,12 +187,10 @@ public class InlineCodegen extends CallGenerator {
//for maxLocals calculation //for maxLocals calculation
MethodVisitor maxCalcAdapter = InlineCodegenUtil.wrapWithMaxLocalCalc(node); MethodVisitor maxCalcAdapter = InlineCodegenUtil.wrapWithMaxLocalCalc(node);
MethodContext methodContext = context.getParentContext().intoFunction(functionDescriptor); MethodContext methodContext = context.getParentContext().intoFunction(functionDescriptor);
MemberCodegen<?> parentCodegen = codegen.getParentCodegen();
if (callDefault) { if (callDefault) {
boolean isStatic = AsmUtil.isStaticMethod(context.getContextKind(), functionDescriptor);
FunctionCodegen.generateDefaultImplBody( FunctionCodegen.generateDefaultImplBody(
methodContext, jvmSignature, functionDescriptor, isStatic, maxCalcAdapter, DefaultParameterValueLoader.DEFAULT, methodContext, functionDescriptor, maxCalcAdapter, DefaultParameterValueLoader.DEFAULT,
(JetNamedFunction) element, parentCodegen, state (JetNamedFunction) element, codegen.getParentCodegen()
); );
} }
else { else {