[_fe_analyzer_shared] Sort declarations in mini_ast.dart and shared_type.dart.
There is no functional change.
Change-Id: I1877d29efddd614688cd34506d5a496a472dea7e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/414260
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Auto-Submit: Paul Berry <paulberry@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
diff --git a/pkg/_fe_analyzer_shared/lib/src/types/shared_type.dart b/pkg/_fe_analyzer_shared/lib/src/types/shared_type.dart
index a4f096c..76a23d1 100644
--- a/pkg/_fe_analyzer_shared/lib/src/types/shared_type.dart
+++ b/pkg/_fe_analyzer_shared/lib/src/types/shared_type.dart
@@ -71,16 +71,6 @@
}
/// Common interface for data structures used by the implementations to
-/// represent a generic type parameter.
-abstract interface class SharedTypeParameter {
- /// The bound of the type parameter.
- SharedType? get boundShared;
-
- /// The name of the type parameter, for display to the user.
- String get displayName;
-}
-
-/// Common interface for data structures used by the implementations to
/// represent a type.
abstract interface class SharedType {
/// If this type ends in a suffix (`?` or `*`), the suffix it ends with;
@@ -98,6 +88,16 @@
}
/// Common interface for data structures used by the implementations to
+/// represent a generic type parameter.
+abstract interface class SharedTypeParameter {
+ /// The bound of the type parameter.
+ SharedType? get boundShared;
+
+ /// The name of the type parameter, for display to the user.
+ String get displayName;
+}
+
+/// Common interface for data structures used by the implementations to
/// represent the unknown type schema (`_`).
///
/// Note below that there is no `SharedUnknownTypeView`, only
@@ -154,6 +154,13 @@
}
}
+extension type SharedTypeParameterView(SharedTypeParameter _typeParameter)
+ implements Object {
+ TypeParameter unwrapTypeParameterViewAsTypeParameterStructure<
+ TypeParameter extends SharedTypeParameter>() =>
+ _typeParameter as TypeParameter;
+}
+
extension type SharedTypeSchemaView(SharedType _typeStructure)
implements Object {
NullabilitySuffix get nullabilitySuffix => _typeStructure.nullabilitySuffix;
@@ -179,13 +186,6 @@
_typeStructure as TypeStructure;
}
-extension type SharedTypeParameterView(SharedTypeParameter _typeParameter)
- implements Object {
- TypeParameter unwrapTypeParameterViewAsTypeParameterStructure<
- TypeParameter extends SharedTypeParameter>() =>
- _typeParameter as TypeParameter;
-}
-
/// Note that there is no `SharedUnknownTypeView`, only
/// [SharedUnknownTypeSchemaView], since we want to restrict
/// [SharedUnknownType] from appearing in type views and
diff --git a/pkg/_fe_analyzer_shared/test/mini_ast.dart b/pkg/_fe_analyzer_shared/test/mini_ast.dart
index 645a54f..9019748 100644
--- a/pkg/_fe_analyzer_shared/test/mini_ast.dart
+++ b/pkg/_fe_analyzer_shared/test/mini_ast.dart
@@ -28,8 +28,8 @@
as shared;
import 'package:_fe_analyzer_shared/src/type_inference/type_analyzer.dart'
hide MapPatternEntry, RecordPatternField;
-import 'package:_fe_analyzer_shared/src/type_inference/type_constraint.dart';
import 'package:_fe_analyzer_shared/src/type_inference/type_analyzer_operations.dart';
+import 'package:_fe_analyzer_shared/src/type_inference/type_constraint.dart';
import 'package:_fe_analyzer_shared/src/type_inference/variable_bindings.dart';
import 'package:_fe_analyzer_shared/src/types/shared_type.dart';
import 'package:test/test.dart';
@@ -1241,6 +1241,46 @@
}
}
+// Represents the entire dot shorthand expression.
+// e.g. `.current.errorZone`
+class DotShorthand extends Expression {
+ final Expression expr;
+
+ DotShorthand._(this.expr, {required super.location});
+
+ @override
+ void preVisit(PreVisitor visitor) {
+ expr.preVisit(visitor);
+ }
+
+ @override
+ String toString() => '$expr';
+
+ @override
+ ExpressionTypeAnalysisResult visit(Harness h, SharedTypeSchemaView schema) {
+ return h.typeAnalyzer.analyzeDotShorthandExpression(expr, schema);
+ }
+}
+
+// Represents the head of a dot shorthand.
+// e.g. `.zero`
+class DotShorthandHead extends Expression {
+ final String name;
+
+ DotShorthandHead._(this.name, {required super.location});
+
+ @override
+ void preVisit(PreVisitor visitor) {}
+
+ @override
+ String toString() => '.$name';
+
+ @override
+ ExpressionTypeAnalysisResult visit(Harness h, SharedTypeSchemaView schema) {
+ return h.typeAnalyzer.analyzeDotShorthandHeadExpression(this, name, schema);
+ }
+}
+
class Equal extends Expression {
final Expression lhs;
final Expression rhs;
@@ -2732,6 +2772,23 @@
}
}
+ @override
+ TypeConstraintGenerator<Var, Type, String, Node>
+ createTypeConstraintGenerator(
+ {required TypeConstraintGenerationDataForTesting?
+ typeConstraintGenerationDataForTesting,
+ required List<SharedTypeParameterView> typeParametersToInfer,
+ required TypeAnalyzerOperations<Var, Type, String>
+ typeAnalyzerOperations,
+ required bool inferenceUsingBoundsIsEnabled}) {
+ return TypeConstraintGatherer({
+ for (var typeParameter in typeParametersToInfer)
+ typeParameter
+ .unwrapTypeParameterViewAsTypeParameterStructure<TypeParameter>()
+ .name
+ });
+ }
+
/// Returns the downward inference result of a type with the given [name],
/// in the [context]. For example infer `List<int>` from `Iterable<int>`.
Type downwardInfer(String name, Type context) {
@@ -3181,23 +3238,6 @@
Type withNullabilitySuffixInternal(Type type, NullabilitySuffix modifier) {
return type.withNullability(modifier);
}
-
- @override
- TypeConstraintGenerator<Var, Type, String, Node>
- createTypeConstraintGenerator(
- {required TypeConstraintGenerationDataForTesting?
- typeConstraintGenerationDataForTesting,
- required List<SharedTypeParameterView> typeParametersToInfer,
- required TypeAnalyzerOperations<Var, Type, String>
- typeAnalyzerOperations,
- required bool inferenceUsingBoundsIsEnabled}) {
- return TypeConstraintGatherer({
- for (var typeParameter in typeParametersToInfer)
- typeParameter
- .unwrapTypeParameterViewAsTypeParameterStructure<TypeParameter>()
- .name
- });
- }
}
/// Representation of an expression or statement in the pseudo-Dart language
@@ -3386,46 +3426,6 @@
}
}
-// Represents the head of a dot shorthand.
-// e.g. `.zero`
-class DotShorthandHead extends Expression {
- final String name;
-
- DotShorthandHead._(this.name, {required super.location});
-
- @override
- void preVisit(PreVisitor visitor) {}
-
- @override
- String toString() => '.$name';
-
- @override
- ExpressionTypeAnalysisResult visit(Harness h, SharedTypeSchemaView schema) {
- return h.typeAnalyzer.analyzeDotShorthandHeadExpression(this, name, schema);
- }
-}
-
-// Represents the entire dot shorthand expression.
-// e.g. `.current.errorZone`
-class DotShorthand extends Expression {
- final Expression expr;
-
- DotShorthand._(this.expr, {required super.location});
-
- @override
- void preVisit(PreVisitor visitor) {
- expr.preVisit(visitor);
- }
-
- @override
- String toString() => '$expr';
-
- @override
- ExpressionTypeAnalysisResult visit(Harness h, SharedTypeSchemaView schema) {
- return h.typeAnalyzer.analyzeDotShorthandExpression(expr, schema);
- }
-}
-
class ParenthesizedExpression extends Expression {
final Expression expr;
@@ -3920,6 +3920,14 @@
/// variable).
mixin ProtoExpression
implements ProtoStatement<Expression>, ProtoCollectionElement<Expression> {
+ /// If `this` is an expression `x`, creates a dot shorthand wrapper around
+ /// `x`.
+ Expression get dotShorthand {
+ var location = computeLocation();
+ return new DotShorthand._(asExpression(location: location),
+ location: location);
+ }
+
/// If `this` is an expression `x`, creates the expression `x!`.
Expression get nonNullAssert {
var location = computeLocation();
@@ -3933,14 +3941,6 @@
return new Not._(asExpression(location: location), location: location);
}
- /// If `this` is an expression `x`, creates a dot shorthand wrapper around
- /// `x`.
- Expression get dotShorthand {
- var location = computeLocation();
- return new DotShorthand._(asExpression(location: location),
- location: location);
- }
-
/// If `this` is an expression `x`, creates the expression `(x)`.
Expression get parenthesized {
var location = computeLocation();
@@ -5560,6 +5560,19 @@
flow.doStatement_end(condition);
}
+ ExpressionTypeAnalysisResult analyzeDotShorthandExpression(
+ Expression expression, SharedTypeSchemaView schema) {
+ var type = analyzeDotShorthand(expression, schema);
+ return new ExpressionTypeAnalysisResult(type: type);
+ }
+
+ ExpressionTypeAnalysisResult analyzeDotShorthandHeadExpression(
+ Expression node, String name, SharedTypeSchemaView schema) {
+ _irBuilder.atom(name, Kind.expression, location: node.location);
+ return new ExpressionTypeAnalysisResult(
+ type: SharedTypeView(getDotShorthandContext().unwrapTypeSchemaView()));
+ }
+
void analyzeExpressionStatement(Expression expression) {
analyzeExpression(expression, operations.unknownType);
}
@@ -5645,19 +5658,6 @@
return new ExpressionTypeAnalysisResult(type: SharedTypeView(nullType));
}
- ExpressionTypeAnalysisResult analyzeDotShorthandHeadExpression(
- Expression node, String name, SharedTypeSchemaView schema) {
- _irBuilder.atom(name, Kind.expression, location: node.location);
- return new ExpressionTypeAnalysisResult(
- type: SharedTypeView(getDotShorthandContext().unwrapTypeSchemaView()));
- }
-
- ExpressionTypeAnalysisResult analyzeDotShorthandExpression(
- Expression expression, SharedTypeSchemaView schema) {
- var type = analyzeDotShorthand(expression, schema);
- return new ExpressionTypeAnalysisResult(type: type);
- }
-
ExpressionTypeAnalysisResult analyzeParenthesizedExpression(
Expression node, Expression expression, SharedTypeSchemaView schema) {
var type = analyzeExpression(expression, schema);