Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(299)

Side by Side Diff: pkg/compiler/lib/src/kernel/element_map.dart

Issue 2992863002: Support forEachClassMember on closure classes (Closed)
Patch Set: Updated cf. comments Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 import 'package:kernel/ast.dart' as ir; 5 import 'package:kernel/ast.dart' as ir;
6 6
7 import '../closure.dart'; 7 import '../closure.dart';
8 import '../common.dart'; 8 import '../common.dart';
9 import '../constants/values.dart'; 9 import '../constants/values.dart';
10 import '../common_elements.dart'; 10 import '../common_elements.dart';
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 MemberKind get kind; 224 MemberKind get kind;
225 225
226 /// The defining [ir.Node] for this member, if supported by its [kind]. 226 /// The defining [ir.Node] for this member, if supported by its [kind].
227 /// 227 ///
228 /// For a regular class this is the [ir.Class] node. For closure classes this 228 /// For a regular class this is the [ir.Class] node. For closure classes this
229 /// might be an [ir.FunctionExpression] node if needed. 229 /// might be an [ir.FunctionExpression] node if needed.
230 ir.Node get node; 230 ir.Node get node;
231 231
232 /// The canonical location of [member]. This is used for sorting the members 232 /// The canonical location of [member]. This is used for sorting the members
233 /// in the emitted code. 233 /// in the emitted code.
234 ir.Location get location; 234 SourceSpan get location;
235 } 235 }
236 236
237 enum ClassKind { 237 enum ClassKind {
238 regular, 238 regular,
239 closure, 239 closure,
240 } 240 }
241 241
242 /// A member directly defined by its [ir.Member] node. 242 /// A member directly defined by its [ir.Member] node.
243 class RegularMemberDefinition implements MemberDefinition { 243 class RegularMemberDefinition implements MemberDefinition {
244 final MemberEntity member; 244 final MemberEntity member;
245 final ir.Member node; 245 final ir.Member node;
246 246
247 RegularMemberDefinition(this.member, this.node); 247 RegularMemberDefinition(this.member, this.node);
248 248
249 ir.Location get location => node.location; 249 SourceSpan get location => computeSourceSpanFromTreeNode(node);
250 250
251 MemberKind get kind => MemberKind.regular; 251 MemberKind get kind => MemberKind.regular;
252 252
253 String toString() => 'RegularMemberDefinition(kind:$kind,member:$member,' 253 String toString() => 'RegularMemberDefinition(kind:$kind,member:$member,'
254 'node:$node,location:$location)'; 254 'node:$node,location:$location)';
255 } 255 }
256 256
257 /// The definition of a special kind of member 257 /// The definition of a special kind of member
258 class SpecialMemberDefinition implements MemberDefinition { 258 class SpecialMemberDefinition implements MemberDefinition {
259 final MemberEntity member; 259 final MemberEntity member;
260 final ir.TreeNode node; 260 final ir.TreeNode node;
261 final MemberKind kind; 261 final MemberKind kind;
262 262
263 SpecialMemberDefinition(this.member, this.node, this.kind); 263 SpecialMemberDefinition(this.member, this.node, this.kind);
264 264
265 ir.Location get location => node.location; 265 SourceSpan get location => computeSourceSpanFromTreeNode(node);
266 266
267 String toString() => 'SpecialMemberDefinition(kind:$kind,member:$member,' 267 String toString() => 'SpecialMemberDefinition(kind:$kind,member:$member,'
268 'node:$node,location:$location)'; 268 'node:$node,location:$location)';
269 } 269 }
270 270
271 /// Definition information for a [ClassEntity]. 271 /// Definition information for a [ClassEntity].
272 abstract class ClassDefinition { 272 abstract class ClassDefinition {
273 /// The defined class. 273 /// The defined class.
274 ClassEntity get cls; 274 ClassEntity get cls;
275 275
276 /// The kind of the defined class. This determines the semantics of [node]. 276 /// The kind of the defined class. This determines the semantics of [node].
277 ClassKind get kind; 277 ClassKind get kind;
278 278
279 /// The defining [ir.Node] for this class, if supported by its [kind]. 279 /// The defining [ir.Node] for this class, if supported by its [kind].
280 ir.Node get node; 280 ir.Node get node;
281 281
282 /// The canonical location of [cls]. This is used for sorting the classes 282 /// The canonical location of [cls]. This is used for sorting the classes
283 /// in the emitted code. 283 /// in the emitted code.
284 ir.Location get location; 284 SourceSpan get location;
285 } 285 }
286 286
287 /// A class directly defined by its [ir.Class] node. 287 /// A class directly defined by its [ir.Class] node.
288 class RegularClassDefinition implements ClassDefinition { 288 class RegularClassDefinition implements ClassDefinition {
289 final ClassEntity cls; 289 final ClassEntity cls;
290 final ir.Class node; 290 final ir.Class node;
291 291
292 RegularClassDefinition(this.cls, this.node); 292 RegularClassDefinition(this.cls, this.node);
293 293
294 ir.Location get location => node.location; 294 SourceSpan get location => computeSourceSpanFromTreeNode(node);
295 295
296 ClassKind get kind => ClassKind.regular; 296 ClassKind get kind => ClassKind.regular;
297 297
298 String toString() => 'RegularClassDefinition(kind:$kind,cls:$cls,' 298 String toString() => 'RegularClassDefinition(kind:$kind,cls:$cls,'
299 'node:$node,location:$location)'; 299 'node:$node,location:$location)';
300 } 300 }
301 301
302 /// Kinds of foreign functions. 302 /// Kinds of foreign functions.
303 enum ForeignKind { 303 enum ForeignKind {
304 JS, 304 JS,
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 /// [closureClassMaps]. 424 /// [closureClassMaps].
425 CapturedLoopScope getCapturedLoopScope( 425 CapturedLoopScope getCapturedLoopScope(
426 ClosureDataLookup closureLookup, ir.TreeNode node); 426 ClosureDataLookup closureLookup, ir.TreeNode node);
427 } 427 }
428 428
429 /// Comparator for the canonical order or named arguments. 429 /// Comparator for the canonical order or named arguments.
430 // TODO(johnniwinther): Remove this when named parameters are sorted in dill. 430 // TODO(johnniwinther): Remove this when named parameters are sorted in dill.
431 int namedOrdering(ir.VariableDeclaration a, ir.VariableDeclaration b) { 431 int namedOrdering(ir.VariableDeclaration a, ir.VariableDeclaration b) {
432 return a.name.compareTo(b.name); 432 return a.name.compareTo(b.name);
433 } 433 }
434
435 SourceSpan computeSourceSpanFromTreeNode(ir.TreeNode node) {
436 // TODO(johnniwinther): Use [ir.Location] directly as a [SourceSpan].
437 Uri uri;
438 int offset;
439 while (node != null) {
440 if (node.fileOffset != ir.TreeNode.noOffset) {
441 offset = node.fileOffset;
442 uri = Uri.parse(node.location.file);
443 break;
444 }
445 node = node.parent;
446 }
447 if (uri != null) {
448 return new SourceSpan(uri, offset, offset + 1);
449 }
450 return null;
451 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/js_model/elements.dart ('k') | pkg/compiler/lib/src/kernel/element_map_impl.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698