Skip to content

Commit 41caa76

Browse files
johnniwintherdart-scoped@luci-project-accounts.iam.gserviceaccount.com
authored andcommitted
[cfe][InternalNodes] Use InternalSet/Map/ListLiteral
This uses the internal nodes for set/map/list literals. This is a step towards separating the internal AST from the external AST. Change-Id: Ifa283047b11c404624b35f1d35cda9f492c9e530 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/521241 Commit-Queue: Johnni Winther <johnniwinther@google.com> Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
1 parent 828fdbb commit 41caa76

6 files changed

Lines changed: 411 additions & 452 deletions

File tree

‎pkg/front_end/lib/src/kernel/body_builder.dart‎

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ import 'constness.dart' show Constness;
107107
import 'expression_generator.dart';
108108
import 'expression_generator_helper.dart';
109109
import 'external_ast_helper.dart' as extern;
110-
import 'implicit_type_argument.dart' show ImplicitTypeArgument;
111110
import 'internal_ast.dart';
112111
import 'internal_ast_helper.dart' as intern;
113112
import 'kernel_variable_builder.dart';
@@ -605,8 +604,6 @@ class BodyBuilderImpl extends StackListenerImpl
605604
return _context.instanceTypeParameterAccessState;
606605
}
607606

608-
DartType get implicitTypeArgument => const ImplicitTypeArgument();
609-
610607
void _enterLocalState({bool inLateLocalInitializer = false}) {
611608
_localInitializerState = _localInitializerState.prepend(
612609
inLateLocalInitializer,
@@ -4320,7 +4317,7 @@ class BodyBuilderImpl extends StackListenerImpl
43204317

43214318
List<TypeBuilder>? typeArguments = pop() as List<TypeBuilder>?;
43224319

4323-
DartType typeArgument;
4320+
DartType? typeArgument;
43244321
if (typeArguments != null) {
43254322
if (typeArguments.length > 1) {
43264323
addProblem(
@@ -4337,11 +4334,9 @@ class BodyBuilderImpl extends StackListenerImpl
43374334
);
43384335
typeArgument = instantiateToBounds(typeArgument, coreTypes.objectClass);
43394336
}
4340-
} else {
4341-
typeArgument = implicitTypeArgument;
43424337
}
43434338

4344-
ListLiteral node = intern.createListLiteral(
4339+
InternalExpression node = intern.createListLiteral(
43454340
// TODO(johnniwinther): The file offset computed below will not be
43464341
// correct if there are type arguments but no `const` keyword.
43474342
offsetForToken(constKeyword ?? leftBracket),
@@ -4569,16 +4564,14 @@ class BodyBuilderImpl extends StackListenerImpl
45694564
Token leftBrace,
45704565
List<dynamic>? setOrMapEntries,
45714566
) {
4572-
DartType typeArgument;
4567+
DartType? typeArgument;
45734568
if (typeArguments != null) {
45744569
typeArgument = buildDartType(
45754570
typeArguments.single,
45764571
TypeUse.literalTypeArgument,
45774572
allowPotentiallyConstantType: false,
45784573
);
45794574
typeArgument = instantiateToBounds(typeArgument, coreTypes.objectClass);
4580-
} else {
4581-
typeArgument = implicitTypeArgument;
45824575
}
45834576

45844577
List<Expression> expressions = <Expression>[];
@@ -4599,7 +4592,7 @@ class BodyBuilderImpl extends StackListenerImpl
45994592
}
46004593
}
46014594

4602-
SetLiteral node = intern.createSetLiteral(
4595+
InternalExpression node = intern.createSetLiteral(
46034596
// TODO(johnniwinther): The file offset computed below will not be
46044597
// correct if there are type arguments but no `const` keyword.
46054598
offsetForToken(constKeyword ?? leftBrace),
@@ -4849,8 +4842,8 @@ class BodyBuilderImpl extends StackListenerImpl
48494842
Token leftBrace,
48504843
List<MapLiteralEntry> entries,
48514844
) {
4852-
DartType keyType;
4853-
DartType valueType;
4845+
DartType? keyType;
4846+
DartType? valueType;
48544847
if (typeArguments != null) {
48554848
if (typeArguments.length != 2) {
48564849
keyType = const InvalidType();
@@ -4869,12 +4862,9 @@ class BodyBuilderImpl extends StackListenerImpl
48694862
keyType = instantiateToBounds(keyType, coreTypes.objectClass);
48704863
valueType = instantiateToBounds(valueType, coreTypes.objectClass);
48714864
}
4872-
} else {
4873-
keyType = implicitTypeArgument;
4874-
valueType = implicitTypeArgument;
48754865
}
48764866

4877-
MapLiteral node = intern.createMapLiteral(
4867+
InternalExpression node = intern.createMapLiteral(
48784868
// TODO(johnniwinther): The file offset computed below will not be
48794869
// correct if there are type arguments but no `const` keyword.
48804870
offsetForToken(constKeyword ?? leftBrace),

‎pkg/front_end/lib/src/kernel/collections.dart‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1089,7 +1089,6 @@ MapLiteralEntry convertToMapEntry(
10891089
return result;
10901090
}
10911091
} else {
1092-
// Coverage-ignore-block(suite): Not run.
10931092
return _convertToErroneousMapEntry(
10941093
element,
10951094
problemReporting,

‎pkg/front_end/lib/src/kernel/implicit_type_argument.dart‎

Lines changed: 0 additions & 91 deletions
This file was deleted.

‎pkg/front_end/lib/src/kernel/internal_ast.dart‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9095,7 +9095,6 @@ class InternalIsExpression extends InternalExpression {
90959095
}
90969096
}
90979097

9098-
// Coverage-ignore(suite): Not run.
90999098
class InternalListLiteral extends InternalExpression {
91009099
final bool isConst;
91019100
final DartType? typeArgument;
@@ -9120,6 +9119,7 @@ class InternalListLiteral extends InternalExpression {
91209119
}
91219120

91229121
@override
9122+
// Coverage-ignore(suite): Not run.
91239123
void toTextInternal(AstPrinter printer) {
91249124
if (isConst) {
91259125
printer.write('const ');
@@ -9174,7 +9174,6 @@ class InternalLogicalExpression extends InternalExpression {
91749174
}
91759175
}
91769176

9177-
// Coverage-ignore(suite): Not run.
91789177
class InternalMapLiteral extends InternalExpression {
91799178
final bool isConst;
91809179
final DartType? keyType;
@@ -9201,6 +9200,7 @@ class InternalMapLiteral extends InternalExpression {
92019200
}
92029201

92039202
@override
9203+
// Coverage-ignore(suite): Not run.
92049204
void toTextInternal(AstPrinter printer) {
92059205
if (isConst) {
92069206
printer.write('const ');
@@ -9336,7 +9336,6 @@ class InternalRethrow extends InternalExpression {
93369336
}
93379337
}
93389338

9339-
// Coverage-ignore(suite): Not run.
93409339
class InternalSetLiteral extends InternalExpression {
93419340
final bool isConst;
93429341
final DartType? typeArgument;
@@ -9361,6 +9360,7 @@ class InternalSetLiteral extends InternalExpression {
93619360
}
93629361

93639362
@override
9363+
// Coverage-ignore(suite): Not run.
93649364
void toTextInternal(AstPrinter printer) {
93659365
if (isConst) {
93669366
printer.write('const ');

‎pkg/front_end/lib/src/kernel/internal_ast_helper.dart‎

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -792,17 +792,18 @@ InternalLet createLetForEffect({
792792
/// argument, there is more than one type argument, or if the type argument
793793
/// cannot be resolved. The list of [expressions] is a list of the
794794
/// representations of the list elements.
795-
ListLiteral createListLiteral(
795+
InternalExpression createListLiteral(
796796
int fileOffset,
797-
DartType typeArgument,
797+
DartType? typeArgument,
798798
List<Expression> expressions, {
799799
required bool isConst,
800800
}) {
801-
return new ListLiteral(
801+
return new InternalListLiteral(
802802
expressions,
803803
typeArgument: typeArgument,
804804
isConst: isConst,
805-
)..fileOffset = fileOffset;
805+
fileOffset: fileOffset,
806+
);
806807
}
807808

808809
InternalPattern createListPattern(
@@ -919,19 +920,20 @@ MapLiteralEntry createMapEntry(
919920
/// the map literal, or `null` if there are not exactly two type arguments or
920921
/// if the second type argument cannot be resolved. The list of [entries] is a
921922
/// list of the representations of the map entries.
922-
MapLiteral createMapLiteral(
923+
InternalExpression createMapLiteral(
923924
int fileOffset,
924-
DartType keyType,
925-
DartType valueType,
925+
DartType? keyType,
926+
DartType? valueType,
926927
List<MapLiteralEntry> entries, {
927928
required bool isConst,
928929
}) {
929-
return new MapLiteral(
930+
return new InternalMapLiteral(
930931
entries,
931932
keyType: keyType,
932933
valueType: valueType,
933934
isConst: isConst,
934-
)..fileOffset = fileOffset;
935+
fileOffset: fileOffset,
936+
);
935937
}
936938

937939
MapLiteralEntry createMapLiteralEntry(
@@ -1408,17 +1410,18 @@ InternalReturnStatement createReturnStatement({
14081410
/// argument, there is more than one type argument, or if the type argument
14091411
/// cannot be resolved. The list of [expressions] is a list of the
14101412
/// representations of the set elements.
1411-
SetLiteral createSetLiteral(
1413+
InternalExpression createSetLiteral(
14121414
int fileOffset,
1413-
DartType typeArgument,
1415+
DartType? typeArgument,
14141416
List<Expression> expressions, {
14151417
required bool isConst,
14161418
}) {
1417-
return new SetLiteral(
1419+
return new InternalSetLiteral(
14181420
expressions,
14191421
typeArgument: typeArgument,
14201422
isConst: isConst,
1421-
)..fileOffset = fileOffset;
1423+
fileOffset: fileOffset,
1424+
);
14221425
}
14231426

14241427
Expression createSpreadElement(

0 commit comments

Comments
 (0)