OLD | NEW |
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.node_listener; | 5 library dart2js.parser.node_listener; |
6 | 6 |
7 import '../common.dart'; | 7 import '../common.dart'; |
8 import '../elements/elements.dart' show CompilationUnitElement; | 8 import '../elements/elements.dart' show CompilationUnitElement; |
9 import 'package:front_end/src/fasta/scanner/precedence.dart' as Precedence | 9 import 'package:front_end/src/fasta/scanner/precedence.dart' as Precedence |
10 show INDEX_INFO; | 10 show INDEX_INFO; |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 pushNode(node); | 119 pushNode(node); |
120 super.endTopLevelDeclaration(token); | 120 super.endTopLevelDeclaration(token); |
121 } | 121 } |
122 | 122 |
123 @override | 123 @override |
124 void endCompilationUnit(int count, Token token) { | 124 void endCompilationUnit(int count, Token token) { |
125 pushNode(makeNodeList(count, null, null, '\n')); | 125 pushNode(makeNodeList(count, null, null, '\n')); |
126 } | 126 } |
127 | 127 |
128 @override | 128 @override |
129 void endFunctionTypeAlias( | 129 void endFunctionTypeAlias(Token typedefKeyword, Token endToken) { |
130 Token typedefKeyword, Token equals, Token endToken) { | 130 NodeList formals = popNode(); |
131 bool isGeneralizedTypeAlias; | 131 NodeList typeParameters = popNode(); |
132 NodeList templateParameters; | 132 Identifier name = popNode(); |
133 TypeAnnotation returnType; | 133 TypeAnnotation returnType = popNode(); |
134 Identifier name; | |
135 NodeList typeParameters; | |
136 NodeList formals; | |
137 if (equals == null) { | |
138 isGeneralizedTypeAlias = false; | |
139 formals = popNode(); | |
140 templateParameters = popNode(); | |
141 name = popNode(); | |
142 returnType = popNode(); | |
143 } else { | |
144 // TODO(floitsch): keep using the `FunctionTypeAnnotation' node. | |
145 isGeneralizedTypeAlias = true; | |
146 Node type = popNode(); | |
147 if (type.asFunctionTypeAnnotation() == null) { | |
148 // TODO(floitsch): The parser should diagnose this problem, not | |
149 // this listener. | |
150 // However, this problem goes away, when we allow aliases for | |
151 // non-function types too. | |
152 reportFatalError(type, 'Expected a function type.'); | |
153 } | |
154 FunctionTypeAnnotation functionType = type; | |
155 templateParameters = popNode(); | |
156 name = popNode(); | |
157 returnType = functionType.returnType; | |
158 typeParameters = functionType.typeParameters; | |
159 formals = functionType.formals; | |
160 } | |
161 pushNode(new Typedef( | 134 pushNode(new Typedef( |
162 isGeneralizedTypeAlias, | 135 returnType, name, typeParameters, formals, typedefKeyword, endToken)); |
163 templateParameters, | |
164 returnType, | |
165 name, | |
166 typeParameters, | |
167 formals, | |
168 typedefKeyword, | |
169 endToken)); | |
170 } | |
171 | |
172 void handleNoName(Token token) { | |
173 pushNode(null); | |
174 } | 136 } |
175 | 137 |
176 @override | 138 @override |
177 void handleFunctionType(Token functionToken, Token endToken) { | |
178 NodeList formals = popNode(); | |
179 NodeList typeParameters = popNode(); | |
180 TypeAnnotation returnType = popNode(); | |
181 pushNode(new FunctionTypeAnnotation( | |
182 returnType, functionToken, typeParameters, formals)); | |
183 } | |
184 | |
185 @override | |
186 void endNamedMixinApplication( | 139 void endNamedMixinApplication( |
187 Token beginToken, Token classKeyword, Token equals, | 140 Token beginToken, Token classKeyword, Token equals, |
188 Token implementsKeyword, Token endToken) { | 141 Token implementsKeyword, Token endToken) { |
189 NodeList interfaces = (implementsKeyword != null) ? popNode() : null; | 142 NodeList interfaces = (implementsKeyword != null) ? popNode() : null; |
190 Node mixinApplication = popNode(); | 143 Node mixinApplication = popNode(); |
191 NodeList typeParameters = popNode(); | 144 NodeList typeParameters = popNode(); |
192 Identifier name = popNode(); | 145 Identifier name = popNode(); |
193 Modifiers modifiers = popNode(); | 146 Modifiers modifiers = popNode(); |
194 pushNode(new NamedMixinApplication(name, typeParameters, modifiers, | 147 pushNode(new NamedMixinApplication(name, typeParameters, modifiers, |
195 mixinApplication, interfaces, beginToken, endToken)); | 148 mixinApplication, interfaces, beginToken, endToken)); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 @override | 222 @override |
270 void endConstructorReference( | 223 void endConstructorReference( |
271 Token start, Token periodBeforeName, Token endToken) { | 224 Token start, Token periodBeforeName, Token endToken) { |
272 Identifier name = null; | 225 Identifier name = null; |
273 if (periodBeforeName != null) { | 226 if (periodBeforeName != null) { |
274 name = popNode(); | 227 name = popNode(); |
275 } | 228 } |
276 NodeList typeArguments = popNode(); | 229 NodeList typeArguments = popNode(); |
277 Node classReference = popNode(); | 230 Node classReference = popNode(); |
278 if (typeArguments != null) { | 231 if (typeArguments != null) { |
279 classReference = new NominalTypeAnnotation(classReference, typeArguments); | 232 classReference = new TypeAnnotation(classReference, typeArguments); |
280 } else { | 233 } else { |
281 Identifier identifier = classReference.asIdentifier(); | 234 Identifier identifier = classReference.asIdentifier(); |
282 Send send = classReference.asSend(); | 235 Send send = classReference.asSend(); |
283 if (identifier != null) { | 236 if (identifier != null) { |
284 // TODO(ahe): Should be: | 237 // TODO(ahe): Should be: |
285 // classReference = new Send(null, identifier); | 238 // classReference = new Send(null, identifier); |
286 classReference = identifier; | 239 classReference = identifier; |
287 } else if (send != null) { | 240 } else if (send != null) { |
288 classReference = send; | 241 classReference = send; |
289 } else { | 242 } else { |
(...skipping 617 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
907 NodeList arguments = popNode(); | 860 NodeList arguments = popNode(); |
908 if (arguments == null) { | 861 if (arguments == null) { |
909 // This is a constant expression. | 862 // This is a constant expression. |
910 Identifier name; | 863 Identifier name; |
911 if (periodBeforeName != null) { | 864 if (periodBeforeName != null) { |
912 name = popNode(); | 865 name = popNode(); |
913 } | 866 } |
914 NodeList typeArguments = popNode(); | 867 NodeList typeArguments = popNode(); |
915 Node receiver = popNode(); | 868 Node receiver = popNode(); |
916 if (typeArguments != null) { | 869 if (typeArguments != null) { |
917 receiver = new NominalTypeAnnotation(receiver, typeArguments); | 870 receiver = new TypeAnnotation(receiver, typeArguments); |
918 recoverableError(typeArguments, 'Type arguments are not allowed here.'); | 871 recoverableError(typeArguments, 'Type arguments are not allowed here.'); |
919 } else { | 872 } else { |
920 Identifier identifier = receiver.asIdentifier(); | 873 Identifier identifier = receiver.asIdentifier(); |
921 Send send = receiver.asSend(); | 874 Send send = receiver.asSend(); |
922 if (identifier != null) { | 875 if (identifier != null) { |
923 receiver = new Send(null, identifier); | 876 receiver = new Send(null, identifier); |
924 } else if (send == null) { | 877 } else if (send == null) { |
925 internalError(node: receiver); | 878 internalError(node: receiver); |
926 } | 879 } |
927 } | 880 } |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1001 } | 954 } |
1002 lastErrorWasNativeFunctionBody = false; | 955 lastErrorWasNativeFunctionBody = false; |
1003 } | 956 } |
1004 | 957 |
1005 void internalError({Token token, Node node}) { | 958 void internalError({Token token, Node node}) { |
1006 // TODO(ahe): This should call reporter.internalError. | 959 // TODO(ahe): This should call reporter.internalError. |
1007 Spannable spannable = (token == null) ? node : token; | 960 Spannable spannable = (token == null) ? node : token; |
1008 throw new SpannableAssertionFailure(spannable, 'Internal error in parser.'); | 961 throw new SpannableAssertionFailure(spannable, 'Internal error in parser.'); |
1009 } | 962 } |
1010 } | 963 } |
OLD | NEW |