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

Side by Side Diff: pkg/compiler/lib/src/parser/element_listener.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
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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.parser.element_listener; 5 library dart2js.parser.element_listener;
6 6
7 import '../diagnostics/diagnostic_listener.dart'; 7 import '../diagnostics/diagnostic_listener.dart';
8 import '../diagnostics/messages.dart'; 8 import '../diagnostics/messages.dart';
9 import '../diagnostics/spannable.dart' show 9 import '../diagnostics/spannable.dart' show
10 Spannable; 10 Spannable;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 typedef int IdGenerator(); 56 typedef int IdGenerator();
57 57
58 /** 58 /**
59 * A parser event listener designed to work with [PartialParser]. It 59 * A parser event listener designed to work with [PartialParser]. It
60 * builds elements representing the top-level declarations found in 60 * builds elements representing the top-level declarations found in
61 * the parsed compilation unit and records them in 61 * the parsed compilation unit and records them in
62 * [compilationUnitElement]. 62 * [compilationUnitElement].
63 */ 63 */
64 class ElementListener extends Listener { 64 class ElementListener extends Listener {
65 final IdGenerator idGenerator; 65 final IdGenerator idGenerator;
66 final DiagnosticListener listener; 66 final DiagnosticReporter reporter;
67 final CompilationUnitElementX compilationUnitElement; 67 final CompilationUnitElementX compilationUnitElement;
68 final StringValidator stringValidator; 68 final StringValidator stringValidator;
69 Link<StringQuoting> interpolationScope; 69 Link<StringQuoting> interpolationScope;
70 70
71 Link<Node> nodes = const Link<Node>(); 71 Link<Node> nodes = const Link<Node>();
72 72
73 LinkBuilder<MetadataAnnotation> metadata = 73 LinkBuilder<MetadataAnnotation> metadata =
74 new LinkBuilder<MetadataAnnotation>(); 74 new LinkBuilder<MetadataAnnotation>();
75 75
76 /// Records a stack of booleans for each member parsed (a stack is used to 76 /// Records a stack of booleans for each member parsed (a stack is used to
77 /// support nested members which isn't currently possible, but it also serves 77 /// support nested members which isn't currently possible, but it also serves
78 /// as a simple way to tell we're currently parsing a member). In this case, 78 /// as a simple way to tell we're currently parsing a member). In this case,
79 /// member refers to members of a library or a class (but currently, classes 79 /// member refers to members of a library or a class (but currently, classes
80 /// themselves are not considered members). If the top of the stack 80 /// themselves are not considered members). If the top of the stack
81 /// (memberErrors.head) is true, the current member has already reported at 81 /// (memberErrors.head) is true, the current member has already reported at
82 /// least one parse error. 82 /// least one parse error.
83 Link<bool> memberErrors = const Link<bool>(); 83 Link<bool> memberErrors = const Link<bool>();
84 84
85 bool suppressParseErrors = false; 85 bool suppressParseErrors = false;
86 86
87 ElementListener( 87 ElementListener(
88 DiagnosticListener listener, 88 DiagnosticReporter reporter,
89 this.compilationUnitElement, 89 this.compilationUnitElement,
90 this.idGenerator) 90 this.idGenerator)
91 : this.listener = listener, 91 : this.reporter = reporter,
92 stringValidator = new StringValidator(listener), 92 stringValidator = new StringValidator(reporter),
93 interpolationScope = const Link<StringQuoting>(); 93 interpolationScope = const Link<StringQuoting>();
94 94
95 bool get currentMemberHasParseError { 95 bool get currentMemberHasParseError {
96 return !memberErrors.isEmpty && memberErrors.head; 96 return !memberErrors.isEmpty && memberErrors.head;
97 } 97 }
98 98
99 void pushQuoting(StringQuoting quoting) { 99 void pushQuoting(StringQuoting quoting) {
100 interpolationScope = interpolationScope.prepend(quoting); 100 interpolationScope = interpolationScope.prepend(quoting);
101 } 101 }
102 102
103 StringQuoting popQuoting() { 103 StringQuoting popQuoting() {
104 StringQuoting result = interpolationScope.head; 104 StringQuoting result = interpolationScope.head;
105 interpolationScope = interpolationScope.tail; 105 interpolationScope = interpolationScope.tail;
106 return result; 106 return result;
107 } 107 }
108 108
109 StringNode popLiteralString() { 109 StringNode popLiteralString() {
110 StringNode node = popNode(); 110 StringNode node = popNode();
111 // TODO(lrn): Handle interpolations in script tags. 111 // TODO(lrn): Handle interpolations in script tags.
112 if (node.isInterpolation) { 112 if (node.isInterpolation) {
113 listener.internalError(node, 113 reporter.internalError(node,
114 "String interpolation not supported in library tags."); 114 "String interpolation not supported in library tags.");
115 return null; 115 return null;
116 } 116 }
117 return node; 117 return node;
118 } 118 }
119 119
120 bool allowLibraryTags() { 120 bool allowLibraryTags() {
121 // Library tags are only allowed in the library file itself, not 121 // Library tags are only allowed in the library file itself, not
122 // in sourced files. 122 // in sourced files.
123 LibraryElement library = compilationUnitElement.implementationLibrary; 123 LibraryElement library = compilationUnitElement.implementationLibrary;
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 popMetadata(compilationUnitElement))); 194 popMetadata(compilationUnitElement)));
195 } 195 }
196 196
197 void endPartOf(Token partKeyword, Token semicolon) { 197 void endPartOf(Token partKeyword, Token semicolon) {
198 Expression name = popNode(); 198 Expression name = popNode();
199 addPartOfTag(new PartOf(partKeyword, name, 199 addPartOfTag(new PartOf(partKeyword, name,
200 popMetadata(compilationUnitElement))); 200 popMetadata(compilationUnitElement)));
201 } 201 }
202 202
203 void addPartOfTag(PartOf tag) { 203 void addPartOfTag(PartOf tag) {
204 compilationUnitElement.setPartOf(tag, listener); 204 compilationUnitElement.setPartOf(tag, reporter);
205 } 205 }
206 206
207 void endMetadata(Token beginToken, Token periodBeforeName, Token endToken) { 207 void endMetadata(Token beginToken, Token periodBeforeName, Token endToken) {
208 if (periodBeforeName != null) { 208 if (periodBeforeName != null) {
209 popNode(); // Discard name. 209 popNode(); // Discard name.
210 } 210 }
211 popNode(); // Discard node (Send or Identifier). 211 popNode(); // Discard node (Send or Identifier).
212 pushMetadata(new PartialMetadataAnnotation(beginToken, endToken)); 212 pushMetadata(new PartialMetadataAnnotation(beginToken, endToken));
213 } 213 }
214 214
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after
587 return next; 587 return next;
588 } 588 }
589 589
590 void recoverableError(Spannable node, String message) { 590 void recoverableError(Spannable node, String message) {
591 // TODO(johnniwinther): Make recoverable errors non-fatal. 591 // TODO(johnniwinther): Make recoverable errors non-fatal.
592 reportFatalError(node, message); 592 reportFatalError(node, message);
593 } 593 }
594 594
595 void pushElement(Element element) { 595 void pushElement(Element element) {
596 popMetadata(element); 596 popMetadata(element);
597 compilationUnitElement.addMember(element, listener); 597 compilationUnitElement.addMember(element, reporter);
598 } 598 }
599 599
600 List<MetadataAnnotation> popMetadata(ElementX element) { 600 List<MetadataAnnotation> popMetadata(ElementX element) {
601 List<MetadataAnnotation> result = metadata.toList(); 601 List<MetadataAnnotation> result = metadata.toList();
602 element.metadata = result; 602 element.metadata = result;
603 metadata.clear(); 603 metadata.clear();
604 return result; 604 return result;
605 } 605 }
606 606
607 void pushMetadata(MetadataAnnotation annotation) { 607 void pushMetadata(MetadataAnnotation annotation) {
608 metadata.addLast(annotation); 608 metadata.addLast(annotation);
609 } 609 }
610 610
611 void addLibraryTag(LibraryTag tag) { 611 void addLibraryTag(LibraryTag tag) {
612 if (!allowLibraryTags()) { 612 if (!allowLibraryTags()) {
613 recoverableError(tag, 'Library tags not allowed here.'); 613 recoverableError(tag, 'Library tags not allowed here.');
614 } 614 }
615 LibraryElementX implementationLibrary = 615 LibraryElementX implementationLibrary =
616 compilationUnitElement.implementationLibrary; 616 compilationUnitElement.implementationLibrary;
617 implementationLibrary.addTag(tag, listener); 617 implementationLibrary.addTag(tag, reporter);
618 } 618 }
619 619
620 void pushNode(Node node) { 620 void pushNode(Node node) {
621 nodes = nodes.prepend(node); 621 nodes = nodes.prepend(node);
622 if (VERBOSE) log("push $nodes"); 622 if (VERBOSE) log("push $nodes");
623 } 623 }
624 624
625 Node popNode() { 625 Node popNode() {
626 assert(!nodes.isEmpty); 626 assert(!nodes.isEmpty);
627 Node node = nodes.head; 627 Node node = nodes.head;
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
741 } 741 }
742 742
743 void reportError(Spannable spannable, 743 void reportError(Spannable spannable,
744 MessageKind errorCode, 744 MessageKind errorCode,
745 [Map arguments = const {}]) { 745 [Map arguments = const {}]) {
746 if (currentMemberHasParseError) return; // Error already reported. 746 if (currentMemberHasParseError) return; // Error already reported.
747 if (suppressParseErrors) return; 747 if (suppressParseErrors) return;
748 if (!memberErrors.isEmpty) { 748 if (!memberErrors.isEmpty) {
749 memberErrors = memberErrors.tail.prepend(true); 749 memberErrors = memberErrors.tail.prepend(true);
750 } 750 }
751 listener.reportErrorMessage(spannable, errorCode, arguments); 751 reporter.reportErrorMessage(spannable, errorCode, arguments);
752 } 752 }
753 } 753 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/parser/diet_parser_task.dart ('k') | pkg/compiler/lib/src/parser/member_listener.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698