use of org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodParameterSignature in project kotlin by JetBrains.
the class ImplementationBodyCodegen method generateSuperCallImplicitArguments.
@NotNull
private ArgumentGenerator generateSuperCallImplicitArguments(@NotNull InstructionAdapter iv, @NotNull ExpressionCodegen codegen, @NotNull ConstructorDescriptor constructorDescriptor, @NotNull ConstructorDescriptor superConstructor, @NotNull CallableMethod superCallable, @NotNull List<JvmMethodParameterSignature> superParameters, @NotNull List<JvmMethodParameterSignature> parameters) {
int offset = 1;
int superIndex = 0;
// them all onto the stack and update "offset" variable so that in the end it points to the slot of the first VALUE argument
for (JvmMethodParameterSignature parameter : parameters) {
if (superIndex >= superParameters.size())
break;
JvmMethodParameterKind superKind = superParameters.get(superIndex).getKind();
JvmMethodParameterKind kind = parameter.getKind();
Type type = parameter.getAsmType();
if (superKind == JvmMethodParameterKind.VALUE && kind == JvmMethodParameterKind.SUPER_CALL_PARAM) {
// Stop when we reach the actual value parameters present in the code; they will be generated via ResolvedCall below
break;
}
if (superKind == JvmMethodParameterKind.OUTER) {
assert kind == JvmMethodParameterKind.OUTER || kind == JvmMethodParameterKind.SUPER_CALL_PARAM : String.format("Non-outer parameter incorrectly mapped to outer for %s: %s vs %s", constructorDescriptor, parameters, superParameters);
// Super constructor requires OUTER parameter, but our OUTER instance may be different from what is expected by the super
// constructor. We need to traverse our outer classes from the bottom up, to find the needed class. See innerExtendsOuter.kt
ClassDescriptor outerForSuper = (ClassDescriptor) superConstructor.getContainingDeclaration().getContainingDeclaration();
StackValue outer = codegen.generateThisOrOuter(outerForSuper, true, true);
outer.put(outer.type, codegen.v);
superIndex++;
} else if (kind == JvmMethodParameterKind.SUPER_CALL_PARAM || kind == JvmMethodParameterKind.ENUM_NAME_OR_ORDINAL) {
iv.load(offset, type);
superIndex++;
}
offset += type.getSize();
}
if (isAnonymousObject(descriptor)) {
List<JvmMethodParameterSignature> superValues = superParameters.subList(superIndex, superParameters.size());
return new ObjectSuperCallArgumentGenerator(superValues, iv, offset);
} else {
return new CallBasedArgumentGenerator(codegen, codegen.defaultCallGenerator, superConstructor.getValueParameters(), superCallable.getValueParameterTypes());
}
}
use of org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodParameterSignature in project kotlin by JetBrains.
the class ImplementationBodyCodegen method generateThisCallImplicitArguments.
@NotNull
private static ArgumentGenerator generateThisCallImplicitArguments(@NotNull InstructionAdapter iv, @NotNull ExpressionCodegen codegen, @NotNull ConstructorDescriptor delegatingConstructor, @NotNull CallableMethod delegatingCallable, @NotNull List<JvmMethodParameterSignature> delegatingParameters, @NotNull List<JvmMethodParameterSignature> parameters) {
int offset = 1;
int index = 0;
for (; index < delegatingParameters.size(); index++) {
JvmMethodParameterKind delegatingKind = delegatingParameters.get(index).getKind();
if (delegatingKind == JvmMethodParameterKind.VALUE) {
assert index == parameters.size() || parameters.get(index).getKind() == JvmMethodParameterKind.VALUE : "Delegating constructor has not enough implicit parameters";
break;
}
assert index < parameters.size() && parameters.get(index).getKind() == delegatingKind : "Constructors of the same class should have the same set of implicit arguments";
JvmMethodParameterSignature parameter = parameters.get(index);
iv.load(offset, parameter.getAsmType());
offset += parameter.getAsmType().getSize();
}
assert index == parameters.size() || parameters.get(index).getKind() == JvmMethodParameterKind.VALUE : "Delegating constructor has not enough parameters";
return new CallBasedArgumentGenerator(codegen, codegen.defaultCallGenerator, delegatingConstructor.getValueParameters(), delegatingCallable.getValueParameterTypes());
}
use of org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodParameterSignature in project kotlin by JetBrains.
the class FunctionCodegen method generateLocalVariablesForParameters.
private static void generateLocalVariablesForParameters(@NotNull MethodVisitor mv, @NotNull JvmMethodSignature jvmMethodSignature, @Nullable Type thisType, @NotNull Label methodBegin, @NotNull Label methodEnd, Collection<ValueParameterDescriptor> valueParameters, boolean isStatic, KotlinTypeMapper typeMapper, int shiftForDestructuringVariables) {
Iterator<ValueParameterDescriptor> valueParameterIterator = valueParameters.iterator();
List<JvmMethodParameterSignature> params = jvmMethodSignature.getValueParameters();
int shift = 0;
if (!isStatic) {
//add this
if (thisType != null) {
mv.visitLocalVariable("this", thisType.getDescriptor(), null, methodBegin, methodEnd, shift);
} else {
//TODO: provide thisType for callable reference
}
shift++;
}
for (int i = 0; i < params.size(); i++) {
JvmMethodParameterSignature param = params.get(i);
JvmMethodParameterKind kind = param.getKind();
String parameterName;
if (kind == JvmMethodParameterKind.VALUE) {
ValueParameterDescriptor parameter = valueParameterIterator.next();
List<VariableDescriptor> destructuringVariables = ValueParameterDescriptorImpl.getDestructuringVariablesOrNull(parameter);
parameterName = destructuringVariables == null ? computeParameterName(i, parameter) : "$" + joinParameterNames(destructuringVariables);
} else {
String lowercaseKind = kind.name().toLowerCase();
parameterName = needIndexForVar(kind) ? "$" + lowercaseKind + "$" + i : "$" + lowercaseKind;
}
Type type = param.getAsmType();
mv.visitLocalVariable(parameterName, type.getDescriptor(), null, methodBegin, methodEnd, shift);
shift += type.getSize();
}
shift += shiftForDestructuringVariables;
for (ValueParameterDescriptor parameter : valueParameters) {
List<VariableDescriptor> destructuringVariables = ValueParameterDescriptorImpl.getDestructuringVariablesOrNull(parameter);
if (destructuringVariables == null)
continue;
for (VariableDescriptor entry : CodegenUtilKt.filterOutDescriptorsWithSpecialNames(destructuringVariables)) {
Type type = typeMapper.mapType(entry.getType());
mv.visitLocalVariable(entry.getName().asString(), type.getDescriptor(), null, methodBegin, methodEnd, shift);
shift += type.getSize();
}
}
}
use of org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodParameterSignature in project kotlin by JetBrains.
the class JvmSignatureWriter method makeJvmMethodSignature.
@NotNull
public JvmMethodGenericSignature makeJvmMethodSignature(@NotNull String name) {
List<Type> types = new ArrayList<Type>(kotlinParameterTypes.size());
for (JvmMethodParameterSignature parameter : kotlinParameterTypes) {
types.add(parameter.getAsmType());
}
Method asmMethod = new Method(name, jvmReturnType, types.toArray(new Type[types.size()]));
return new JvmMethodGenericSignature(asmMethod, kotlinParameterTypes, makeJavaGenericSignature());
}
use of org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodParameterSignature in project kotlin by JetBrains.
the class JvmSignatureWriter method writeParameterTypeEnd.
public void writeParameterTypeEnd() {
//noinspection ConstantConditions
kotlinParameterTypes.add(new JvmMethodParameterSignature(getJvmCurrentType(), currentParameterKind));
currentSignatureSize += getJvmCurrentType().getSize();
currentParameterKind = null;
clearCurrentType();
}
Aggregations