| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 part of scanner; | 5 part of scanner; |
| 6 | 6 |
| 7 const bool VERBOSE = false; | 7 const bool VERBOSE = false; |
| 8 | 8 |
| 9 /** | 9 /** |
| 10 * A parser event listener that does nothing except throw exceptions | 10 * A parser event listener that does nothing except throw exceptions |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 | 341 |
| 342 void beginThrowStatement(Token token) { | 342 void beginThrowStatement(Token token) { |
| 343 } | 343 } |
| 344 | 344 |
| 345 void endThrowStatement(Token throwToken, Token endToken) { | 345 void endThrowStatement(Token throwToken, Token endToken) { |
| 346 } | 346 } |
| 347 | 347 |
| 348 void endRethrowStatement(Token throwToken, Token endToken) { | 348 void endRethrowStatement(Token throwToken, Token endToken) { |
| 349 } | 349 } |
| 350 | 350 |
| 351 void endTopLevelDeclaration(Token token) { |
| 352 } |
| 353 |
| 351 void beginTopLevelMember(Token token) { | 354 void beginTopLevelMember(Token token) { |
| 352 } | 355 } |
| 353 | 356 |
| 354 void endTopLevelFields(int count, Token beginToken, Token endToken) { | 357 void endTopLevelFields(int count, Token beginToken, Token endToken) { |
| 355 } | 358 } |
| 356 | 359 |
| 357 void endTopLevelMethod(Token beginToken, Token getOrSet, Token endToken) { | 360 void endTopLevelMethod(Token beginToken, Token getOrSet, Token endToken) { |
| 358 } | 361 } |
| 359 | 362 |
| 360 void beginTryStatement(Token token) { | 363 void beginTryStatement(Token token) { |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 675 bool allowLibraryTags() { | 678 bool allowLibraryTags() { |
| 676 // Library tags are only allowed in the library file itself, not | 679 // Library tags are only allowed in the library file itself, not |
| 677 // in sourced files. | 680 // in sourced files. |
| 678 LibraryElement library = compilationUnitElement.getLibrary(); | 681 LibraryElement library = compilationUnitElement.getLibrary(); |
| 679 return !compilationUnitElement.hasMembers | 682 return !compilationUnitElement.hasMembers |
| 680 && library.entryCompilationUnit == compilationUnitElement; | 683 && library.entryCompilationUnit == compilationUnitElement; |
| 681 } | 684 } |
| 682 | 685 |
| 683 void endLibraryName(Token libraryKeyword, Token semicolon) { | 686 void endLibraryName(Token libraryKeyword, Token semicolon) { |
| 684 Expression name = popNode(); | 687 Expression name = popNode(); |
| 685 addLibraryTag(new LibraryName(libraryKeyword, name)); | 688 addLibraryTag(new LibraryName(libraryKeyword, name, popMetadata(compilationU
nitElement))); |
| 686 } | 689 } |
| 687 | 690 |
| 688 void endImport(Token importKeyword, Token asKeyword, Token semicolon) { | 691 void endImport(Token importKeyword, Token asKeyword, Token semicolon) { |
| 689 NodeList combinators = popNode(); | 692 NodeList combinators = popNode(); |
| 690 Identifier prefix; | 693 Identifier prefix; |
| 691 if (asKeyword != null) { | 694 if (asKeyword != null) { |
| 692 prefix = popNode(); | 695 prefix = popNode(); |
| 693 } | 696 } |
| 694 StringNode uri = popLiteralString(); | 697 StringNode uri = popLiteralString(); |
| 695 addLibraryTag(new Import(importKeyword, uri, prefix, combinators)); | 698 addLibraryTag(new Import(importKeyword, uri, prefix, combinators, |
| 699 popMetadata(compilationUnitElement))); |
| 696 } | 700 } |
| 697 | 701 |
| 698 void endExport(Token exportKeyword, Token semicolon) { | 702 void endExport(Token exportKeyword, Token semicolon) { |
| 699 NodeList combinators = popNode(); | 703 NodeList combinators = popNode(); |
| 700 StringNode uri = popNode(); | 704 StringNode uri = popNode(); |
| 701 addLibraryTag(new Export(exportKeyword, uri, combinators)); | 705 addLibraryTag(new Export(exportKeyword, uri, combinators)); |
| 702 } | 706 } |
| 703 | 707 |
| 704 void endCombinators(int count) { | 708 void endCombinators(int count) { |
| 705 if (0 == count) { | 709 if (0 == count) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 721 void endIdentifierList(int count) { | 725 void endIdentifierList(int count) { |
| 722 pushNode(makeNodeList(count, null, null, ",")); | 726 pushNode(makeNodeList(count, null, null, ",")); |
| 723 } | 727 } |
| 724 | 728 |
| 725 void endTypeList(int count) { | 729 void endTypeList(int count) { |
| 726 pushNode(makeNodeList(count, null, null, ",")); | 730 pushNode(makeNodeList(count, null, null, ",")); |
| 727 } | 731 } |
| 728 | 732 |
| 729 void endPart(Token partKeyword, Token semicolon) { | 733 void endPart(Token partKeyword, Token semicolon) { |
| 730 StringNode uri = popLiteralString(); | 734 StringNode uri = popLiteralString(); |
| 731 addLibraryTag(new Part(partKeyword, uri)); | 735 addLibraryTag(new Part(partKeyword, uri, popMetadata(compilationUnitElement)
)); |
| 732 } | 736 } |
| 733 | 737 |
| 734 void endPartOf(Token partKeyword, Token semicolon) { | 738 void endPartOf(Token partKeyword, Token semicolon) { |
| 735 Expression name = popNode(); | 739 Expression name = popNode(); |
| 736 addPartOfTag(new PartOf(partKeyword, name)); | 740 addPartOfTag(new PartOf(partKeyword, name, popMetadata(compilationUnitElemen
t))); |
| 737 } | 741 } |
| 738 | 742 |
| 739 void addPartOfTag(PartOf tag) { | 743 void addPartOfTag(PartOf tag) { |
| 740 compilationUnitElement.setPartOf(tag, listener); | 744 compilationUnitElement.setPartOf(tag, listener); |
| 741 } | 745 } |
| 742 | 746 |
| 743 void endScriptTag(bool hasPrefix, Token beginToken, Token endToken) { | 747 void endScriptTag(bool hasPrefix, Token beginToken, Token endToken) { |
| 744 LiteralString prefix = null; | 748 LiteralString prefix = null; |
| 745 Identifier argumentName = null; | 749 Identifier argumentName = null; |
| 746 if (hasPrefix) { | 750 if (hasPrefix) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 761 } | 765 } |
| 762 | 766 |
| 763 void endMetadata(Token beginToken, Token periodBeforeName, Token endToken) { | 767 void endMetadata(Token beginToken, Token periodBeforeName, Token endToken) { |
| 764 if (periodBeforeName != null) { | 768 if (periodBeforeName != null) { |
| 765 popNode(); // Discard name. | 769 popNode(); // Discard name. |
| 766 } | 770 } |
| 767 popNode(); // Discard node (Send or Identifier). | 771 popNode(); // Discard node (Send or Identifier). |
| 768 pushMetadata(new PartialMetadataAnnotation(beginToken)); | 772 pushMetadata(new PartialMetadataAnnotation(beginToken)); |
| 769 } | 773 } |
| 770 | 774 |
| 775 void endTopLevelDeclaration(Token token) { |
| 776 if (!metadata.isEmpty) { |
| 777 recoverableError('Error: Metadata not supported here.', |
| 778 token: metadata.head.beginToken); |
| 779 metadata = const Link<MetadataAnnotation>(); |
| 780 } |
| 781 } |
| 782 |
| 771 void endClassDeclaration(int interfacesCount, Token beginToken, | 783 void endClassDeclaration(int interfacesCount, Token beginToken, |
| 772 Token extendsKeyword, Token implementsKeyword, | 784 Token extendsKeyword, Token implementsKeyword, |
| 773 Token endToken) { | 785 Token endToken) { |
| 774 SourceString nativeTagInfo = native.checkForNativeClass(this); | 786 SourceString nativeTagInfo = native.checkForNativeClass(this); |
| 775 NodeList interfaces = | 787 NodeList interfaces = |
| 776 makeNodeList(interfacesCount, implementsKeyword, null, ","); | 788 makeNodeList(interfacesCount, implementsKeyword, null, ","); |
| 777 Node supertype = popNode(); | 789 Node supertype = popNode(); |
| 778 NodeList typeParameters = popNode(); | 790 NodeList typeParameters = popNode(); |
| 779 Identifier name = popNode(); | 791 Identifier name = popNode(); |
| 780 int id = idGenerator(); | 792 int id = idGenerator(); |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1043 Token unmatched(Token token) { | 1055 Token unmatched(Token token) { |
| 1044 listener.cancel("unmatched '${token.slowToString()}'", token: token); | 1056 listener.cancel("unmatched '${token.slowToString()}'", token: token); |
| 1045 return skipToEof(token); | 1057 return skipToEof(token); |
| 1046 } | 1058 } |
| 1047 | 1059 |
| 1048 void recoverableError(String message, {Token token, Node node}) { | 1060 void recoverableError(String message, {Token token, Node node}) { |
| 1049 listener.cancel(message, token: token, node: node); | 1061 listener.cancel(message, token: token, node: node); |
| 1050 } | 1062 } |
| 1051 | 1063 |
| 1052 void pushElement(Element element) { | 1064 void pushElement(Element element) { |
| 1065 popMetadata(element); |
| 1066 compilationUnitElement.addMember(element, listener); |
| 1067 } |
| 1068 |
| 1069 Link<MetadataAnnotation> popMetadata(Element element) { |
| 1070 var result = metadata; |
| 1053 for (Link link = metadata; !link.isEmpty; link = link.tail) { | 1071 for (Link link = metadata; !link.isEmpty; link = link.tail) { |
| 1054 element.addMetadata(link.head); | 1072 element.addMetadata(link.head); |
| 1055 } | 1073 } |
| 1056 metadata = const Link<MetadataAnnotation>(); | 1074 metadata = const Link<MetadataAnnotation>(); |
| 1057 compilationUnitElement.addMember(element, listener); | 1075 return result; |
| 1058 } | 1076 } |
| 1059 | 1077 |
| 1060 void pushMetadata(MetadataAnnotation annotation) { | 1078 void pushMetadata(MetadataAnnotation annotation) { |
| 1061 metadata = metadata.prepend(annotation); | 1079 metadata = metadata.prepend(annotation); |
| 1062 } | 1080 } |
| 1063 | 1081 |
| 1064 // TODO(ahe): Remove this method. | 1082 // TODO(ahe): Remove this method. |
| 1065 void addScriptTag(ScriptTag tag) { | 1083 void addScriptTag(ScriptTag tag) { |
| 1066 listener.onDeprecatedFeature(tag, '# tags'); | 1084 listener.onDeprecatedFeature(tag, '# tags'); |
| 1067 addLibraryTag(tag.toLibraryTag()); | 1085 addLibraryTag(tag.toLibraryTag()); |
| (...skipping 956 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2024 | 2042 |
| 2025 Node parse(DiagnosticListener diagnosticListener, | 2043 Node parse(DiagnosticListener diagnosticListener, |
| 2026 CompilationUnitElement element, | 2044 CompilationUnitElement element, |
| 2027 doParse(Parser parser)) { | 2045 doParse(Parser parser)) { |
| 2028 NodeListener listener = new NodeListener(diagnosticListener, element); | 2046 NodeListener listener = new NodeListener(diagnosticListener, element); |
| 2029 doParse(new Parser(listener)); | 2047 doParse(new Parser(listener)); |
| 2030 Node node = listener.popNode(); | 2048 Node node = listener.popNode(); |
| 2031 assert(listener.nodes.isEmpty); | 2049 assert(listener.nodes.isEmpty); |
| 2032 return node; | 2050 return node; |
| 2033 } | 2051 } |
| OLD | NEW |