Added flag 'declared locally' (in function body) to control flow analyzer

This commit is contained in:
svtk
2011-10-21 15:48:27 +04:00
parent 54bd401026
commit 2df7f1324a
2 changed files with 25 additions and 9 deletions
@@ -27,11 +27,13 @@ public class ControlFlowAnalyzer {
private TopDownAnalysisContext context; private TopDownAnalysisContext context;
private ExpressionTypingServices typeInferrerServices; private ExpressionTypingServices typeInferrerServices;
private final JetControlFlowDataTraceFactory flowDataTraceFactory; private final JetControlFlowDataTraceFactory flowDataTraceFactory;
private final boolean declaredLocally;
public ControlFlowAnalyzer(TopDownAnalysisContext context, JetControlFlowDataTraceFactory flowDataTraceFactory) { public ControlFlowAnalyzer(TopDownAnalysisContext context, JetControlFlowDataTraceFactory flowDataTraceFactory, boolean declaredLocally) {
this.context = context; this.context = context;
this.flowDataTraceFactory = flowDataTraceFactory; this.flowDataTraceFactory = flowDataTraceFactory;
this.typeInferrerServices = context.getSemanticServices().getTypeInferrerServices(context.getTrace()); this.typeInferrerServices = context.getSemanticServices().getTypeInferrerServices(context.getTrace());
this.declaredLocally = declaredLocally;
} }
public void process() { public void process() {
@@ -60,9 +62,11 @@ public class ControlFlowAnalyzer {
} }
private void checkFunction(JetDeclarationWithBody function, FunctionDescriptor functionDescriptor, final @NotNull JetType expectedReturnType) { private void checkFunction(JetDeclarationWithBody function, FunctionDescriptor functionDescriptor, final @NotNull JetType expectedReturnType) {
assert function instanceof JetDeclaration;
JetExpression bodyExpression = function.getBodyExpression(); JetExpression bodyExpression = function.getBodyExpression();
if (bodyExpression == null) return; if (bodyExpression == null) return;
JetFlowInformationProvider flowInformationProvider = new JetFlowInformationProvider((JetElement) function, bodyExpression, flowDataTraceFactory, context.getTrace()); JetFlowInformationProvider flowInformationProvider = new JetFlowInformationProvider((JetDeclaration) function, bodyExpression, flowDataTraceFactory, context.getTrace());
final boolean blockBody = function.hasBlockBody(); final boolean blockBody = function.hasBlockBody();
List<JetElement> unreachableElements = Lists.newArrayList(); List<JetElement> unreachableElements = Lists.newArrayList();
@@ -108,8 +112,9 @@ public class ControlFlowAnalyzer {
} }
}); });
} }
if (!declaredLocally) {
//flowInformationProvider.markUninitializedVariables(function.asElement()); flowInformationProvider.markUninitializedVariables(function.asElement());
}
} }
private void checkProperty(JetProperty property) { private void checkProperty(JetProperty property) {
@@ -55,16 +55,17 @@ public class TopDownAnalyzer {
public ClassObjectStatus setClassObjectDescriptor(@NotNull MutableClassDescriptor classObjectDescriptor) { public ClassObjectStatus setClassObjectDescriptor(@NotNull MutableClassDescriptor classObjectDescriptor) {
return ClassObjectStatus.NOT_ALLOWED; return ClassObjectStatus.NOT_ALLOWED;
} }
}, Collections.<JetDeclaration>singletonList(object), JetControlFlowDataTraceFactory.EMPTY); }, Collections.<JetDeclaration>singletonList(object), JetControlFlowDataTraceFactory.EMPTY, true);
} }
public static void process( private static void process(
@NotNull JetSemanticServices semanticServices, @NotNull JetSemanticServices semanticServices,
@NotNull BindingTrace trace, @NotNull BindingTrace trace,
@NotNull JetScope outerScope, @NotNull JetScope outerScope,
NamespaceLike owner, NamespaceLike owner,
@NotNull List<? extends JetDeclaration> declarations, @NotNull List<? extends JetDeclaration> declarations,
@NotNull JetControlFlowDataTraceFactory flowDataTraceFactory) { @NotNull JetControlFlowDataTraceFactory flowDataTraceFactory,
boolean declaredLocally) {
TopDownAnalysisContext context = new TopDownAnalysisContext(semanticServices, trace); TopDownAnalysisContext context = new TopDownAnalysisContext(semanticServices, trace);
new TypeHierarchyResolver(context).process(outerScope, owner, declarations); new TypeHierarchyResolver(context).process(outerScope, owner, declarations);
new DeclarationResolver(context).process(); new DeclarationResolver(context).process();
@@ -72,7 +73,17 @@ public class TopDownAnalyzer {
new OverrideResolver(context).process(); new OverrideResolver(context).process();
new BodyResolver(context).resolveBehaviorDeclarationBodies(); new BodyResolver(context).resolveBehaviorDeclarationBodies();
new DeclarationsChecker(context).process(); new DeclarationsChecker(context).process();
new ControlFlowAnalyzer(context, flowDataTraceFactory).process(); new ControlFlowAnalyzer(context, flowDataTraceFactory, declaredLocally).process();
}
public static void process(
@NotNull JetSemanticServices semanticServices,
@NotNull BindingTrace trace,
@NotNull JetScope outerScope,
NamespaceLike owner,
@NotNull List<? extends JetDeclaration> declarations,
@NotNull JetControlFlowDataTraceFactory flowDataTraceFactory) {
process(semanticServices, trace, outerScope, owner, declarations, flowDataTraceFactory, false);
} }
public static void processStandardLibraryNamespace( public static void processStandardLibraryNamespace(