Refactor JvmMethodSignature

Rename kotlinParameterTypes -> valueParameters. Inline some other methods
This commit is contained in:
Alexander Udalov
2013-12-29 20:53:26 +04:00
parent d73b2057e3
commit 6a6d7bd236
5 changed files with 25 additions and 37 deletions
@@ -22,12 +22,14 @@ import org.jetbrains.asm4.Type;
import org.jetbrains.asm4.commons.InstructionAdapter;
import org.jetbrains.asm4.commons.Method;
import org.jetbrains.asm4.util.Printer;
import org.jetbrains.jet.codegen.signature.JvmMethodParameterKind;
import org.jetbrains.jet.codegen.signature.JvmMethodParameterSignature;
import org.jetbrains.jet.codegen.signature.JvmMethodSignature;
import org.jetbrains.jet.codegen.state.GenerationState;
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
import org.jetbrains.jet.lang.resolve.java.JvmAbi;
import java.util.ArrayList;
import java.util.List;
import static org.jetbrains.asm4.Opcodes.INVOKESPECIAL;
@@ -70,12 +72,19 @@ public class CallableMethod implements Callable {
@NotNull
public List<JvmMethodParameterSignature> getValueParameters() {
return signature.getKotlinParameterTypes();
return signature.getValueParameters();
}
@NotNull
public List<Type> getValueParameterTypes() {
return signature.getValueParameterTypes();
List<JvmMethodParameterSignature> valueParameters = signature.getValueParameters();
List<Type> result = new ArrayList<Type>(valueParameters.size());
for (JvmMethodParameterSignature parameter : valueParameters) {
if (parameter.getKind() == JvmMethodParameterKind.VALUE) {
result.add(parameter.getAsmType());
}
}
return result;
}
@NotNull
@@ -29,7 +29,7 @@ public class ConstructorFrameMap extends FrameMap {
public ConstructorFrameMap(@NotNull JvmMethodSignature signature) {
enterTemp(OBJECT_TYPE); // this
for (JvmMethodParameterSignature parameterType : signature.getKotlinParameterTypes()) {
for (JvmMethodParameterSignature parameterType : signature.getValueParameters()) {
if (parameterType.getKind() == JvmMethodParameterKind.OUTER) {
myOuterThisIndex = enterTemp(OBJECT_TYPE); // this0
}
@@ -154,7 +154,7 @@ public class FunctionCodegen extends ParentCodegenAwareImpl {
@NotNull JvmMethodSignature jvmSignature
) {
Iterator<ValueParameterDescriptor> iterator = functionDescriptor.getValueParameters().iterator();
List<JvmMethodParameterSignature> kotlinParameterTypes = jvmSignature.getKotlinParameterTypes();
List<JvmMethodParameterSignature> kotlinParameterTypes = jvmSignature.getValueParameters();
for (int i = 0; i < kotlinParameterTypes.size(); i++) {
JvmMethodParameterKind kind = kotlinParameterTypes.get(i).getKind();
@@ -178,7 +178,7 @@ public class FunctionCodegen extends ParentCodegenAwareImpl {
@NotNull JvmMethodSignature jvmSignature
) {
Iterator<ValueParameterDescriptor> descriptors = functionDescriptor.getValueParameters().iterator();
List<JvmMethodParameterSignature> kotlinParameterTypes = jvmSignature.getKotlinParameterTypes();
List<JvmMethodParameterSignature> kotlinParameterTypes = jvmSignature.getValueParameters();
for (int i = 0; i < kotlinParameterTypes.size(); i++) {
JvmMethodParameterKind kind = kotlinParameterTypes.get(i).getKind();
@@ -305,7 +305,7 @@ public class FunctionCodegen extends ParentCodegenAwareImpl {
@NotNull OwnerKind ownerKind
) {
Iterator<ValueParameterDescriptor> valueParameters = functionDescriptor.getValueParameters().iterator();
List<JvmMethodParameterSignature> params = jvmMethodSignature.getKotlinParameterTypes();
List<JvmMethodParameterSignature> params = jvmMethodSignature.getValueParameters();
int shift = 0;
boolean isStatic = AsmUtil.isStaticMethod(ownerKind, functionDescriptor);
@@ -563,7 +563,7 @@ public class FunctionCodegen extends ParentCodegenAwareImpl {
int countOfExtraVarsInMethodArgs = 0;
for (JvmMethodParameterSignature parameterSignature : signature.getKotlinParameterTypes()) {
for (JvmMethodParameterSignature parameterSignature : signature.getValueParameters()) {
if (parameterSignature.getKind() != JvmMethodParameterKind.VALUE) {
countOfExtraVarsInMethodArgs++;
frameMap.enterTemp(parameterSignature.getAsmType());
@@ -629,7 +629,7 @@ public class FunctionCodegen extends ParentCodegenAwareImpl {
var += ownerType.getSize();
}
for (JvmMethodParameterSignature parameterSignature : signature.getKotlinParameterTypes()) {
for (JvmMethodParameterSignature parameterSignature : signature.getValueParameters()) {
if (parameterSignature.getKind() != JvmMethodParameterKind.VALUE) {
Type type = parameterSignature.getAsmType();
iv.load(var, type);
@@ -21,25 +21,21 @@ import org.jetbrains.annotations.Nullable;
import org.jetbrains.asm4.Type;
import org.jetbrains.asm4.commons.Method;
import java.util.ArrayList;
import java.util.List;
public class JvmMethodSignature {
@NotNull
private final Method asmMethod;
@Nullable
private final String genericsSignature;
@NotNull
private final List<JvmMethodParameterSignature> kotlinParameterTypes;
private final List<JvmMethodParameterSignature> valueParameters;
protected JvmMethodSignature(
@NotNull Method asmMethod,
@Nullable String genericsSignature,
@NotNull List<JvmMethodParameterSignature> kotlinParameterTypes
@NotNull List<JvmMethodParameterSignature> valueParameters
) {
this.asmMethod = asmMethod;
this.genericsSignature = genericsSignature;
this.kotlinParameterTypes = kotlinParameterTypes;
this.valueParameters = valueParameters;
}
@NotNull
@@ -53,8 +49,8 @@ public class JvmMethodSignature {
}
@NotNull
public List<JvmMethodParameterSignature> getKotlinParameterTypes() {
return kotlinParameterTypes;
public List<JvmMethodParameterSignature> getValueParameters() {
return valueParameters;
}
@NotNull
@@ -62,27 +58,11 @@ public class JvmMethodSignature {
return asmMethod.getReturnType();
}
@NotNull
public List<Type> getValueParameterTypes() {
List<Type> r = new ArrayList<Type>(kotlinParameterTypes.size());
for (JvmMethodParameterSignature p : kotlinParameterTypes) {
if (p.getKind() == JvmMethodParameterKind.VALUE) {
r.add(p.getAsmType());
}
}
return r;
}
@NotNull
public JvmMethodSignature replaceName(@NotNull String newName) {
return newName.equals(asmMethod.getName()) ?
this :
new JvmMethodSignature(new Method(newName, asmMethod.getDescriptor()), genericsSignature, kotlinParameterTypes);
}
@NotNull
public String getName() {
return asmMethod.getName();
new JvmMethodSignature(new Method(newName, asmMethod.getDescriptor()), genericsSignature, valueParameters);
}
@Override
@@ -767,10 +767,9 @@ public class JetTypeMapper extends BindingTraceAware {
.get(BindingContext.REFERENCE_TARGET, superCall.getCalleeExpression().getConstructorReferenceExpression());
if (superDescriptor instanceof ConstructorDescriptor && isAnonymousObject(descriptor.getContainingDeclaration())) {
List<JvmMethodParameterSignature> types = mapSignature((ConstructorDescriptor) superDescriptor).getKotlinParameterTypes();
for (JvmMethodParameterSignature type : types) {
for (JvmMethodParameterSignature parameter : mapSignature((ConstructorDescriptor) superDescriptor).getValueParameters()) {
signatureWriter.writeParameterType(JvmMethodParameterKind.SUPER_CALL_PARAM);
signatureWriter.writeAsmType(type.getAsmType());
signatureWriter.writeAsmType(parameter.getAsmType());
signatureWriter.writeParameterTypeEnd();
}
}