| 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 | 7 import 'package:kernel/ast.dart' show |
| 8 AsyncMarker, | 8 AsyncMarker, |
| 9 ProcedureKind; | 9 ProcedureKind; |
| 10 | 10 |
| 11 import 'package:front_end/src/fasta/parser/parser.dart' show | 11 import '../parser/parser.dart' show |
| 12 FormalParameterType, | 12 FormalParameterType, |
| 13 optional; | 13 optional; |
| 14 | 14 |
| 15 import 'package:front_end/src/fasta/scanner/token.dart' show | 15 import '../scanner/token.dart' show |
| 16 Token; | 16 Token; |
| 17 | 17 |
| 18 import '../util/link.dart' show |
| 19 Link; |
| 20 |
| 18 import '../combinator.dart' show | 21 import '../combinator.dart' show |
| 19 Combinator; | 22 Combinator; |
| 20 | 23 |
| 21 import '../errors.dart' show | 24 import '../errors.dart' show |
| 22 internalError; | 25 internalError; |
| 23 | 26 |
| 24 import '../builder/builder.dart'; | 27 import '../builder/builder.dart'; |
| 25 | 28 |
| 26 import '../modifier.dart' show | 29 import '../modifier.dart' show |
| 27 Modifier; | 30 Modifier; |
| 28 | 31 |
| 29 import 'source_library_builder.dart' show | 32 import 'source_library_builder.dart' show |
| 30 SourceLibraryBuilder; | 33 SourceLibraryBuilder; |
| 31 | 34 |
| 32 import 'unhandled_listener.dart' show | 35 import 'unhandled_listener.dart' show |
| 33 NullValue, | 36 NullValue, |
| 34 Unhandled, | 37 Unhandled, |
| 35 UnhandledListener; | 38 UnhandledListener; |
| 36 | 39 |
| 40 import '../parser/error_kind.dart' show |
| 41 ErrorKind; |
| 42 |
| 43 import '../parser/dart_vm_native.dart' show |
| 44 removeNativeClause, |
| 45 skipNativeClause; |
| 46 |
| 37 enum MethodBody { | 47 enum MethodBody { |
| 38 Abstract, | 48 Abstract, |
| 39 Regular, | 49 Regular, |
| 40 RedirectingFactoryBody, | 50 RedirectingFactoryBody, |
| 41 } | 51 } |
| 42 | 52 |
| 43 AsyncMarker asyncMarkerFromTokens(Token asyncToken, Token starToken) { | 53 AsyncMarker asyncMarkerFromTokens(Token asyncToken, Token starToken) { |
| 44 if (asyncToken == null || identical(asyncToken.stringValue, "sync")) { | 54 if (asyncToken == null || identical(asyncToken.stringValue, "sync")) { |
| 45 if (starToken == null) { | 55 if (starToken == null) { |
| 46 return AsyncMarker.Sync; | 56 return AsyncMarker.Sync; |
| 47 } else { | 57 } else { |
| 48 assert(identical(starToken.stringValue, "*")); | 58 assert(identical(starToken.stringValue, "*")); |
| 49 return AsyncMarker.SyncStar; | 59 return AsyncMarker.SyncStar; |
| 50 } | 60 } |
| 51 } else if (identical(asyncToken.stringValue, "async")) { | 61 } else if (identical(asyncToken.stringValue, "async")) { |
| 52 if (starToken == null) { | 62 if (starToken == null) { |
| 53 return AsyncMarker.Async; | 63 return AsyncMarker.Async; |
| 54 } else { | 64 } else { |
| 55 assert(identical(starToken.stringValue, "*")); | 65 assert(identical(starToken.stringValue, "*")); |
| 56 return AsyncMarker.AsyncStar; | 66 return AsyncMarker.AsyncStar; |
| 57 } | 67 } |
| 58 } else { | 68 } else { |
| 59 return internalError("Unknown async modifier: $asyncToken"); | 69 return internalError("Unknown async modifier: $asyncToken"); |
| 60 } | 70 } |
| 61 } | 71 } |
| 62 | 72 |
| 63 class OutlineBuilder extends UnhandledListener { | 73 class OutlineBuilder extends UnhandledListener { |
| 64 final SourceLibraryBuilder library; | 74 final SourceLibraryBuilder library; |
| 65 | 75 |
| 66 OutlineBuilder(this.library); | 76 final bool isDartLibrary; |
| 77 |
| 78 OutlineBuilder(SourceLibraryBuilder library) |
| 79 : library = library, |
| 80 isDartLibrary = library.uri.scheme == "dart"; |
| 67 | 81 |
| 68 @override | 82 @override |
| 69 Uri get uri => library.uri; | 83 Uri get uri => library.uri; |
| 70 | 84 |
| 71 @override | 85 @override |
| 72 void endMetadata(Token beginToken, Token periodBeforeName, Token endToken) { | 86 void endMetadata(Token beginToken, Token periodBeforeName, Token endToken) { |
| 73 debugEvent("Metadata"); | 87 debugEvent("Metadata"); |
| 74 List arguments = pop(); | 88 List arguments = pop(); |
| 75 String postfix = popIfNotNull(periodBeforeName); | 89 String postfix = popIfNotNull(periodBeforeName); |
| 76 List<TypeBuilder> typeArguments = pop(); | 90 List<TypeBuilder> typeArguments = pop(); |
| (...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 518 push(new Modifier.fromString(token.stringValue)); | 532 push(new Modifier.fromString(token.stringValue)); |
| 519 } | 533 } |
| 520 | 534 |
| 521 @override | 535 @override |
| 522 void handleModifiers(int count) { | 536 void handleModifiers(int count) { |
| 523 debugEvent("Modifiers"); | 537 debugEvent("Modifiers"); |
| 524 push(popList(count) ?? NullValue.Modifiers); | 538 push(popList(count) ?? NullValue.Modifiers); |
| 525 } | 539 } |
| 526 | 540 |
| 527 @override | 541 @override |
| 542 Token handleUnrecoverableError(Token token, ErrorKind kind, Map arguments) { |
| 543 if (isDartLibrary && kind == ErrorKind.ExpectedBlockToSkip) { |
| 544 Token recover = skipNativeClause(token); |
| 545 if (recover != null) return recover; |
| 546 } |
| 547 return super.handleUnrecoverableError(token, kind, arguments); |
| 548 } |
| 549 |
| 550 @override |
| 551 Link<Token> handleMemberName(Link<Token> identifiers) { |
| 552 if (!isDartLibrary || identifiers.isEmpty) return identifiers; |
| 553 return removeNativeClause(identifiers); |
| 554 } |
| 555 |
| 556 @override |
| 528 void debugEvent(String name) { | 557 void debugEvent(String name) { |
| 529 // printEvent(name); | 558 // printEvent(name); |
| 530 } | 559 } |
| 531 } | 560 } |
| OLD | NEW |