Skip to content

Commit 327bc45

Browse files
kallentucommit-bot@chromium.org
authored andcommitted
Added variance support in listeners to ast.
Pass variance data to field in TypeParameter through the listeners. ast_to_text will print variances for classes and mixins if specified. Avoids serialization/deserialization (impl in future CL). Change-Id: I298537604823710f0d30001f4cb5f1e81530959f Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/118464 Commit-Queue: Kallen Tu <[email protected]> Reviewed-by: Dmitry Stefantsov <[email protected]>
1 parent 07db94d commit 327bc45

22 files changed

+176
-48
lines changed

pkg/analyzer/lib/src/fasta/ast_builder.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2090,7 +2090,8 @@ class AstBuilder extends StackListener {
20902090
}
20912091

20922092
@override
2093-
void endTypeVariable(Token token, int index, Token extendsOrSuper) {
2093+
void endTypeVariable(
2094+
Token token, int index, Token extendsOrSuper, Token variance) {
20942095
debugEvent("TypeVariable");
20952096
assert(extendsOrSuper == null ||
20962097
optional('extends', extendsOrSuper) ||

pkg/analyzer/test/generated/parser_fasta_listener.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,9 +1152,10 @@ class ForwardingTestListener extends ForwardingListener {
11521152
}
11531153

11541154
@override
1155-
void endTypeVariable(Token token, int index, Token extendsOrSuper) {
1155+
void endTypeVariable(
1156+
Token token, int index, Token extendsOrSuper, Token variance) {
11561157
end('TypeVariable');
1157-
super.endTypeVariable(token, index, extendsOrSuper);
1158+
super.endTypeVariable(token, index, extendsOrSuper, variance);
11581159
}
11591160

11601161
@override

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4767,14 +4767,18 @@ class BodyBuilder extends ScopeListener<JumpTarget>
47674767
}
47684768

47694769
@override
4770-
void endTypeVariable(Token token, int index, Token extendsOrSuper) {
4770+
void endTypeVariable(
4771+
Token token, int index, Token extendsOrSuper, Token variance) {
47714772
debugEvent("TypeVariable");
47724773
UnresolvedType bound = pop();
47734774
// Peek to leave type parameters on top of stack.
47744775
List<TypeVariableBuilder> typeVariables = peek();
47754776

47764777
TypeVariableBuilder variable = typeVariables[index];
47774778
variable.bound = bound?.builder;
4779+
if (variance != null) {
4780+
variable.variance = Variance.fromString(variance.lexeme);
4781+
}
47784782
}
47794783

47804784
@override

pkg/front_end/lib/src/fasta/parser/forwarding_listener.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -993,8 +993,9 @@ class ForwardingListener implements Listener {
993993
}
994994

995995
@override
996-
void endTypeVariable(Token token, int index, Token extendsOrSuper) {
997-
listener?.endTypeVariable(token, index, extendsOrSuper);
996+
void endTypeVariable(
997+
Token token, int index, Token extendsOrSuper, Token variance) {
998+
listener?.endTypeVariable(token, index, extendsOrSuper, variance);
998999
}
9991000

10001001
@override

pkg/front_end/lib/src/fasta/parser/listener.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1220,7 +1220,8 @@ class Listener implements UnescapeErrorListener {
12201220
/// - Type bound
12211221
///
12221222
/// See [beginTypeVariable] for additional substructures.
1223-
void endTypeVariable(Token token, int index, Token extendsOrSuper) {
1223+
void endTypeVariable(
1224+
Token token, int index, Token extendsOrSuper, Token variance) {
12241225
logEvent("TypeVariable");
12251226
}
12261227

pkg/front_end/lib/src/fasta/parser/type_info_impl.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,7 @@ class SimpleTypeArgument1 extends TypeParamOrArgInfo {
763763
listener.beginTypeVariable(token);
764764
listener.handleTypeVariablesDefined(token, 1);
765765
listener.handleNoType(token);
766-
listener.endTypeVariable(endGroup, 0, null);
766+
listener.endTypeVariable(endGroup, 0, null, null);
767767
listener.endTypeVariables(beginGroup, endGroup);
768768
return endGroup;
769769
}
@@ -1075,7 +1075,7 @@ class ComplexTypeParamOrArgInfo extends TypeParamOrArgInfo {
10751075
// Type variables are "completed" in reverse order, so capture the last
10761076
// consumed token from the first "completed" type variable.
10771077
token ??= token2;
1078-
listener.endTypeVariable(next2, --count, extendsOrSuper);
1078+
listener.endTypeVariable(next2, --count, extendsOrSuper, variance);
10791079

10801080
typeStarts = typeStarts.tail;
10811081
superTypeInfos = superTypeInfos.tail;

pkg/front_end/lib/src/fasta/source/diet_listener.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,8 @@ class DietListener extends StackListener {
544544
}
545545

546546
@override
547-
void endTypeVariable(Token token, int index, Token extendsOrSuper) {
547+
void endTypeVariable(
548+
Token token, int index, Token extendsOrSuper, Token variance) {
548549
debugEvent("endTypeVariable");
549550
}
550551

pkg/front_end/lib/src/fasta/source/outline_builder.dart

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
library fasta.outline_builder;
66

7-
import 'package:kernel/ast.dart' show ProcedureKind;
7+
import 'package:kernel/ast.dart' show ProcedureKind, Variance;
88

99
import '../builder/builder.dart';
1010

@@ -1574,13 +1574,17 @@ class OutlineBuilder extends StackListener {
15741574
}
15751575

15761576
@override
1577-
void endTypeVariable(Token token, int index, Token extendsOrSuper) {
1577+
void endTypeVariable(
1578+
Token token, int index, Token extendsOrSuper, Token variance) {
15781579
debugEvent("endTypeVariable");
15791580
TypeBuilder bound = nullIfParserRecovery(pop());
15801581
// Peek to leave type parameters on top of stack.
15811582
List<TypeVariableBuilder> typeParameters = peek();
15821583
if (typeParameters != null) {
15831584
typeParameters[index].bound = bound;
1585+
if (variance != null) {
1586+
typeParameters[index].variance = Variance.fromString(variance.lexeme);
1587+
}
15841588
}
15851589
}
15861590

pkg/front_end/lib/src/fasta/source/type_promotion_look_ahead_listener.dart

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1316,7 +1316,8 @@ class TypePromotionLookAheadListener extends Listener {
13161316
}
13171317

13181318
@override
1319-
void endTypeVariable(Token token, int index, Token extendsOrSuper) {
1319+
void endTypeVariable(
1320+
Token token, int index, Token extendsOrSuper, Token variance) {
13201321
debugEvent("TypeVariable", token);
13211322
state.pop(); // Name.
13221323
}
@@ -1326,6 +1327,11 @@ class TypePromotionLookAheadListener extends Listener {
13261327
debugEvent("TypeVariables", beginToken);
13271328
}
13281329

1330+
@override
1331+
void handleVarianceModifier(Token variance) {
1332+
debugEvent("VarianceModifier", variance);
1333+
}
1334+
13291335
@override
13301336
void handleNoTypeVariables(Token token) {
13311337
debugEvent("NoTypeVariables", token);

0 commit comments

Comments
 (0)