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 '../native/native.dart' as native; | 9 import '../native/native.dart' as native; |
10 import '../tokens/precedence_constants.dart' as Precedence show INDEX_INFO; | 10 import '../tokens/precedence_constants.dart' as Precedence show INDEX_INFO; |
11 import '../tokens/token.dart' show ErrorToken, StringToken, Token; | 11 import '../tokens/token.dart' show ErrorToken, StringToken, Token; |
12 import '../tree/tree.dart'; | 12 import '../tree/tree.dart'; |
13 import '../util/util.dart' show Link; | 13 import '../util/util.dart' show Link; |
14 import 'element_listener.dart' show ElementListener, ScannerOptions; | 14 import 'element_listener.dart' show ElementListener, ScannerOptions; |
15 import 'partial_elements.dart' show PartialFunctionElement; | 15 import 'partial_elements.dart' show PartialFunctionElement; |
16 | 16 |
17 class NodeListener extends ElementListener { | 17 class NodeListener extends ElementListener { |
18 NodeListener(ScannerOptions scannerOptions, DiagnosticReporter reporter, | 18 NodeListener(ScannerOptions scannerOptions, DiagnosticReporter reporter, |
19 CompilationUnitElement element) | 19 CompilationUnitElement element) |
20 : super(scannerOptions, reporter, element, null); | 20 : super(scannerOptions, reporter, element, null); |
21 | 21 |
22 void addLibraryTag(LibraryTag tag) { | 22 void addLibraryTag(LibraryTag tag) { |
23 pushNode(tag); | 23 pushNode(tag); |
24 } | 24 } |
25 | 25 |
26 void addPartOfTag(PartOf tag) { | 26 void addPartOfTag(PartOf tag) { |
27 pushNode(tag); | 27 pushNode(tag); |
28 } | 28 } |
29 | 29 |
30 void endLibraryName(Token libraryKeyword, Token semicolon) { | |
31 Expression name = popNode(); | |
32 pushNode(new LibraryName(libraryKeyword, name, | |
33 // TODO(sigmund): Import AST nodes have pointers to MetadataAnnotation | |
34 // (element) instead of Metatada (node). | |
35 null)); | |
36 } | |
37 | |
38 void endImport(Token importKeyword, Token deferredKeyword, Token asKeyword, | |
39 Token semicolon) { | |
40 NodeList combinators = popNode(); | |
41 Identifier prefix = asKeyword != null ? popNode() : null; | |
42 NodeList conditionalUris = popNode(); | |
43 StringNode uri = popLiteralString(); | |
44 pushNode(new Import(importKeyword, uri, conditionalUris, prefix, | |
45 combinators, | |
46 // TODO(sigmund): Import AST nodes have pointers to MetadataAnnotation | |
47 // (element) instead of Metatada (node). | |
48 null, isDeferred: deferredKeyword != null)); | |
49 } | |
50 | |
51 void endExport(Token exportKeyword, Token semicolon) { | |
52 NodeList combinators = popNode(); | |
53 NodeList conditionalUris = popNode(); | |
54 StringNode uri = popLiteralString(); | |
55 pushNode(new Export(exportKeyword, uri, conditionalUris, combinators, | |
56 // TODO(sigmund): Import AST nodes have pointers to MetadataAnnotation | |
57 // (element) instead of Metatada (node). | |
58 null)); | |
59 } | |
60 | |
61 void endPart(Token partKeyword, Token semicolon) { | |
62 StringNode uri = popLiteralString(); | |
63 pushNode(new Part(partKeyword, uri, | |
64 // TODO(sigmund): Import AST nodes have pointers to MetadataAnnotation | |
65 // (element) instead of Metatada (node). | |
66 null)); | |
67 } | |
68 | |
69 void endPartOf(Token partKeyword, Token semicolon) { | |
70 Expression name = popNode(); // name | |
71 pushNode(new PartOf(partKeyword, name, | |
72 // TODO(sigmund): Import AST nodes have pointers to MetadataAnnotation | |
73 // (element) instead of Metatada (node). | |
74 null)); | |
75 } | |
76 | |
30 void endClassDeclaration(int interfacesCount, Token beginToken, | 77 void endClassDeclaration(int interfacesCount, Token beginToken, |
31 Token extendsKeyword, Token implementsKeyword, Token endToken) { | 78 Token extendsKeyword, Token implementsKeyword, Token endToken) { |
32 NodeList body = popNode(); | 79 NodeList body = popNode(); |
33 NodeList interfaces = | 80 NodeList interfaces = |
34 makeNodeList(interfacesCount, implementsKeyword, null, ","); | 81 makeNodeList(interfacesCount, implementsKeyword, null, ","); |
35 Node supertype = popNode(); | 82 Node supertype = popNode(); |
36 NodeList typeParameters = popNode(); | 83 NodeList typeParameters = popNode(); |
37 Identifier name = popNode(); | 84 Identifier name = popNode(); |
38 Modifiers modifiers = popNode(); | 85 Modifiers modifiers = popNode(); |
39 pushNode(new ClassNode(modifiers, name, typeParameters, supertype, | 86 pushNode(new ClassNode(modifiers, name, typeParameters, supertype, |
40 interfaces, beginToken, extendsKeyword, body, endToken)); | 87 interfaces, beginToken, extendsKeyword, body, endToken)); |
41 } | 88 } |
42 | 89 |
90 void endTopLevelDeclaration(Token token) { | |
91 // TODO(sigmund): consider moving metadata into each declaration | |
92 // element instead. | |
93 Node node = popNode(); // top-level declaration | |
94 popNode(); // Discard metadata | |
95 pushNode(node); | |
96 super.endTopLevelDeclaration(token); | |
97 } | |
98 | |
43 void endCompilationUnit(int count, Token token) { | 99 void endCompilationUnit(int count, Token token) { |
44 pushNode(makeNodeList(count, null, null, '\n')); | 100 pushNode(makeNodeList(count, null, null, '\n')); |
45 } | 101 } |
46 | 102 |
47 void endFunctionTypeAlias(Token typedefKeyword, Token endToken) { | 103 void endFunctionTypeAlias(Token typedefKeyword, Token endToken) { |
48 NodeList formals = popNode(); | 104 NodeList formals = popNode(); |
49 NodeList typeParameters = popNode(); | 105 NodeList typeParameters = popNode(); |
50 Identifier name = popNode(); | 106 Identifier name = popNode(); |
51 TypeAnnotation returnType = popNode(); | 107 TypeAnnotation returnType = popNode(); |
52 pushNode(new Typedef( | 108 pushNode(new Typedef( |
(...skipping 22 matching lines...) Expand all Loading... | |
75 } | 131 } |
76 | 132 |
77 void endTopLevelFields(int count, Token beginToken, Token endToken) { | 133 void endTopLevelFields(int count, Token beginToken, Token endToken) { |
78 NodeList variables = makeNodeList(count, null, endToken, ","); | 134 NodeList variables = makeNodeList(count, null, endToken, ","); |
79 TypeAnnotation type = popNode(); | 135 TypeAnnotation type = popNode(); |
80 Modifiers modifiers = popNode(); | 136 Modifiers modifiers = popNode(); |
81 pushNode(new VariableDefinitions(type, modifiers, variables)); | 137 pushNode(new VariableDefinitions(type, modifiers, variables)); |
82 } | 138 } |
83 | 139 |
84 void endTopLevelMethod(Token beginToken, Token getOrSet, Token endToken) { | 140 void endTopLevelMethod(Token beginToken, Token getOrSet, Token endToken) { |
85 popNode(); // body | 141 Statement body = popNode(); |
86 popNode(); // formalParameters | 142 AsyncModifier asyncModifier = popNode(); |
87 popNode(); // typeVariables | 143 NodeList formals = popNode(); |
144 NodeList typeVariables = popNode(); | |
88 Identifier name = popNode(); | 145 Identifier name = popNode(); |
89 popNode(); // type | 146 TypeAnnotation type = popNode(); |
90 Modifiers modifiers = popNode(); | 147 Modifiers modifiers = popNode(); |
91 PartialFunctionElement element = new PartialFunctionElement(name.source, | 148 pushNode(new FunctionExpression(name, typeVariables, formals, body, type, |
Siggi Cherem (dart-lang)
2016/09/30 22:28:07
note: this was inconsistent (likely copy/paste err
| |
92 beginToken, getOrSet, endToken, modifiers, compilationUnitElement); | 149 modifiers, null, getOrSet, asyncModifier)); |
93 pushElement(element); | |
94 } | 150 } |
95 | 151 |
96 void endFormalParameter(Token thisKeyword) { | 152 void endFormalParameter(Token thisKeyword) { |
97 Expression name = popNode(); | 153 Expression name = popNode(); |
98 if (thisKeyword != null) { | 154 if (thisKeyword != null) { |
99 Identifier thisIdentifier = new Identifier(thisKeyword); | 155 Identifier thisIdentifier = new Identifier(thisKeyword); |
100 if (name.asSend() == null) { | 156 if (name.asSend() == null) { |
101 name = new Send(thisIdentifier, name); | 157 name = new Send(thisIdentifier, name); |
102 } else { | 158 } else { |
103 name = name.asSend().copyWithReceiver(thisIdentifier, false); | 159 name = name.asSend().copyWithReceiver(thisIdentifier, false); |
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
474 } | 530 } |
475 | 531 |
476 void endInitializers(int count, Token beginToken, Token endToken) { | 532 void endInitializers(int count, Token beginToken, Token endToken) { |
477 pushNode(makeNodeList(count, beginToken, null, ',')); | 533 pushNode(makeNodeList(count, beginToken, null, ',')); |
478 } | 534 } |
479 | 535 |
480 void handleNoInitializers() { | 536 void handleNoInitializers() { |
481 pushNode(null); | 537 pushNode(null); |
482 } | 538 } |
483 | 539 |
540 void endMember() { | |
541 // TODO(sigmund): consider moving metadata into each declaration | |
542 // element instead. | |
543 Node node = popNode(); // member | |
544 popNode(); // Discard metadata | |
545 pushNode(node); | |
546 super.endMember(); | |
547 } | |
548 | |
484 void endFields(int count, Token beginToken, Token endToken) { | 549 void endFields(int count, Token beginToken, Token endToken) { |
485 NodeList variables = makeNodeList(count, null, endToken, ","); | 550 NodeList variables = makeNodeList(count, null, endToken, ","); |
486 TypeAnnotation type = popNode(); | 551 TypeAnnotation type = popNode(); |
487 Modifiers modifiers = popNode(); | 552 Modifiers modifiers = popNode(); |
488 pushNode(new VariableDefinitions(type, modifiers, variables)); | 553 pushNode(new VariableDefinitions(type, modifiers, variables)); |
489 } | 554 } |
490 | 555 |
491 void endMethod(Token getOrSet, Token beginToken, Token endToken) { | 556 void endMethod(Token getOrSet, Token beginToken, Token endToken) { |
492 Statement body = popNode(); | 557 Statement body = popNode(); |
493 AsyncModifier asyncModifier = popNode(); | 558 AsyncModifier asyncModifier = popNode(); |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
686 if (awaitToken == null) { | 751 if (awaitToken == null) { |
687 pushNode(new SyncForIn( | 752 pushNode(new SyncForIn( |
688 declaredIdentifier, expression, body, forToken, inKeyword)); | 753 declaredIdentifier, expression, body, forToken, inKeyword)); |
689 } else { | 754 } else { |
690 pushNode(new AsyncForIn(declaredIdentifier, expression, body, awaitToken, | 755 pushNode(new AsyncForIn(declaredIdentifier, expression, body, awaitToken, |
691 forToken, inKeyword)); | 756 forToken, inKeyword)); |
692 } | 757 } |
693 } | 758 } |
694 | 759 |
695 void endMetadataStar(int count, bool forParameter) { | 760 void endMetadataStar(int count, bool forParameter) { |
696 // TODO(johnniwinther): Handle metadata for all node kinds. | 761 if (0 == count) { |
697 if (forParameter) { | 762 pushNode(null); |
698 if (0 == count) { | 763 } else { |
699 pushNode(null); | 764 pushNode(makeNodeList(count, null, null, ' ')); |
700 } else { | |
701 pushNode(makeNodeList(count, null, null, ' ')); | |
702 } | |
703 } | 765 } |
704 } | 766 } |
705 | 767 |
706 void endMetadata(Token beginToken, Token periodBeforeName, Token endToken) { | 768 void endMetadata(Token beginToken, Token periodBeforeName, Token endToken) { |
707 NodeList arguments = popNode(); | 769 NodeList arguments = popNode(); |
708 if (arguments == null) { | 770 if (arguments == null) { |
709 // This is a constant expression. | 771 // This is a constant expression. |
710 Identifier name; | 772 Identifier name; |
711 if (periodBeforeName != null) { | 773 if (periodBeforeName != null) { |
712 name = popNode(); | 774 name = popNode(); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
787 void log(message) { | 849 void log(message) { |
788 reporter.log(message); | 850 reporter.log(message); |
789 } | 851 } |
790 | 852 |
791 void internalError({Token token, Node node}) { | 853 void internalError({Token token, Node node}) { |
792 // TODO(ahe): This should call reporter.internalError. | 854 // TODO(ahe): This should call reporter.internalError. |
793 Spannable spannable = (token == null) ? node : token; | 855 Spannable spannable = (token == null) ? node : token; |
794 throw new SpannableAssertionFailure(spannable, 'Internal error in parser.'); | 856 throw new SpannableAssertionFailure(spannable, 'Internal error in parser.'); |
795 } | 857 } |
796 } | 858 } |
OLD | NEW |