Fix Android byte code generation inside complex expressions

This commit is contained in:
Yan Zhulanow
2015-03-24 16:43:16 +03:00
parent de06a0cbc2
commit 96074bc948
3 changed files with 68 additions and 42 deletions
@@ -1914,8 +1914,9 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
ExpressionCodegenExtension.Context context = new ExpressionCodegenExtension.Context(typeMapper, v);
JetType returnType = propertyDescriptor.getReturnType();
for (ExpressionCodegenExtension extension : codegenExtensions) {
if (returnType != null && extension.apply(receiver, resolvedCall, context)) {
return StackValue.onStack(typeMapper.mapType(returnType));
if (returnType != null) {
StackValue value = extension.applyProperty(receiver, resolvedCall, context);
if (value != null) return value;
}
}
}
@@ -2352,7 +2353,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
if (!codegenExtensions.isEmpty()) {
ExpressionCodegenExtension.Context context = new ExpressionCodegenExtension.Context(typeMapper, v);
for (ExpressionCodegenExtension extension : codegenExtensions) {
if (extension.apply(receiver, resolvedCall, context)) return;
if (extension.applyFunction(receiver, resolvedCall, context)) return;
}
}
@@ -35,9 +35,17 @@ public trait ExpressionCodegenExtension {
public val v: InstructionAdapter
)
// Function is responsible to put the value on stack by itself.
// Returns false if not applicable, and if stack was not modified.
public fun apply(receiver: StackValue, resolvedCall: ResolvedCall<*>, c: Context): Boolean
/**
* Used for generating custom byte code for the property value obtain. This function has lazy semantics.
* Returns new stack value.
*/
public fun applyProperty(receiver: StackValue, resolvedCall: ResolvedCall<*>, c: Context): StackValue? = null
/**
* Used for generating custom byte code for the function call. This function has non-lazy semantics.
* Returns true if the stack was modified.
*/
public fun applyFunction(receiver: StackValue, resolvedCall: ResolvedCall<*>, c: Context): Boolean = false
public fun generateClassSyntheticParts(
classBuilder: ClassBuilder,