Minor, static import BindingContext.* in ExpressionCodegen
This commit is contained in:
@@ -267,7 +267,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
}
|
}
|
||||||
|
|
||||||
private StackValue visitClassOrObject(JetClassOrObject declaration) {
|
private StackValue visitClassOrObject(JetClassOrObject declaration) {
|
||||||
ClassDescriptor descriptor = bindingContext.get(BindingContext.CLASS, declaration);
|
ClassDescriptor descriptor = bindingContext.get(CLASS, declaration);
|
||||||
assert descriptor != null;
|
assert descriptor != null;
|
||||||
|
|
||||||
Type asmType = asmTypeForAnonymousClass(bindingContext, declaration);
|
Type asmType = asmTypeForAnonymousClass(bindingContext, declaration);
|
||||||
@@ -294,15 +294,11 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
return StackValue.thisOrOuter(this, getSuperCallLabelTarget(expression), true, true);
|
return StackValue.thisOrOuter(this, getSuperCallLabelTarget(expression), true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ClassDescriptor getSuperCallLabelTarget(JetSuperExpression expression) {
|
|
||||||
return getSuperCallLabelTarget(expression, bindingContext, context);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private static ClassDescriptor getSuperCallLabelTarget(JetSuperExpression expression, BindingContext bindingContext, CodegenContext context) {
|
private ClassDescriptor getSuperCallLabelTarget(JetSuperExpression expression) {
|
||||||
PsiElement labelPsi = bindingContext.get(BindingContext.LABEL_TARGET, expression.getTargetLabel());
|
PsiElement labelPsi = bindingContext.get(LABEL_TARGET, expression.getTargetLabel());
|
||||||
ClassDescriptor labelTarget = (ClassDescriptor) bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, labelPsi);
|
ClassDescriptor labelTarget = (ClassDescriptor) bindingContext.get(DECLARATION_TO_DESCRIPTOR, labelPsi);
|
||||||
DeclarationDescriptor descriptor = bindingContext.get(BindingContext.REFERENCE_TARGET, expression.getInstanceReference());
|
DeclarationDescriptor descriptor = bindingContext.get(REFERENCE_TARGET, expression.getInstanceReference());
|
||||||
// "super<descriptor>@labelTarget"
|
// "super<descriptor>@labelTarget"
|
||||||
if (labelTarget != null) {
|
if (labelTarget != null) {
|
||||||
return labelTarget;
|
return labelTarget;
|
||||||
@@ -476,27 +472,26 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
}
|
}
|
||||||
|
|
||||||
JetExpression loopRange = forExpression.getLoopRange();
|
JetExpression loopRange = forExpression.getLoopRange();
|
||||||
JetType loopRangeType = bindingContext.get(BindingContext.EXPRESSION_TYPE, loopRange);
|
JetType loopRangeType = bindingContext.get(EXPRESSION_TYPE, loopRange);
|
||||||
assert loopRangeType != null;
|
assert loopRangeType != null;
|
||||||
Type asmLoopRangeType = asmType(loopRangeType);
|
Type asmLoopRangeType = asmType(loopRangeType);
|
||||||
if (asmLoopRangeType.getSort() == Type.ARRAY) {
|
if (asmLoopRangeType.getSort() == Type.ARRAY) {
|
||||||
generateForLoop(new ForInArrayLoopGenerator(forExpression));
|
generateForLoop(new ForInArrayLoopGenerator(forExpression));
|
||||||
return StackValue.none();
|
return StackValue.none();
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
if (RangeCodegenUtil.isRange(loopRangeType)) {
|
|
||||||
generateForLoop(new ForInRangeInstanceLoopGenerator(forExpression));
|
|
||||||
return StackValue.none();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (RangeCodegenUtil.isProgression(loopRangeType)) {
|
if (RangeCodegenUtil.isRange(loopRangeType)) {
|
||||||
generateForLoop(new ForInProgressionExpressionLoopGenerator(forExpression));
|
generateForLoop(new ForInRangeInstanceLoopGenerator(forExpression));
|
||||||
return StackValue.none();
|
|
||||||
}
|
|
||||||
|
|
||||||
generateForLoop(new IteratorForLoopGenerator(forExpression));
|
|
||||||
return StackValue.none();
|
return StackValue.none();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (RangeCodegenUtil.isProgression(loopRangeType)) {
|
||||||
|
generateForLoop(new ForInProgressionExpressionLoopGenerator(forExpression));
|
||||||
|
return StackValue.none();
|
||||||
|
}
|
||||||
|
|
||||||
|
generateForLoop(new IteratorForLoopGenerator(forExpression));
|
||||||
|
return StackValue.none();
|
||||||
}
|
}
|
||||||
|
|
||||||
private OwnerKind contextKind() {
|
private OwnerKind contextKind() {
|
||||||
@@ -561,7 +556,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
JetParameter loopParameter = forExpression.getLoopParameter();
|
JetParameter loopParameter = forExpression.getLoopParameter();
|
||||||
if (loopParameter != null) {
|
if (loopParameter != null) {
|
||||||
// E e = tmp<iterator>.next()
|
// E e = tmp<iterator>.next()
|
||||||
final VariableDescriptor parameterDescriptor = bindingContext.get(BindingContext.VALUE_PARAMETER, loopParameter);
|
final VariableDescriptor parameterDescriptor = bindingContext.get(VALUE_PARAMETER, loopParameter);
|
||||||
@SuppressWarnings("ConstantConditions") final Type asmTypeForParameter = asmType(parameterDescriptor.getType());
|
@SuppressWarnings("ConstantConditions") final Type asmTypeForParameter = asmType(parameterDescriptor.getType());
|
||||||
loopParameterVar = myFrameMap.enter(parameterDescriptor, asmTypeForParameter);
|
loopParameterVar = myFrameMap.enter(parameterDescriptor, asmTypeForParameter);
|
||||||
scheduleLeaveVariable(new Runnable() {
|
scheduleLeaveVariable(new Runnable() {
|
||||||
@@ -603,7 +598,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
|
|
||||||
private void generateMultiVariables(List<JetMultiDeclarationEntry> entries) {
|
private void generateMultiVariables(List<JetMultiDeclarationEntry> entries) {
|
||||||
for (JetMultiDeclarationEntry variableDeclaration : entries) {
|
for (JetMultiDeclarationEntry variableDeclaration : entries) {
|
||||||
final VariableDescriptor componentDescriptor = bindingContext.get(BindingContext.VARIABLE, variableDeclaration);
|
final VariableDescriptor componentDescriptor = bindingContext.get(VARIABLE, variableDeclaration);
|
||||||
|
|
||||||
@SuppressWarnings("ConstantConditions") final Type componentAsmType = asmType(componentDescriptor.getReturnType());
|
@SuppressWarnings("ConstantConditions") final Type componentAsmType = asmType(componentDescriptor.getReturnType());
|
||||||
final int componentVarIndex = myFrameMap.enter(componentDescriptor, componentAsmType);
|
final int componentVarIndex = myFrameMap.enter(componentDescriptor, componentAsmType);
|
||||||
@@ -618,9 +613,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
ResolvedCall<FunctionDescriptor> resolvedCall = bindingContext.get(COMPONENT_RESOLVED_CALL, variableDeclaration);
|
||||||
ResolvedCall<FunctionDescriptor> resolvedCall =
|
|
||||||
bindingContext.get(BindingContext.COMPONENT_RESOLVED_CALL, variableDeclaration);
|
|
||||||
assert resolvedCall != null : "Resolved call is null for " + variableDeclaration.getText();
|
assert resolvedCall != null : "Resolved call is null for " + variableDeclaration.getText();
|
||||||
Call call = makeFakeCall(new TransientReceiver(elementType));
|
Call call = makeFakeCall(new TransientReceiver(elementType));
|
||||||
invokeFunction(call, StackValue.local(loopParameterVar, asmElementType), resolvedCall);
|
invokeFunction(call, StackValue.local(loopParameterVar, asmElementType), resolvedCall);
|
||||||
@@ -759,7 +752,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
|
|
||||||
private ForInArrayLoopGenerator(@NotNull JetForExpression forExpression) {
|
private ForInArrayLoopGenerator(@NotNull JetForExpression forExpression) {
|
||||||
super(forExpression);
|
super(forExpression);
|
||||||
loopRangeType = bindingContext.get(BindingContext.EXPRESSION_TYPE, forExpression.getLoopRange());
|
loopRangeType = bindingContext.get(EXPRESSION_TYPE, forExpression.getLoopRange());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -1223,9 +1216,9 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public static CompileTimeConstant getCompileTimeConstant(@NotNull JetExpression expression, @NotNull BindingContext bindingContext) {
|
public static CompileTimeConstant getCompileTimeConstant(@NotNull JetExpression expression, @NotNull BindingContext bindingContext) {
|
||||||
CompileTimeConstant<?> compileTimeValue = bindingContext.get(BindingContext.COMPILE_TIME_VALUE, expression);
|
CompileTimeConstant<?> compileTimeValue = bindingContext.get(COMPILE_TIME_VALUE, expression);
|
||||||
if (compileTimeValue instanceof IntegerValueTypeConstant) {
|
if (compileTimeValue instanceof IntegerValueTypeConstant) {
|
||||||
JetType expectedType = bindingContext.get(BindingContext.EXPRESSION_TYPE, expression);
|
JetType expectedType = bindingContext.get(EXPRESSION_TYPE, expression);
|
||||||
return EvaluatePackage.createCompileTimeConstantWithType((IntegerValueTypeConstant) compileTimeValue, expectedType);
|
return EvaluatePackage.createCompileTimeConstantWithType((IntegerValueTypeConstant) compileTimeValue, expectedType);
|
||||||
}
|
}
|
||||||
return compileTimeValue;
|
return compileTimeValue;
|
||||||
@@ -1293,7 +1286,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
}
|
}
|
||||||
|
|
||||||
StackValue closure = genClosure(function, null, KotlinSyntheticClass.Kind.LOCAL_FUNCTION);
|
StackValue closure = genClosure(function, null, KotlinSyntheticClass.Kind.LOCAL_FUNCTION);
|
||||||
DeclarationDescriptor descriptor = bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, function);
|
DeclarationDescriptor descriptor = bindingContext.get(DECLARATION_TO_DESCRIPTOR, function);
|
||||||
int index = lookupLocalIndex(descriptor);
|
int index = lookupLocalIndex(descriptor);
|
||||||
closure.put(OBJECT_TYPE, v);
|
closure.put(OBJECT_TYPE, v);
|
||||||
v.store(index, OBJECT_TYPE);
|
v.store(index, OBJECT_TYPE);
|
||||||
@@ -1302,9 +1295,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public StackValue visitFunctionLiteralExpression(@NotNull JetFunctionLiteralExpression expression, StackValue receiver) {
|
public StackValue visitFunctionLiteralExpression(@NotNull JetFunctionLiteralExpression expression, StackValue receiver) {
|
||||||
//noinspection ConstantConditions
|
if (Boolean.TRUE.equals(bindingContext.get(BLOCK, expression))) {
|
||||||
if (bindingContext.get(BindingContext.BLOCK, expression)) {
|
|
||||||
//noinspection ConstantConditions
|
|
||||||
return gen(expression.getFunctionLiteral().getBodyExpression());
|
return gen(expression.getFunctionLiteral().getBodyExpression());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -1318,7 +1309,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
@Nullable ClassDescriptor samInterfaceClass,
|
@Nullable ClassDescriptor samInterfaceClass,
|
||||||
@NotNull KotlinSyntheticClass.Kind kind
|
@NotNull KotlinSyntheticClass.Kind kind
|
||||||
) {
|
) {
|
||||||
FunctionDescriptor descriptor = bindingContext.get(BindingContext.FUNCTION, declaration);
|
FunctionDescriptor descriptor = bindingContext.get(FUNCTION, declaration);
|
||||||
assert descriptor != null : "Function is not resolved to descriptor: " + declaration.getText();
|
assert descriptor != null : "Function is not resolved to descriptor: " + declaration.getText();
|
||||||
|
|
||||||
Type closureSuperClass = samInterfaceClass == null ? getFunctionImplType(descriptor) : OBJECT_TYPE;
|
Type closureSuperClass = samInterfaceClass == null ? getFunctionImplType(descriptor) : OBJECT_TYPE;
|
||||||
@@ -1335,7 +1326,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
public StackValue visitObjectLiteralExpression(@NotNull JetObjectLiteralExpression expression, StackValue receiver) {
|
public StackValue visitObjectLiteralExpression(@NotNull JetObjectLiteralExpression expression, StackValue receiver) {
|
||||||
CalculatedClosure closure = this.generateObjectLiteral(state, expression);
|
CalculatedClosure closure = this.generateObjectLiteral(state, expression);
|
||||||
|
|
||||||
ConstructorDescriptor constructorDescriptor = bindingContext.get(BindingContext.CONSTRUCTOR, expression.getObjectDeclaration());
|
ConstructorDescriptor constructorDescriptor = bindingContext.get(CONSTRUCTOR, expression.getObjectDeclaration());
|
||||||
assert constructorDescriptor != null;
|
assert constructorDescriptor != null;
|
||||||
CallableMethod constructor = typeMapper.mapToCallableMethod(constructorDescriptor);
|
CallableMethod constructor = typeMapper.mapToCallableMethod(constructorDescriptor);
|
||||||
|
|
||||||
@@ -1350,7 +1341,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
JetDelegatorToSuperCall superCall = closure.getSuperCall();
|
JetDelegatorToSuperCall superCall = closure.getSuperCall();
|
||||||
if (superCall != null) {
|
if (superCall != null) {
|
||||||
ConstructorDescriptor superConstructor = (ConstructorDescriptor) bindingContext
|
ConstructorDescriptor superConstructor = (ConstructorDescriptor) bindingContext
|
||||||
.get(BindingContext.REFERENCE_TARGET, superCall.getCalleeExpression().getConstructorReferenceExpression());
|
.get(REFERENCE_TARGET, superCall.getCalleeExpression().getConstructorReferenceExpression());
|
||||||
assert superConstructor != null;
|
assert superConstructor != null;
|
||||||
CallableMethod superCallable = typeMapper.mapToCallableMethod(superConstructor);
|
CallableMethod superCallable = typeMapper.mapToCallableMethod(superConstructor);
|
||||||
Type[] argumentTypes = superCallable.getAsmMethod().getArgumentTypes();
|
Type[] argumentTypes = superCallable.getAsmMethod().getArgumentTypes();
|
||||||
@@ -1451,7 +1442,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
final @NotNull Label blockEnd,
|
final @NotNull Label blockEnd,
|
||||||
@NotNull List<Function<StackValue, Void>> leaveTasks
|
@NotNull List<Function<StackValue, Void>> leaveTasks
|
||||||
) {
|
) {
|
||||||
final VariableDescriptor variableDescriptor = bindingContext.get(BindingContext.VARIABLE, variableDeclaration);
|
final VariableDescriptor variableDescriptor = bindingContext.get(VARIABLE, variableDeclaration);
|
||||||
assert variableDescriptor != null;
|
assert variableDescriptor != null;
|
||||||
|
|
||||||
final Label scopeStart = new Label();
|
final Label scopeStart = new Label();
|
||||||
@@ -1493,7 +1484,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
@NotNull JetNamedFunction namedFunction,
|
@NotNull JetNamedFunction namedFunction,
|
||||||
@NotNull List<Function<StackValue, Void>> leaveTasks
|
@NotNull List<Function<StackValue, Void>> leaveTasks
|
||||||
) {
|
) {
|
||||||
final DeclarationDescriptor descriptor = bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, namedFunction);
|
final DeclarationDescriptor descriptor = bindingContext.get(DECLARATION_TO_DESCRIPTOR, namedFunction);
|
||||||
myFrameMap.enter(descriptor, OBJECT_TYPE);
|
myFrameMap.enter(descriptor, OBJECT_TYPE);
|
||||||
|
|
||||||
leaveTasks.add(new Function<StackValue, Void>() {
|
leaveTasks.add(new Function<StackValue, Void>() {
|
||||||
@@ -1623,11 +1614,11 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public StackValue visitSimpleNameExpression(@NotNull JetSimpleNameExpression expression, StackValue receiver) {
|
public StackValue visitSimpleNameExpression(@NotNull JetSimpleNameExpression expression, StackValue receiver) {
|
||||||
ResolvedCall<?> resolvedCall = bindingContext.get(BindingContext.RESOLVED_CALL, expression);
|
ResolvedCall<?> resolvedCall = bindingContext.get(RESOLVED_CALL, expression);
|
||||||
|
|
||||||
DeclarationDescriptor descriptor;
|
DeclarationDescriptor descriptor;
|
||||||
if (resolvedCall == null) {
|
if (resolvedCall == null) {
|
||||||
descriptor = bindingContext.get(BindingContext.REFERENCE_TARGET, expression);
|
descriptor = bindingContext.get(REFERENCE_TARGET, expression);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (resolvedCall instanceof VariableAsFunctionResolvedCall) {
|
if (resolvedCall instanceof VariableAsFunctionResolvedCall) {
|
||||||
@@ -1781,7 +1772,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
private static JetType getPropertyDelegateType(@NotNull PropertyDescriptor descriptor, @NotNull BindingContext bindingContext) {
|
private static JetType getPropertyDelegateType(@NotNull PropertyDescriptor descriptor, @NotNull BindingContext bindingContext) {
|
||||||
PropertyGetterDescriptor getter = descriptor.getGetter();
|
PropertyGetterDescriptor getter = descriptor.getGetter();
|
||||||
if (getter != null) {
|
if (getter != null) {
|
||||||
Call call = bindingContext.get(BindingContext.DELEGATED_PROPERTY_CALL, getter);
|
Call call = bindingContext.get(DELEGATED_PROPERTY_CALL, getter);
|
||||||
return call != null ? call.getExplicitReceiver().getType() : null;
|
return call != null ? call.getExplicitReceiver().getType() : null;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@@ -1837,7 +1828,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (isSuper && !isInterface(containingDeclaration)) {
|
if (isSuper && !isInterface(containingDeclaration)) {
|
||||||
ClassDescriptor owner = getSuperCallLabelTarget(superExpression, bindingContext, context);
|
ClassDescriptor owner = getSuperCallLabelTarget(superExpression);
|
||||||
CodegenContext c = context.findParentContextWithDescriptor(owner);
|
CodegenContext c = context.findParentContextWithDescriptor(owner);
|
||||||
assert c != null : "Couldn't find a context for a super-call: " + propertyDescriptor;
|
assert c != null : "Couldn't find a context for a super-call: " + propertyDescriptor;
|
||||||
if (c != context.getParentContext()) {
|
if (c != context.getParentContext()) {
|
||||||
@@ -2410,7 +2401,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int indexOfLocal(JetReferenceExpression lhs) {
|
public int indexOfLocal(JetReferenceExpression lhs) {
|
||||||
DeclarationDescriptor declarationDescriptor = bindingContext.get(BindingContext.REFERENCE_TARGET, lhs);
|
DeclarationDescriptor declarationDescriptor = bindingContext.get(REFERENCE_TARGET, lhs);
|
||||||
if (isVarCapturedInClosure(bindingContext, declarationDescriptor)) {
|
if (isVarCapturedInClosure(bindingContext, declarationDescriptor)) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -2643,7 +2634,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
return StackValue.onStack(returnType);
|
return StackValue.onStack(returnType);
|
||||||
}
|
}
|
||||||
|
|
||||||
Call call = bindingContext.get(BindingContext.CALL, reference);
|
Call call = bindingContext.get(CALL, reference);
|
||||||
return invokeFunction(call, receiver, resolvedCall);
|
return invokeFunction(call, receiver, resolvedCall);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2840,7 +2831,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
gen(right, type);
|
gen(right, type);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Call call = bindingContext.get(BindingContext.CALL, expression.getOperationReference());
|
Call call = bindingContext.get(CALL, expression.getOperationReference());
|
||||||
StackValue result = invokeFunction(call, receiver, resolvedCall);
|
StackValue result = invokeFunction(call, receiver, resolvedCall);
|
||||||
type = Type.INT_TYPE;
|
type = Type.INT_TYPE;
|
||||||
result.put(type, v);
|
result.put(type, v);
|
||||||
@@ -2866,8 +2857,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
Type lhsType = expressionType(lhs);
|
Type lhsType = expressionType(lhs);
|
||||||
|
|
||||||
boolean keepReturnValue;
|
boolean keepReturnValue;
|
||||||
//noinspection ConstantConditions
|
if (Boolean.TRUE.equals(bindingContext.get(VARIABLE_REASSIGNMENT, expression))) {
|
||||||
if (bindingContext.get(BindingContext.VARIABLE_REASSIGNMENT, expression)) {
|
|
||||||
if (callable instanceof IntrinsicMethod) {
|
if (callable instanceof IntrinsicMethod) {
|
||||||
StackValue value = gen(lhs); // receiver
|
StackValue value = gen(lhs); // receiver
|
||||||
value.dupReceiver(v); // receiver receiver
|
value.dupReceiver(v); // receiver receiver
|
||||||
@@ -2897,7 +2887,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
@NotNull Type lhsType,
|
@NotNull Type lhsType,
|
||||||
boolean keepReturnValue
|
boolean keepReturnValue
|
||||||
) {
|
) {
|
||||||
Call call = bindingContext.get(BindingContext.CALL, expression.getOperationReference());
|
Call call = bindingContext.get(CALL, expression.getOperationReference());
|
||||||
assert call != null : "Call should be not null for operation reference in " + expression.getText();
|
assert call != null : "Call should be not null for operation reference in " + expression.getText();
|
||||||
|
|
||||||
StackValue value = gen(expression.getLeft());
|
StackValue value = gen(expression.getLeft());
|
||||||
@@ -2954,7 +2944,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
return genQualified(receiver, expression.getBaseExpression());
|
return genQualified(receiver, expression.getBaseExpression());
|
||||||
}
|
}
|
||||||
|
|
||||||
DeclarationDescriptor op = bindingContext.get(BindingContext.REFERENCE_TARGET, expression.getOperationReference());
|
DeclarationDescriptor op = bindingContext.get(REFERENCE_TARGET, expression.getOperationReference());
|
||||||
assert op instanceof FunctionDescriptor : String.valueOf(op);
|
assert op instanceof FunctionDescriptor : String.valueOf(op);
|
||||||
Callable callable = resolveToCallable((FunctionDescriptor) op, false);
|
Callable callable = resolveToCallable((FunctionDescriptor) op, false);
|
||||||
if (callable instanceof IntrinsicMethod) {
|
if (callable instanceof IntrinsicMethod) {
|
||||||
@@ -2968,7 +2958,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
ResolvedCall<?> resolvedCall = resolvedCall(expression.getOperationReference());
|
ResolvedCall<?> resolvedCall = resolvedCall(expression.getOperationReference());
|
||||||
|
|
||||||
if (isPrimitiveNumberClassDescriptor(cls) || !(op.getName().asString().equals("inc") || op.getName().asString().equals("dec"))) {
|
if (isPrimitiveNumberClassDescriptor(cls) || !(op.getName().asString().equals("inc") || op.getName().asString().equals("dec"))) {
|
||||||
Call call = bindingContext.get(BindingContext.CALL, expression.getOperationReference());
|
Call call = bindingContext.get(CALL, expression.getOperationReference());
|
||||||
return invokeFunction(call, receiver, resolvedCall);
|
return invokeFunction(call, receiver, resolvedCall);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3003,7 +2993,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
return StackValue.onStack(base.type);
|
return StackValue.onStack(base.type);
|
||||||
}
|
}
|
||||||
|
|
||||||
DeclarationDescriptor op = bindingContext.get(BindingContext.REFERENCE_TARGET, expression.getOperationReference());
|
DeclarationDescriptor op = bindingContext.get(REFERENCE_TARGET, expression.getOperationReference());
|
||||||
if (!(op instanceof FunctionDescriptor)) {
|
if (!(op instanceof FunctionDescriptor)) {
|
||||||
throw new UnsupportedOperationException("Don't know how to generate this postfix expression: " + op);
|
throw new UnsupportedOperationException("Don't know how to generate this postfix expression: " + op);
|
||||||
}
|
}
|
||||||
@@ -3126,8 +3116,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
initializeLocalVariable(variableDeclaration, new Function<VariableDescriptor, Void>() {
|
initializeLocalVariable(variableDeclaration, new Function<VariableDescriptor, Void>() {
|
||||||
@Override
|
@Override
|
||||||
public Void fun(VariableDescriptor descriptor) {
|
public Void fun(VariableDescriptor descriptor) {
|
||||||
ResolvedCall<FunctionDescriptor> resolvedCall =
|
ResolvedCall<FunctionDescriptor> resolvedCall = bindingContext.get(COMPONENT_RESOLVED_CALL, variableDeclaration);
|
||||||
bindingContext.get(BindingContext.COMPONENT_RESOLVED_CALL, variableDeclaration);
|
|
||||||
assert resolvedCall != null : "Resolved call is null for " + variableDeclaration.getText();
|
assert resolvedCall != null : "Resolved call is null for " + variableDeclaration.getText();
|
||||||
Call call = makeFakeCall(initializerAsReceiver);
|
Call call = makeFakeCall(initializerAsReceiver);
|
||||||
invokeFunction(call, local, resolvedCall);
|
invokeFunction(call, local, resolvedCall);
|
||||||
@@ -3136,7 +3125,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if(initializerAsmType.getSort() == Type.OBJECT || initializerAsmType.getSort() == Type.ARRAY) {
|
if (initializerAsmType.getSort() == Type.OBJECT || initializerAsmType.getSort() == Type.ARRAY) {
|
||||||
v.aconst(null);
|
v.aconst(null);
|
||||||
v.store(tempVarIndex, initializerAsmType);
|
v.store(tempVarIndex, initializerAsmType);
|
||||||
}
|
}
|
||||||
@@ -3149,8 +3138,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
@NotNull JetVariableDeclaration variableDeclaration,
|
@NotNull JetVariableDeclaration variableDeclaration,
|
||||||
@NotNull Function<VariableDescriptor, Void> generateInitializer
|
@NotNull Function<VariableDescriptor, Void> generateInitializer
|
||||||
) {
|
) {
|
||||||
|
VariableDescriptor variableDescriptor = bindingContext.get(VARIABLE, variableDeclaration);
|
||||||
VariableDescriptor variableDescriptor = bindingContext.get(BindingContext.VARIABLE, variableDeclaration);
|
|
||||||
|
|
||||||
if (JetPsiUtil.isScriptDeclaration(variableDeclaration)) {
|
if (JetPsiUtil.isScriptDeclaration(variableDeclaration)) {
|
||||||
return;
|
return;
|
||||||
@@ -3295,10 +3283,10 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
@Override
|
@Override
|
||||||
public StackValue visitArrayAccessExpression(@NotNull JetArrayAccessExpression expression, StackValue receiver) {
|
public StackValue visitArrayAccessExpression(@NotNull JetArrayAccessExpression expression, StackValue receiver) {
|
||||||
JetExpression array = expression.getArrayExpression();
|
JetExpression array = expression.getArrayExpression();
|
||||||
JetType type = bindingContext.get(BindingContext.EXPRESSION_TYPE, array);
|
JetType type = bindingContext.get(EXPRESSION_TYPE, array);
|
||||||
Type arrayType = expressionType(array);
|
Type arrayType = expressionType(array);
|
||||||
List<JetExpression> indices = expression.getIndexExpressions();
|
List<JetExpression> indices = expression.getIndexExpressions();
|
||||||
FunctionDescriptor operationDescriptor = (FunctionDescriptor) bindingContext.get(BindingContext.REFERENCE_TARGET, expression);
|
FunctionDescriptor operationDescriptor = (FunctionDescriptor) bindingContext.get(REFERENCE_TARGET, expression);
|
||||||
assert operationDescriptor != null;
|
assert operationDescriptor != null;
|
||||||
if (arrayType.getSort() == Type.ARRAY &&
|
if (arrayType.getSort() == Type.ARRAY &&
|
||||||
indices.size() == 1 &&
|
indices.size() == 1 &&
|
||||||
@@ -3317,8 +3305,8 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ResolvedCall<FunctionDescriptor> resolvedSetCall = bindingContext.get(BindingContext.INDEXED_LVALUE_SET, expression);
|
ResolvedCall<FunctionDescriptor> resolvedSetCall = bindingContext.get(INDEXED_LVALUE_SET, expression);
|
||||||
ResolvedCall<FunctionDescriptor> resolvedGetCall = bindingContext.get(BindingContext.INDEXED_LVALUE_GET, expression);
|
ResolvedCall<FunctionDescriptor> resolvedGetCall = bindingContext.get(INDEXED_LVALUE_GET, expression);
|
||||||
|
|
||||||
boolean isGetter = "get".equals(operationDescriptor.getName().asString());
|
boolean isGetter = "get".equals(operationDescriptor.getName().asString());
|
||||||
|
|
||||||
@@ -3358,7 +3346,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public StackValue visitThisExpression(@NotNull JetThisExpression expression, StackValue receiver) {
|
public StackValue visitThisExpression(@NotNull JetThisExpression expression, StackValue receiver) {
|
||||||
DeclarationDescriptor descriptor = bindingContext.get(BindingContext.REFERENCE_TARGET, expression.getInstanceReference());
|
DeclarationDescriptor descriptor = bindingContext.get(REFERENCE_TARGET, expression.getInstanceReference());
|
||||||
if (descriptor instanceof ClassDescriptor) {
|
if (descriptor instanceof ClassDescriptor) {
|
||||||
return StackValue.thisOrOuter(this, (ClassDescriptor) descriptor, false, true);
|
return StackValue.thisOrOuter(this, (ClassDescriptor) descriptor, false, true);
|
||||||
}
|
}
|
||||||
@@ -3387,7 +3375,7 @@ The "returned" value of try expression with no finally is either the last expres
|
|||||||
blockStackElements.push(finallyBlockStackElement);
|
blockStackElements.push(finallyBlockStackElement);
|
||||||
}
|
}
|
||||||
|
|
||||||
JetType jetType = bindingContext.get(BindingContext.EXPRESSION_TYPE, expression);
|
JetType jetType = bindingContext.get(EXPRESSION_TYPE, expression);
|
||||||
assert jetType != null;
|
assert jetType != null;
|
||||||
Type expectedAsmType = isStatement ? Type.VOID_TYPE : asmType(jetType);
|
Type expectedAsmType = isStatement ? Type.VOID_TYPE : asmType(jetType);
|
||||||
|
|
||||||
@@ -3420,7 +3408,7 @@ The "returned" value of try expression with no finally is either the last expres
|
|||||||
Label clauseStart = new Label();
|
Label clauseStart = new Label();
|
||||||
v.mark(clauseStart);
|
v.mark(clauseStart);
|
||||||
|
|
||||||
VariableDescriptor descriptor = bindingContext.get(BindingContext.VALUE_PARAMETER, clause.getCatchParameter());
|
VariableDescriptor descriptor = bindingContext.get(VALUE_PARAMETER, clause.getCatchParameter());
|
||||||
assert descriptor != null;
|
assert descriptor != null;
|
||||||
Type descriptorType = asmType(descriptor.getType());
|
Type descriptorType = asmType(descriptor.getType());
|
||||||
myFrameMap.enter(descriptor, descriptorType);
|
myFrameMap.enter(descriptor, descriptorType);
|
||||||
@@ -3513,7 +3501,7 @@ The "returned" value of try expression with no finally is either the last expres
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
JetTypeReference typeReference = expression.getRight();
|
JetTypeReference typeReference = expression.getRight();
|
||||||
JetType rightType = bindingContext.get(BindingContext.TYPE, typeReference);
|
JetType rightType = bindingContext.get(TYPE, typeReference);
|
||||||
assert rightType != null;
|
assert rightType != null;
|
||||||
Type rightTypeAsm = boxType(asmType(rightType));
|
Type rightTypeAsm = boxType(asmType(rightType));
|
||||||
JetExpression left = expression.getLeft();
|
JetExpression left = expression.getLeft();
|
||||||
@@ -3527,7 +3515,7 @@ The "returned" value of try expression with no finally is either the last expres
|
|||||||
v.dup();
|
v.dup();
|
||||||
Label nonnull = new Label();
|
Label nonnull = new Label();
|
||||||
v.ifnonnull(nonnull);
|
v.ifnonnull(nonnull);
|
||||||
JetType leftType = bindingContext.get(BindingContext.EXPRESSION_TYPE, left);
|
JetType leftType = bindingContext.get(EXPRESSION_TYPE, left);
|
||||||
assert leftType != null;
|
assert leftType != null;
|
||||||
throwNewException("kotlin/TypeCastException", DescriptorRenderer.FQ_NAMES_IN_TYPES.renderType(leftType) +
|
throwNewException("kotlin/TypeCastException", DescriptorRenderer.FQ_NAMES_IN_TYPES.renderType(leftType) +
|
||||||
" cannot be cast to " +
|
" cannot be cast to " +
|
||||||
@@ -3564,7 +3552,7 @@ The "returned" value of try expression with no finally is either the last expres
|
|||||||
if (expressionToMatch != null) {
|
if (expressionToMatch != null) {
|
||||||
Type subjectType = expressionToMatch.type;
|
Type subjectType = expressionToMatch.type;
|
||||||
expressionToMatch.put(subjectType, v);
|
expressionToMatch.put(subjectType, v);
|
||||||
JetType condJetType = bindingContext.get(BindingContext.EXPRESSION_TYPE, patternExpression);
|
JetType condJetType = bindingContext.get(EXPRESSION_TYPE, patternExpression);
|
||||||
Type condType;
|
Type condType;
|
||||||
if (isNumberPrimitive(subjectType) || subjectType.getSort() == Type.BOOLEAN) {
|
if (isNumberPrimitive(subjectType) || subjectType.getSort() == Type.BOOLEAN) {
|
||||||
assert condJetType != null;
|
assert condJetType != null;
|
||||||
@@ -3586,7 +3574,7 @@ The "returned" value of try expression with no finally is either the last expres
|
|||||||
}
|
}
|
||||||
|
|
||||||
private StackValue generateIsCheck(StackValue expressionToMatch, JetTypeReference typeReference, boolean negated) {
|
private StackValue generateIsCheck(StackValue expressionToMatch, JetTypeReference typeReference, boolean negated) {
|
||||||
JetType jetType = bindingContext.get(BindingContext.TYPE, typeReference);
|
JetType jetType = bindingContext.get(TYPE, typeReference);
|
||||||
generateInstanceOf(expressionToMatch, jetType, false);
|
generateInstanceOf(expressionToMatch, jetType, false);
|
||||||
StackValue value = StackValue.onStack(Type.BOOLEAN_TYPE);
|
StackValue value = StackValue.onStack(Type.BOOLEAN_TYPE);
|
||||||
return negated ? StackValue.not(value) : value;
|
return negated ? StackValue.not(value) : value;
|
||||||
@@ -3685,7 +3673,7 @@ The "returned" value of try expression with no finally is either the last expres
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void putUnitInstanceOntoStackForNonExhaustiveWhen(@NotNull JetWhenExpression expression) {
|
private void putUnitInstanceOntoStackForNonExhaustiveWhen(@NotNull JetWhenExpression expression) {
|
||||||
if (Boolean.TRUE.equals(bindingContext.get(BindingContext.EXHAUSTIVE_WHEN, expression))) {
|
if (Boolean.TRUE.equals(bindingContext.get(EXHAUSTIVE_WHEN, expression))) {
|
||||||
// when() is supposed to be exhaustive
|
// when() is supposed to be exhaustive
|
||||||
throwNewException("kotlin/NoWhenBranchMatchedException");
|
throwNewException("kotlin/NoWhenBranchMatchedException");
|
||||||
}
|
}
|
||||||
@@ -3717,7 +3705,7 @@ The "returned" value of try expression with no finally is either the last expres
|
|||||||
}
|
}
|
||||||
|
|
||||||
private StackValue generateSwitch(@NotNull JetWhenExpression expression, @NotNull Type subjectType, @NotNull Type resultType, boolean isStatement) {
|
private StackValue generateSwitch(@NotNull JetWhenExpression expression, @NotNull Type subjectType, @NotNull Type resultType, boolean isStatement) {
|
||||||
JetType subjectJetType = bindingContext.get(BindingContext.EXPRESSION_TYPE, expression.getSubjectExpression());
|
JetType subjectJetType = bindingContext.get(EXPRESSION_TYPE, expression.getSubjectExpression());
|
||||||
assert subjectJetType != null : "Subject expression in when should not be null";
|
assert subjectJetType != null : "Subject expression in when should not be null";
|
||||||
|
|
||||||
Map<Integer, Label> transitions = Maps.newTreeMap();
|
Map<Integer, Label> transitions = Maps.newTreeMap();
|
||||||
@@ -3870,7 +3858,7 @@ The "returned" value of try expression with no finally is either the last expres
|
|||||||
if (rangeExpression instanceof JetBinaryExpression) {
|
if (rangeExpression instanceof JetBinaryExpression) {
|
||||||
JetBinaryExpression binaryExpression = (JetBinaryExpression) rangeExpression;
|
JetBinaryExpression binaryExpression = (JetBinaryExpression) rangeExpression;
|
||||||
if (binaryExpression.getOperationReference().getReferencedNameElementType() == JetTokens.RANGE) {
|
if (binaryExpression.getOperationReference().getReferencedNameElementType() == JetTokens.RANGE) {
|
||||||
JetType jetType = bindingContext.get(BindingContext.EXPRESSION_TYPE, rangeExpression);
|
JetType jetType = bindingContext.get(EXPRESSION_TYPE, rangeExpression);
|
||||||
assert jetType != null;
|
assert jetType != null;
|
||||||
DeclarationDescriptor descriptor = jetType.getConstructor().getDeclarationDescriptor();
|
DeclarationDescriptor descriptor = jetType.getConstructor().getDeclarationDescriptor();
|
||||||
return INTEGRAL_RANGES.contains(descriptor);
|
return INTEGRAL_RANGES.contains(descriptor);
|
||||||
|
|||||||
Reference in New Issue
Block a user