[cfe] Extract field initializer tokens from the token stream
During outline building the token stream was split after every field
initializer needed for top-level type inference. Since the token
stream is a doubly-linked list it's also necessary to split the token
stream before the field initializer in order to possibly collect the
unnecessary tokens.
Change-Id: Iafac8eee1eb87d43458f66ef08f6398634ded5df
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/103622
Auto-Submit: Kevin Millikin <kmillikin@google.com>
Commit-Queue: Dan Rubel <danrubel@google.com>
Reviewed-by: Dan Rubel <danrubel@google.com>
diff --git a/pkg/front_end/lib/src/fasta/source/source_library_builder.dart b/pkg/front_end/lib/src/fasta/source/source_library_builder.dart
index fb12c34..3323184 100644
--- a/pkg/front_end/lib/src/fasta/source/source_library_builder.dart
+++ b/pkg/front_end/lib/src/fasta/source/source_library_builder.dart
@@ -396,26 +396,18 @@
void addFields(String documentationComment, List<MetadataBuilder> metadata,
int modifiers, T type, List<FieldInfo> fieldInfos) {
for (FieldInfo info in fieldInfos) {
- String name = info.name;
- int charOffset = info.charOffset;
- int charEndOffset = info.charEndOffset;
- bool hasInitializer = info.initializerTokenForInference != null;
- Token initializerTokenForInference =
+ Token startToken =
type != null || legacyMode ? null : info.initializerTokenForInference;
- if (initializerTokenForInference != null) {
- Token beforeLast = info.beforeLast;
- beforeLast.setNext(new Token.eof(beforeLast.next.offset));
+ if (startToken != null) {
+ // Extract only the tokens for the initializer expression from the
+ // token stream.
+ Token endToken = info.beforeLast;
+ endToken.setNext(new Token.eof(endToken.next.offset));
+ new Token.eof(startToken.previous.offset).setNext(startToken);
}
- addField(
- documentationComment,
- metadata,
- modifiers,
- type,
- name,
- charOffset,
- charEndOffset,
- initializerTokenForInference,
- hasInitializer);
+ bool hasInitializer = info.initializerTokenForInference != null;
+ addField(documentationComment, metadata, modifiers, type, info.name,
+ info.charOffset, info.charEndOffset, startToken, hasInitializer);
}
}