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

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

Issue 2969013002: Support creating elements from IR nodes in JsKernelToElementMap (Closed)
Patch Set: Updated cf. comments Created 3 years, 5 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 library dart2js.kernel.element_map; 5 library dart2js.kernel.element_map;
6 6
7 import 'package:kernel/ast.dart' as ir; 7 import 'package:kernel/ast.dart' as ir;
8 8
9 import '../common.dart'; 9 import '../common.dart';
10 import '../common/names.dart' show Identifiers; 10 import '../common/names.dart' show Identifiers;
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 506
507 ir.Member _getMemberNode(covariant IndexedMember member) { 507 ir.Member _getMemberNode(covariant IndexedMember member) {
508 return _memberData[member.memberIndex].node; 508 return _memberData[member.memberIndex].node;
509 } 509 }
510 510
511 ir.Class _getClassNode(covariant IndexedClass cls) { 511 ir.Class _getClassNode(covariant IndexedClass cls) {
512 return _classEnvs[cls.classIndex].cls; 512 return _classEnvs[cls.classIndex].cls;
513 } 513 }
514 } 514 }
515 515
516 /// Mixin that implements the abstract methods in [KernelToElementMapBase] by 516 /// Mixin that implements the abstract methods in [KernelToElementMapBase].
517 /// creating K-model elements. 517 abstract class ElementCreatorMixin {
518 abstract class KElementCreatorMixin {
519 ProgramEnv get _env; 518 ProgramEnv get _env;
520 List<LibraryEntity> get _libraryList; 519 List<LibraryEntity> get _libraryList;
521 List<LibraryEnv> get _libraryEnvs; 520 List<LibraryEnv> get _libraryEnvs;
522 List<ClassEntity> get _classList; 521 List<ClassEntity> get _classList;
523 List<ClassEnv> get _classEnvs; 522 List<ClassEnv> get _classEnvs;
524 List<MemberEntity> get _memberList; 523 List<MemberEntity> get _memberList;
525 List<MemberData> get _memberData; 524 List<MemberData> get _memberData;
526 525
527 Map<ir.Library, KLibrary> _libraryMap = <ir.Library, KLibrary>{}; 526 Map<ir.Library, IndexedLibrary> _libraryMap = <ir.Library, IndexedLibrary>{};
528 Map<ir.Class, KClass> _classMap = <ir.Class, KClass>{}; 527 Map<ir.Class, IndexedClass> _classMap = <ir.Class, IndexedClass>{};
529 Map<ir.TypeParameter, KTypeVariable> _typeVariableMap = 528 Map<ir.TypeParameter, TypeVariableEntity> _typeVariableMap =
530 <ir.TypeParameter, KTypeVariable>{}; 529 <ir.TypeParameter, TypeVariableEntity>{};
531 Map<ir.Member, KConstructor> _constructorMap = <ir.Member, KConstructor>{}; 530 Map<ir.Member, IndexedConstructor> _constructorMap =
532 Map<ir.Procedure, KFunction> _methodMap = <ir.Procedure, KFunction>{}; 531 <ir.Member, IndexedConstructor>{};
533 Map<ir.Field, KField> _fieldMap = <ir.Field, KField>{}; 532 Map<ir.Procedure, IndexedFunction> _methodMap =
534 Map<ir.TreeNode, KLocalFunction> _localFunctionMap = 533 <ir.Procedure, IndexedFunction>{};
535 <ir.TreeNode, KLocalFunction>{}; 534 Map<ir.Field, IndexedField> _fieldMap = <ir.Field, IndexedField>{};
535 Map<ir.TreeNode, Local> _localFunctionMap = <ir.TreeNode, Local>{};
536 536
537 Name getName(ir.Name node); 537 Name getName(ir.Name node);
538 FunctionType getFunctionType(ir.FunctionNode node); 538 FunctionType getFunctionType(ir.FunctionNode node);
539 MemberEntity getMember(ir.Member node); 539 MemberEntity getMember(ir.Member node);
540 540
541 Iterable<LibraryEntity> get _libraries { 541 Iterable<LibraryEntity> get _libraries {
542 if (_env.length != _libraryMap.length) { 542 if (_env.length != _libraryMap.length) {
543 // Create a [KLibrary] for each library. 543 // Create a [KLibrary] for each library.
544 _env.forEachLibrary((LibraryEnv env) { 544 _env.forEachLibrary((LibraryEnv env) {
545 _getLibrary(env.library, env); 545 _getLibrary(env.library, env);
546 }); 546 });
547 } 547 }
548 return _libraryMap.values; 548 return _libraryMap.values;
549 } 549 }
550 550
551 LibraryEntity _getLibrary(ir.Library node, [LibraryEnv libraryEnv]) { 551 LibraryEntity _getLibrary(ir.Library node, [LibraryEnv libraryEnv]) {
552 return _libraryMap.putIfAbsent(node, () { 552 return _libraryMap.putIfAbsent(node, () {
553 Uri canonicalUri = node.importUri; 553 Uri canonicalUri = node.importUri;
554 _libraryEnvs.add(libraryEnv ?? _env.lookupLibrary(canonicalUri)); 554 _libraryEnvs.add(libraryEnv ?? _env.lookupLibrary(canonicalUri));
555 String name = node.name; 555 String name = node.name;
556 if (name == null) { 556 if (name == null) {
557 // Use the file name as script name. 557 // Use the file name as script name.
558 String path = canonicalUri.path; 558 String path = canonicalUri.path;
559 name = path.substring(path.lastIndexOf('/') + 1); 559 name = path.substring(path.lastIndexOf('/') + 1);
560 } 560 }
561 LibraryEntity library = 561 LibraryEntity library =
562 new KLibrary(_libraryMap.length, name, canonicalUri); 562 createLibrary(_libraryMap.length, name, canonicalUri);
563 _libraryList.add(library); 563 _libraryList.add(library);
564 return library; 564 return library;
565 }); 565 });
566 } 566 }
567 567
568 ClassEntity _getClass(ir.Class node, [ClassEnv classEnv]) { 568 ClassEntity _getClass(ir.Class node, [ClassEnv classEnv]) {
569 return _classMap.putIfAbsent(node, () { 569 return _classMap.putIfAbsent(node, () {
570 KLibrary library = _getLibrary(node.enclosingLibrary); 570 KLibrary library = _getLibrary(node.enclosingLibrary);
571 if (classEnv == null) { 571 if (classEnv == null) {
572 classEnv = _libraryEnvs[library.libraryIndex].lookupClass(node.name); 572 classEnv = _libraryEnvs[library.libraryIndex].lookupClass(node.name);
573 } 573 }
574 _classEnvs.add(classEnv); 574 _classEnvs.add(classEnv);
575 ClassEntity cls = new KClass(library, _classMap.length, node.name, 575 ClassEntity cls = createClass(library, _classMap.length, node.name,
576 isAbstract: node.isAbstract); 576 isAbstract: node.isAbstract);
577 _classList.add(cls); 577 _classList.add(cls);
578 return cls; 578 return cls;
579 }); 579 });
580 } 580 }
581 581
582 TypeVariableEntity _getTypeVariable(ir.TypeParameter node) { 582 TypeVariableEntity _getTypeVariable(ir.TypeParameter node) {
583 return _typeVariableMap.putIfAbsent(node, () { 583 return _typeVariableMap.putIfAbsent(node, () {
584 if (node.parent is ir.Class) { 584 if (node.parent is ir.Class) {
585 ir.Class cls = node.parent; 585 ir.Class cls = node.parent;
586 int index = cls.typeParameters.indexOf(node); 586 int index = cls.typeParameters.indexOf(node);
587 return new KTypeVariable(_getClass(cls), node.name, index); 587 return createTypeVariable(_getClass(cls), node.name, index);
588 } 588 }
589 if (node.parent is ir.FunctionNode) { 589 if (node.parent is ir.FunctionNode) {
590 ir.FunctionNode func = node.parent; 590 ir.FunctionNode func = node.parent;
591 int index = func.typeParameters.indexOf(node); 591 int index = func.typeParameters.indexOf(node);
592 if (func.parent is ir.Constructor) { 592 if (func.parent is ir.Constructor) {
593 ir.Constructor constructor = func.parent; 593 ir.Constructor constructor = func.parent;
594 ir.Class cls = constructor.enclosingClass; 594 ir.Class cls = constructor.enclosingClass;
595 return _getTypeVariable(cls.typeParameters[index]); 595 return _getTypeVariable(cls.typeParameters[index]);
596 } 596 }
597 if (func.parent is ir.Procedure) { 597 if (func.parent is ir.Procedure) {
598 ir.Procedure procedure = func.parent; 598 ir.Procedure procedure = func.parent;
599 if (procedure.kind == ir.ProcedureKind.Factory) { 599 if (procedure.kind == ir.ProcedureKind.Factory) {
600 ir.Class cls = procedure.enclosingClass; 600 ir.Class cls = procedure.enclosingClass;
601 return _getTypeVariable(cls.typeParameters[index]); 601 return _getTypeVariable(cls.typeParameters[index]);
602 } else { 602 } else {
603 return new KTypeVariable(_getMethod(procedure), node.name, index); 603 return createTypeVariable(_getMethod(procedure), node.name, index);
604 } 604 }
605 } 605 }
606 } 606 }
607 throw new UnsupportedError('Unsupported type parameter type node $node.'); 607 throw new UnsupportedError('Unsupported type parameter type node $node.');
608 }); 608 });
609 } 609 }
610 610
611 ConstructorEntity _getConstructor(ir.Member node) { 611 ConstructorEntity _getConstructor(ir.Member node) {
612 return _constructorMap.putIfAbsent(node, () { 612 return _constructorMap.putIfAbsent(node, () {
613 int memberIndex = _memberData.length; 613 int memberIndex = _memberData.length;
614 KConstructor constructor; 614 KConstructor constructor;
615 KClass enclosingClass = _getClass(node.enclosingClass); 615 KClass enclosingClass = _getClass(node.enclosingClass);
616 Name name = getName(node.name); 616 Name name = getName(node.name);
617 bool isExternal = node.isExternal; 617 bool isExternal = node.isExternal;
618 618
619 ir.FunctionNode functionNode; 619 ir.FunctionNode functionNode;
620 if (node is ir.Constructor) { 620 if (node is ir.Constructor) {
621 functionNode = node.function; 621 functionNode = node.function;
622 constructor = new KGenerativeConstructor(memberIndex, enclosingClass, 622 constructor = createGenerativeConstructor(memberIndex, enclosingClass,
623 name, _getParameterStructure(functionNode), 623 name, _getParameterStructure(functionNode),
624 isExternal: isExternal, isConst: node.isConst); 624 isExternal: isExternal, isConst: node.isConst);
625 } else if (node is ir.Procedure) { 625 } else if (node is ir.Procedure) {
626 functionNode = node.function; 626 functionNode = node.function;
627 bool isFromEnvironment = isExternal && 627 bool isFromEnvironment = isExternal &&
628 name.text == 'fromEnvironment' && 628 name.text == 'fromEnvironment' &&
629 const ['int', 'bool', 'String'].contains(enclosingClass.name); 629 const ['int', 'bool', 'String'].contains(enclosingClass.name);
630 constructor = new KFactoryConstructor(memberIndex, enclosingClass, name, 630 constructor = createFactoryConstructor(memberIndex, enclosingClass,
631 _getParameterStructure(functionNode), 631 name, _getParameterStructure(functionNode),
632 isExternal: isExternal, 632 isExternal: isExternal,
633 isConst: node.isConst, 633 isConst: node.isConst,
634 isFromEnvironmentConstructor: isFromEnvironment); 634 isFromEnvironmentConstructor: isFromEnvironment);
635 } else { 635 } else {
636 // TODO(johnniwinther): Convert `node.location` to a [SourceSpan]. 636 // TODO(johnniwinther): Convert `node.location` to a [SourceSpan].
637 throw new SpannableAssertionFailure( 637 throw new SpannableAssertionFailure(
638 NO_LOCATION_SPANNABLE, "Unexpected constructor node: ${node}."); 638 NO_LOCATION_SPANNABLE, "Unexpected constructor node: ${node}.");
639 } 639 }
640 _memberData.add(new ConstructorData(node, functionNode)); 640 _memberData.add(new ConstructorData(node, functionNode));
641 _memberList.add(constructor); 641 _memberList.add(constructor);
642 return constructor; 642 return constructor;
643 }); 643 });
644 } 644 }
645 645
646 FunctionEntity _getMethod(ir.Procedure node) { 646 FunctionEntity _getMethod(ir.Procedure node) {
647 return _methodMap.putIfAbsent(node, () { 647 return _methodMap.putIfAbsent(node, () {
648 int memberIndex = _memberData.length; 648 int memberIndex = _memberData.length;
649 LibraryEntity library; 649 LibraryEntity library;
650 ClassEntity enclosingClass; 650 ClassEntity enclosingClass;
651 if (node.enclosingClass != null) { 651 if (node.enclosingClass != null) {
652 enclosingClass = _getClass(node.enclosingClass); 652 enclosingClass = _getClass(node.enclosingClass);
653 library = enclosingClass.library; 653 library = enclosingClass.library;
654 } else { 654 } else {
655 library = _getLibrary(node.enclosingLibrary); 655 library = _getLibrary(node.enclosingLibrary);
656 } 656 }
657 Name name = getName(node.name); 657 Name name = getName(node.name);
658 bool isStatic = node.isStatic; 658 bool isStatic = node.isStatic;
659 bool isExternal = node.isExternal; 659 bool isExternal = node.isExternal;
660 bool isAbstract = node.isAbstract; 660 bool isAbstract = node.isAbstract;
661 KFunction function; 661 IndexedFunction function;
662 AsyncMarker asyncMarker; 662 AsyncMarker asyncMarker;
663 switch (node.function.asyncMarker) { 663 switch (node.function.asyncMarker) {
664 case ir.AsyncMarker.Async: 664 case ir.AsyncMarker.Async:
665 asyncMarker = AsyncMarker.ASYNC; 665 asyncMarker = AsyncMarker.ASYNC;
666 break; 666 break;
667 case ir.AsyncMarker.AsyncStar: 667 case ir.AsyncMarker.AsyncStar:
668 asyncMarker = AsyncMarker.ASYNC_STAR; 668 asyncMarker = AsyncMarker.ASYNC_STAR;
669 break; 669 break;
670 case ir.AsyncMarker.Sync: 670 case ir.AsyncMarker.Sync:
671 asyncMarker = AsyncMarker.SYNC; 671 asyncMarker = AsyncMarker.SYNC;
672 break; 672 break;
673 case ir.AsyncMarker.SyncStar: 673 case ir.AsyncMarker.SyncStar:
674 asyncMarker = AsyncMarker.SYNC_STAR; 674 asyncMarker = AsyncMarker.SYNC_STAR;
675 break; 675 break;
676 case ir.AsyncMarker.SyncYielding: 676 case ir.AsyncMarker.SyncYielding:
677 throw new UnsupportedError( 677 throw new UnsupportedError(
678 "Async marker ${node.function.asyncMarker} is not supported."); 678 "Async marker ${node.function.asyncMarker} is not supported.");
679 } 679 }
680 switch (node.kind) { 680 switch (node.kind) {
681 case ir.ProcedureKind.Factory: 681 case ir.ProcedureKind.Factory:
682 throw new UnsupportedError("Cannot create method from factory."); 682 throw new UnsupportedError("Cannot create method from factory.");
683 case ir.ProcedureKind.Getter: 683 case ir.ProcedureKind.Getter:
684 function = new KGetter( 684 function = createGetter(
685 memberIndex, library, enclosingClass, name, asyncMarker, 685 memberIndex, library, enclosingClass, name, asyncMarker,
686 isStatic: isStatic, 686 isStatic: isStatic,
687 isExternal: isExternal, 687 isExternal: isExternal,
688 isAbstract: isAbstract); 688 isAbstract: isAbstract);
689 break; 689 break;
690 case ir.ProcedureKind.Method: 690 case ir.ProcedureKind.Method:
691 case ir.ProcedureKind.Operator: 691 case ir.ProcedureKind.Operator:
692 function = new KMethod(memberIndex, library, enclosingClass, name, 692 function = createMethod(memberIndex, library, enclosingClass, name,
693 _getParameterStructure(node.function), asyncMarker, 693 _getParameterStructure(node.function), asyncMarker,
694 isStatic: isStatic, 694 isStatic: isStatic,
695 isExternal: isExternal, 695 isExternal: isExternal,
696 isAbstract: isAbstract); 696 isAbstract: isAbstract);
697 break; 697 break;
698 case ir.ProcedureKind.Setter: 698 case ir.ProcedureKind.Setter:
699 assert(asyncMarker == AsyncMarker.SYNC); 699 assert(asyncMarker == AsyncMarker.SYNC);
700 function = new KSetter( 700 function = createSetter(
701 memberIndex, library, enclosingClass, getName(node.name).setter, 701 memberIndex, library, enclosingClass, name.setter,
702 isStatic: isStatic, 702 isStatic: isStatic,
703 isExternal: isExternal, 703 isExternal: isExternal,
704 isAbstract: isAbstract); 704 isAbstract: isAbstract);
705 break; 705 break;
706 } 706 }
707 _memberData.add(new FunctionData(node, node.function)); 707 _memberData.add(new FunctionData(node, node.function));
708 _memberList.add(function); 708 _memberList.add(function);
709 return function; 709 return function;
710 }); 710 });
711 } 711 }
712 712
713 FieldEntity _getField(ir.Field node) { 713 FieldEntity _getField(ir.Field node) {
714 return _fieldMap.putIfAbsent(node, () { 714 return _fieldMap.putIfAbsent(node, () {
715 int memberIndex = _memberData.length; 715 int memberIndex = _memberData.length;
716 LibraryEntity library; 716 LibraryEntity library;
717 ClassEntity enclosingClass; 717 ClassEntity enclosingClass;
718 if (node.enclosingClass != null) { 718 if (node.enclosingClass != null) {
719 enclosingClass = _getClass(node.enclosingClass); 719 enclosingClass = _getClass(node.enclosingClass);
720 library = enclosingClass.library; 720 library = enclosingClass.library;
721 } else { 721 } else {
722 library = _getLibrary(node.enclosingLibrary); 722 library = _getLibrary(node.enclosingLibrary);
723 } 723 }
724 Name name = getName(node.name); 724 Name name = getName(node.name);
725 bool isStatic = node.isStatic; 725 bool isStatic = node.isStatic;
726 _memberData.add(new FieldData(node)); 726 _memberData.add(new FieldData(node));
727 FieldEntity field = new KField(memberIndex, library, enclosingClass, name, 727 FieldEntity field = createField(
728 memberIndex, library, enclosingClass, name,
728 isStatic: isStatic, 729 isStatic: isStatic,
729 isAssignable: node.isMutable, 730 isAssignable: node.isMutable,
730 isConst: node.isConst); 731 isConst: node.isConst);
731 _memberList.add(field); 732 _memberList.add(field);
732 return field; 733 return field;
733 }); 734 });
734 } 735 }
735 736
736 ParameterStructure _getParameterStructure(ir.FunctionNode node) { 737 ParameterStructure _getParameterStructure(ir.FunctionNode node) {
737 // TODO(johnniwinther): Cache the computed function type. 738 // TODO(johnniwinther): Cache the computed function type.
(...skipping 10 matching lines...) Expand all
748 MemberEntity memberContext; 749 MemberEntity memberContext;
749 Entity executableContext; 750 Entity executableContext;
750 ir.TreeNode parent = node.parent; 751 ir.TreeNode parent = node.parent;
751 while (parent != null) { 752 while (parent != null) {
752 if (parent is ir.Member) { 753 if (parent is ir.Member) {
753 executableContext = memberContext = getMember(parent); 754 executableContext = memberContext = getMember(parent);
754 break; 755 break;
755 } 756 }
756 if (parent is ir.FunctionDeclaration || 757 if (parent is ir.FunctionDeclaration ||
757 parent is ir.FunctionExpression) { 758 parent is ir.FunctionExpression) {
758 KLocalFunction localFunction = _getLocalFunction(parent); 759 Local localFunction = _getLocalFunction(parent);
759 executableContext = localFunction; 760 executableContext = localFunction;
760 memberContext = localFunction.memberContext; 761 memberContext = localFunction.memberContext;
761 break; 762 break;
762 } 763 }
763 parent = parent.parent; 764 parent = parent.parent;
764 } 765 }
765 String name; 766 String name;
766 FunctionType functionType; 767 FunctionType functionType;
767 if (node is ir.FunctionDeclaration) { 768 if (node is ir.FunctionDeclaration) {
768 name = node.variable.name; 769 name = node.variable.name;
769 functionType = getFunctionType(node.function); 770 functionType = getFunctionType(node.function);
770 } else if (node is ir.FunctionExpression) { 771 } else if (node is ir.FunctionExpression) {
771 functionType = getFunctionType(node.function); 772 functionType = getFunctionType(node.function);
772 } 773 }
773 return new KLocalFunction( 774 return createLocalFunction(
774 name, memberContext, executableContext, functionType); 775 name, memberContext, executableContext, functionType);
775 }); 776 });
776 } 777 }
778
779 IndexedLibrary createLibrary(int libraryIndex, String name, Uri canonicalUri);
780
781 IndexedClass createClass(LibraryEntity library, int classIndex, String name,
782 {bool isAbstract});
783
784 TypeVariableEntity createTypeVariable(
785 Entity typeDeclaration, String name, int index);
786
787 IndexedConstructor createGenerativeConstructor(
788 int memberIndex,
789 ClassEntity enclosingClass,
790 Name name,
791 ParameterStructure parameterStructure,
792 {bool isExternal,
793 bool isConst});
794
795 IndexedConstructor createFactoryConstructor(
796 int memberIndex,
797 ClassEntity enclosingClass,
798 Name name,
799 ParameterStructure parameterStructure,
800 {bool isExternal,
801 bool isConst,
802 bool isFromEnvironmentConstructor});
803
804 IndexedFunction createGetter(int memberIndex, LibraryEntity library,
805 ClassEntity enclosingClass, Name name, AsyncMarker asyncMarker,
806 {bool isStatic, bool isExternal, bool isAbstract});
807
808 IndexedFunction createMethod(
809 int memberIndex,
810 LibraryEntity library,
811 ClassEntity enclosingClass,
812 Name name,
813 ParameterStructure parameterStructure,
814 AsyncMarker asyncMarker,
815 {bool isStatic,
816 bool isExternal,
817 bool isAbstract});
818
819 IndexedFunction createSetter(int memberIndex, LibraryEntity library,
820 ClassEntity enclosingClass, Name name,
821 {bool isStatic, bool isExternal, bool isAbstract});
822
823 IndexedField createField(int memberIndex, LibraryEntity library,
824 ClassEntity enclosingClass, Name name,
825 {bool isStatic, bool isAssignable, bool isConst});
826
827 Local createLocalFunction(String name, MemberEntity memberContext,
828 Entity executableContext, FunctionType functionType);
829 }
830
831 /// Completes the [ElementCreatorMixin] by creating K-model elements.
832 abstract class KElementCreatorMixin implements ElementCreatorMixin {
833 IndexedLibrary createLibrary(
834 int libraryIndex, String name, Uri canonicalUri) {
835 return new KLibrary(libraryIndex, name, canonicalUri);
836 }
837
838 IndexedClass createClass(LibraryEntity library, int classIndex, String name,
839 {bool isAbstract}) {
840 return new KClass(library, classIndex, name, isAbstract: isAbstract);
841 }
842
843 TypeVariableEntity createTypeVariable(
844 Entity typeDeclaration, String name, int index) {
845 return new KTypeVariable(typeDeclaration, name, index);
846 }
847
848 IndexedConstructor createGenerativeConstructor(
849 int memberIndex,
850 ClassEntity enclosingClass,
851 Name name,
852 ParameterStructure parameterStructure,
853 {bool isExternal,
854 bool isConst}) {
855 return new KGenerativeConstructor(
856 memberIndex, enclosingClass, name, parameterStructure,
857 isExternal: isExternal, isConst: isConst);
858 }
859
860 IndexedConstructor createFactoryConstructor(
861 int memberIndex,
862 ClassEntity enclosingClass,
863 Name name,
864 ParameterStructure parameterStructure,
865 {bool isExternal,
866 bool isConst,
867 bool isFromEnvironmentConstructor}) {
868 return new KFactoryConstructor(
869 memberIndex, enclosingClass, name, parameterStructure,
870 isExternal: isExternal,
871 isConst: isConst,
872 isFromEnvironmentConstructor: isFromEnvironmentConstructor);
873 }
874
875 IndexedFunction createGetter(int memberIndex, LibraryEntity library,
876 ClassEntity enclosingClass, Name name, AsyncMarker asyncMarker,
877 {bool isStatic, bool isExternal, bool isAbstract}) {
878 return new KGetter(memberIndex, library, enclosingClass, name, asyncMarker,
879 isStatic: isStatic, isExternal: isExternal, isAbstract: isAbstract);
880 }
881
882 IndexedFunction createMethod(
883 int memberIndex,
884 LibraryEntity library,
885 ClassEntity enclosingClass,
886 Name name,
887 ParameterStructure parameterStructure,
888 AsyncMarker asyncMarker,
889 {bool isStatic,
890 bool isExternal,
891 bool isAbstract}) {
892 return new KMethod(memberIndex, library, enclosingClass, name,
893 parameterStructure, asyncMarker,
894 isStatic: isStatic, isExternal: isExternal, isAbstract: isAbstract);
895 }
896
897 IndexedFunction createSetter(int memberIndex, LibraryEntity library,
898 ClassEntity enclosingClass, Name name,
899 {bool isStatic, bool isExternal, bool isAbstract}) {
900 return new KSetter(memberIndex, library, enclosingClass, name,
901 isStatic: isStatic, isExternal: isExternal, isAbstract: isAbstract);
902 }
903
904 IndexedField createField(int memberIndex, LibraryEntity library,
905 ClassEntity enclosingClass, Name name,
906 {bool isStatic, bool isAssignable, bool isConst}) {
907 return new KField(memberIndex, library, enclosingClass, name,
908 isStatic: isStatic, isAssignable: isAssignable, isConst: isConst);
909 }
910
911 Local createLocalFunction(String name, MemberEntity memberContext,
912 Entity executableContext, FunctionType functionType) {
913 return new KLocalFunction(
914 name, memberContext, executableContext, functionType);
915 }
777 } 916 }
778 917
779 /// Implementation of [KernelToElementMapForImpact] that only supports world 918 /// Implementation of [KernelToElementMapForImpact] that only supports world
780 /// impact computation. 919 /// impact computation.
781 // TODO(johnniwinther): Merge this with [KernelToElementMapForImpactImpl] when 920 // TODO(johnniwinther): Merge this with [KernelToElementMapForImpactImpl] when
782 // [JsStrategy] is the default. 921 // [JsStrategy] is the default.
783 abstract class KernelToElementMapForImpactImpl 922 abstract class KernelToElementMapForImpactImpl
784 implements 923 implements
785 KernelToElementMapBase, 924 KernelToElementMapBase,
786 KernelToElementMapForImpact, 925 KernelToElementMapForImpact,
(...skipping 27 matching lines...) Expand all
814 } 953 }
815 954
816 /// Implementation of [KernelToElementMapForImpact] that only supports world 955 /// Implementation of [KernelToElementMapForImpact] that only supports world
817 /// impact computation. 956 /// impact computation.
818 // TODO(johnniwinther): Merge this with [KernelToElementMapForImpactImpl] when 957 // TODO(johnniwinther): Merge this with [KernelToElementMapForImpactImpl] when
819 // [JsStrategy] is the default. 958 // [JsStrategy] is the default.
820 class KernelToElementMapForImpactImpl2 extends KernelToElementMapBase 959 class KernelToElementMapForImpactImpl2 extends KernelToElementMapBase
821 with 960 with
822 KernelToElementMapForImpactMixin, 961 KernelToElementMapForImpactMixin,
823 KernelToElementMapForImpactImpl, 962 KernelToElementMapForImpactImpl,
963 ElementCreatorMixin,
824 KElementCreatorMixin { 964 KElementCreatorMixin {
825 KernelToElementMapForImpactImpl2( 965 KernelToElementMapForImpactImpl2(
826 DiagnosticReporter reporter, Environment environment) 966 DiagnosticReporter reporter, Environment environment)
827 : super(reporter, environment); 967 : super(reporter, environment);
828 } 968 }
829 969
830 /// Element builder used for creating elements and types corresponding to Kernel 970 /// Element builder used for creating elements and types corresponding to Kernel
831 /// IR nodes. 971 /// IR nodes.
832 // TODO(johnniwinther): Use this in the JsStrategy 972 // TODO(johnniwinther): Use this in the JsStrategy
833 class KernelToElementMapForBuildingImpl extends KernelToElementMapBase 973 class KernelToElementMapForBuildingImpl extends KernelToElementMapBase
834 with KernelToElementMapForBuildingMixin, KElementCreatorMixin 974 with
975 KernelToElementMapForBuildingMixin,
976 ElementCreatorMixin,
977 KElementCreatorMixin
835 implements KernelToWorldBuilder { 978 implements KernelToWorldBuilder {
836 KernelToElementMapForBuildingImpl( 979 KernelToElementMapForBuildingImpl(
837 DiagnosticReporter reporter, Environment environment) 980 DiagnosticReporter reporter, Environment environment)
838 : super(reporter, environment); 981 : super(reporter, environment);
839 982
840 ConstantEnvironment get constantEnvironment => _constantEnvironment; 983 ConstantEnvironment get constantEnvironment => _constantEnvironment;
841 984
842 @override 985 @override
843 ConstantValue getFieldConstantValue(ir.Field field) { 986 ConstantValue getFieldConstantValue(ir.Field field) {
844 // TODO(johnniwinther): Cache the result in [FieldData]. 987 // TODO(johnniwinther): Cache the result in [FieldData].
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
886 } 1029 }
887 } 1030 }
888 1031
889 /// [KernelToElementMap] implementation used for both world impact computation 1032 /// [KernelToElementMap] implementation used for both world impact computation
890 /// and SSA building. 1033 /// and SSA building.
891 // TODO(johnniwinther): Remove this when [JsStrategy] is the default. 1034 // TODO(johnniwinther): Remove this when [JsStrategy] is the default.
892 class KernelToElementMapImpl extends KernelToElementMapForBuildingImpl 1035 class KernelToElementMapImpl extends KernelToElementMapForBuildingImpl
893 with 1036 with
894 KernelToElementMapForImpactMixin, 1037 KernelToElementMapForImpactMixin,
895 KernelToElementMapForImpactImpl, 1038 KernelToElementMapForImpactImpl,
1039 ElementCreatorMixin,
896 KElementCreatorMixin 1040 KElementCreatorMixin
897 implements KernelToElementMapForImpactImpl2 { 1041 implements KernelToElementMapForImpactImpl2 {
898 KernelToElementMapImpl(DiagnosticReporter reporter, Environment environment) 1042 KernelToElementMapImpl(DiagnosticReporter reporter, Environment environment)
899 : super(reporter, environment); 1043 : super(reporter, environment);
900 } 1044 }
901 1045
902 class KernelElementEnvironment implements ElementEnvironment { 1046 class KernelElementEnvironment implements ElementEnvironment {
903 final KernelToElementMapBase elementMap; 1047 final KernelToElementMapBase elementMap;
904 1048
905 KernelElementEnvironment(this.elementMap); 1049 KernelElementEnvironment(this.elementMap);
(...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after
1526 MemberEntity toBackendMember(covariant IndexedMember member) { 1670 MemberEntity toBackendMember(covariant IndexedMember member) {
1527 return _backend._memberList[member.memberIndex]; 1671 return _backend._memberList[member.memberIndex];
1528 } 1672 }
1529 1673
1530 MemberEntity toFrontendMember(covariant IndexedMember member) { 1674 MemberEntity toFrontendMember(covariant IndexedMember member) {
1531 return _frontend._memberList[member.memberIndex]; 1675 return _frontend._memberList[member.memberIndex];
1532 } 1676 }
1533 } 1677 }
1534 1678
1535 class JsKernelToElementMap extends KernelToElementMapBase 1679 class JsKernelToElementMap extends KernelToElementMapBase
1536 with KernelToElementMapForBuildingMixin, JsElementCreatorMixin 1680 with
1537 implements KernelToWorldBuilder { 1681 KernelToElementMapForBuildingMixin,
1682 JsElementCreatorMixin,
1683 // TODO(johnniwinther): Avoid mixin in [ElementCreatorMixin]. The
1684 // codegen world should be a strict subset of the resolution world and
1685 // creating elements for IR nodes should therefore not be needed.
1686 // Currently some are created purely for testing (like
1687 // `element == commonElements.foo`, where 'foo' might not be live).
1688 // Others are created because we do a
1689 // `elementEnvironment.forEachLibraryMember(...)` call on each emitted
1690 // library.
1691 ElementCreatorMixin
1692 implements
1693 KernelToWorldBuilder {
1538 JsToFrontendMap _jsToFrontendMap; 1694 JsToFrontendMap _jsToFrontendMap;
1539 1695
1540 Map<ir.Library, JLibrary> _libraryMap = <ir.Library, JLibrary>{};
1541 Map<ir.Class, JClass> _classMap = <ir.Class, JClass>{};
1542 Map<ir.TypeParameter, JTypeVariable> _typeVariableMap =
1543 <ir.TypeParameter, JTypeVariable>{};
1544 Map<ir.Member, JConstructor> _constructorMap = <ir.Member, JConstructor>{};
1545 Map<ir.Procedure, JFunction> _methodMap = <ir.Procedure, JFunction>{};
1546 Map<ir.Field, JField> _fieldMap = <ir.Field, JField>{};
1547
1548 JsKernelToElementMap(DiagnosticReporter reporter, Environment environment, 1696 JsKernelToElementMap(DiagnosticReporter reporter, Environment environment,
1549 KernelToElementMapForImpactImpl _elementMap) 1697 KernelToElementMapForImpactImpl _elementMap)
1550 : super(reporter, environment) { 1698 : super(reporter, environment) {
1551 _jsToFrontendMap = new JsToFrontendMapImpl(_elementMap, this); 1699 _jsToFrontendMap = new JsToFrontendMapImpl(_elementMap, this);
1552 _env.copyFrom(_elementMap._env); 1700 _env.copyFrom(_elementMap._env);
1553 for (int libraryIndex = 0; 1701 for (int libraryIndex = 0;
1554 libraryIndex < _elementMap._libraryEnvs.length; 1702 libraryIndex < _elementMap._libraryEnvs.length;
1555 libraryIndex++) { 1703 libraryIndex++) {
1556 LibraryEnv env = _elementMap._libraryEnvs[libraryIndex]; 1704 LibraryEnv env = _elementMap._libraryEnvs[libraryIndex];
1557 LibraryEntity oldLibrary = _elementMap._libraryList[libraryIndex]; 1705 LibraryEntity oldLibrary = _elementMap._libraryList[libraryIndex];
1558 JLibrary newLibrary = createLibrary(oldLibrary); 1706 LibraryEntity newLibrary = convertLibrary(oldLibrary);
1559 _libraryMap[env.library] = newLibrary; 1707 _libraryMap[env.library] = newLibrary;
1560 _libraryList.add(newLibrary); 1708 _libraryList.add(newLibrary);
1561 _libraryEnvs.add(env); 1709 _libraryEnvs.add(env);
1562 } 1710 }
1563 for (int classIndex = 0; 1711 for (int classIndex = 0;
1564 classIndex < _elementMap._classEnvs.length; 1712 classIndex < _elementMap._classEnvs.length;
1565 classIndex++) { 1713 classIndex++) {
1566 ClassEnv env = _elementMap._classEnvs[classIndex]; 1714 ClassEnv env = _elementMap._classEnvs[classIndex];
1567 ClassEntity oldClass = _elementMap._classList[classIndex]; 1715 ClassEntity oldClass = _elementMap._classList[classIndex];
1568 IndexedLibrary oldLibrary = oldClass.library; 1716 IndexedLibrary oldLibrary = oldClass.library;
1569 JLibrary newLibrary = _libraryList[oldLibrary.libraryIndex]; 1717 LibraryEntity newLibrary = _libraryList[oldLibrary.libraryIndex];
1570 JClass newClass = createClass(newLibrary, oldClass); 1718 ClassEntity newClass = convertClass(newLibrary, oldClass);
1571 _classMap[env.cls] = newClass; 1719 _classMap[env.cls] = newClass;
1572 _classList.add(newClass); 1720 _classList.add(newClass);
1573 _classEnvs.add(env); 1721 _classEnvs.add(env);
1574 } 1722 }
1575 for (int memberIndex = 0; 1723 for (int memberIndex = 0;
1576 memberIndex < _elementMap._memberData.length; 1724 memberIndex < _elementMap._memberData.length;
1577 memberIndex++) { 1725 memberIndex++) {
1578 MemberData data = _elementMap._memberData[memberIndex]; 1726 MemberData data = _elementMap._memberData[memberIndex];
1579 MemberEntity oldMember = _elementMap._memberList[memberIndex]; 1727 MemberEntity oldMember = _elementMap._memberList[memberIndex];
1580 IndexedLibrary oldLibrary = oldMember.library; 1728 IndexedLibrary oldLibrary = oldMember.library;
1581 IndexedClass oldClass = oldMember.enclosingClass; 1729 IndexedClass oldClass = oldMember.enclosingClass;
1582 JLibrary newLibrary = _libraryList[oldLibrary.libraryIndex]; 1730 LibraryEntity newLibrary = _libraryList[oldLibrary.libraryIndex];
1583 JClass newClass = 1731 ClassEntity newClass =
1584 oldClass != null ? _classList[oldClass.classIndex] : null; 1732 oldClass != null ? _classList[oldClass.classIndex] : null;
1585 JMember newMember = createMember(newLibrary, newClass, oldMember); 1733 IndexedMember newMember = convertMember(newLibrary, newClass, oldMember);
1586 _memberList.add(newMember); 1734 _memberList.add(newMember);
1587 _memberData.add(data); 1735 _memberData.add(data);
1588 if (newMember.isField) { 1736 if (newMember.isField) {
1589 _fieldMap[data.node] = newMember; 1737 _fieldMap[data.node] = newMember;
1590 } else if (newMember.isConstructor) { 1738 } else if (newMember.isConstructor) {
1591 _constructorMap[data.node] = newMember; 1739 _constructorMap[data.node] = newMember;
1592 } else { 1740 } else {
1593 _methodMap[data.node] = newMember; 1741 _methodMap[data.node] = newMember;
1594 } 1742 }
1595 } 1743 }
(...skipping 27 matching lines...) Expand all
1623 ClassEntity cls = _classMap[node]; 1771 ClassEntity cls = _classMap[node];
1624 assert(cls != null, "No class entity for $node"); 1772 assert(cls != null, "No class entity for $node");
1625 return cls; 1773 return cls;
1626 } 1774 }
1627 1775
1628 @override 1776 @override
1629 TypeVariableEntity _getTypeVariable(ir.TypeParameter node) { 1777 TypeVariableEntity _getTypeVariable(ir.TypeParameter node) {
1630 throw new UnsupportedError("JsKernelToElementMap._getTypeVariable"); 1778 throw new UnsupportedError("JsKernelToElementMap._getTypeVariable");
1631 } 1779 }
1632 1780
1633 @override 1781 // TODO(johnniwinther): Reinsert these when [ElementCreatorMixin] is no longer
1782 // mixed in.
1783 /*@override
1634 FieldEntity _getField(ir.Field node) { 1784 FieldEntity _getField(ir.Field node) {
1635 FieldEntity field = _fieldMap[node]; 1785 FieldEntity field = _fieldMap[node];
1636 assert(field != null, "No field entity for $node"); 1786 assert(field != null, "No field entity for $node");
1637 return field; 1787 return field;
1638 } 1788 }*/
1639 1789
1640 @override 1790 /*@override
1641 FunctionEntity _getMethod(ir.Procedure node) { 1791 FunctionEntity _getMethod(ir.Procedure node) {
1642 FunctionEntity function = _methodMap[node]; 1792 FunctionEntity function = _methodMap[node];
1643 assert(function != null, "No function entity for $node"); 1793 assert(function != null, "No function entity for $node");
1644 return function; 1794 return function;
1645 } 1795 }*/
1646 1796
1647 @override 1797 @override
1648 ConstructorEntity _getConstructor(ir.Member node) { 1798 ConstructorEntity _getConstructor(ir.Member node) {
1649 ConstructorEntity constructor = _constructorMap[node]; 1799 ConstructorEntity constructor = _constructorMap[node];
1650 assert(constructor != null, "No constructor entity for $node"); 1800 assert(constructor != null, "No constructor entity for $node");
1651 return constructor; 1801 return constructor;
1652 } 1802 }
1653 1803
1654 @override 1804 @override
1655 ir.Member getMemberNode(MemberEntity member) { 1805 ir.Member getMemberNode(MemberEntity member) {
(...skipping 21 matching lines...) Expand all
1677 throw new UnsupportedError( 1827 throw new UnsupportedError(
1678 "JsKernelToElementMap.getConstantFieldInitializer"); 1828 "JsKernelToElementMap.getConstantFieldInitializer");
1679 } 1829 }
1680 1830
1681 @override 1831 @override
1682 bool hasConstantFieldInitializer(FieldEntity field) { 1832 bool hasConstantFieldInitializer(FieldEntity field) {
1683 throw new UnsupportedError( 1833 throw new UnsupportedError(
1684 "JsKernelToElementMap.hasConstantFieldInitializer"); 1834 "JsKernelToElementMap.hasConstantFieldInitializer");
1685 } 1835 }
1686 } 1836 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/js_model/js_strategy.dart ('k') | pkg/compiler/lib/src/kernel/kelements.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698