Extracted util function 'recordScopeAndDataFlowInfo'

This commit is contained in:
Svetlana Isakova
2014-08-23 12:11:55 +04:00
parent 7f9ecc50c2
commit 0b9c62ab54
4 changed files with 17 additions and 30 deletions
@@ -27,6 +27,8 @@ import org.jetbrains.jet.lang.psi.JetDeclarationWithBody
import org.jetbrains.jet.lang.resolve.DescriptorUtils
import org.jetbrains.jet.lang.descriptors.impl.AnonymousFunctionDescriptor
import org.jetbrains.jet.lang.psi.JetExpression
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo
import org.jetbrains.jet.lang.resolve.calls.context.ResolutionContext
public fun JetReturnExpression.getTargetFunctionDescriptor(context: BindingContext): FunctionDescriptor? {
val targetLabel = getTargetLabel()
@@ -43,3 +45,12 @@ public fun JetReturnExpression.getTargetFunctionDescriptor(context: BindingConte
public fun JetExpression.isUsedAsExpression(context: BindingContext): Boolean = context[BindingContext.USED_AS_EXPRESSION, this]!!
public fun JetExpression.isUsedAsStatement(context: BindingContext): Boolean = !isUsedAsExpression(context)
public fun <C : ResolutionContext<C>> ResolutionContext<C>.recordScopeAndDataFlowInfo(expression: JetExpression?) {
if (expression == null) return
trace.record(BindingContext.RESOLUTION_SCOPE, expression, scope)
if (dataFlowInfo != DataFlowInfo.EMPTY) {
trace.record(BindingContext.EXPRESSION_DATA_FLOW_INFO, expression, dataFlowInfo)
}
}
@@ -53,8 +53,7 @@ import java.util.List;
import static org.jetbrains.jet.lang.diagnostics.Errors.NOT_A_CLASS;
import static org.jetbrains.jet.lang.diagnostics.Errors.NO_CONSTRUCTOR;
import static org.jetbrains.jet.lang.resolve.BindingContext.EXPRESSION_DATA_FLOW_INFO;
import static org.jetbrains.jet.lang.resolve.BindingContext.RESOLUTION_SCOPE;
import static org.jetbrains.jet.lang.resolve.bindingContextUtil.BindingContextUtilPackage.recordScopeAndDataFlowInfo;
import static org.jetbrains.jet.lang.resolve.calls.CallResolverUtil.ResolveArgumentsMode.RESOLVE_FUNCTION_ARGUMENTS;
import static org.jetbrains.jet.lang.resolve.calls.CallResolverUtil.ResolveArgumentsMode.SHAPE_FUNCTION_ARGUMENTS;
import static org.jetbrains.jet.lang.resolve.calls.results.OverloadResolutionResults.Code.*;
@@ -349,7 +348,8 @@ public class CallResolver {
}
if (results == null) {
BasicCallResolutionContext newContext = context.replaceBindingTrace(traceToResolveCall);
results = doResolveCallAndRecordDebugInfo(newContext, prioritizedTasks, callTransformer, tracing);
recordScopeAndDataFlowInfo(newContext, newContext.call.getCalleeExpression());
results = doResolveCall(newContext, prioritizedTasks, callTransformer, tracing);
DelegatingBindingTrace deltasTraceForTypeInference = ((OverloadResolutionResultsImpl) results).getTrace();
if (deltasTraceForTypeInference != null) {
deltasTraceForTypeInference.addAllMyDataTo(traceToResolveCall);
@@ -405,22 +405,6 @@ public class CallResolver {
return OverloadResolutionResultsImpl.nameNotFound();
}
@NotNull
private <D extends CallableDescriptor, F extends D> OverloadResolutionResultsImpl<F> doResolveCallAndRecordDebugInfo(
@NotNull BasicCallResolutionContext context,
@NotNull List<ResolutionTask<D, F>> prioritizedTasks, // high to low priority
@NotNull CallTransformer<D, F> callTransformer,
@NotNull TracingStrategy tracing
) {
context.trace.record(RESOLUTION_SCOPE, context.call.getCalleeExpression(), context.scope);
if (context.dataFlowInfo != DataFlowInfo.EMPTY) {
context.trace.record(EXPRESSION_DATA_FLOW_INFO, context.call.getCalleeExpression(), context.dataFlowInfo);
}
return doResolveCall(context, prioritizedTasks, callTransformer, tracing);
}
@NotNull
private <D extends CallableDescriptor, F extends D> OverloadResolutionResultsImpl<F> doResolveCall(
@NotNull BasicCallResolutionContext context,
@@ -122,10 +122,7 @@ fun createQualifier(
if (packageViewDescriptor == null && classifierDescriptor == null) return null
context.trace.record(RESOLUTION_SCOPE, expression, context.scope)
if (context.dataFlowInfo != DataFlowInfo.EMPTY) {
context.trace.record(EXPRESSION_DATA_FLOW_INFO, expression, context.dataFlowInfo)
}
context.recordScopeAndDataFlowInfo(expression)
val qualifier = QualifierReceiver(expression, packageViewDescriptor, classifierDescriptor)
context.trace.record(QUALIFIER, qualifier.expression, qualifier)
@@ -21,7 +21,6 @@ import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.BindingContextUtils;
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
import org.jetbrains.jet.lang.types.DeferredType;
import org.jetbrains.jet.lang.types.ErrorUtils;
@@ -29,6 +28,7 @@ import org.jetbrains.jet.lang.types.JetTypeInfo;
import org.jetbrains.jet.util.ReenteringLazyValueComputationException;
import static org.jetbrains.jet.lang.diagnostics.Errors.TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM;
import static org.jetbrains.jet.lang.resolve.bindingContextUtil.BindingContextUtilPackage.recordScopeAndDataFlowInfo;
public class ExpressionTypingVisitorDispatcher extends JetVisitor<JetTypeInfo, ExpressionTypingContext> implements ExpressionTypingInternals {
@@ -149,13 +149,8 @@ public class ExpressionTypingVisitorDispatcher extends JetVisitor<JetTypeInfo, E
result = JetTypeInfo.create(null, context.dataFlowInfo);
}
if (!context.trace.get(BindingContext.PROCESSED, expression) && !BindingContextUtils.isExpressionWithValidReference(expression, context.trace.getBindingContext())) {
context.trace.record(BindingContext.RESOLUTION_SCOPE, expression, context.scope);
}
context.trace.record(BindingContext.PROCESSED, expression);
if (result.getDataFlowInfo() != DataFlowInfo.EMPTY) {
context.trace.record(BindingContext.EXPRESSION_DATA_FLOW_INFO, expression, result.getDataFlowInfo());
}
recordScopeAndDataFlowInfo(context.replaceDataFlowInfo(result.getDataFlowInfo()), expression);
return result;
}