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.element_listener; | 5 library dart2js.parser.element_listener; |
6 | 6 |
7 import '../common.dart'; | 7 import '../common.dart'; |
8 import '../diagnostics/messages.dart' show MessageTemplate; | 8 import '../diagnostics/messages.dart' show MessageTemplate; |
9 import '../elements/elements.dart' | 9 import '../elements/elements.dart' |
10 show Element, LibraryElement, MetadataAnnotation; | 10 show Element, LibraryElement, MetadataAnnotation; |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 void rejectBuiltInIdentifier(Identifier name) { | 280 void rejectBuiltInIdentifier(Identifier name) { |
281 if (name.token is KeywordToken) { | 281 if (name.token is KeywordToken) { |
282 Keyword keyword = (name.token as KeywordToken).keyword; | 282 Keyword keyword = (name.token as KeywordToken).keyword; |
283 if (!keyword.isPseudo) { | 283 if (!keyword.isPseudo) { |
284 recoverableError(name, "Illegal name '${keyword.syntax}'."); | 284 recoverableError(name, "Illegal name '${keyword.syntax}'."); |
285 } | 285 } |
286 } | 286 } |
287 } | 287 } |
288 | 288 |
289 @override | 289 @override |
290 void endFunctionTypeAlias( | 290 void endFunctionTypeAlias(Token typedefKeyword, Token endToken) { |
291 Token typedefKeyword, Token equals, Token endToken) { | 291 popNode(); // TODO(karlklose): do not throw away typeVariables. |
292 Identifier name; | 292 Identifier name = popNode(); |
293 if (equals == null) { | 293 popNode(); // returnType |
294 popNode(); // TODO(karlklose): do not throw away typeVariables. | |
295 name = popNode(); | |
296 popNode(); // returnType | |
297 } else { | |
298 popNode(); // Function type. | |
299 popNode(); // TODO(karlklose): do not throw away typeVariables. | |
300 name = popNode(); | |
301 } | |
302 pushElement(new PartialTypedefElement( | 294 pushElement(new PartialTypedefElement( |
303 name.source, compilationUnitElement, typedefKeyword, endToken)); | 295 name.source, compilationUnitElement, typedefKeyword, endToken)); |
304 rejectBuiltInIdentifier(name); | 296 rejectBuiltInIdentifier(name); |
305 } | 297 } |
306 | 298 |
307 @override | 299 @override |
308 void endNamedMixinApplication( | 300 void endNamedMixinApplication( |
309 Token beginToken, Token classKeyword, Token equals, | 301 Token beginToken, Token classKeyword, Token equals, |
310 Token implementsKeyword, Token endToken) { | 302 Token implementsKeyword, Token endToken) { |
311 NodeList interfaces = (implementsKeyword != null) ? popNode() : null; | 303 NodeList interfaces = (implementsKeyword != null) ? popNode() : null; |
(...skipping 13 matching lines...) Expand all Loading... |
325 int id = idGenerator.getNextFreeId(); | 317 int id = idGenerator.getNextFreeId(); |
326 Element enclosing = compilationUnitElement; | 318 Element enclosing = compilationUnitElement; |
327 pushElement(new NamedMixinApplicationElementX( | 319 pushElement(new NamedMixinApplicationElementX( |
328 name.source, enclosing, id, namedMixinApplication)); | 320 name.source, enclosing, id, namedMixinApplication)); |
329 rejectBuiltInIdentifier(name); | 321 rejectBuiltInIdentifier(name); |
330 } | 322 } |
331 | 323 |
332 @override | 324 @override |
333 void endMixinApplication() { | 325 void endMixinApplication() { |
334 NodeList mixins = popNode(); | 326 NodeList mixins = popNode(); |
335 NominalTypeAnnotation superclass = popNode(); | 327 TypeAnnotation superclass = popNode(); |
336 pushNode(new MixinApplication(superclass, mixins)); | 328 pushNode(new MixinApplication(superclass, mixins)); |
337 } | 329 } |
338 | 330 |
339 @override | 331 @override |
340 void handleVoidKeyword(Token token) { | 332 void handleVoidKeyword(Token token) { |
341 pushNode(new NominalTypeAnnotation(new Identifier(token), null)); | 333 pushNode(new TypeAnnotation(new Identifier(token), null)); |
342 } | 334 } |
343 | 335 |
344 @override | 336 @override |
345 void endTopLevelMethod(Token beginToken, Token getOrSet, Token endToken) { | 337 void endTopLevelMethod(Token beginToken, Token getOrSet, Token endToken) { |
346 bool hasParseError = currentMemberHasParseError; | 338 bool hasParseError = currentMemberHasParseError; |
347 memberErrors = memberErrors.tail; | 339 memberErrors = memberErrors.tail; |
348 popNode(); // typeVariables | 340 popNode(); // typeVariables |
349 Identifier name = popNode(); | 341 Identifier name = popNode(); |
350 popNode(); // type | 342 popNode(); // type |
351 Modifiers modifiers = popNode(); | 343 Modifiers modifiers = popNode(); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
404 pushNode(new Send(first, last)); | 396 pushNode(new Send(first, last)); |
405 } | 397 } |
406 | 398 |
407 @override | 399 @override |
408 void handleNoType(Token token) { | 400 void handleNoType(Token token) { |
409 pushNode(null); | 401 pushNode(null); |
410 } | 402 } |
411 | 403 |
412 @override | 404 @override |
413 void endTypeVariable(Token token, Token extendsOrSuper) { | 405 void endTypeVariable(Token token, Token extendsOrSuper) { |
414 NominalTypeAnnotation bound = popNode(); | 406 TypeAnnotation bound = popNode(); |
415 Identifier name = popNode(); | 407 Identifier name = popNode(); |
416 pushNode(new TypeVariable(name, extendsOrSuper, bound)); | 408 pushNode(new TypeVariable(name, extendsOrSuper, bound)); |
417 rejectBuiltInIdentifier(name); | 409 rejectBuiltInIdentifier(name); |
418 } | 410 } |
419 | 411 |
420 @override | 412 @override |
421 void endTypeVariables(int count, Token beginToken, Token endToken) { | 413 void endTypeVariables(int count, Token beginToken, Token endToken) { |
422 pushNode(makeNodeList(count, beginToken, endToken, ',')); | 414 pushNode(makeNodeList(count, beginToken, endToken, ',')); |
423 } | 415 } |
424 | 416 |
425 @override | 417 @override |
426 void handleNoTypeVariables(Token token) { | 418 void handleNoTypeVariables(Token token) { |
427 pushNode(null); | 419 pushNode(null); |
428 } | 420 } |
429 | 421 |
430 @override | 422 @override |
431 void endTypeArguments(int count, Token beginToken, Token endToken) { | 423 void endTypeArguments(int count, Token beginToken, Token endToken) { |
432 pushNode(makeNodeList(count, beginToken, endToken, ',')); | 424 pushNode(makeNodeList(count, beginToken, endToken, ',')); |
433 } | 425 } |
434 | 426 |
435 @override | 427 @override |
436 void handleNoTypeArguments(Token token) { | 428 void handleNoTypeArguments(Token token) { |
437 pushNode(null); | 429 pushNode(null); |
438 } | 430 } |
439 | 431 |
440 @override | 432 @override |
441 void handleType(Token beginToken, Token endToken) { | 433 void endType(Token beginToken, Token endToken) { |
442 NodeList typeArguments = popNode(); | 434 NodeList typeArguments = popNode(); |
443 Expression typeName = popNode(); | 435 Expression typeName = popNode(); |
444 pushNode(new NominalTypeAnnotation(typeName, typeArguments)); | 436 pushNode(new TypeAnnotation(typeName, typeArguments)); |
445 } | |
446 | |
447 void handleNoName(Token token) { | |
448 pushNode(null); | |
449 } | 437 } |
450 | 438 |
451 @override | 439 @override |
452 void handleFunctionType(Token functionToken, Token endToken) { | |
453 popNode(); // Type parameters. | |
454 popNode(); // Return type. | |
455 pushNode(null); | |
456 } | |
457 | |
458 @override | |
459 void handleParenthesizedExpression(BeginGroupToken token) { | 440 void handleParenthesizedExpression(BeginGroupToken token) { |
460 Expression expression = popNode(); | 441 Expression expression = popNode(); |
461 pushNode(new ParenthesizedExpression(expression, token)); | 442 pushNode(new ParenthesizedExpression(expression, token)); |
462 } | 443 } |
463 | 444 |
464 @override | 445 @override |
465 void handleModifier(Token token) { | 446 void handleModifier(Token token) { |
466 pushNode(new Identifier(token)); | 447 pushNode(new Identifier(token)); |
467 } | 448 } |
468 | 449 |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
644 errorCode = MessageKind.INVALID_AWAIT_FOR; | 625 errorCode = MessageKind.INVALID_AWAIT_FOR; |
645 break; | 626 break; |
646 | 627 |
647 case ErrorKind.AsciiControlCharacter: | 628 case ErrorKind.AsciiControlCharacter: |
648 case ErrorKind.NonAsciiIdentifier: | 629 case ErrorKind.NonAsciiIdentifier: |
649 case ErrorKind.NonAsciiWhitespace: | 630 case ErrorKind.NonAsciiWhitespace: |
650 case ErrorKind.Encoding: | 631 case ErrorKind.Encoding: |
651 errorCode = MessageKind.BAD_INPUT_CHARACTER; | 632 errorCode = MessageKind.BAD_INPUT_CHARACTER; |
652 break; | 633 break; |
653 | 634 |
654 case ErrorKind.InvalidInlineFunctionType: | |
655 errorCode = MessageKind.INVALID_INLINE_FUNCTION_TYPE; | |
656 break; | |
657 | |
658 case ErrorKind.InvalidSyncModifier: | 635 case ErrorKind.InvalidSyncModifier: |
659 errorCode = MessageKind.INVALID_SYNC_MODIFIER; | 636 errorCode = MessageKind.INVALID_SYNC_MODIFIER; |
660 break; | 637 break; |
661 | 638 |
662 case ErrorKind.InvalidVoid: | 639 case ErrorKind.InvalidVoid: |
663 errorCode = MessageKind.VOID_NOT_ALLOWED; | 640 errorCode = MessageKind.VOID_NOT_ALLOWED; |
664 break; | 641 break; |
665 | 642 |
666 case ErrorKind.UnexpectedDollarInString: | 643 case ErrorKind.UnexpectedDollarInString: |
667 errorCode = MessageKind.MALFORMED_STRING_LITERAL; | 644 errorCode = MessageKind.MALFORMED_STRING_LITERAL; |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
935 memberErrors = memberErrors.tail.prepend(true); | 912 memberErrors = memberErrors.tail.prepend(true); |
936 } | 913 } |
937 reporter.reportErrorMessage(spannable, errorCode, arguments); | 914 reporter.reportErrorMessage(spannable, errorCode, arguments); |
938 } | 915 } |
939 | 916 |
940 void reportErrorFromToken(Token token, MessageKind errorCode, | 917 void reportErrorFromToken(Token token, MessageKind errorCode, |
941 [Map arguments = const {}]) { | 918 [Map arguments = const {}]) { |
942 reportError(reporter.spanFromToken(token), errorCode, arguments); | 919 reportError(reporter.spanFromToken(token), errorCode, arguments); |
943 } | 920 } |
944 } | 921 } |
OLD | NEW |