Skip to content

Commit 03fd2aa

Browse files
stereotype441Commit Queue
authored and
Commit Queue
committed
[analyzer] Use AstNodeImpl when interfacing with shared code
Change the analyzer's use of the following generic types so that it supplies the type parameter `AstNodeImpl` instead of `AstNode` as the type it uses to represent AST nodes: - `AssignedVariables` - `AssignedVariablesForTesting` - `CaseHeadOrDefaultInfo` - `FlowAnalysis` - `MatchContext` - `SwitchExpressionMemberInfo` - `SwitchStatementMemberInfo` - `TypeAnalyzer` - `TypeAnalyzerErrors` In some places I was able to avoid adding casts by changing method parameters to accept concrete AST node types instead of abstract public interface types. This required adding the `covariant` keyword to one method (`ResolverVisitor.visitTryStatement`). This is part of a larger arc of work to change the analyzer's use of the shared code so that the type parameters it supplies are not part of the analyzer public API. See #59763. Change-Id: I98a6df704b64ff3efd3c73d05fb47409828fbf04 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/403281 Reviewed-by: Konstantin Shcheglov <[email protected]> Commit-Queue: Paul Berry <[email protected]>
1 parent f023483 commit 03fd2aa

File tree

4 files changed

+27
-23
lines changed

4 files changed

+27
-23
lines changed

