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

Side by Side Diff: pkg/compiler/lib/src/parser/member_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.member_listener; 5 library dart2js.parser.member_listener;
6 6
7 import '../diagnostics/diagnostic_listener.dart' show 7 import '../diagnostics/diagnostic_listener.dart' show
8 DiagnosticListener; 8 DiagnosticReporter;
9 import '../diagnostics/messages.dart' show 9 import '../diagnostics/messages.dart' show
10 MessageKind; 10 MessageKind;
11 import '../elements/elements.dart' show 11 import '../elements/elements.dart' show
12 Element, 12 Element,
13 ElementKind, 13 ElementKind,
14 Elements, 14 Elements,
15 MetadataAnnotation; 15 MetadataAnnotation;
16 import '../elements/modelx.dart' show 16 import '../elements/modelx.dart' show
17 ClassElementX, 17 ClassElementX,
18 ElementX, 18 ElementX,
19 FieldElementX, 19 FieldElementX,
20 VariableList; 20 VariableList;
21 import '../tokens/token.dart' show 21 import '../tokens/token.dart' show
22 Token; 22 Token;
23 import '../tree/tree.dart'; 23 import '../tree/tree.dart';
24 import '../util/util.dart' show 24 import '../util/util.dart' show
25 Link; 25 Link;
26 26
27 import 'partial_elements.dart' show 27 import 'partial_elements.dart' show
28 PartialConstructorElement, 28 PartialConstructorElement,
29 PartialFunctionElement, 29 PartialFunctionElement,
30 PartialMetadataAnnotation; 30 PartialMetadataAnnotation;
31 import 'node_listener.dart' show 31 import 'node_listener.dart' show
32 NodeListener; 32 NodeListener;
33 33
34 class MemberListener extends NodeListener { 34 class MemberListener extends NodeListener {
35 final ClassElementX enclosingClass; 35 final ClassElementX enclosingClass;
36 36
37 MemberListener(DiagnosticListener listener, 37 MemberListener(DiagnosticReporter listener,
38 ClassElementX enclosingElement) 38 ClassElementX enclosingElement)
39 : this.enclosingClass = enclosingElement, 39 : this.enclosingClass = enclosingElement,
40 super(listener, enclosingElement.compilationUnit); 40 super(listener, enclosingElement.compilationUnit);
41 41
42 bool isConstructorName(Node nameNode) { 42 bool isConstructorName(Node nameNode) {
43 if (enclosingClass == null || 43 if (enclosingClass == null ||
44 enclosingClass.kind != ElementKind.CLASS) { 44 enclosingClass.kind != ElementKind.CLASS) {
45 return false; 45 return false;
46 } 46 }
47 String name; 47 String name;
(...skipping 17 matching lines...) Expand all
65 Identifier selector = send.selector.asIdentifier(); 65 Identifier selector = send.selector.asIdentifier();
66 Operator operator = selector.asOperator(); 66 Operator operator = selector.asOperator();
67 if (operator != null) { 67 if (operator != null) {
68 assert(identical(receiver.source, 'operator')); 68 assert(identical(receiver.source, 'operator'));
69 // TODO(ahe): It is a hack to compare to ')', but it beats 69 // TODO(ahe): It is a hack to compare to ')', but it beats
70 // parsing the node. 70 // parsing the node.
71 bool isUnary = identical(operator.token.next.next.stringValue, ')'); 71 bool isUnary = identical(operator.token.next.next.stringValue, ')');
72 return Elements.constructOperatorName(operator.source, isUnary); 72 return Elements.constructOperatorName(operator.source, isUnary);
73 } else { 73 } else {
74 if (receiver == null || receiver.source != enclosingClass.name) { 74 if (receiver == null || receiver.source != enclosingClass.name) {
75 listener.reportErrorMessage( 75 reporter.reportErrorMessage(
76 send.receiver, 76 send.receiver,
77 MessageKind.INVALID_CONSTRUCTOR_NAME, 77 MessageKind.INVALID_CONSTRUCTOR_NAME,
78 {'name': enclosingClass.name}); 78 {'name': enclosingClass.name});
79 } 79 }
80 return selector.source; 80 return selector.source;
81 } 81 }
82 } 82 }
83 83
84 void endMethod(Token getOrSet, Token beginToken, Token endToken) { 84 void endMethod(Token getOrSet, Token beginToken, Token endToken) {
85 super.endMethod(getOrSet, beginToken, endToken); 85 super.endMethod(getOrSet, beginToken, endToken);
(...skipping 20 matching lines...) Expand all
106 } 106 }
107 107
108 void endFactoryMethod(Token beginToken, Token endToken) { 108 void endFactoryMethod(Token beginToken, Token endToken) {
109 super.endFactoryMethod(beginToken, endToken); 109 super.endFactoryMethod(beginToken, endToken);
110 FunctionExpression method = popNode(); 110 FunctionExpression method = popNode();
111 pushNode(null); 111 pushNode(null);
112 String name = getMethodNameHack(method.name); 112 String name = getMethodNameHack(method.name);
113 Identifier singleIdentifierName = method.name.asIdentifier(); 113 Identifier singleIdentifierName = method.name.asIdentifier();
114 if (singleIdentifierName != null && singleIdentifierName.source == name) { 114 if (singleIdentifierName != null && singleIdentifierName.source == name) {
115 if (name != enclosingClass.name) { 115 if (name != enclosingClass.name) {
116 listener.reportErrorMessage( 116 reporter.reportErrorMessage(
117 singleIdentifierName, 117 singleIdentifierName,
118 MessageKind.INVALID_UNNAMED_CONSTRUCTOR_NAME, 118 MessageKind.INVALID_UNNAMED_CONSTRUCTOR_NAME,
119 {'name': enclosingClass.name}); 119 {'name': enclosingClass.name});
120 } 120 }
121 } 121 }
122 Element memberElement = new PartialConstructorElement( 122 Element memberElement = new PartialConstructorElement(
123 name, beginToken, endToken, 123 name, beginToken, endToken,
124 ElementKind.FUNCTION, 124 ElementKind.FUNCTION,
125 method.modifiers, 125 method.modifiers,
126 enclosingClass); 126 enclosingClass);
(...skipping 26 matching lines...) Expand all
153 void endInitializers(int count, Token beginToken, Token endToken) { 153 void endInitializers(int count, Token beginToken, Token endToken) {
154 pushNode(null); 154 pushNode(null);
155 } 155 }
156 156
157 void addMetadata(ElementX memberElement) { 157 void addMetadata(ElementX memberElement) {
158 memberElement.metadata = metadata.toList(); 158 memberElement.metadata = metadata.toList();
159 } 159 }
160 160
161 void addMember(ElementX memberElement) { 161 void addMember(ElementX memberElement) {
162 addMetadata(memberElement); 162 addMetadata(memberElement);
163 enclosingClass.addMember(memberElement, listener); 163 enclosingClass.addMember(memberElement, reporter);
164 } 164 }
165 165
166 void endMetadata(Token beginToken, Token periodBeforeName, Token endToken) { 166 void endMetadata(Token beginToken, Token periodBeforeName, Token endToken) {
167 popNode(); // Discard arguments. 167 popNode(); // Discard arguments.
168 if (periodBeforeName != null) { 168 if (periodBeforeName != null) {
169 popNode(); // Discard name. 169 popNode(); // Discard name.
170 } 170 }
171 popNode(); // Discard node (Send or Identifier). 171 popNode(); // Discard node (Send or Identifier).
172 pushMetadata(new PartialMetadataAnnotation(beginToken, endToken)); 172 pushMetadata(new PartialMetadataAnnotation(beginToken, endToken));
173 } 173 }
174 } 174 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/parser/element_listener.dart ('k') | pkg/compiler/lib/src/parser/node_listener.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698