mirror of
https://github.com/dart-lang/sdk
synced 2024-09-06 00:59:09 +00:00
Flow analysis: Make TypeSystemTypeOperations public so it can be reused.
Change-Id: Ia5d494f6e4042fbb018a8b5c041b2ba07043f525 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/119161 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Reviewed-by: Konstantin Shcheglov <scheglov@google.com> Commit-Queue: Paul Berry <paulberry@google.com>
This commit is contained in:
parent
2cbaaba7ad
commit
605422c94e
|
@ -48,7 +48,7 @@ class FlowAnalysisHelper {
|
|||
final NodeOperations<Expression> _nodeOperations;
|
||||
|
||||
/// The reused instance for creating new [FlowAnalysis] instances.
|
||||
final _TypeSystemTypeOperations _typeOperations;
|
||||
final TypeSystemTypeOperations _typeOperations;
|
||||
|
||||
/// Precomputed sets of potentially assigned variables.
|
||||
final AssignedVariables<AstNode, VariableElement> assignedVariables;
|
||||
|
@ -65,7 +65,7 @@ class FlowAnalysisHelper {
|
|||
TypeSystem typeSystem, AstNode node, bool retainDataForTesting) {
|
||||
return FlowAnalysisHelper._(
|
||||
const AnalyzerNodeOperations(),
|
||||
_TypeSystemTypeOperations(typeSystem),
|
||||
TypeSystemTypeOperations(typeSystem),
|
||||
computeAssignedVariables(node),
|
||||
retainDataForTesting ? FlowAnalysisResult() : null);
|
||||
}
|
||||
|
@ -333,6 +333,38 @@ class FlowAnalysisResult {
|
|||
final List<AstNode> unassignedNodes = [];
|
||||
}
|
||||
|
||||
class TypeSystemTypeOperations
|
||||
implements TypeOperations<VariableElement, DartType> {
|
||||
final TypeSystem typeSystem;
|
||||
|
||||
TypeSystemTypeOperations(this.typeSystem);
|
||||
|
||||
@override
|
||||
bool isLocalVariable(VariableElement element) {
|
||||
return element is LocalVariableElement;
|
||||
}
|
||||
|
||||
@override
|
||||
bool isSameType(covariant TypeImpl type1, covariant TypeImpl type2) {
|
||||
return type1 == type2;
|
||||
}
|
||||
|
||||
@override
|
||||
bool isSubtypeOf(DartType leftType, DartType rightType) {
|
||||
return typeSystem.isSubtypeOf(leftType, rightType);
|
||||
}
|
||||
|
||||
@override
|
||||
DartType promoteToNonNull(DartType type) {
|
||||
return typeSystem.promoteToNonNull(type);
|
||||
}
|
||||
|
||||
@override
|
||||
DartType variableType(VariableElement variable) {
|
||||
return variable.type;
|
||||
}
|
||||
}
|
||||
|
||||
/// The visitor that gathers local variables that are potentially assigned
|
||||
/// in corresponding statements, such as loops, `switch` and `try`.
|
||||
class _AssignedVariablesVisitor extends RecursiveAstVisitor<void> {
|
||||
|
@ -458,35 +490,3 @@ class _LocalVariableTypeProvider implements LocalVariableTypeProvider {
|
|||
return promotedType ?? variable.type;
|
||||
}
|
||||
}
|
||||
|
||||
class _TypeSystemTypeOperations
|
||||
implements TypeOperations<VariableElement, DartType> {
|
||||
final TypeSystem typeSystem;
|
||||
|
||||
_TypeSystemTypeOperations(this.typeSystem);
|
||||
|
||||
@override
|
||||
bool isLocalVariable(VariableElement element) {
|
||||
return element is LocalVariableElement;
|
||||
}
|
||||
|
||||
@override
|
||||
bool isSameType(covariant TypeImpl type1, covariant TypeImpl type2) {
|
||||
return type1 == type2;
|
||||
}
|
||||
|
||||
@override
|
||||
bool isSubtypeOf(DartType leftType, DartType rightType) {
|
||||
return typeSystem.isSubtypeOf(leftType, rightType);
|
||||
}
|
||||
|
||||
@override
|
||||
DartType promoteToNonNull(DartType type) {
|
||||
return typeSystem.promoteToNonNull(type);
|
||||
}
|
||||
|
||||
@override
|
||||
DartType variableType(VariableElement variable) {
|
||||
return variable.type;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue