OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 fasta.outline_builder; | 5 library fasta.outline_builder; |
6 | 6 |
7 import 'package:kernel/ast.dart' show AsyncMarker, ProcedureKind; | 7 import 'package:kernel/ast.dart' show AsyncMarker, ProcedureKind; |
8 | 8 |
9 import '../parser/parser.dart' show FormalParameterType, optional; | 9 import '../parser/parser.dart' show FormalParameterType, optional; |
10 | 10 |
| 11 import '../parser/identifier_context.dart' show IdentifierContext; |
| 12 |
11 import '../scanner/token.dart' show Token; | 13 import '../scanner/token.dart' show Token; |
12 | 14 |
13 import '../util/link.dart' show Link; | 15 import '../util/link.dart' show Link; |
14 | 16 |
15 import '../combinator.dart' show Combinator; | 17 import '../combinator.dart' show Combinator; |
16 | 18 |
17 import '../errors.dart' show internalError; | 19 import '../errors.dart' show internalError; |
18 | 20 |
19 import '../builder/builder.dart'; | 21 import '../builder/builder.dart'; |
20 | 22 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 String nativeMethodName; | 69 String nativeMethodName; |
68 | 70 |
69 OutlineBuilder(SourceLibraryBuilder library) | 71 OutlineBuilder(SourceLibraryBuilder library) |
70 : library = library, | 72 : library = library, |
71 isDartLibrary = library.uri.scheme == "dart"; | 73 isDartLibrary = library.uri.scheme == "dart"; |
72 | 74 |
73 @override | 75 @override |
74 Uri get uri => library.fileUri; | 76 Uri get uri => library.fileUri; |
75 | 77 |
76 @override | 78 @override |
| 79 int popCharOffset() => pop(); |
| 80 |
| 81 List<String> popIdentifierList(int count) { |
| 82 if (count == 0) return null; |
| 83 List<String> list = new List<String>.filled(count, null, growable: true); |
| 84 for (int i = count - 1; i >= 0; i--) { |
| 85 popCharOffset(); |
| 86 list[i] = pop(); |
| 87 } |
| 88 return list; |
| 89 } |
| 90 |
| 91 @override |
77 void endMetadata(Token beginToken, Token periodBeforeName, Token endToken) { | 92 void endMetadata(Token beginToken, Token periodBeforeName, Token endToken) { |
78 debugEvent("Metadata"); | 93 debugEvent("Metadata"); |
79 List arguments = pop(); | 94 List arguments = pop(); |
| 95 popIfNotNull(periodBeforeName); // charOffset. |
80 String postfix = popIfNotNull(periodBeforeName); | 96 String postfix = popIfNotNull(periodBeforeName); |
81 List<TypeBuilder> typeArguments = pop(); | 97 List<TypeBuilder> typeArguments = pop(); |
82 if (arguments == null) { | 98 if (arguments == null) { |
| 99 int charOffset = pop(); |
83 String expression = pop(); | 100 String expression = pop(); |
84 push(new MetadataBuilder.fromExpression( | 101 push(new MetadataBuilder.fromExpression( |
85 expression, postfix, library, beginToken.charOffset)); | 102 expression, postfix, library, charOffset)); |
86 } else { | 103 } else { |
| 104 int charOffset = pop(); |
87 String typeName = pop(); | 105 String typeName = pop(); |
88 push(new MetadataBuilder.fromConstructor( | 106 push(new MetadataBuilder.fromConstructor( |
89 library.addConstructorReference( | 107 library.addConstructorReference( |
90 typeName, typeArguments, postfix, beginToken.next.charOffset), | 108 typeName, typeArguments, postfix, charOffset), |
91 arguments, | 109 arguments, |
92 library, | 110 library, |
93 beginToken.charOffset)); | 111 beginToken.charOffset)); |
94 } | 112 } |
95 } | 113 } |
96 | 114 |
97 @override | 115 @override |
98 void endHide(Token hideKeyword) { | 116 void endHide(Token hideKeyword) { |
99 debugEvent("Hide"); | 117 debugEvent("Hide"); |
100 List<String> names = pop(); | 118 List<String> names = pop(); |
(...skipping 11 matching lines...) Expand all Loading... |
112 void endCombinators(int count) { | 130 void endCombinators(int count) { |
113 debugEvent("Combinators"); | 131 debugEvent("Combinators"); |
114 push(popList(count) ?? NullValue.Combinators); | 132 push(popList(count) ?? NullValue.Combinators); |
115 } | 133 } |
116 | 134 |
117 @override | 135 @override |
118 void endExport(Token exportKeyword, Token semicolon) { | 136 void endExport(Token exportKeyword, Token semicolon) { |
119 debugEvent("Export"); | 137 debugEvent("Export"); |
120 List<Combinator> combinators = pop(); | 138 List<Combinator> combinators = pop(); |
121 Unhandled conditionalUris = pop(); | 139 Unhandled conditionalUris = pop(); |
| 140 popCharOffset(); |
122 String uri = pop(); | 141 String uri = pop(); |
123 List<MetadataBuilder> metadata = pop(); | 142 List<MetadataBuilder> metadata = pop(); |
124 if (uri != null) { | 143 if (uri != null) { |
125 library.addExport(metadata, uri, conditionalUris, combinators, | 144 library.addExport(metadata, uri, conditionalUris, combinators, |
126 exportKeyword.charOffset); | 145 exportKeyword.charOffset); |
127 } | 146 } |
128 checkEmpty(exportKeyword.charOffset); | 147 checkEmpty(exportKeyword.charOffset); |
129 } | 148 } |
130 | 149 |
131 @override | 150 @override |
132 void endImport(Token importKeyword, Token deferredKeyword, Token asKeyword, | 151 void endImport(Token importKeyword, Token deferredKeyword, Token asKeyword, |
133 Token semicolon) { | 152 Token semicolon) { |
134 debugEvent("endImport"); | 153 debugEvent("endImport"); |
135 List<Combinator> combinators = pop(); | 154 List<Combinator> combinators = pop(); |
| 155 int prefixOffset = popIfNotNull(asKeyword) ?? -1; |
136 String prefix = popIfNotNull(asKeyword); | 156 String prefix = popIfNotNull(asKeyword); |
137 Unhandled conditionalUris = pop(); | 157 Unhandled conditionalUris = pop(); |
| 158 popCharOffset(); |
138 String uri = pop(); | 159 String uri = pop(); |
139 List<MetadataBuilder> metadata = pop(); | 160 List<MetadataBuilder> metadata = pop(); |
140 if (uri != null) { | 161 if (uri != null) { |
141 library.addImport( | 162 library.addImport(metadata, uri, conditionalUris, prefix, combinators, |
142 metadata, | 163 deferredKeyword != null, importKeyword.charOffset, prefixOffset); |
143 uri, | |
144 conditionalUris, | |
145 prefix, | |
146 combinators, | |
147 deferredKeyword != null, | |
148 importKeyword.charOffset, | |
149 asKeyword?.next?.charOffset ?? -1); | |
150 } | 164 } |
151 checkEmpty(importKeyword.charOffset); | 165 checkEmpty(importKeyword.charOffset); |
152 } | 166 } |
153 | 167 |
154 @override | 168 @override |
155 void handleRecoverExpression(Token token) { | 169 void handleRecoverExpression(Token token) { |
156 debugEvent("RecoverExpression"); | 170 debugEvent("RecoverExpression"); |
157 push(NullValue.Expression); | 171 push(NullValue.Expression); |
| 172 push(token.charOffset); |
158 } | 173 } |
159 | 174 |
160 @override | 175 @override |
161 void endPart(Token partKeyword, Token semicolon) { | 176 void endPart(Token partKeyword, Token semicolon) { |
162 debugEvent("Part"); | 177 debugEvent("Part"); |
| 178 popCharOffset(); |
163 String uri = pop(); | 179 String uri = pop(); |
164 List<MetadataBuilder> metadata = pop(); | 180 List<MetadataBuilder> metadata = pop(); |
165 if (uri != null) { | 181 if (uri != null) { |
166 library.addPart(metadata, uri); | 182 library.addPart(metadata, uri); |
167 } | 183 } |
168 checkEmpty(partKeyword.charOffset); | 184 checkEmpty(partKeyword.charOffset); |
169 } | 185 } |
170 | 186 |
171 @override | 187 @override |
172 void handleOperatorName(Token operatorKeyword, Token token) { | 188 void handleOperatorName(Token operatorKeyword, Token token) { |
173 debugEvent("OperatorName"); | 189 debugEvent("OperatorName"); |
174 push(operatorFromString(token.stringValue)); | 190 push(operatorFromString(token.stringValue)); |
| 191 push(token.charOffset); |
| 192 } |
| 193 |
| 194 @override |
| 195 void handleIdentifier(Token token, IdentifierContext context) { |
| 196 super.handleIdentifier(token, context); |
| 197 push(token.charOffset); |
| 198 } |
| 199 |
| 200 @override |
| 201 void handleNoName(Token token) { |
| 202 super.handleNoName(token); |
| 203 push(token.charOffset); |
| 204 } |
| 205 |
| 206 @override |
| 207 void endLiteralString(int interpolationCount, Token endToken) { |
| 208 debugEvent("endLiteralString"); |
| 209 if (interpolationCount == 0) { |
| 210 Token token = pop(); |
| 211 push(unescapeString(token.lexeme)); |
| 212 push(token.charOffset); |
| 213 } else { |
| 214 internalError("String interpolation not implemented."); |
| 215 } |
| 216 } |
| 217 |
| 218 @override |
| 219 void handleStringJuxtaposition(int literalCount) { |
| 220 debugEvent("StringJuxtaposition"); |
| 221 List<String> list = |
| 222 new List<String>.filled(literalCount, null, growable: false); |
| 223 int charOffset = -1; |
| 224 for (int i = literalCount - 1; i >= 0; i--) { |
| 225 charOffset = pop(); |
| 226 list[i] = pop(); |
| 227 } |
| 228 push(list.join("")); |
| 229 push(charOffset); |
175 } | 230 } |
176 | 231 |
177 @override | 232 @override |
178 void endIdentifierList(int count) { | 233 void endIdentifierList(int count) { |
179 debugEvent("endIdentifierList"); | 234 debugEvent("endIdentifierList"); |
180 push(popList(count) ?? NullValue.IdentifierList); | 235 push(popIdentifierList(count) ?? NullValue.IdentifierList); |
181 } | 236 } |
182 | 237 |
183 @override | 238 @override |
184 void handleQualified(Token period) { | 239 void handleQualified(Token period) { |
185 debugEvent("handleQualified"); | 240 debugEvent("handleQualified"); |
| 241 int charOffset = pop(); |
186 String name = pop(); | 242 String name = pop(); |
| 243 charOffset = pop(); // We just want the charOffset of receiver. |
187 String receiver = pop(); | 244 String receiver = pop(); |
188 push("$receiver.$name"); | 245 push("$receiver.$name"); |
| 246 push(charOffset); |
189 } | 247 } |
190 | 248 |
191 @override | 249 @override |
192 void endLibraryName(Token libraryKeyword, Token semicolon) { | 250 void endLibraryName(Token libraryKeyword, Token semicolon) { |
193 debugEvent("endLibraryName"); | 251 debugEvent("endLibraryName"); |
| 252 popCharOffset(); |
194 String name = pop(); | 253 String name = pop(); |
195 List<MetadataBuilder> metadata = pop(); | 254 List<MetadataBuilder> metadata = pop(); |
196 library.name = name; | 255 library.name = name; |
197 library.metadata = metadata; | 256 library.metadata = metadata; |
198 } | 257 } |
199 | 258 |
200 @override | 259 @override |
201 void beginClassDeclaration(Token begin, Token name) { | 260 void beginClassDeclaration(Token begin, Token name) { |
202 library.beginNestedDeclaration(name.lexeme); | 261 library.beginNestedDeclaration(name.lexeme); |
203 } | 262 } |
204 | 263 |
205 @override | 264 @override |
206 void endClassDeclaration( | 265 void endClassDeclaration( |
207 int interfacesCount, | 266 int interfacesCount, |
208 Token beginToken, | 267 Token beginToken, |
209 Token classKeyword, | 268 Token classKeyword, |
210 Token extendsKeyword, | 269 Token extendsKeyword, |
211 Token implementsKeyword, | 270 Token implementsKeyword, |
212 Token endToken) { | 271 Token endToken) { |
213 debugEvent("endClassDeclaration"); | 272 debugEvent("endClassDeclaration"); |
214 List<TypeBuilder> interfaces = popList(interfacesCount); | 273 List<TypeBuilder> interfaces = popList(interfacesCount); |
215 TypeBuilder supertype = pop(); | 274 TypeBuilder supertype = pop(); |
216 List<TypeVariableBuilder> typeVariables = pop(); | 275 List<TypeVariableBuilder> typeVariables = pop(); |
| 276 int charOffset = pop(); |
217 String name = pop(); | 277 String name = pop(); |
218 if (typeVariables != null && supertype is MixinApplicationBuilder) { | 278 if (typeVariables != null && supertype is MixinApplicationBuilder) { |
219 supertype.typeVariables = typeVariables; | 279 supertype.typeVariables = typeVariables; |
220 supertype.subclassName = name; | 280 supertype.subclassName = name; |
221 } | 281 } |
222 int modifiers = Modifier.validate(pop()); | 282 int modifiers = Modifier.validate(pop()); |
223 List<MetadataBuilder> metadata = pop(); | 283 List<MetadataBuilder> metadata = pop(); |
224 library.addClass(metadata, modifiers, name, typeVariables, supertype, | 284 library.addClass(metadata, modifiers, name, typeVariables, supertype, |
225 interfaces, classKeyword.next?.charOffset ?? beginToken.charOffset); | 285 interfaces, charOffset); |
226 checkEmpty(beginToken.charOffset); | 286 checkEmpty(beginToken.charOffset); |
227 } | 287 } |
228 | 288 |
229 ProcedureKind computeProcedureKind(Token token) { | 289 ProcedureKind computeProcedureKind(Token token) { |
230 if (token == null) return ProcedureKind.Method; | 290 if (token == null) return ProcedureKind.Method; |
231 if (optional("get", token)) return ProcedureKind.Getter; | 291 if (optional("get", token)) return ProcedureKind.Getter; |
232 if (optional("set", token)) return ProcedureKind.Setter; | 292 if (optional("set", token)) return ProcedureKind.Setter; |
233 return internalError("Unhandled: ${token.lexeme}"); | 293 return internalError("Unhandled: ${token.lexeme}"); |
234 } | 294 } |
235 | 295 |
236 @override | 296 @override |
237 void beginTopLevelMethod(Token token, Token name) { | 297 void beginTopLevelMethod(Token token, Token name) { |
238 library.beginNestedDeclaration(name.lexeme, hasMembers: false); | 298 library.beginNestedDeclaration(name.lexeme, hasMembers: false); |
239 } | 299 } |
240 | 300 |
241 @override | 301 @override |
242 void endTopLevelMethod(Token beginToken, Token getOrSet, Token endToken) { | 302 void endTopLevelMethod(Token beginToken, Token getOrSet, Token endToken) { |
243 debugEvent("endTopLevelMethod"); | 303 debugEvent("endTopLevelMethod"); |
244 MethodBody kind = pop(); | 304 MethodBody kind = pop(); |
245 AsyncMarker asyncModifier = pop(); | 305 AsyncMarker asyncModifier = pop(); |
246 List<FormalParameterBuilder> formals = pop(); | 306 List<FormalParameterBuilder> formals = pop(); |
247 int formalsOffset = pop(); | 307 int formalsOffset = pop(); |
248 List<TypeVariableBuilder> typeVariables = pop(); | 308 List<TypeVariableBuilder> typeVariables = pop(); |
| 309 int charOffset = pop(); |
249 String name = pop(); | 310 String name = pop(); |
250 TypeBuilder returnType = pop(); | 311 TypeBuilder returnType = pop(); |
251 int modifiers = | 312 int modifiers = |
252 Modifier.validate(pop(), isAbstract: kind == MethodBody.Abstract); | 313 Modifier.validate(pop(), isAbstract: kind == MethodBody.Abstract); |
253 List<MetadataBuilder> metadata = pop(); | 314 List<MetadataBuilder> metadata = pop(); |
254 checkEmpty(beginToken.charOffset); | 315 checkEmpty(beginToken.charOffset); |
255 library.addProcedure( | 316 library.addProcedure( |
256 metadata, | 317 metadata, |
257 modifiers, | 318 modifiers, |
258 returnType, | 319 returnType, |
259 name, | 320 name, |
260 typeVariables, | 321 typeVariables, |
261 formals, | 322 formals, |
262 asyncModifier, | 323 asyncModifier, |
263 computeProcedureKind(getOrSet), | 324 computeProcedureKind(getOrSet), |
264 beginToken.charOffset, | 325 charOffset, |
265 formalsOffset, | 326 formalsOffset, |
266 endToken.charOffset, | 327 endToken.charOffset, |
267 nativeMethodName, | 328 nativeMethodName, |
268 isTopLevel: true); | 329 isTopLevel: true); |
269 nativeMethodName = null; | 330 nativeMethodName = null; |
270 } | 331 } |
271 | 332 |
272 @override | 333 @override |
273 void handleNoFunctionBody(Token token) { | 334 void handleNoFunctionBody(Token token) { |
274 debugEvent("NoFunctionBody"); | 335 debugEvent("NoFunctionBody"); |
(...skipping 16 matching lines...) Expand all Loading... |
291 debugEvent("Method"); | 352 debugEvent("Method"); |
292 MethodBody bodyKind = pop(); | 353 MethodBody bodyKind = pop(); |
293 if (bodyKind == MethodBody.RedirectingFactoryBody) { | 354 if (bodyKind == MethodBody.RedirectingFactoryBody) { |
294 // This will cause an error later. | 355 // This will cause an error later. |
295 pop(); | 356 pop(); |
296 } | 357 } |
297 AsyncMarker asyncModifier = pop(); | 358 AsyncMarker asyncModifier = pop(); |
298 List<FormalParameterBuilder> formals = pop(); | 359 List<FormalParameterBuilder> formals = pop(); |
299 int formalsOffset = pop(); | 360 int formalsOffset = pop(); |
300 List<TypeVariableBuilder> typeVariables = pop(); | 361 List<TypeVariableBuilder> typeVariables = pop(); |
| 362 int charOffset = pop(); |
301 dynamic nameOrOperator = pop(); | 363 dynamic nameOrOperator = pop(); |
302 if (Operator.subtract == nameOrOperator && formals == null) { | 364 if (Operator.subtract == nameOrOperator && formals == null) { |
303 nameOrOperator = Operator.unaryMinus; | 365 nameOrOperator = Operator.unaryMinus; |
304 } | 366 } |
305 String name; | 367 String name; |
306 ProcedureKind kind; | 368 ProcedureKind kind; |
307 if (nameOrOperator is Operator) { | 369 if (nameOrOperator is Operator) { |
308 name = operatorToString(nameOrOperator); | 370 name = operatorToString(nameOrOperator); |
309 kind = ProcedureKind.Operator; | 371 kind = ProcedureKind.Operator; |
310 } else { | 372 } else { |
311 name = nameOrOperator; | 373 name = nameOrOperator; |
312 kind = computeProcedureKind(getOrSet); | 374 kind = computeProcedureKind(getOrSet); |
313 } | 375 } |
314 TypeBuilder returnType = pop(); | 376 TypeBuilder returnType = pop(); |
315 int modifiers = | 377 int modifiers = |
316 Modifier.validate(pop(), isAbstract: bodyKind == MethodBody.Abstract); | 378 Modifier.validate(pop(), isAbstract: bodyKind == MethodBody.Abstract); |
317 List<MetadataBuilder> metadata = pop(); | 379 List<MetadataBuilder> metadata = pop(); |
318 library.addProcedure( | 380 library.addProcedure( |
319 metadata, | 381 metadata, |
320 modifiers, | 382 modifiers, |
321 returnType, | 383 returnType, |
322 name, | 384 name, |
323 typeVariables, | 385 typeVariables, |
324 formals, | 386 formals, |
325 asyncModifier, | 387 asyncModifier, |
326 kind, | 388 kind, |
327 beginToken.charOffset, | 389 charOffset, |
328 formalsOffset, | 390 formalsOffset, |
329 endToken.charOffset, | 391 endToken.charOffset, |
330 nativeMethodName, | 392 nativeMethodName, |
331 isTopLevel: false); | 393 isTopLevel: false); |
332 nativeMethodName = null; | 394 nativeMethodName = null; |
333 } | 395 } |
334 | 396 |
335 @override | 397 @override |
336 void endMixinApplication(Token withKeyword) { | 398 void endMixinApplication(Token withKeyword) { |
337 debugEvent("MixinApplication"); | 399 debugEvent("MixinApplication"); |
338 List<TypeBuilder> mixins = pop(); | 400 List<TypeBuilder> mixins = pop(); |
339 TypeBuilder supertype = pop(); | 401 TypeBuilder supertype = pop(); |
340 push(library.addMixinApplication(supertype, mixins, -1)); | 402 push(library.addMixinApplication(supertype, mixins, -1)); |
341 } | 403 } |
342 | 404 |
343 @override | 405 @override |
344 void beginNamedMixinApplication(Token begin, Token name) { | 406 void beginNamedMixinApplication(Token begin, Token name) { |
345 library.beginNestedDeclaration(name.lexeme, hasMembers: false); | 407 library.beginNestedDeclaration(name.lexeme, hasMembers: false); |
346 } | 408 } |
347 | 409 |
348 @override | 410 @override |
349 void endNamedMixinApplication(Token beginToken, Token classKeyword, | 411 void endNamedMixinApplication(Token beginToken, Token classKeyword, |
350 Token equals, Token implementsKeyword, Token endToken) { | 412 Token equals, Token implementsKeyword, Token endToken) { |
351 debugEvent("endNamedMixinApplication"); | 413 debugEvent("endNamedMixinApplication"); |
352 List<TypeBuilder> interfaces = popIfNotNull(implementsKeyword); | 414 List<TypeBuilder> interfaces = popIfNotNull(implementsKeyword); |
353 TypeBuilder mixinApplication = pop(); | 415 TypeBuilder mixinApplication = pop(); |
354 List<TypeVariableBuilder> typeVariables = pop(); | 416 List<TypeVariableBuilder> typeVariables = pop(); |
| 417 int charOffset = pop(); |
355 String name = pop(); | 418 String name = pop(); |
356 if (typeVariables != null && mixinApplication is MixinApplicationBuilder) { | 419 if (typeVariables != null && mixinApplication is MixinApplicationBuilder) { |
357 mixinApplication.typeVariables = typeVariables; | 420 mixinApplication.typeVariables = typeVariables; |
358 mixinApplication.subclassName = name; | 421 mixinApplication.subclassName = name; |
359 } | 422 } |
360 int modifiers = Modifier.validate(pop()); | 423 int modifiers = Modifier.validate(pop()); |
361 List<MetadataBuilder> metadata = pop(); | 424 List<MetadataBuilder> metadata = pop(); |
362 library.addNamedMixinApplication(metadata, name, typeVariables, modifiers, | 425 library.addNamedMixinApplication(metadata, name, typeVariables, modifiers, |
363 mixinApplication, interfaces, beginToken.charOffset); | 426 mixinApplication, interfaces, charOffset); |
364 checkEmpty(beginToken.charOffset); | 427 checkEmpty(beginToken.charOffset); |
365 } | 428 } |
366 | 429 |
367 @override | 430 @override |
368 void endTypeArguments(int count, Token beginToken, Token endToken) { | 431 void endTypeArguments(int count, Token beginToken, Token endToken) { |
369 debugEvent("TypeArguments"); | 432 debugEvent("TypeArguments"); |
370 push(popList(count) ?? NullValue.TypeArguments); | 433 push(popList(count) ?? NullValue.TypeArguments); |
371 } | 434 } |
372 | 435 |
373 @override | 436 @override |
374 void handleScript(Token token) { | 437 void handleScript(Token token) { |
375 debugEvent("Script"); | 438 debugEvent("Script"); |
376 } | 439 } |
377 | 440 |
378 @override | 441 @override |
379 void handleType(Token beginToken, Token endToken) { | 442 void handleType(Token beginToken, Token endToken) { |
380 debugEvent("Type"); | 443 debugEvent("Type"); |
381 List<TypeBuilder> arguments = pop(); | 444 List<TypeBuilder> arguments = pop(); |
| 445 int charOffset = pop(); |
382 String name = pop(); | 446 String name = pop(); |
383 push(library.addNamedType(name, arguments, beginToken.charOffset)); | 447 push(library.addNamedType(name, arguments, charOffset)); |
384 } | 448 } |
385 | 449 |
386 @override | 450 @override |
387 void endTypeList(int count) { | 451 void endTypeList(int count) { |
388 debugEvent("TypeList"); | 452 debugEvent("TypeList"); |
389 push(popList(count) ?? NullValue.TypeList); | 453 push(popList(count) ?? NullValue.TypeList); |
390 } | 454 } |
391 | 455 |
392 @override | 456 @override |
393 void endTypeVariables(int count, Token beginToken, Token endToken) { | 457 void endTypeVariables(int count, Token beginToken, Token endToken) { |
394 debugEvent("TypeVariables"); | 458 debugEvent("TypeVariables"); |
395 push(popList(count) ?? NullValue.TypeVariables); | 459 push(popList(count) ?? NullValue.TypeVariables); |
396 } | 460 } |
397 | 461 |
398 @override | 462 @override |
399 void handleVoidKeyword(Token token) { | 463 void handleVoidKeyword(Token token) { |
400 debugEvent("VoidKeyword"); | 464 debugEvent("VoidKeyword"); |
401 push(library.addVoidType(token.charOffset)); | 465 push(library.addVoidType(token.charOffset)); |
402 } | 466 } |
403 | 467 |
404 @override | 468 @override |
405 void endFormalParameter(Token covariantKeyword, Token thisKeyword, | 469 void endFormalParameter(Token covariantKeyword, Token thisKeyword, |
406 Token nameToken, FormalParameterType kind) { | 470 Token nameToken, FormalParameterType kind) { |
407 debugEvent("FormalParameter"); | 471 debugEvent("FormalParameter"); |
| 472 int charOffset = pop(); |
408 String name = pop(); | 473 String name = pop(); |
409 TypeBuilder type = pop(); | 474 TypeBuilder type = pop(); |
410 int modifiers = Modifier.validate(pop()); | 475 int modifiers = Modifier.validate(pop()); |
411 List<MetadataBuilder> metadata = pop(); | 476 List<MetadataBuilder> metadata = pop(); |
412 // TODO(ahe): Needs begin token. | |
413 push(library.addFormalParameter( | 477 push(library.addFormalParameter( |
414 metadata, | 478 metadata, modifiers, type, name, thisKeyword != null, charOffset)); |
415 modifiers, | |
416 type, | |
417 name, | |
418 thisKeyword != null, | |
419 thisKeyword?.charOffset ?? nameToken?.charOffset ?? -1)); | |
420 } | 479 } |
421 | 480 |
422 @override | 481 @override |
423 void handleValuedFormalParameter(Token equals, Token token) { | 482 void handleValuedFormalParameter(Token equals, Token token) { |
424 debugEvent("ValuedFormalParameter"); | 483 debugEvent("ValuedFormalParameter"); |
425 // Ignored for now. | 484 // Ignored for now. |
426 } | 485 } |
427 | 486 |
428 @override | 487 @override |
429 void handleFormalParameterWithoutValue(Token token) { | 488 void handleFormalParameterWithoutValue(Token token) { |
430 debugEvent("FormalParameterWithoutValue"); | 489 debugEvent("FormalParameterWithoutValue"); |
431 // Ignored for now. | 490 // Ignored for now. |
432 } | 491 } |
433 | 492 |
434 @override | 493 @override |
435 void endFunctionTypedFormalParameter( | 494 void endFunctionTypedFormalParameter( |
436 Token covariantKeyword, Token thisKeyword, FormalParameterType kind) { | 495 Token covariantKeyword, Token thisKeyword, FormalParameterType kind) { |
437 debugEvent("FunctionTypedFormalParameter"); | 496 debugEvent("FunctionTypedFormalParameter"); |
438 pop(); // Function type parameters. | 497 pop(); // Function type parameters. |
439 pop(); // Formals offset | 498 pop(); // Formals offset |
440 pop(); // Type variables. | 499 pop(); // Type variables. |
| 500 int charOffset = pop(); |
441 String name = pop(); | 501 String name = pop(); |
442 pop(); // Return type. | 502 pop(); // Return type. |
443 push(NullValue.Type); | 503 push(NullValue.Type); |
444 push(name); | 504 push(name); |
| 505 push(charOffset); |
445 } | 506 } |
446 | 507 |
447 @override | 508 @override |
448 void endOptionalFormalParameters( | 509 void endOptionalFormalParameters( |
449 int count, Token beginToken, Token endToken) { | 510 int count, Token beginToken, Token endToken) { |
450 debugEvent("OptionalFormalParameters"); | 511 debugEvent("OptionalFormalParameters"); |
451 FormalParameterType kind = optional("{", beginToken) | 512 FormalParameterType kind = optional("{", beginToken) |
452 ? FormalParameterType.NAMED | 513 ? FormalParameterType.NAMED |
453 : FormalParameterType.POSITIONAL; | 514 : FormalParameterType.POSITIONAL; |
454 // When recovering from an empty list of optional arguments, count may be | 515 // When recovering from an empty list of optional arguments, count may be |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
495 } | 556 } |
496 | 557 |
497 @override | 558 @override |
498 void handleNoFormalParameters(Token token) { | 559 void handleNoFormalParameters(Token token) { |
499 push(token.charOffset); | 560 push(token.charOffset); |
500 super.handleNoFormalParameters(token); | 561 super.handleNoFormalParameters(token); |
501 } | 562 } |
502 | 563 |
503 @override | 564 @override |
504 void endEnum(Token enumKeyword, Token endBrace, int count) { | 565 void endEnum(Token enumKeyword, Token endBrace, int count) { |
505 List<String> constants = popList(count); | 566 List constantNamesAndOffsets = popList(count * 2); |
| 567 int charOffset = pop(); |
506 String name = pop(); | 568 String name = pop(); |
507 List<MetadataBuilder> metadata = pop(); | 569 List<MetadataBuilder> metadata = pop(); |
508 library.addEnum( | 570 library.addEnum(metadata, name, constantNamesAndOffsets, charOffset, |
509 metadata, name, constants, enumKeyword.charOffset, endBrace.charOffset); | 571 endBrace.charOffset); |
510 checkEmpty(enumKeyword.charOffset); | 572 checkEmpty(enumKeyword.charOffset); |
511 } | 573 } |
512 | 574 |
513 @override | 575 @override |
514 void beginFunctionTypeAlias(Token token) { | 576 void beginFunctionTypeAlias(Token token) { |
515 library.beginNestedDeclaration(null, hasMembers: false); | 577 library.beginNestedDeclaration(null, hasMembers: false); |
516 } | 578 } |
517 | 579 |
518 @override | 580 @override |
519 void handleFunctionType(Token functionToken, Token endToken) { | 581 void handleFunctionType(Token functionToken, Token endToken) { |
520 debugEvent("FunctionType"); | 582 debugEvent("FunctionType"); |
521 List<FormalParameterBuilder> formals = pop(); | 583 List<FormalParameterBuilder> formals = pop(); |
522 pop(); // formals offset | 584 pop(); // formals offset |
523 List<TypeVariableBuilder> typeVariables = pop(); | 585 List<TypeVariableBuilder> typeVariables = pop(); |
524 TypeBuilder returnType = pop(); | 586 TypeBuilder returnType = pop(); |
525 push(library.addFunctionType( | 587 push(library.addFunctionType( |
526 returnType, typeVariables, formals, functionToken.charOffset)); | 588 returnType, typeVariables, formals, functionToken.charOffset)); |
527 } | 589 } |
528 | 590 |
529 @override | 591 @override |
530 void endFunctionTypeAlias( | 592 void endFunctionTypeAlias( |
531 Token typedefKeyword, Token equals, Token endToken) { | 593 Token typedefKeyword, Token equals, Token endToken) { |
532 debugEvent("endFunctionTypeAlias"); | 594 debugEvent("endFunctionTypeAlias"); |
533 List<FormalParameterBuilder> formals; | 595 List<FormalParameterBuilder> formals; |
534 List<TypeVariableBuilder> typeVariables; | 596 List<TypeVariableBuilder> typeVariables; |
535 String name; | 597 String name; |
536 TypeBuilder returnType; | 598 TypeBuilder returnType; |
| 599 int charOffset; |
537 if (equals == null) { | 600 if (equals == null) { |
538 formals = pop(); | 601 formals = pop(); |
539 pop(); // formals offset | 602 pop(); // formals offset |
540 typeVariables = pop(); | 603 typeVariables = pop(); |
| 604 charOffset = pop(); |
541 name = pop(); | 605 name = pop(); |
542 returnType = pop(); | 606 returnType = pop(); |
543 } else { | 607 } else { |
544 var type = pop(); | 608 var type = pop(); |
545 typeVariables = pop(); | 609 typeVariables = pop(); |
| 610 charOffset = pop(); |
546 name = pop(); | 611 name = pop(); |
547 if (type is FunctionTypeBuilder) { | 612 if (type is FunctionTypeBuilder) { |
548 // TODO(ahe): We need to start a nested declaration when parsing the | 613 // TODO(ahe): We need to start a nested declaration when parsing the |
549 // formals and return type so we can correctly bind | 614 // formals and return type so we can correctly bind |
550 // `type.typeVariables`. A typedef can have type variables, and a new | 615 // `type.typeVariables`. A typedef can have type variables, and a new |
551 // function type can also have type variables (representing the type of | 616 // function type can also have type variables (representing the type of |
552 // a generic function). | 617 // a generic function). |
553 formals = type.formals; | 618 formals = type.formals; |
554 returnType = type.returnType; | 619 returnType = type.returnType; |
555 } else { | 620 } else { |
556 // TODO(ahe): Improve this error message. | 621 // TODO(ahe): Improve this error message. |
557 library.addCompileTimeError( | 622 library.addCompileTimeError( |
558 equals.charOffset, "Can't create typedef from non-function type."); | 623 equals.charOffset, "Can't create typedef from non-function type."); |
559 } | 624 } |
560 } | 625 } |
561 List<MetadataBuilder> metadata = pop(); | 626 List<MetadataBuilder> metadata = pop(); |
562 library.addFunctionTypeAlias(metadata, returnType, name, typeVariables, | 627 library.addFunctionTypeAlias( |
563 formals, typedefKeyword.charOffset); | 628 metadata, returnType, name, typeVariables, formals, charOffset); |
564 checkEmpty(typedefKeyword.charOffset); | 629 checkEmpty(typedefKeyword.charOffset); |
565 } | 630 } |
566 | 631 |
567 @override | 632 @override |
568 void endTopLevelFields(int count, Token beginToken, Token endToken) { | 633 void endTopLevelFields(int count, Token beginToken, Token endToken) { |
569 debugEvent("endTopLevelFields"); | 634 debugEvent("endTopLevelFields"); |
570 List<String> names = popList(count); | 635 List namesAndOffsets = popList(count * 2); |
571 TypeBuilder type = pop(); | 636 TypeBuilder type = pop(); |
572 int modifiers = Modifier.validate(pop()); | 637 int modifiers = Modifier.validate(pop()); |
573 List<MetadataBuilder> metadata = pop(); | 638 List<MetadataBuilder> metadata = pop(); |
574 library.addFields(metadata, modifiers, type, names); | 639 library.addFields(metadata, modifiers, type, namesAndOffsets); |
575 checkEmpty(beginToken.charOffset); | 640 checkEmpty(beginToken.charOffset); |
576 } | 641 } |
577 | 642 |
578 @override | 643 @override |
579 void endFields( | 644 void endFields( |
580 int count, Token covariantToken, Token beginToken, Token endToken) { | 645 int count, Token covariantToken, Token beginToken, Token endToken) { |
581 debugEvent("Fields"); | 646 debugEvent("Fields"); |
582 List<String> names = popList(count); | 647 List namesAndOffsets = popList(count * 2); |
583 TypeBuilder type = pop(); | 648 TypeBuilder type = pop(); |
584 int modifiers = Modifier.validate(pop()); | 649 int modifiers = Modifier.validate(pop()); |
585 List<MetadataBuilder> metadata = pop(); | 650 List<MetadataBuilder> metadata = pop(); |
586 library.addFields(metadata, modifiers, type, names); | 651 library.addFields(metadata, modifiers, type, namesAndOffsets); |
587 } | 652 } |
588 | 653 |
589 @override | 654 @override |
590 void endTypeVariable(Token token, Token extendsOrSuper) { | 655 void endTypeVariable(Token token, Token extendsOrSuper) { |
591 debugEvent("endTypeVariable"); | 656 debugEvent("endTypeVariable"); |
592 TypeBuilder bound = pop(); | 657 TypeBuilder bound = pop(); |
| 658 int charOffset = pop(); |
593 String name = pop(); | 659 String name = pop(); |
594 // TODO(paulberry): type variable metadata should not be ignored. See | 660 // TODO(paulberry): type variable metadata should not be ignored. See |
595 // dartbug.com/28981. | 661 // dartbug.com/28981. |
596 /* List<MetadataBuilder> metadata = */ pop(); | 662 /* List<MetadataBuilder> metadata = */ pop(); |
597 push(library.addTypeVariable(name, bound, token.charOffset)); | 663 push(library.addTypeVariable(name, bound, charOffset)); |
598 } | 664 } |
599 | 665 |
600 @override | 666 @override |
601 void endPartOf(Token partKeyword, Token semicolon, bool hasName) { | 667 void endPartOf(Token partKeyword, Token semicolon, bool hasName) { |
602 debugEvent("endPartOf"); | 668 debugEvent("endPartOf"); |
| 669 popCharOffset(); |
603 String containingLibrary = pop(); | 670 String containingLibrary = pop(); |
604 List<MetadataBuilder> metadata = pop(); | 671 List<MetadataBuilder> metadata = pop(); |
605 if (hasName) { | 672 if (hasName) { |
606 library.addPartOf(metadata, containingLibrary, null); | 673 library.addPartOf(metadata, containingLibrary, null); |
607 } else { | 674 } else { |
608 library.addPartOf(metadata, null, containingLibrary); | 675 library.addPartOf(metadata, null, containingLibrary); |
609 } | 676 } |
610 } | 677 } |
611 | 678 |
612 @override | 679 @override |
613 void endConstructorReference( | 680 void endConstructorReference( |
614 Token start, Token periodBeforeName, Token endToken) { | 681 Token start, Token periodBeforeName, Token endToken) { |
615 debugEvent("ConstructorReference"); | 682 debugEvent("ConstructorReference"); |
| 683 popIfNotNull(periodBeforeName); // charOffset. |
616 String suffix = popIfNotNull(periodBeforeName); | 684 String suffix = popIfNotNull(periodBeforeName); |
617 List<TypeBuilder> typeArguments = pop(); | 685 List<TypeBuilder> typeArguments = pop(); |
| 686 int charOffset = pop(); |
618 String name = pop(); | 687 String name = pop(); |
619 push(library.addConstructorReference( | 688 push(library.addConstructorReference( |
620 name, typeArguments, suffix, start.charOffset)); | 689 name, typeArguments, suffix, charOffset)); |
621 } | 690 } |
622 | 691 |
623 @override | 692 @override |
624 void beginFactoryMethod(Token token) { | 693 void beginFactoryMethod(Token token) { |
625 library.beginNestedDeclaration(null, hasMembers: false); | 694 library.beginNestedDeclaration(null, hasMembers: false); |
626 } | 695 } |
627 | 696 |
628 @override | 697 @override |
629 void endFactoryMethod( | 698 void endFactoryMethod( |
630 Token beginToken, Token factoryKeyword, Token endToken) { | 699 Token beginToken, Token factoryKeyword, Token endToken) { |
631 debugEvent("FactoryMethod"); | 700 debugEvent("FactoryMethod"); |
632 MethodBody kind = pop(); | 701 MethodBody kind = pop(); |
633 ConstructorReferenceBuilder redirectionTarget; | 702 ConstructorReferenceBuilder redirectionTarget; |
634 if (kind == MethodBody.RedirectingFactoryBody) { | 703 if (kind == MethodBody.RedirectingFactoryBody) { |
635 redirectionTarget = pop(); | 704 redirectionTarget = pop(); |
636 } | 705 } |
637 AsyncMarker asyncModifier = pop(); | 706 AsyncMarker asyncModifier = pop(); |
638 List<FormalParameterBuilder> formals = pop(); | 707 List<FormalParameterBuilder> formals = pop(); |
639 int formalsOffset = pop(); | 708 int formalsOffset = pop(); |
640 var name = pop(); | 709 var name = pop(); |
641 int modifiers = Modifier.validate(pop()); | 710 int modifiers = Modifier.validate(pop()); |
642 List<MetadataBuilder> metadata = pop(); | 711 List<MetadataBuilder> metadata = pop(); |
643 library.addFactoryMethod( | 712 library.addFactoryMethod( |
644 metadata, | 713 metadata, |
645 modifiers, | 714 modifiers, |
646 name, | 715 name, |
647 formals, | 716 formals, |
648 asyncModifier, | 717 asyncModifier, |
649 redirectionTarget, | 718 redirectionTarget, |
650 beginToken.charOffset, | 719 factoryKeyword.next.charOffset, |
651 formalsOffset, | 720 formalsOffset, |
652 endToken.charOffset, | 721 endToken.charOffset, |
653 nativeMethodName); | 722 nativeMethodName); |
654 nativeMethodName = null; | 723 nativeMethodName = null; |
655 } | 724 } |
656 | 725 |
657 @override | 726 @override |
658 void endRedirectingFactoryBody(Token beginToken, Token endToken) { | 727 void endRedirectingFactoryBody(Token beginToken, Token endToken) { |
659 debugEvent("RedirectingFactoryBody"); | 728 debugEvent("RedirectingFactoryBody"); |
660 push(MethodBody.RedirectingFactoryBody); | 729 push(MethodBody.RedirectingFactoryBody); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
728 Link<Token> handleMemberName(Link<Token> identifiers) { | 797 Link<Token> handleMemberName(Link<Token> identifiers) { |
729 if (!isDartLibrary || identifiers.isEmpty) return identifiers; | 798 if (!isDartLibrary || identifiers.isEmpty) return identifiers; |
730 return removeNativeClause(identifiers); | 799 return removeNativeClause(identifiers); |
731 } | 800 } |
732 | 801 |
733 @override | 802 @override |
734 void debugEvent(String name) { | 803 void debugEvent(String name) { |
735 // printEvent(name); | 804 // printEvent(name); |
736 } | 805 } |
737 } | 806 } |
OLD | NEW |