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

Side by Side Diff: pkg/compiler/lib/src/js_model/closure.dart

Issue 3010473002: Adding JRecord and boxing mechanics.
Patch Set: .. Created 3 years, 3 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 '../common/tasks.dart'; 9 import '../common/tasks.dart';
10 import '../constants/expressions.dart'; 10 import '../constants/expressions.dart';
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 381
382 FieldEntity get thisFieldEntity => localToFieldMap[thisLocal]; 382 FieldEntity get thisFieldEntity => localToFieldMap[thisLocal];
383 383
384 void forEachCapturedVariable(f(Local from, JField to)) { 384 void forEachCapturedVariable(f(Local from, JField to)) {
385 localToFieldMap.forEach(f); 385 localToFieldMap.forEach(f);
386 } 386 }
387 387
388 @override 388 @override
389 void forEachBoxedVariable(f(Local local, JField field)) { 389 void forEachBoxedVariable(f(Local local, JField field)) {
390 for (Local l in localToFieldMap.keys) { 390 for (Local l in localToFieldMap.keys) {
391 if (localToFieldMap[l] is JBoxedField) f(l, localToFieldMap[l]); 391 if (localToFieldMap[l] is JRecord) f(l, localToFieldMap[l]);
392 } 392 }
393 } 393 }
394 394
395 void forEachFreeVariable(f(Local variable, JField field)) { 395 void forEachFreeVariable(f(Local variable, JField field)) {
396 for (Local l in localToFieldMap.keys) { 396 for (Local l in localToFieldMap.keys) {
397 var jField = localToFieldMap[l]; 397 var jField = localToFieldMap[l];
398 if (jField is! JBoxedField && jField is! BoxLocal) f(l, jField); 398 if (jField is! JRecord && jField is! BoxLocal) f(l, jField);
399 } 399 }
400 } 400 }
401 401
402 bool isVariableBoxed(Local variable) => 402 bool isVariableBoxed(Local variable) =>
403 localToFieldMap.keys.contains(variable); 403 localToFieldMap.keys.contains(variable);
404 404
405 bool get isClosure => true; 405 bool get isClosure => true;
406 } 406 }
407 407
408 /// A local variable to disambiguate between a variable that has been captured 408 /// A local variable to disambiguate between a variable that has been captured
(...skipping 21 matching lines...) Expand all
430 : super( 430 : super(
431 memberIndex, 431 memberIndex,
432 containingClass.closureClassEntity.library, 432 containingClass.closureClassEntity.library,
433 containingClass.closureClassEntity, 433 containingClass.closureClassEntity,
434 new Name(name, containingClass.closureClassEntity.library), 434 new Name(name, containingClass.closureClassEntity.library),
435 isAssignable: isAssignable, 435 isAssignable: isAssignable,
436 isConst: isConst, 436 isConst: isConst,
437 isStatic: false); 437 isStatic: false);
438 } 438 }
439 439
440 /// A ClosureField that has been "boxed" to prevent name shadowing with the 440 /// A container for variables declared in a particular scope that are accessed
441 /// elsewhere.
442 // TODO(efortuna, johnniwinther): Don't implement JClass. This isn't actually a
443 // class.
444 class JRecordContainer implements JClass {
445 final JLibrary library;
446 final String name;
447
448 /// Index into the classData, classList and classEnvironment lists where this
449 /// entity is stored in [JsToFrontendMapImpl].
450 final int classIndex;
451
452 JRecordContainer(this.library, this.classIndex, this.name);
453
454 bool get isAbstract => false;
455
456 bool get isClosure => false;
457
458 String toString() => '${jsElementPrefix}record_container($name)';
459 }
460
461 /// A variable that has been "boxed" to prevent name shadowing with the
441 /// original variable and ensure that this variable is updated/read with the 462 /// original variable and ensure that this variable is updated/read with the
442 /// most recent value. 463 /// most recent value.
443 /// This corresponds to BoxFieldElement; we reuse BoxLocal from the original 464 /// This corresponds to BoxFieldElement; we reuse BoxLocal from the original
444 /// algorithm to correspond to the actual name of the variable. 465 /// algorithm to correspond to the actual name of the variable.
445 class JBoxedField extends JField { 466 class JRecord extends JField {
446 final BoxLocal box; 467 final BoxLocal box;
447 JBoxedField(String name, int memberIndex, this.box, JClass containingClass, 468 JRecord(String name, int memberIndex, this.box, JClass containingClass,
448 bool isConst, bool isAssignable) 469 bool isConst)
449 : super(memberIndex, containingClass.library, containingClass, 470 : super(memberIndex, containingClass.library, containingClass,
450 new Name(name, containingClass.library), 471 new Name(name, containingClass.library),
451 isAssignable: isAssignable, isConst: isConst); 472 isStatic: false, isAssignable: true, isConst: isConst);
452 } 473 }
453 474
454 class ClosureClassDefinition implements ClassDefinition { 475 class ClosureClassDefinition implements ClassDefinition {
455 final ClassEntity cls; 476 final ClassEntity cls;
456 final SourceSpan location; 477 final SourceSpan location;
457 478
458 ClosureClassDefinition(this.cls, this.location); 479 ClosureClassDefinition(this.cls, this.location);
459 480
460 ClassKind get kind => ClassKind.closure; 481 ClassKind get kind => ClassKind.closure;
461 482
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 final SourceSpan location; 562 final SourceSpan location;
542 final MemberKind kind; 563 final MemberKind kind;
543 final ir.Node node; 564 final ir.Node node;
544 565
545 ClosureMemberDefinition(this.member, this.location, this.kind, this.node); 566 ClosureMemberDefinition(this.member, this.location, this.kind, this.node);
546 567
547 String toString() => 568 String toString() =>
548 'ClosureMemberDefinition(kind:$kind,member:$member,location:$location)'; 569 'ClosureMemberDefinition(kind:$kind,member:$member,location:$location)';
549 } 570 }
550 571
572 class RecordContainerDefinition implements ClassDefinition {
573 final ClassEntity cls;
574 final SourceSpan location;
575
576 RecordContainerDefinition(this.cls, this.location);
577
578 ClassKind get kind => ClassKind.container;
579
580 ir.Node get node =>
581 throw new UnsupportedError('RecordContainerDefinition.node for $cls');
582
583 String toString() =>
584 'RecordContainerDefinition(kind:$kind,cls:$cls,location:$location)';
585 }
586
551 /// Collection of scope data collected for a single member. 587 /// Collection of scope data collected for a single member.
552 class ScopeModel { 588 class ScopeModel {
553 /// Collection [ScopeInfo] data for the member. 589 /// Collection [ScopeInfo] data for the member.
554 KernelScopeInfo scopeInfo; 590 KernelScopeInfo scopeInfo;
555 591
556 /// Collected [CapturedScope] data for nodes. 592 /// Collected [CapturedScope] data for nodes.
557 Map<ir.Node, KernelCapturedScope> capturedScopesMap = 593 Map<ir.Node, KernelCapturedScope> capturedScopesMap =
558 <ir.Node, KernelCapturedScope>{}; 594 <ir.Node, KernelCapturedScope>{};
559 595
560 /// Collected [ScopeInfo] data for nodes. 596 /// Collected [ScopeInfo] data for nodes.
561 Map<ir.FunctionNode, KernelScopeInfo> closuresToGenerate = 597 Map<ir.FunctionNode, KernelScopeInfo> closuresToGenerate =
562 <ir.FunctionNode, KernelScopeInfo>{}; 598 <ir.FunctionNode, KernelScopeInfo>{};
563 } 599 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/js_backend/field_naming_mixin.dart ('k') | pkg/compiler/lib/src/kernel/element_map.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698