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);
functionCodegen.generateDefaultIfNeeded(context.intoFunction(funDescriptor),
typeMapper.mapSignature(funDescriptor),
funDescriptor,
context.getContextKind(),
DefaultParameterValueLoader.DEFAULT,
null);
functionCodegen.generateDefaultIfNeeded(
context.intoFunction(funDescriptor), funDescriptor, context.getContextKind(), DefaultParameterValueLoader.DEFAULT, null
);
}
@Override
@@ -106,15 +106,12 @@ public class FunctionCodegen {
assert functionDescriptor != null : "No descriptor for function " + function.getText() + "\n" +
"in " + function.getContainingFile().getVirtualFile();
OwnerKind kind = owner.getContextKind();
JvmMethodSignature method = typeMapper.mapSignature(functionDescriptor, kind);
if (kind != OwnerKind.TRAIT_IMPL || function.hasBody()) {
if (owner.getContextKind() != OwnerKind.TRAIT_IMPL || function.hasBody()) {
generateMethod(OtherOrigin(function, functionDescriptor), functionDescriptor,
new FunctionGenerationStrategy.FunctionDefault(state, functionDescriptor, function));
}
generateDefaultIfNeeded(owner.intoFunction(functionDescriptor), method, functionDescriptor, kind,
generateDefaultIfNeeded(owner.intoFunction(functionDescriptor), functionDescriptor, owner.getContextKind(),
DefaultParameterValueLoader.DEFAULT, function);
}
@@ -593,7 +590,6 @@ public class FunctionCodegen {
void generateDefaultIfNeeded(
@NotNull MethodContext owner,
@NotNull JvmMethodSignature signature,
@NotNull FunctionDescriptor functionDescriptor,
@NotNull OwnerKind kind,
@NotNull DefaultParameterValueLoader loadStrategy,
@@ -611,18 +607,19 @@ public class FunctionCodegen {
return;
}
Method jvmSignature = signature.getAsmMethod();
int flags = getVisibilityAccessFlag(functionDescriptor) | getDeprecatedAccessFlag(functionDescriptor);
boolean isConstructor = "<init>".equals(jvmSignature.getName());
int flags = getVisibilityAccessFlag(functionDescriptor) |
getDeprecatedAccessFlag(functionDescriptor) |
(functionDescriptor instanceof ConstructorDescriptor ? 0 : ACC_STATIC);
Method defaultMethod = typeMapper.mapDefaultMethod(functionDescriptor, kind, owner);
MethodVisitor mv = v.newMethod(Synthetic(function, functionDescriptor), flags | (isConstructor ? 0 : ACC_STATIC),
defaultMethod.getName(),
defaultMethod.getDescriptor(), null,
getThrownExceptions(functionDescriptor, typeMapper));
MethodVisitor mv = v.newMethod(
Synthetic(function, functionDescriptor),
flags,
defaultMethod.getName(),
defaultMethod.getDescriptor(), null,
getThrownExceptions(functionDescriptor, typeMapper)
);
if (state.getClassBuilderMode() == ClassBuilderMode.FULL) {
if (this.owner instanceof PackageFacadeContext) {
@@ -631,36 +628,25 @@ public class FunctionCodegen {
endVisit(mv, "default method delegation", callableDescriptorToDeclaration(functionDescriptor));
}
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(
@NotNull MethodContext methodContext,
@NotNull JvmMethodSignature signature,
@NotNull FunctionDescriptor functionDescriptor,
boolean isStatic,
@NotNull MethodVisitor mv,
@NotNull DefaultParameterValueLoader loadStrategy,
@Nullable JetNamedFunction function,
@NotNull MemberCodegen<?> parentCodegen,
@NotNull GenerationState state
@NotNull MemberCodegen<?> parentCodegen
) {
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);
ExpressionCodegen codegen = new ExpressionCodegen(mv, frameMap, signature.getReturnType(), methodContext, state, parentCodegen);
@@ -753,7 +753,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
});
functionCodegen.generateDefaultIfNeeded(
context.intoFunction(function), typeMapper.mapSignature(function), function, OwnerKind.IMPLEMENTATION,
context.intoFunction(function), function, OwnerKind.IMPLEMENTATION,
new DefaultParameterValueLoader() {
@Override
public StackValue genValue(ValueParameterDescriptor valueParameter, ExpressionCodegen codegen) {
@@ -1056,8 +1056,8 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
}
);
functionCodegen.generateDefaultIfNeeded(constructorContext, typeMapper.mapSignature(constructorDescriptor), constructorDescriptor,
OwnerKind.IMPLEMENTATION, DefaultParameterValueLoader.DEFAULT, null);
functionCodegen.generateDefaultIfNeeded(constructorContext, constructorDescriptor, OwnerKind.IMPLEMENTATION,
DefaultParameterValueLoader.DEFAULT, null);
CallableMethod callableMethod = typeMapper.mapToCallableMethod(constructorDescriptor);
FunctionCodegen.generateConstructorWithoutParametersIfNeeded(state, callableMethod, constructorDescriptor, v, myClass);
@@ -190,8 +190,7 @@ public class PackageCodegen {
);
memberCodegen.functionCodegen.generateDefaultIfNeeded(
context.intoFunction(function), state.getTypeMapper().mapSignature(function, OwnerKind.PACKAGE),
function, OwnerKind.PACKAGE, DefaultParameterValueLoader.DEFAULT, null
context.intoFunction(function), function, OwnerKind.PACKAGE, DefaultParameterValueLoader.DEFAULT, null
);
}
else if (member instanceof DeserializedPropertyDescriptor) {
@@ -187,12 +187,10 @@ public class InlineCodegen extends CallGenerator {
//for maxLocals calculation
MethodVisitor maxCalcAdapter = InlineCodegenUtil.wrapWithMaxLocalCalc(node);
MethodContext methodContext = context.getParentContext().intoFunction(functionDescriptor);
MemberCodegen<?> parentCodegen = codegen.getParentCodegen();
if (callDefault) {
boolean isStatic = AsmUtil.isStaticMethod(context.getContextKind(), functionDescriptor);
FunctionCodegen.generateDefaultImplBody(
methodContext, jvmSignature, functionDescriptor, isStatic, maxCalcAdapter, DefaultParameterValueLoader.DEFAULT,
(JetNamedFunction) element, parentCodegen, state
methodContext, functionDescriptor, maxCalcAdapter, DefaultParameterValueLoader.DEFAULT,
(JetNamedFunction) element, codegen.getParentCodegen()
);
}
else {