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

Side by Side Diff: pkg/compiler/lib/src/parser/node_listener.dart

Issue 2567133002: Add support for the new function-type syntax. (Closed)
Patch Set: Fixes after rebase. Created 3 years, 9 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.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
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(Token typedefKeyword, Token endToken) { 129 void endFunctionTypeAlias(
130 NodeList formals = popNode(); 130 Token typedefKeyword, Token equals, Token endToken) {
131 NodeList typeParameters = popNode(); 131 bool isGeneralizedTypeAlias;
132 Identifier name = popNode(); 132 NodeList templateParameters;
133 TypeAnnotation returnType = popNode(); 133 TypeAnnotation returnType;
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 }
134 pushNode(new Typedef( 161 pushNode(new Typedef(
135 returnType, name, typeParameters, formals, typedefKeyword, endToken)); 162 isGeneralizedTypeAlias,
163 templateParameters,
164 returnType,
165 name,
166 typeParameters,
167 formals,
168 typedefKeyword,
169 endToken));
170 }
171
172 void handleNoName(Token token) {
173 pushNode(null);
136 } 174 }
137 175
138 @override 176 @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
139 void endNamedMixinApplication( 186 void endNamedMixinApplication(
140 Token beginToken, Token classKeyword, Token equals, 187 Token beginToken, Token classKeyword, Token equals,
141 Token implementsKeyword, Token endToken) { 188 Token implementsKeyword, Token endToken) {
142 NodeList interfaces = (implementsKeyword != null) ? popNode() : null; 189 NodeList interfaces = (implementsKeyword != null) ? popNode() : null;
143 Node mixinApplication = popNode(); 190 Node mixinApplication = popNode();
144 NodeList typeParameters = popNode(); 191 NodeList typeParameters = popNode();
145 Identifier name = popNode(); 192 Identifier name = popNode();
146 Modifiers modifiers = popNode(); 193 Modifiers modifiers = popNode();
147 pushNode(new NamedMixinApplication(name, typeParameters, modifiers, 194 pushNode(new NamedMixinApplication(name, typeParameters, modifiers,
148 mixinApplication, interfaces, beginToken, endToken)); 195 mixinApplication, interfaces, beginToken, endToken));
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 @override 269 @override
223 void endConstructorReference( 270 void endConstructorReference(
224 Token start, Token periodBeforeName, Token endToken) { 271 Token start, Token periodBeforeName, Token endToken) {
225 Identifier name = null; 272 Identifier name = null;
226 if (periodBeforeName != null) { 273 if (periodBeforeName != null) {
227 name = popNode(); 274 name = popNode();
228 } 275 }
229 NodeList typeArguments = popNode(); 276 NodeList typeArguments = popNode();
230 Node classReference = popNode(); 277 Node classReference = popNode();
231 if (typeArguments != null) { 278 if (typeArguments != null) {
232 classReference = new TypeAnnotation(classReference, typeArguments); 279 classReference = new NominalTypeAnnotation(classReference, typeArguments);
233 } else { 280 } else {
234 Identifier identifier = classReference.asIdentifier(); 281 Identifier identifier = classReference.asIdentifier();
235 Send send = classReference.asSend(); 282 Send send = classReference.asSend();
236 if (identifier != null) { 283 if (identifier != null) {
237 // TODO(ahe): Should be: 284 // TODO(ahe): Should be:
238 // classReference = new Send(null, identifier); 285 // classReference = new Send(null, identifier);
239 classReference = identifier; 286 classReference = identifier;
240 } else if (send != null) { 287 } else if (send != null) {
241 classReference = send; 288 classReference = send;
242 } else { 289 } else {
(...skipping 617 matching lines...) Expand 10 before | Expand all | Expand 10 after
860 NodeList arguments = popNode(); 907 NodeList arguments = popNode();
861 if (arguments == null) { 908 if (arguments == null) {
862 // This is a constant expression. 909 // This is a constant expression.
863 Identifier name; 910 Identifier name;
864 if (periodBeforeName != null) { 911 if (periodBeforeName != null) {
865 name = popNode(); 912 name = popNode();
866 } 913 }
867 NodeList typeArguments = popNode(); 914 NodeList typeArguments = popNode();
868 Node receiver = popNode(); 915 Node receiver = popNode();
869 if (typeArguments != null) { 916 if (typeArguments != null) {
870 receiver = new TypeAnnotation(receiver, typeArguments); 917 receiver = new NominalTypeAnnotation(receiver, typeArguments);
871 recoverableError(typeArguments, 'Type arguments are not allowed here.'); 918 recoverableError(typeArguments, 'Type arguments are not allowed here.');
872 } else { 919 } else {
873 Identifier identifier = receiver.asIdentifier(); 920 Identifier identifier = receiver.asIdentifier();
874 Send send = receiver.asSend(); 921 Send send = receiver.asSend();
875 if (identifier != null) { 922 if (identifier != null) {
876 receiver = new Send(null, identifier); 923 receiver = new Send(null, identifier);
877 } else if (send == null) { 924 } else if (send == null) {
878 internalError(node: receiver); 925 internalError(node: receiver);
879 } 926 }
880 } 927 }
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
954 } 1001 }
955 lastErrorWasNativeFunctionBody = false; 1002 lastErrorWasNativeFunctionBody = false;
956 } 1003 }
957 1004
958 void internalError({Token token, Node node}) { 1005 void internalError({Token token, Node node}) {
959 // TODO(ahe): This should call reporter.internalError. 1006 // TODO(ahe): This should call reporter.internalError.
960 Spannable spannable = (token == null) ? node : token; 1007 Spannable spannable = (token == null) ? node : token;
961 throw new SpannableAssertionFailure(spannable, 'Internal error in parser.'); 1008 throw new SpannableAssertionFailure(spannable, 'Internal error in parser.');
962 } 1009 }
963 } 1010 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698