pkg/analyzer/lib/src/dart/resolver/flow_analysis_visitor.dart

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class FlowAnalysisHelper {
7777
final TypeSystemOperations typeOperations;
7878

7979
/// Precomputed sets of potentially assigned variables.
80-
AssignedVariables<AstNode, PromotableElementImpl2>? assignedVariables;
80+
AssignedVariables<AstNodeImpl, PromotableElementImpl2>? assignedVariables;
8181

8282
/// The result for post-resolution stages of analysis, for testing only.
8383
final FlowAnalysisDataForTesting? dataForTesting;
@@ -96,8 +96,8 @@ class FlowAnalysisHelper {
9696
final bool inferenceUpdate4Enabled;
9797

9898
/// The current flow, when resolving a function body, or `null` otherwise.
99-
FlowAnalysis<AstNode, StatementImpl, ExpressionImpl, PromotableElementImpl2,
100-
SharedTypeView<DartType>>? flow;
99+
FlowAnalysis<AstNodeImpl, StatementImpl, ExpressionImpl,
100+
PromotableElementImpl2, SharedTypeView<DartType>>? flow;
101101

102102
FlowAnalysisHelper(bool retainDataForTesting, FeatureSet featureSet,
103103
{required TypeSystemOperations typeSystemOperations})
@@ -174,10 +174,10 @@ class FlowAnalysisHelper {
174174
retainDataForTesting: dataForTesting != null, visit: visit);
175175
if (dataForTesting != null) {
176176
dataForTesting!.assignedVariables[node] = assignedVariables
177-
as AssignedVariablesForTesting<AstNode, PromotableElementImpl2>;
177+
as AssignedVariablesForTesting<AstNodeImpl, PromotableElementImpl2>;
178178
}
179179
flow = isNonNullableByDefault
180-
? FlowAnalysis<AstNode, StatementImpl, ExpressionImpl,
180+
? FlowAnalysis<AstNodeImpl, StatementImpl, ExpressionImpl,
181181
PromotableElementImpl2, SharedTypeView<DartType>>(
182182
typeOperations,
183183
assignedVariables!,
@@ -186,7 +186,7 @@ class FlowAnalysisHelper {
186186
fieldPromotionEnabled: fieldPromotionEnabled,
187187
inferenceUpdate4Enabled: inferenceUpdate4Enabled,
188188
)
189-
: FlowAnalysis<AstNode, StatementImpl, ExpressionImpl,
189+
: FlowAnalysis<AstNodeImpl, StatementImpl, ExpressionImpl,
190190
PromotableElementImpl2, SharedTypeView<DartType>>.legacy(
191191
typeOperations, assignedVariables!);
192192
}
@@ -228,7 +228,7 @@ class FlowAnalysisHelper {
228228
}
229229

230230
void executableDeclaration_enter(
231-
AstNode node, FormalParameterList? parameters,
231+
AstNodeImpl node, FormalParameterList? parameters,
232232
{required bool isClosure}) {
233233
if (isClosure) {
234234
flow!.functionExpression_begin(node);
@@ -261,7 +261,7 @@ class FlowAnalysisHelper {
261261
flow?.for_bodyBegin(node is StatementImpl ? node : null, condition);
262262
}
263263

264-
void for_conditionBegin(AstNode node) {
264+
void for_conditionBegin(AstNodeImpl node) {
265265
flow?.for_conditionBegin(node);
266266
}
267267

@@ -348,11 +348,11 @@ class FlowAnalysisHelper {
348348
}
349349

350350
/// Computes the [AssignedVariables] map for the given [node].
351-
static AssignedVariables<AstNode, PromotableElementImpl2>
351+
static AssignedVariables<AstNodeImpl, PromotableElementImpl2>
352352
computeAssignedVariables(AstNode node, FormalParameterList? parameters,
353353
{bool retainDataForTesting = false,
354354
void Function(AstVisitor<Object?> visitor)? visit}) {
355-
AssignedVariables<AstNode, PromotableElementImpl2> assignedVariables =
355+
AssignedVariables<AstNodeImpl, PromotableElementImpl2> assignedVariables =
356356
retainDataForTesting
357357
? AssignedVariablesForTesting()
358358
: AssignedVariables();

pkg/analyzer/lib/src/dart/resolver/for_resolver.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ class ForResolver {
120120
return iteratedType.typeArguments.single;
121121
}
122122

123-
void _forEachParts(AstNode node, bool isAsync, ForEachPartsImpl forEachParts,
124-
void Function() visitBody) {
123+
void _forEachParts(AstNodeImpl node, bool isAsync,
124+
ForEachPartsImpl forEachParts, void Function() visitBody) {
125125
ExpressionImpl iterable = forEachParts.iterable;
126126
DeclaredIdentifierImpl? loopVariable;
127127
SimpleIdentifierImpl? identifier;
@@ -200,7 +200,7 @@ class ForResolver {
200200
}
201201

202202
void _forParts(
203-
AstNode node, ForPartsImpl forParts, void Function() visitBody) {
203+
AstNodeImpl node, ForPartsImpl forParts, void Function() visitBody) {
204204
if (forParts is ForPartsWithDeclarationsImpl) {
205205
forParts.variables.accept(_resolver);
206206
} else if (forParts is ForPartsWithExpressionImpl) {

pkg/analyzer/lib/src/dart/resolver/shared_type_analyzer.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ typedef SharedPatternField
2222
class SharedTypeAnalyzerErrors
2323
implements
2424
shared.TypeAnalyzerErrors<
25-
AstNode,
25+
AstNodeImpl,
2626
StatementImpl,
2727
ExpressionImpl,
2828
PromotableElementImpl2,

pkg/analyzer/lib/src/generated/resolver.dart

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ import 'package:analyzer/src/utilities/extensions/object.dart';
9797
/// By default, no files have inference logging enabled.
9898
bool Function(Source) inferenceLoggingPredicate = (_) => false;
9999

100-
typedef SharedMatchContext = shared.MatchContext<AstNode, ExpressionImpl,
100+
typedef SharedMatchContext = shared.MatchContext<AstNodeImpl, ExpressionImpl,
101101
DartPatternImpl, SharedTypeView<DartType>, PromotableElementImpl2>;
102102

103103
typedef SharedPatternField
@@ -122,7 +122,7 @@ class ResolverVisitor extends ThrowingAstVisitor<void>
122122
ErrorDetectionHelpers,
123123
TypeAnalyzer<
124124
DartType,
125-
AstNode,
125+
AstNodeImpl,
126126
StatementImpl,
127127
ExpressionImpl,
128128
PromotableElementImpl2,
@@ -437,7 +437,11 @@ class ResolverVisitor extends ThrowingAstVisitor<void>
437437
ExecutableElement? get enclosingFunction => _enclosingFunction;
438438

439439
@override
440-
FlowAnalysis<AstNode, StatementImpl, ExpressionImpl, PromotableElementImpl2,
440+
FlowAnalysis<
441+
AstNodeImpl,
442+
StatementImpl,
443+
ExpressionImpl,
444+
PromotableElementImpl2,
441445
SharedTypeView<DartType>> get flow => flowAnalysis.flow!;
442446

443447
bool get isConstructorTearoffsEnabled =>
@@ -810,7 +814,7 @@ class ResolverVisitor extends ThrowingAstVisitor<void>
810814

811815
@override
812816
PatternResult<DartType> dispatchPattern(
813-
SharedMatchContext context, AstNode node) {
817+
SharedMatchContext context, AstNodeImpl node) {
814818
shared.PatternResult<DartType> analysisResult;
815819
if (node is DartPatternImpl) {
816820
analysisResult = node.resolvePattern(this, context);
@@ -977,8 +981,8 @@ class ResolverVisitor extends ThrowingAstVisitor<void>
977981
}
978982

979983
@override
980-
SwitchExpressionMemberInfo<AstNode, ExpressionImpl, PromotableElementImpl2>
981-
getSwitchExpressionMemberInfo(
984+
SwitchExpressionMemberInfo<AstNodeImpl, ExpressionImpl,
985+
PromotableElementImpl2> getSwitchExpressionMemberInfo(
982986
covariant SwitchExpressionImpl node,
983987
int index,
984988
) {
@@ -995,12 +999,12 @@ class ResolverVisitor extends ThrowingAstVisitor<void>
995999
}
9961000

9971001
@override
998-
SwitchStatementMemberInfo<AstNode, StatementImpl, ExpressionImpl,
1002+
SwitchStatementMemberInfo<AstNodeImpl, StatementImpl, ExpressionImpl,
9991003
PromotableElementImpl2> getSwitchStatementMemberInfo(
10001004
covariant SwitchStatementImpl node,
10011005
int index,
10021006
) {
1003-
CaseHeadOrDefaultInfo<AstNode, ExpressionImpl, PromotableElementImpl2>
1007+
CaseHeadOrDefaultInfo<AstNodeImpl, ExpressionImpl, PromotableElementImpl2>
10041008
ofMember(
10051009
SwitchMemberImpl member,
10061010
) {
@@ -3792,7 +3796,7 @@ class ResolverVisitor extends ThrowingAstVisitor<void>
37923796
}
37933797

37943798
@override
3795-
void visitTryStatement(TryStatement node) {
3799+
void visitTryStatement(covariant TryStatementImpl node) {
37963800
inferenceLogWriter?.enterStatement(node);
37973801
checkUnreachableNode(node);
37983802
var flow = flowAnalysis.flow!;

0 commit comments

Comments
 (0)