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

Side by Side Diff: pkg/compiler/lib/src/elements/modelx.dart

Issue 1383483006: Extract DiagnosticReporter implementation from Compiler. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Fixes after rebase. Created 5 years, 2 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
« no previous file with comments | « pkg/compiler/lib/src/elements/elements.dart ('k') | pkg/compiler/lib/src/enqueue.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 elements.modelx; 5 library elements.modelx;
6 6
7 import '../common/resolution.dart' show 7 import '../common/resolution.dart' show
8 Resolution, 8 Resolution,
9 Parsing; 9 Parsing;
10 import '../compiler.dart' show 10 import '../compiler.dart' show
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 final int hashCode = ++elementHashCode; 64 final int hashCode = ++elementHashCode;
65 List<MetadataAnnotation> metadataInternal; 65 List<MetadataAnnotation> metadataInternal;
66 66
67 ElementX(this.name, this.kind, this.enclosingElement) { 67 ElementX(this.name, this.kind, this.enclosingElement) {
68 assert(isErroneous || implementationLibrary != null); 68 assert(isErroneous || implementationLibrary != null);
69 } 69 }
70 70
71 Modifiers get modifiers => Modifiers.EMPTY; 71 Modifiers get modifiers => Modifiers.EMPTY;
72 72
73 Node parseNode(Parsing parsing) { 73 Node parseNode(Parsing parsing) {
74 parsing.listener.internalError(this, 74 parsing.reporter.internalError(this,
75 'parseNode not implemented on $this.'); 75 'parseNode not implemented on $this.');
76 return null; 76 return null;
77 } 77 }
78 78
79 void set metadata(List<MetadataAnnotation> metadata) { 79 void set metadata(List<MetadataAnnotation> metadata) {
80 assert(metadataInternal == null); 80 assert(metadataInternal == null);
81 for (MetadataAnnotationX annotation in metadata) { 81 for (MetadataAnnotationX annotation in metadata) {
82 assert(annotation.annotatedElement == null); 82 assert(annotation.annotatedElement == null);
83 annotation.annotatedElement = this; 83 annotation.annotatedElement = this;
84 } 84 }
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 final WrappedMessage info; 464 final WrappedMessage info;
465 465
466 /// The element whose usage cause a warning. 466 /// The element whose usage cause a warning.
467 final Element wrappedElement; 467 final Element wrappedElement;
468 468
469 WarnOnUseElementX(WrappedMessage this.warning, WrappedMessage this.info, 469 WarnOnUseElementX(WrappedMessage this.warning, WrappedMessage this.info,
470 Element enclosingElement, Element wrappedElement) 470 Element enclosingElement, Element wrappedElement)
471 : this.wrappedElement = wrappedElement, 471 : this.wrappedElement = wrappedElement,
472 super(wrappedElement.name, ElementKind.WARN_ON_USE, enclosingElement); 472 super(wrappedElement.name, ElementKind.WARN_ON_USE, enclosingElement);
473 473
474 Element unwrap(DiagnosticListener listener, Spannable usageSpannable) { 474 Element unwrap(DiagnosticReporter reporter, Spannable usageSpannable) {
475 var unwrapped = wrappedElement; 475 var unwrapped = wrappedElement;
476 if (warning != null) { 476 if (warning != null) {
477 Spannable spannable = warning.spannable; 477 Spannable spannable = warning.spannable;
478 if (spannable == null) spannable = usageSpannable; 478 if (spannable == null) spannable = usageSpannable;
479 DiagnosticMessage warningMessage = listener.createMessage( 479 DiagnosticMessage warningMessage = reporter.createMessage(
480 spannable, warning.messageKind, warning.messageArguments); 480 spannable, warning.messageKind, warning.messageArguments);
481 List<DiagnosticMessage> infos = <DiagnosticMessage>[]; 481 List<DiagnosticMessage> infos = <DiagnosticMessage>[];
482 if (info != null) { 482 if (info != null) {
483 Spannable spannable = info.spannable; 483 Spannable spannable = info.spannable;
484 if (spannable == null) spannable = usageSpannable; 484 if (spannable == null) spannable = usageSpannable;
485 infos.add(listener.createMessage( 485 infos.add(reporter.createMessage(
486 spannable, info.messageKind, info.messageArguments)); 486 spannable, info.messageKind, info.messageArguments));
487 } 487 }
488 listener.reportWarning(warningMessage, infos); 488 reporter.reportWarning(warningMessage, infos);
489 } 489 }
490 if (unwrapped.isWarnOnUse) { 490 if (unwrapped.isWarnOnUse) {
491 unwrapped = unwrapped.unwrap(listener, usageSpannable); 491 unwrapped = unwrapped.unwrap(reporter, usageSpannable);
492 } 492 }
493 return unwrapped; 493 return unwrapped;
494 } 494 }
495 495
496 accept(ElementVisitor visitor, arg) { 496 accept(ElementVisitor visitor, arg) {
497 return visitor.visitWarnOnUseElement(this, arg); 497 return visitor.visitWarnOnUseElement(this, arg);
498 } 498 }
499 } 499 }
500 500
501 abstract class AmbiguousElementX extends ElementX implements AmbiguousElement { 501 abstract class AmbiguousElementX extends ElementX implements AmbiguousElement {
(...skipping 29 matching lines...) Expand all
531 while (element.isAmbiguous) { 531 while (element.isAmbiguous) {
532 AmbiguousElement ambiguous = element; 532 AmbiguousElement ambiguous = element;
533 set.add(ambiguous.newElement); 533 set.add(ambiguous.newElement);
534 element = ambiguous.existingElement; 534 element = ambiguous.existingElement;
535 } 535 }
536 set.add(element); 536 set.add(element);
537 return set; 537 return set;
538 } 538 }
539 539
540 List<DiagnosticMessage> computeInfos(Element context, 540 List<DiagnosticMessage> computeInfos(Element context,
541 DiagnosticListener listener) { 541 DiagnosticReporter reporter) {
542 return const <DiagnosticMessage>[]; 542 return const <DiagnosticMessage>[];
543 } 543 }
544 544
545 accept(ElementVisitor visitor, arg) { 545 accept(ElementVisitor visitor, arg) {
546 return visitor.visitAmbiguousElement(this, arg); 546 return visitor.visitAmbiguousElement(this, arg);
547 } 547 }
548 548
549 bool get isTopLevel => false; 549 bool get isTopLevel => false;
550 550
551 DynamicType get type => const DynamicType(); 551 DynamicType get type => const DynamicType();
552 } 552 }
553 553
554 /// Element synthesized to diagnose an ambiguous import. 554 /// Element synthesized to diagnose an ambiguous import.
555 class AmbiguousImportX extends AmbiguousElementX { 555 class AmbiguousImportX extends AmbiguousElementX {
556 AmbiguousImportX( 556 AmbiguousImportX(
557 MessageKind messageKind, 557 MessageKind messageKind,
558 Map messageArguments, 558 Map messageArguments,
559 Element enclosingElement, Element existingElement, Element newElement) 559 Element enclosingElement, Element existingElement, Element newElement)
560 : super(messageKind, messageArguments, enclosingElement, existingElement, 560 : super(messageKind, messageArguments, enclosingElement, existingElement,
561 newElement); 561 newElement);
562 562
563 List<DiagnosticMessage> computeInfos( 563 List<DiagnosticMessage> computeInfos(
564 Element context, 564 Element context,
565 DiagnosticListener listener) { 565 DiagnosticReporter reporter) {
566 List<DiagnosticMessage> infos = <DiagnosticMessage>[]; 566 List<DiagnosticMessage> infos = <DiagnosticMessage>[];
567 Setlet ambiguousElements = flatten(); 567 Setlet ambiguousElements = flatten();
568 MessageKind code = (ambiguousElements.length == 1) 568 MessageKind code = (ambiguousElements.length == 1)
569 ? MessageKind.AMBIGUOUS_REEXPORT : MessageKind.AMBIGUOUS_LOCATION; 569 ? MessageKind.AMBIGUOUS_REEXPORT : MessageKind.AMBIGUOUS_LOCATION;
570 LibraryElementX importer = context.library; 570 LibraryElementX importer = context.library;
571 for (Element element in ambiguousElements) { 571 for (Element element in ambiguousElements) {
572 Map arguments = {'name': element.name}; 572 Map arguments = {'name': element.name};
573 infos.add(listener.createMessage(element, code, arguments)); 573 infos.add(reporter.createMessage(element, code, arguments));
574 listener.withCurrentElement(importer, () { 574 reporter.withCurrentElement(importer, () {
575 for (ImportElement import in importer.importers.getImports(element)) { 575 for (ImportElement import in importer.importers.getImports(element)) {
576 infos.add(listener.createMessage( 576 infos.add(reporter.createMessage(
577 import, MessageKind.IMPORTED_HERE, arguments)); 577 import, MessageKind.IMPORTED_HERE, arguments));
578 } 578 }
579 }); 579 });
580 } 580 }
581 return infos; 581 return infos;
582 } 582 }
583 } 583 }
584 584
585 /// Element synthesized to recover from a duplicated member of an element. 585 /// Element synthesized to recover from a duplicated member of an element.
586 class DuplicatedElementX extends AmbiguousElementX { 586 class DuplicatedElementX extends AmbiguousElementX {
(...skipping 10 matching lines...) Expand all
597 class ScopeX { 597 class ScopeX {
598 final Map<String, Element> contents = new Map<String, Element>(); 598 final Map<String, Element> contents = new Map<String, Element>();
599 599
600 bool get isEmpty => contents.isEmpty; 600 bool get isEmpty => contents.isEmpty;
601 Iterable<Element> get values => contents.values; 601 Iterable<Element> get values => contents.values;
602 602
603 Element lookup(String name) { 603 Element lookup(String name) {
604 return contents[name]; 604 return contents[name];
605 } 605 }
606 606
607 void add(Element element, DiagnosticListener listener) { 607 void add(Element element, DiagnosticReporter reporter) {
608 String name = element.name; 608 String name = element.name;
609 if (element.isAccessor) { 609 if (element.isAccessor) {
610 addAccessor(element, contents[name], listener); 610 addAccessor(element, contents[name], reporter);
611 } else { 611 } else {
612 Element existing = contents.putIfAbsent(name, () => element); 612 Element existing = contents.putIfAbsent(name, () => element);
613 if (!identical(existing, element)) { 613 if (!identical(existing, element)) {
614 listener.reportError( 614 reporter.reportError(
615 listener.createMessage( 615 reporter.createMessage(
616 element, 616 element,
617 MessageKind.DUPLICATE_DEFINITION, 617 MessageKind.DUPLICATE_DEFINITION,
618 {'name': name}), 618 {'name': name}),
619 <DiagnosticMessage>[ 619 <DiagnosticMessage>[
620 listener.createMessage( 620 reporter.createMessage(
621 existing, 621 existing,
622 MessageKind.EXISTING_DEFINITION, 622 MessageKind.EXISTING_DEFINITION,
623 {'name': name}), 623 {'name': name}),
624 ]); 624 ]);
625 } 625 }
626 } 626 }
627 } 627 }
628 628
629 /** 629 /**
630 * Adds a definition for an [accessor] (getter or setter) to a scope. 630 * Adds a definition for an [accessor] (getter or setter) to a scope.
631 * The definition binds to an abstract field that can hold both a getter 631 * The definition binds to an abstract field that can hold both a getter
632 * and a setter. 632 * and a setter.
633 * 633 *
634 * The abstract field is added once, for the first getter or setter, and 634 * The abstract field is added once, for the first getter or setter, and
635 * reused if the other one is also added. 635 * reused if the other one is also added.
636 * The abstract field should not be treated as a proper member of the 636 * The abstract field should not be treated as a proper member of the
637 * container, it's simply a way to return two results for one lookup. 637 * container, it's simply a way to return two results for one lookup.
638 * That is, the getter or setter does not have the abstract field as enclosing 638 * That is, the getter or setter does not have the abstract field as enclosing
639 * element, they are enclosed by the class or compilation unit, as is the 639 * element, they are enclosed by the class or compilation unit, as is the
640 * abstract field. 640 * abstract field.
641 */ 641 */
642 void addAccessor(AccessorElementX accessor, 642 void addAccessor(AccessorElementX accessor,
643 Element existing, 643 Element existing,
644 DiagnosticListener listener) { 644 DiagnosticReporter reporter) {
645 void reportError(Element other) { 645 void reportError(Element other) {
646 listener.reportError( 646 reporter.reportError(
647 listener.createMessage( 647 reporter.createMessage(
648 accessor, 648 accessor,
649 MessageKind.DUPLICATE_DEFINITION, 649 MessageKind.DUPLICATE_DEFINITION,
650 {'name': accessor.name}), 650 {'name': accessor.name}),
651 <DiagnosticMessage>[ 651 <DiagnosticMessage>[
652 listener.createMessage( 652 reporter.createMessage(
653 other, 653 other,
654 MessageKind.EXISTING_DEFINITION, 654 MessageKind.EXISTING_DEFINITION,
655 {'name': accessor.name}), 655 {'name': accessor.name}),
656 ]); 656 ]);
657 657
658 contents[accessor.name] = new DuplicatedElementX( 658 contents[accessor.name] = new DuplicatedElementX(
659 MessageKind.DUPLICATE_DEFINITION, {'name': accessor.name}, 659 MessageKind.DUPLICATE_DEFINITION, {'name': accessor.name},
660 accessor.memberContext.enclosingElement, other, accessor); 660 accessor.memberContext.enclosingElement, other, accessor);
661 } 661 }
662 662
(...skipping 22 matching lines...) Expand all
685 } else { 685 } else {
686 Element container = accessor.enclosingClassOrCompilationUnit; 686 Element container = accessor.enclosingClassOrCompilationUnit;
687 AbstractFieldElementX field = 687 AbstractFieldElementX field =
688 new AbstractFieldElementX(accessor.name, container); 688 new AbstractFieldElementX(accessor.name, container);
689 accessor.abstractField = field; 689 accessor.abstractField = field;
690 if (accessor.isGetter) { 690 if (accessor.isGetter) {
691 field.getter = accessor; 691 field.getter = accessor;
692 } else { 692 } else {
693 field.setter = accessor; 693 field.setter = accessor;
694 } 694 }
695 add(field, listener); 695 add(field, reporter);
696 } 696 }
697 } 697 }
698 } 698 }
699 699
700 class CompilationUnitElementX extends ElementX 700 class CompilationUnitElementX extends ElementX
701 with CompilationUnitElementCommon 701 with CompilationUnitElementCommon
702 implements CompilationUnitElement { 702 implements CompilationUnitElement {
703 final Script script; 703 final Script script;
704 PartOf partTag; 704 PartOf partTag;
705 Link<Element> localMembers = const Link<Element>(); 705 Link<Element> localMembers = const Link<Element>();
(...skipping 19 matching lines...) Expand all
725 if (metadataInternal == null) { 725 if (metadataInternal == null) {
726 metadataInternal = <MetadataAnnotation>[]; 726 metadataInternal = <MetadataAnnotation>[];
727 } 727 }
728 metadataInternal.addAll(metadata); 728 metadataInternal.addAll(metadata);
729 } 729 }
730 730
731 void forEachLocalMember(f(Element element)) { 731 void forEachLocalMember(f(Element element)) {
732 localMembers.forEach(f); 732 localMembers.forEach(f);
733 } 733 }
734 734
735 void addMember(Element element, DiagnosticListener listener) { 735 void addMember(Element element, DiagnosticReporter reporter) {
736 // Keep a list of top level members. 736 // Keep a list of top level members.
737 localMembers = localMembers.prepend(element); 737 localMembers = localMembers.prepend(element);
738 // Provide the member to the library to build scope. 738 // Provide the member to the library to build scope.
739 if (enclosingElement.isPatch) { 739 if (enclosingElement.isPatch) {
740 implementationLibrary.addMember(element, listener); 740 implementationLibrary.addMember(element, reporter);
741 } else { 741 } else {
742 library.addMember(element, listener); 742 library.addMember(element, reporter);
743 } 743 }
744 } 744 }
745 745
746 void setPartOf(PartOf tag, DiagnosticListener listener) { 746 void setPartOf(PartOf tag, DiagnosticReporter reporter) {
747 LibraryElementX library = enclosingElement; 747 LibraryElementX library = enclosingElement;
748 if (library.entryCompilationUnit == this) { 748 if (library.entryCompilationUnit == this) {
749 partTag = tag; 749 partTag = tag;
750 listener.reportErrorMessage( 750 reporter.reportErrorMessage(
751 tag, MessageKind.IMPORT_PART_OF); 751 tag, MessageKind.IMPORT_PART_OF);
752 return; 752 return;
753 } 753 }
754 if (!localMembers.isEmpty) { 754 if (!localMembers.isEmpty) {
755 listener.reportErrorMessage( 755 reporter.reportErrorMessage(
756 tag, MessageKind.BEFORE_TOP_LEVEL); 756 tag, MessageKind.BEFORE_TOP_LEVEL);
757 return; 757 return;
758 } 758 }
759 if (partTag != null) { 759 if (partTag != null) {
760 listener.reportWarningMessage(tag, MessageKind.DUPLICATED_PART_OF); 760 reporter.reportWarningMessage(tag, MessageKind.DUPLICATED_PART_OF);
761 return; 761 return;
762 } 762 }
763 partTag = tag; 763 partTag = tag;
764 LibraryName libraryTag = library.libraryTag; 764 LibraryName libraryTag = library.libraryTag;
765 String actualName = tag.name.toString(); 765 String actualName = tag.name.toString();
766 if (libraryTag != null) { 766 if (libraryTag != null) {
767 String expectedName = libraryTag.name.toString(); 767 String expectedName = libraryTag.name.toString();
768 if (expectedName != actualName) { 768 if (expectedName != actualName) {
769 listener.reportWarningMessage( 769 reporter.reportWarningMessage(
770 tag.name, 770 tag.name,
771 MessageKind.LIBRARY_NAME_MISMATCH, 771 MessageKind.LIBRARY_NAME_MISMATCH,
772 {'libraryName': expectedName}); 772 {'libraryName': expectedName});
773 } 773 }
774 } else { 774 } else {
775 listener.reportWarning( 775 reporter.reportWarning(
776 listener.createMessage( 776 reporter.createMessage(
777 library, 777 library,
778 MessageKind.MISSING_LIBRARY_NAME, 778 MessageKind.MISSING_LIBRARY_NAME,
779 {'libraryName': actualName}), 779 {'libraryName': actualName}),
780 <DiagnosticMessage>[ 780 <DiagnosticMessage>[
781 listener.createMessage( 781 reporter.createMessage(
782 tag.name, 782 tag.name,
783 MessageKind.THIS_IS_THE_PART_OF_TAG), 783 MessageKind.THIS_IS_THE_PART_OF_TAG),
784 ]); 784 ]);
785 } 785 }
786 } 786 }
787 787
788 bool get hasMembers => !localMembers.isEmpty; 788 bool get hasMembers => !localMembers.isEmpty;
789 789
790 Element get analyzableElement => library; 790 Element get analyzableElement => library;
791 791
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
830 /** 830 /**
831 * Adds [element] to the import scope of this library. 831 * Adds [element] to the import scope of this library.
832 * 832 *
833 * If an element by the same name is already in the imported scope, an 833 * If an element by the same name is already in the imported scope, an
834 * [ErroneousElement] will be put in the imported scope, allowing for 834 * [ErroneousElement] will be put in the imported scope, allowing for
835 * detection of ambiguous uses of imported names. 835 * detection of ambiguous uses of imported names.
836 */ 836 */
837 void addImport(Element enclosingElement, 837 void addImport(Element enclosingElement,
838 Element element, 838 Element element,
839 ImportElement import, 839 ImportElement import,
840 DiagnosticListener listener) { 840 DiagnosticReporter reporter) {
841 LibraryElementX library = enclosingElement.library; 841 LibraryElementX library = enclosingElement.library;
842 Importers importers = library.importers; 842 Importers importers = library.importers;
843 843
844 String name = element.name; 844 String name = element.name;
845 845
846 // The loadLibrary function always shadows existing bindings to that name. 846 // The loadLibrary function always shadows existing bindings to that name.
847 if (element.isDeferredLoaderGetter) { 847 if (element.isDeferredLoaderGetter) {
848 importScope.remove(name); 848 importScope.remove(name);
849 // TODO(sigurdm): Print a hint. 849 // TODO(sigurdm): Print a hint.
850 } 850 }
851 Element existing = importScope.putIfAbsent(name, () => element); 851 Element existing = importScope.putIfAbsent(name, () => element);
852 importers.registerImport(element, import); 852 importers.registerImport(element, import);
853 853
854 void registerWarnOnUseElement(ImportElement import, 854 void registerWarnOnUseElement(ImportElement import,
855 MessageKind messageKind, 855 MessageKind messageKind,
856 Element hidingElement, 856 Element hidingElement,
857 Element hiddenElement) { 857 Element hiddenElement) {
858 Uri hiddenUri = hiddenElement.library.canonicalUri; 858 Uri hiddenUri = hiddenElement.library.canonicalUri;
859 Uri hidingUri = hidingElement.library.canonicalUri; 859 Uri hidingUri = hidingElement.library.canonicalUri;
860 Element element = new WarnOnUseElementX( 860 Element element = new WarnOnUseElementX(
861 new WrappedMessage( 861 new WrappedMessage(
862 null, // Report on reference to [hidingElement]. 862 null, // Report on reference to [hidingElement].
863 messageKind, 863 messageKind,
864 {'name': name, 'hiddenUri': hiddenUri, 'hidingUri': hidingUri}), 864 {'name': name, 'hiddenUri': hiddenUri, 'hidingUri': hidingUri}),
865 new WrappedMessage( 865 new WrappedMessage(
866 listener.spanFromSpannable(import), 866 reporter.spanFromSpannable(import),
867 MessageKind.IMPORTED_HERE, 867 MessageKind.IMPORTED_HERE,
868 {'name': name}), 868 {'name': name}),
869 enclosingElement, hidingElement); 869 enclosingElement, hidingElement);
870 importScope[name] = element; 870 importScope[name] = element;
871 importers.registerImport(element, import); 871 importers.registerImport(element, import);
872 } 872 }
873 873
874 if (existing != element) { 874 if (existing != element) {
875 ImportElement existingImport = importers.getImport(existing); 875 ImportElement existingImport = importers.getImport(existing);
876 if (existing.library.isPlatformLibrary && 876 if (existing.library.isPlatformLibrary &&
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
1058 } 1058 }
1059 1059
1060 CompilationUnitElement get compilationUnit => entryCompilationUnit; 1060 CompilationUnitElement get compilationUnit => entryCompilationUnit;
1061 1061
1062 Element get analyzableElement => this; 1062 Element get analyzableElement => this;
1063 1063
1064 void addCompilationUnit(CompilationUnitElement element) { 1064 void addCompilationUnit(CompilationUnitElement element) {
1065 compilationUnits = compilationUnits.prepend(element); 1065 compilationUnits = compilationUnits.prepend(element);
1066 } 1066 }
1067 1067
1068 void addTag(LibraryTag tag, DiagnosticListener listener) { 1068 void addTag(LibraryTag tag, DiagnosticReporter reporter) {
1069 if (tagsCache != null) { 1069 if (tagsCache != null) {
1070 listener.internalError(tag, 1070 reporter.internalError(tag,
1071 "Library tags for $this have already been computed."); 1071 "Library tags for $this have already been computed.");
1072 } 1072 }
1073 tagsBuilder.addLast(tag); 1073 tagsBuilder.addLast(tag);
1074 } 1074 }
1075 1075
1076 Iterable<LibraryTag> get tags { 1076 Iterable<LibraryTag> get tags {
1077 if (tagsCache == null) { 1077 if (tagsCache == null) {
1078 tagsCache = tagsBuilder.toList(); 1078 tagsCache = tagsBuilder.toList();
1079 tagsBuilder = null; 1079 tagsBuilder = null;
1080 } 1080 }
(...skipping 14 matching lines...) Expand all
1095 1095
1096 /** 1096 /**
1097 * Adds [element] to the import scope of this library. 1097 * Adds [element] to the import scope of this library.
1098 * 1098 *
1099 * If an element by the same name is already in the imported scope, an 1099 * If an element by the same name is already in the imported scope, an
1100 * [ErroneousElement] will be put in the imported scope, allowing for 1100 * [ErroneousElement] will be put in the imported scope, allowing for
1101 * detection of ambiguous uses of imported names. 1101 * detection of ambiguous uses of imported names.
1102 */ 1102 */
1103 void addImport(Element element, 1103 void addImport(Element element,
1104 ImportElement import, 1104 ImportElement import,
1105 DiagnosticListener listener) { 1105 DiagnosticReporter reporter) {
1106 importScope.addImport(this, element, import, listener); 1106 importScope.addImport(this, element, import, reporter);
1107 } 1107 }
1108 1108
1109 void addMember(Element element, DiagnosticListener listener) { 1109 void addMember(Element element, DiagnosticReporter reporter) {
1110 localMembers = localMembers.prepend(element); 1110 localMembers = localMembers.prepend(element);
1111 addToScope(element, listener); 1111 addToScope(element, reporter);
1112 } 1112 }
1113 1113
1114 void addToScope(Element element, DiagnosticListener listener) { 1114 void addToScope(Element element, DiagnosticReporter reporter) {
1115 localScope.add(element, listener); 1115 localScope.add(element, reporter);
1116 } 1116 }
1117 1117
1118 Element localLookup(String elementName) { 1118 Element localLookup(String elementName) {
1119 Element result = localScope.lookup(elementName); 1119 Element result = localScope.lookup(elementName);
1120 if (result == null && isPatch) { 1120 if (result == null && isPatch) {
1121 result = origin.localLookup(elementName); 1121 result = origin.localLookup(elementName);
1122 } 1122 }
1123 return result; 1123 return result;
1124 } 1124 }
1125 1125
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
1283 bool get isTopLevel => false; 1283 bool get isTopLevel => false;
1284 1284
1285 Element lookupLocalMember(String memberName) => importScope[memberName]; 1285 Element lookupLocalMember(String memberName) => importScope[memberName];
1286 1286
1287 DartType computeType(Resolution resolution) => const DynamicType(); 1287 DartType computeType(Resolution resolution) => const DynamicType();
1288 1288
1289 Token get position => firstPosition; 1289 Token get position => firstPosition;
1290 1290
1291 void addImport(Element element, 1291 void addImport(Element element,
1292 ImportElement import, 1292 ImportElement import,
1293 DiagnosticListener listener) { 1293 DiagnosticReporter reporter) {
1294 importScope.addImport(this, element, import, listener); 1294 importScope.addImport(this, element, import, reporter);
1295 } 1295 }
1296 1296
1297 accept(ElementVisitor visitor, arg) { 1297 accept(ElementVisitor visitor, arg) {
1298 return visitor.visitPrefixElement(this, arg); 1298 return visitor.visitPrefixElement(this, arg);
1299 } 1299 }
1300 1300
1301 String toString() => '$kind($name)'; 1301 String toString() => '$kind($name)';
1302 } 1302 }
1303 1303
1304 class TypedefElementX extends ElementX 1304 class TypedefElementX extends ElementX
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
1356 TypedefType createType(List<DartType> typeArguments) { 1356 TypedefType createType(List<DartType> typeArguments) {
1357 return new TypedefType(this, typeArguments); 1357 return new TypedefType(this, typeArguments);
1358 } 1358 }
1359 1359
1360 Scope buildScope() { 1360 Scope buildScope() {
1361 return new TypeDeclarationScope(enclosingElement.buildScope(), this); 1361 return new TypeDeclarationScope(enclosingElement.buildScope(), this);
1362 } 1362 }
1363 1363
1364 void checkCyclicReference(Resolution resolution) { 1364 void checkCyclicReference(Resolution resolution) {
1365 if (hasBeenCheckedForCycles) return; 1365 if (hasBeenCheckedForCycles) return;
1366 var visitor = new TypedefCyclicVisitor(resolution.listener, this); 1366 TypedefCyclicVisitor visitor =
1367 new TypedefCyclicVisitor(resolution.reporter, this);
1367 computeType(resolution).accept(visitor, null); 1368 computeType(resolution).accept(visitor, null);
1368 hasBeenCheckedForCycles = true; 1369 hasBeenCheckedForCycles = true;
1369 } 1370 }
1370 1371
1371 accept(ElementVisitor visitor, arg) { 1372 accept(ElementVisitor visitor, arg) {
1372 return visitor.visitTypedefElement(this, arg); 1373 return visitor.visitTypedefElement(this, arg);
1373 } 1374 }
1374 1375
1375 // A typedef cannot be patched therefore defines itself. 1376 // A typedef cannot be patched therefore defines itself.
1376 AstElement get definingElement => this; 1377 AstElement get definingElement => this;
(...skipping 900 matching lines...) Expand 10 before | Expand all | Expand 10 after
2277 2278
2278 bool get hasNode => constructor.hasNode; 2279 bool get hasNode => constructor.hasNode;
2279 2280
2280 FunctionExpression get node => constructor.node; 2281 FunctionExpression get node => constructor.node;
2281 2282
2282 List<MetadataAnnotation> get metadata => constructor.metadata; 2283 List<MetadataAnnotation> get metadata => constructor.metadata;
2283 2284
2284 bool get isInstanceMember => true; 2285 bool get isInstanceMember => true;
2285 2286
2286 FunctionType computeType(Resolution resolution) { 2287 FunctionType computeType(Resolution resolution) {
2287 resolution.listener.internalError(this, '$this.computeType.'); 2288 DiagnosticReporter reporter = resolution.reporter;
2289 reporter.internalError(this, '$this.computeType.');
2288 return null; 2290 return null;
2289 } 2291 }
2290 2292
2291 Token get position => constructor.position; 2293 Token get position => constructor.position;
2292 2294
2293 Element get outermostEnclosingMemberOrTopLevel => constructor; 2295 Element get outermostEnclosingMemberOrTopLevel => constructor;
2294 2296
2295 Element get analyzableElement => constructor.analyzableElement; 2297 Element get analyzableElement => constructor.analyzableElement;
2296 2298
2297 accept(ElementVisitor visitor, arg) { 2299 accept(ElementVisitor visitor, arg) {
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
2545 } 2547 }
2546 2548
2547 void ensureResolved(Resolution resolution) { 2549 void ensureResolved(Resolution resolution) {
2548 if (resolutionState == STATE_NOT_STARTED) { 2550 if (resolutionState == STATE_NOT_STARTED) {
2549 resolution.resolveClass(this); 2551 resolution.resolveClass(this);
2550 resolution.registerClass(this); 2552 resolution.registerClass(this);
2551 } 2553 }
2552 } 2554 }
2553 2555
2554 void setDefaultConstructor(FunctionElement constructor, 2556 void setDefaultConstructor(FunctionElement constructor,
2555 DiagnosticListener listener); 2557 DiagnosticReporter reporter);
2556 2558
2557 void addBackendMember(Element member) { 2559 void addBackendMember(Element member) {
2558 // TODO(ngeoffray): Deprecate this method. 2560 // TODO(ngeoffray): Deprecate this method.
2559 assert(member.isGenerativeConstructorBody); 2561 assert(member.isGenerativeConstructorBody);
2560 backendMembers = backendMembers.prepend(member); 2562 backendMembers = backendMembers.prepend(member);
2561 } 2563 }
2562 2564
2563 void reverseBackendMembers() { 2565 void reverseBackendMembers() {
2564 backendMembers = backendMembers.reverse(); 2566 backendMembers = backendMembers.reverse();
2565 } 2567 }
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
2638 } 2640 }
2639 return localMembersCache; 2641 return localMembersCache;
2640 } 2642 }
2641 2643
2642 ClassElementX(String name, Element enclosing, int id, int initialState) 2644 ClassElementX(String name, Element enclosing, int id, int initialState)
2643 : super(name, enclosing, id, initialState); 2645 : super(name, enclosing, id, initialState);
2644 2646
2645 bool get isMixinApplication => false; 2647 bool get isMixinApplication => false;
2646 bool get hasLocalScopeMembers => !localScope.isEmpty; 2648 bool get hasLocalScopeMembers => !localScope.isEmpty;
2647 2649
2648 void addMember(Element element, DiagnosticListener listener) { 2650 void addMember(Element element, DiagnosticReporter reporter) {
2649 localMembersCache = null; 2651 localMembersCache = null;
2650 localMembersReversed = localMembersReversed.prepend(element); 2652 localMembersReversed = localMembersReversed.prepend(element);
2651 addToScope(element, listener); 2653 addToScope(element, reporter);
2652 } 2654 }
2653 2655
2654 void addToScope(Element element, DiagnosticListener listener) { 2656 void addToScope(Element element, DiagnosticReporter reporter) {
2655 if (element.isField && element.name == name) { 2657 if (element.isField && element.name == name) {
2656 listener.reportErrorMessage( 2658 reporter.reportErrorMessage(
2657 element, MessageKind.MEMBER_USES_CLASS_NAME); 2659 element, MessageKind.MEMBER_USES_CLASS_NAME);
2658 } 2660 }
2659 localScope.add(element, listener); 2661 localScope.add(element, reporter);
2660 } 2662 }
2661 2663
2662 Element localLookup(String elementName) { 2664 Element localLookup(String elementName) {
2663 Element result = localScope.lookup(elementName); 2665 Element result = localScope.lookup(elementName);
2664 if (result == null && isPatch) { 2666 if (result == null && isPatch) {
2665 result = origin.localLookup(elementName); 2667 result = origin.localLookup(elementName);
2666 } 2668 }
2667 return result; 2669 return result;
2668 } 2670 }
2669 2671
2670 void forEachLocalMember(void f(Element member)) { 2672 void forEachLocalMember(void f(Element member)) {
2671 localMembers.forEach(f); 2673 localMembers.forEach(f);
2672 } 2674 }
2673 2675
2674 bool get hasConstructor { 2676 bool get hasConstructor {
2675 // Search in scope to be sure we search patched constructors. 2677 // Search in scope to be sure we search patched constructors.
2676 for (var element in localScope.values) { 2678 for (var element in localScope.values) {
2677 if (element.isConstructor) return true; 2679 if (element.isConstructor) return true;
2678 } 2680 }
2679 return false; 2681 return false;
2680 } 2682 }
2681 2683
2682 void setDefaultConstructor(FunctionElement constructor, 2684 void setDefaultConstructor(FunctionElement constructor,
2683 DiagnosticListener listener) { 2685 DiagnosticReporter reporter) {
2684 // The default constructor, although synthetic, is part of a class' API. 2686 // The default constructor, although synthetic, is part of a class' API.
2685 addMember(constructor, listener); 2687 addMember(constructor, reporter);
2686 } 2688 }
2687 2689
2688 List<DartType> computeTypeParameters(Parsing parsing) { 2690 List<DartType> computeTypeParameters(Parsing parsing) {
2689 ClassNode node = parseNode(parsing); 2691 ClassNode node = parseNode(parsing);
2690 return createTypeVariables(node.typeParameters); 2692 return createTypeVariables(node.typeParameters);
2691 } 2693 }
2692 2694
2693 Scope buildScope() => new ClassScope(enclosingElement.buildScope(), this); 2695 Scope buildScope() => new ClassScope(enclosingElement.buildScope(), this);
2694 2696
2695 String toString() { 2697 String toString() {
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
2847 return mixedInElement.isInstanceMember ? mixedInElement : null; 2849 return mixedInElement.isInstanceMember ? mixedInElement : null;
2848 } 2850 }
2849 2851
2850 void forEachLocalMember(void f(Element member)) { 2852 void forEachLocalMember(void f(Element member)) {
2851 constructors.forEach(f); 2853 constructors.forEach(f);
2852 if (mixin != null) mixin.forEachLocalMember((Element mixedInElement) { 2854 if (mixin != null) mixin.forEachLocalMember((Element mixedInElement) {
2853 if (mixedInElement.isInstanceMember) f(mixedInElement); 2855 if (mixedInElement.isInstanceMember) f(mixedInElement);
2854 }); 2856 });
2855 } 2857 }
2856 2858
2857 void addMember(Element element, DiagnosticListener listener) { 2859 void addMember(Element element, DiagnosticReporter reporter) {
2858 throw new UnsupportedError("Cannot add member to $this."); 2860 throw new UnsupportedError("Cannot add member to $this.");
2859 } 2861 }
2860 2862
2861 void addToScope(Element element, DiagnosticListener listener) { 2863 void addToScope(Element element, DiagnosticReporter reporter) {
2862 listener.internalError(this, 'Cannot add to scope of $this.'); 2864 reporter.internalError(this, 'Cannot add to scope of $this.');
2863 } 2865 }
2864 2866
2865 void addConstructor(FunctionElement constructor) { 2867 void addConstructor(FunctionElement constructor) {
2866 constructors = constructors.prepend(constructor); 2868 constructors = constructors.prepend(constructor);
2867 } 2869 }
2868 2870
2869 void setDefaultConstructor(FunctionElement constructor, 2871 void setDefaultConstructor(FunctionElement constructor,
2870 DiagnosticListener listener) { 2872 DiagnosticReporter reporter) {
2871 assert(!hasConstructor); 2873 assert(!hasConstructor);
2872 addConstructor(constructor); 2874 addConstructor(constructor);
2873 } 2875 }
2874 2876
2875 List<DartType> computeTypeParameters(Parsing parsing) { 2877 List<DartType> computeTypeParameters(Parsing parsing) {
2876 NamedMixinApplication named = node.asNamedMixinApplication(); 2878 NamedMixinApplication named = node.asNamedMixinApplication();
2877 if (named == null) { 2879 if (named == null) {
2878 throw new SpannableAssertionFailure(node, 2880 throw new SpannableAssertionFailure(node,
2879 "Type variables on unnamed mixin applications must be set on " 2881 "Type variables on unnamed mixin applications must be set on "
2880 "creation."); 2882 "creation.");
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
3103 AstElement get definingElement; 3105 AstElement get definingElement;
3104 3106
3105 bool get hasResolvedAst => definingElement.hasTreeElements; 3107 bool get hasResolvedAst => definingElement.hasTreeElements;
3106 3108
3107 ResolvedAst get resolvedAst { 3109 ResolvedAst get resolvedAst {
3108 return new ResolvedAst(declaration, 3110 return new ResolvedAst(declaration,
3109 definingElement.node, definingElement.treeElements); 3111 definingElement.node, definingElement.treeElements);
3110 } 3112 }
3111 3113
3112 } 3114 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/elements/elements.dart ('k') | pkg/compiler/lib/src/enqueue.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698