Skip to content

Commit 214a98e

Browse files
stereotype441Commit Queue
authored andcommitted
[flow analysis] clean up public methods that call other public methods.
In a future CL, I plan to introduce some state tracking logic at the top of each public method in `FlowAnalysisImpl` to verify that the caller invokes flow analysis API methods in an order that respects some important invariants. When I do that, it will be confusing if there are some public methods in `FlowAnalysisImpl` that call other public methods. So, to avoid confusion in that future CL, this CL refactors the public methods `lateInitializer_end` and `functionExpression_end` (which are functionally equivalent) so that they call a common private method, rather than one calling the other. Similarly, it refactors the public methods `parenthesizedExpression` and `forwardExpression` (which are functionally equivalent) so that they call a common private method, rather than one calling the other. Change-Id: I7b6d23f2db409c652575beb73bba2ea11b0fa90b Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/303200 Reviewed-by: Konstantin Shcheglov <scheglov@google.com> Commit-Queue: Paul Berry <paulberry@google.com>
1 parent d7fc9ca commit 214a98e

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

pkg/_fe_analyzer_shared/lib/src/flow_analysis/flow_analysis.dart

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4020,12 +4020,7 @@ class _FlowAnalysisImpl<Node extends Object, Statement extends Node,
40204020

40214021
@override
40224022
void forwardExpression(Expression newExpression, Expression oldExpression) {
4023-
if (identical(_expressionWithInfo, oldExpression)) {
4024-
_expressionWithInfo = newExpression;
4025-
}
4026-
if (identical(_expressionWithReference, oldExpression)) {
4027-
_expressionWithReference = newExpression;
4028-
}
4023+
_forwardExpression(newExpression, oldExpression);
40294024
}
40304025

40314026
@override
@@ -4041,9 +4036,7 @@ class _FlowAnalysisImpl<Node extends Object, Statement extends Node,
40414036

40424037
@override
40434038
void functionExpression_end() {
4044-
_SimpleContext<Type> context =
4045-
_stack.removeLast() as _FunctionExpressionContext<Type>;
4046-
_current = context._previous;
4039+
_functionExpression_end();
40474040
}
40484041

40494042
@override
@@ -4264,7 +4257,7 @@ class _FlowAnalysisImpl<Node extends Object, Statement extends Node,
42644257
// `late x = LAZY_MAGIC(() => expr);` (where `LAZY_MAGIC` creates a lazy
42654258
// evaluation thunk that gets replaced by the result of `expr` once it is
42664259
// evaluated).
4267-
functionExpression_end();
4260+
_functionExpression_end();
42684261
}
42694262

42704263
@override
@@ -4423,7 +4416,7 @@ class _FlowAnalysisImpl<Node extends Object, Statement extends Node,
44234416
@override
44244417
void parenthesizedExpression(
44254418
Expression outerExpression, Expression innerExpression) {
4426-
forwardExpression(outerExpression, innerExpression);
4419+
_forwardExpression(outerExpression, innerExpression);
44274420
}
44284421

44294422
@override
@@ -4917,6 +4910,21 @@ class _FlowAnalysisImpl<Node extends Object, Statement extends Node,
49174910
ExpressionInfo<Type> _expressionEnd(Expression? expression) =>
49184911
_getExpressionInfo(expression) ?? new _TrivialExpressionInfo(_current);
49194912

4913+
void _forwardExpression(Expression newExpression, Expression oldExpression) {
4914+
if (identical(_expressionWithInfo, oldExpression)) {
4915+
_expressionWithInfo = newExpression;
4916+
}
4917+
if (identical(_expressionWithReference, oldExpression)) {
4918+
_expressionWithReference = newExpression;
4919+
}
4920+
}
4921+
4922+
void _functionExpression_end() {
4923+
_SimpleContext<Type> context =
4924+
_stack.removeLast() as _FunctionExpressionContext<Type>;
4925+
_current = context._previous;
4926+
}
4927+
49204928
/// Gets the [ExpressionInfo] associated with the [expression] (which should
49214929
/// be the last expression that was traversed). If there is no
49224930
/// [ExpressionInfo] associated with the [expression], then `null` is

0 commit comments

Comments
 (0)