[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 https://github.com/dart-lang/sdk/issues/59763. Change-Id: I98a6df704b64ff3efd3c73d05fb47409828fbf04 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/403281 Reviewed-by: Konstantin Shcheglov <scheglov@google.com> Commit-Queue: Paul Berry <paulberry@google.com>
This commit is contained in:
@@ -77,7 +77,7 @@ class FlowAnalysisHelper {
|
||||
final TypeSystemOperations typeOperations;
|
||||
|
||||
/// Precomputed sets of potentially assigned variables.
|
||||
AssignedVariables<AstNode, PromotableElementImpl2>? assignedVariables;
|
||||
AssignedVariables<AstNodeImpl, PromotableElementImpl2>? assignedVariables;
|
||||
|
||||
/// The result for post-resolution stages of analysis, for testing only.
|
||||
final FlowAnalysisDataForTesting? dataForTesting;
|
||||
@@ -96,8 +96,8 @@ class FlowAnalysisHelper {
|
||||
final bool inferenceUpdate4Enabled;
|
||||
|
||||
/// The current flow, when resolving a function body, or `null` otherwise.
|
||||
FlowAnalysis<AstNode, StatementImpl, ExpressionImpl, PromotableElementImpl2,
|
||||
SharedTypeView<DartType>>? flow;
|
||||
FlowAnalysis<AstNodeImpl, StatementImpl, ExpressionImpl,
|
||||
PromotableElementImpl2, SharedTypeView<DartType>>? flow;
|
||||
|
||||
FlowAnalysisHelper(bool retainDataForTesting, FeatureSet featureSet,
|
||||
{required TypeSystemOperations typeSystemOperations})
|
||||
@@ -174,10 +174,10 @@ class FlowAnalysisHelper {
|
||||
retainDataForTesting: dataForTesting != null, visit: visit);
|
||||
if (dataForTesting != null) {
|
||||
dataForTesting!.assignedVariables[node] = assignedVariables
|
||||
as AssignedVariablesForTesting<AstNode, PromotableElementImpl2>;
|
||||
as AssignedVariablesForTesting<AstNodeImpl, PromotableElementImpl2>;
|
||||
}
|
||||
flow = isNonNullableByDefault
|
||||
? FlowAnalysis<AstNode, StatementImpl, ExpressionImpl,
|
||||
? FlowAnalysis<AstNodeImpl, StatementImpl, ExpressionImpl,
|
||||
PromotableElementImpl2, SharedTypeView<DartType>>(
|
||||
typeOperations,
|
||||
assignedVariables!,
|
||||
@@ -186,7 +186,7 @@ class FlowAnalysisHelper {
|
||||
fieldPromotionEnabled: fieldPromotionEnabled,
|
||||
inferenceUpdate4Enabled: inferenceUpdate4Enabled,
|
||||
)
|
||||
: FlowAnalysis<AstNode, StatementImpl, ExpressionImpl,
|
||||
: FlowAnalysis<AstNodeImpl, StatementImpl, ExpressionImpl,
|
||||
PromotableElementImpl2, SharedTypeView<DartType>>.legacy(
|
||||
typeOperations, assignedVariables!);
|
||||
}
|
||||
@@ -228,7 +228,7 @@ class FlowAnalysisHelper {
|
||||
}
|
||||
|
||||
void executableDeclaration_enter(
|
||||
AstNode node, FormalParameterList? parameters,
|
||||
AstNodeImpl node, FormalParameterList? parameters,
|
||||
{required bool isClosure}) {
|
||||
if (isClosure) {
|
||||
flow!.functionExpression_begin(node);
|
||||
@@ -261,7 +261,7 @@ class FlowAnalysisHelper {
|
||||
flow?.for_bodyBegin(node is StatementImpl ? node : null, condition);
|
||||
}
|
||||
|
||||
void for_conditionBegin(AstNode node) {
|
||||
void for_conditionBegin(AstNodeImpl node) {
|
||||
flow?.for_conditionBegin(node);
|
||||
}
|
||||
|
||||
@@ -348,11 +348,11 @@ class FlowAnalysisHelper {
|
||||
}
|
||||
|
||||
/// Computes the [AssignedVariables] map for the given [node].
|
||||
static AssignedVariables<AstNode, PromotableElementImpl2>
|
||||
static AssignedVariables<AstNodeImpl, PromotableElementImpl2>
|
||||
computeAssignedVariables(AstNode node, FormalParameterList? parameters,
|
||||
{bool retainDataForTesting = false,
|
||||
void Function(AstVisitor<Object?> visitor)? visit}) {
|
||||
AssignedVariables<AstNode, PromotableElementImpl2> assignedVariables =
|
||||
AssignedVariables<AstNodeImpl, PromotableElementImpl2> assignedVariables =
|
||||
retainDataForTesting
|
||||
? AssignedVariablesForTesting()
|
||||
: AssignedVariables();
|
||||
|
||||
@@ -120,8 +120,8 @@ class ForResolver {
|
||||
return iteratedType.typeArguments.single;
|
||||
}
|
||||
|
||||
void _forEachParts(AstNode node, bool isAsync, ForEachPartsImpl forEachParts,
|
||||
void Function() visitBody) {
|
||||
void _forEachParts(AstNodeImpl node, bool isAsync,
|
||||
ForEachPartsImpl forEachParts, void Function() visitBody) {
|
||||
ExpressionImpl iterable = forEachParts.iterable;
|
||||
DeclaredIdentifierImpl? loopVariable;
|
||||
SimpleIdentifierImpl? identifier;
|
||||
@@ -200,7 +200,7 @@ class ForResolver {
|
||||
}
|
||||
|
||||
void _forParts(
|
||||
AstNode node, ForPartsImpl forParts, void Function() visitBody) {
|
||||
AstNodeImpl node, ForPartsImpl forParts, void Function() visitBody) {
|
||||
if (forParts is ForPartsWithDeclarationsImpl) {
|
||||
forParts.variables.accept(_resolver);
|
||||
} else if (forParts is ForPartsWithExpressionImpl) {
|
||||
|
||||
@@ -22,7 +22,7 @@ typedef SharedPatternField
|
||||
class SharedTypeAnalyzerErrors
|
||||
implements
|
||||
shared.TypeAnalyzerErrors<
|
||||
AstNode,
|
||||
AstNodeImpl,
|
||||
StatementImpl,
|
||||
ExpressionImpl,
|
||||
PromotableElementImpl2,
|
||||
|
||||
@@ -97,7 +97,7 @@ import 'package:analyzer/src/utilities/extensions/object.dart';
|
||||
/// By default, no files have inference logging enabled.
|
||||
bool Function(Source) inferenceLoggingPredicate = (_) => false;
|
||||
|
||||
typedef SharedMatchContext = shared.MatchContext<AstNode, ExpressionImpl,
|
||||
typedef SharedMatchContext = shared.MatchContext<AstNodeImpl, ExpressionImpl,
|
||||
DartPatternImpl, SharedTypeView<DartType>, PromotableElementImpl2>;
|
||||
|
||||
typedef SharedPatternField
|
||||
@@ -122,7 +122,7 @@ class ResolverVisitor extends ThrowingAstVisitor<void>
|
||||
ErrorDetectionHelpers,
|
||||
TypeAnalyzer<
|
||||
DartType,
|
||||
AstNode,
|
||||
AstNodeImpl,
|
||||
StatementImpl,
|
||||
ExpressionImpl,
|
||||
PromotableElementImpl2,
|
||||
@@ -437,7 +437,11 @@ class ResolverVisitor extends ThrowingAstVisitor<void>
|
||||
ExecutableElement? get enclosingFunction => _enclosingFunction;
|
||||
|
||||
@override
|
||||
FlowAnalysis<AstNode, StatementImpl, ExpressionImpl, PromotableElementImpl2,
|
||||
FlowAnalysis<
|
||||
AstNodeImpl,
|
||||
StatementImpl,
|
||||
ExpressionImpl,
|
||||
PromotableElementImpl2,
|
||||
SharedTypeView<DartType>> get flow => flowAnalysis.flow!;
|
||||
|
||||
bool get isConstructorTearoffsEnabled =>
|
||||
@@ -810,7 +814,7 @@ class ResolverVisitor extends ThrowingAstVisitor<void>
|
||||
|
||||
@override
|
||||
PatternResult<DartType> dispatchPattern(
|
||||
SharedMatchContext context, AstNode node) {
|
||||
SharedMatchContext context, AstNodeImpl node) {
|
||||
shared.PatternResult<DartType> analysisResult;
|
||||
if (node is DartPatternImpl) {
|
||||
analysisResult = node.resolvePattern(this, context);
|
||||
@@ -977,8 +981,8 @@ class ResolverVisitor extends ThrowingAstVisitor<void>
|
||||
}
|
||||
|
||||
@override
|
||||
SwitchExpressionMemberInfo<AstNode, ExpressionImpl, PromotableElementImpl2>
|
||||
getSwitchExpressionMemberInfo(
|
||||
SwitchExpressionMemberInfo<AstNodeImpl, ExpressionImpl,
|
||||
PromotableElementImpl2> getSwitchExpressionMemberInfo(
|
||||
covariant SwitchExpressionImpl node,
|
||||
int index,
|
||||
) {
|
||||
@@ -995,12 +999,12 @@ class ResolverVisitor extends ThrowingAstVisitor<void>
|
||||
}
|
||||
|
||||
@override
|
||||
SwitchStatementMemberInfo<AstNode, StatementImpl, ExpressionImpl,
|
||||
SwitchStatementMemberInfo<AstNodeImpl, StatementImpl, ExpressionImpl,
|
||||
PromotableElementImpl2> getSwitchStatementMemberInfo(
|
||||
covariant SwitchStatementImpl node,
|
||||
int index,
|
||||
) {
|
||||
CaseHeadOrDefaultInfo<AstNode, ExpressionImpl, PromotableElementImpl2>
|
||||
CaseHeadOrDefaultInfo<AstNodeImpl, ExpressionImpl, PromotableElementImpl2>
|
||||
ofMember(
|
||||
SwitchMemberImpl member,
|
||||
) {
|
||||
@@ -3792,7 +3796,7 @@ class ResolverVisitor extends ThrowingAstVisitor<void>
|
||||
}
|
||||
|
||||
@override
|
||||
void visitTryStatement(TryStatement node) {
|
||||
void visitTryStatement(covariant TryStatementImpl node) {
|
||||
inferenceLogWriter?.enterStatement(node);
|
||||
checkUnreachableNode(node);
|
||||
var flow = flowAnalysis.flow!;
|
||||
|
||||
Reference in New Issue
Block a user