Skip to content

Commit fdd3822

Browse files
johnniwinthercommit-bot@chromium.org
authored andcommitted
[cfe+dart2js] Move annotation testing logic to front_end
Change-Id: Ic53c3d34d5c56232ac011e99972ef8f145aac6da Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/108602 Reviewed-by: Jens Johansen <[email protected]>
1 parent 910064b commit fdd3822

23 files changed

+925
-697
lines changed

pkg/front_end/lib/src/testing/id.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ enum IdKind {
1717
/// Id for a code point or element.
1818
abstract class Id {
1919
IdKind get kind;
20+
21+
/// Indicates whether the id refers to an element defined outside of the test
22+
/// case itself (e.g. some tests may need to refer to properties of elements
23+
/// in `dart:core`).
2024
bool get isGlobal;
2125

2226
/// Display name for this id.
@@ -260,6 +264,9 @@ class ActualData<T> {
260264
abstract class DataRegistry<T> {
261265
Map<Id, ActualData<T>> get actualMap;
262266

267+
/// Registers [value] with [id] in [actualMap].
268+
///
269+
/// Checks for duplicate data for [id].
263270
void registerValue(Uri uri, int offset, Id id, T value, Object object) {
264271
if (actualMap.containsKey(id)) {
265272
ActualData<T> existingData = actualMap[id];
@@ -276,7 +283,9 @@ abstract class DataRegistry<T> {
276283
}
277284
}
278285

286+
/// Called to report duplicate errors.
279287
void report(Uri uri, int offset, String message);
280288

289+
/// Called to raise an exception on duplicate errors.
281290
void fail(String message);
282291
}

pkg/front_end/lib/src/testing/id_extractor.dart

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
1+
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

55
import 'package:kernel/ast.dart';
66
import 'id.dart';
77

88
/// Compute a canonical [Id] for kernel-based nodes.
9-
Id computeEntityId(Member node) {
9+
Id computeMemberId(Member node) {
1010
String className;
1111
if (node.enclosingClass != null) {
1212
className = node.enclosingClass.name;
@@ -34,6 +34,11 @@ abstract class DataExtractor<T> extends Visitor with DataRegistry<T> {
3434
@override
3535
final Map<Id, ActualData<T>> actualMap;
3636

37+
/// Implement this to compute the data corresponding to [cls].
38+
///
39+
/// If `null` is returned, [cls] has no associated data.
40+
T computeClassValue(Id id, Class cls);
41+
3742
/// Implement this to compute the data corresponding to [member].
3843
///
3944
/// If `null` is returned, [member] has no associated data.
@@ -46,8 +51,16 @@ abstract class DataExtractor<T> extends Visitor with DataRegistry<T> {
4651

4752
DataExtractor(this.actualMap);
4853

54+
void computeForClass(Class cls) {
55+
ClassId id = new ClassId(cls.name);
56+
T value = computeClassValue(id, cls);
57+
TreeNode nodeWithOffset = computeTreeNodeWithOffset(cls);
58+
registerValue(nodeWithOffset?.location?.file, nodeWithOffset?.fileOffset,
59+
id, value, cls);
60+
}
61+
4962
void computeForMember(Member member) {
50-
MemberId id = computeEntityId(member);
63+
MemberId id = computeMemberId(member);
5164
if (id == null) return;
5265
T value = computeMemberValue(id, member);
5366
TreeNode nodeWithOffset = computeTreeNodeWithOffset(member);
@@ -261,4 +274,16 @@ abstract class DataExtractor<T> extends Visitor with DataRegistry<T> {
261274
computeForNode(node, createGotoId(node));
262275
super.visitContinueSwitchStatement(node);
263276
}
277+
278+
@override
279+
visitConstantExpression(ConstantExpression node) {
280+
if (node.fileOffset == TreeNode.noOffset) {
281+
// Implicit constants (for instance omitted field initializers, implicit
282+
// default values) and synthetic constants (for instance in noSuchMethod
283+
// forwarders) have no offset.
284+
} else {
285+
computeForNode(node, computeDefaultNodeId(node));
286+
}
287+
super.visitConstantExpression(node);
288+
}
264289
}

0 commit comments

Comments
 (0)