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
55import 'package:kernel/ast.dart' ;
66import '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