| 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 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 | 42 |
| 43 import '../parser/dart_vm_native.dart' show | 43 import '../parser/dart_vm_native.dart' show |
| 44 removeNativeClause, | 44 removeNativeClause, |
| 45 skipNativeClause; | 45 skipNativeClause; |
| 46 | 46 |
| 47 import '../operator.dart' show | 47 import '../operator.dart' show |
| 48 Operator, | 48 Operator, |
| 49 operatorFromString, | 49 operatorFromString, |
| 50 operatorToString; | 50 operatorToString; |
| 51 | 51 |
| 52 import '../quote.dart' show |
| 53 unescapeString; |
| 54 |
| 52 enum MethodBody { | 55 enum MethodBody { |
| 53 Abstract, | 56 Abstract, |
| 54 Regular, | 57 Regular, |
| 55 RedirectingFactoryBody, | 58 RedirectingFactoryBody, |
| 56 } | 59 } |
| 57 | 60 |
| 58 AsyncMarker asyncMarkerFromTokens(Token asyncToken, Token starToken) { | 61 AsyncMarker asyncMarkerFromTokens(Token asyncToken, Token starToken) { |
| 59 if (asyncToken == null || identical(asyncToken.stringValue, "sync")) { | 62 if (asyncToken == null || identical(asyncToken.stringValue, "sync")) { |
| 60 if (starToken == null) { | 63 if (starToken == null) { |
| 61 return AsyncMarker.Sync; | 64 return AsyncMarker.Sync; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 73 } else { | 76 } else { |
| 74 return internalError("Unknown async modifier: $asyncToken"); | 77 return internalError("Unknown async modifier: $asyncToken"); |
| 75 } | 78 } |
| 76 } | 79 } |
| 77 | 80 |
| 78 class OutlineBuilder extends UnhandledListener { | 81 class OutlineBuilder extends UnhandledListener { |
| 79 final SourceLibraryBuilder library; | 82 final SourceLibraryBuilder library; |
| 80 | 83 |
| 81 final bool isDartLibrary; | 84 final bool isDartLibrary; |
| 82 | 85 |
| 86 String nativeMethodName; |
| 87 |
| 83 OutlineBuilder(SourceLibraryBuilder library) | 88 OutlineBuilder(SourceLibraryBuilder library) |
| 84 : library = library, | 89 : library = library, |
| 85 isDartLibrary = library.uri.scheme == "dart"; | 90 isDartLibrary = library.uri.scheme == "dart"; |
| 86 | 91 |
| 87 @override | 92 @override |
| 88 Uri get uri => library.uri; | 93 Uri get uri => library.uri; |
| 89 | 94 |
| 90 @override | 95 @override |
| 91 void endMetadata(Token beginToken, Token periodBeforeName, Token endToken) { | 96 void endMetadata(Token beginToken, Token periodBeforeName, Token endToken) { |
| 92 debugEvent("Metadata"); | 97 debugEvent("Metadata"); |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 List<FormalParameterBuilder> formals = pop(); | 238 List<FormalParameterBuilder> formals = pop(); |
| 234 List<TypeVariableBuilder> typeVariables = pop(); | 239 List<TypeVariableBuilder> typeVariables = pop(); |
| 235 String name = pop(); | 240 String name = pop(); |
| 236 TypeBuilder returnType = pop(); | 241 TypeBuilder returnType = pop(); |
| 237 int modifiers = Modifier.validate(pop(), | 242 int modifiers = Modifier.validate(pop(), |
| 238 isAbstract: kind == MethodBody.Abstract); | 243 isAbstract: kind == MethodBody.Abstract); |
| 239 List<MetadataBuilder> metadata = pop(); | 244 List<MetadataBuilder> metadata = pop(); |
| 240 checkEmpty(); | 245 checkEmpty(); |
| 241 library.addProcedure(metadata, modifiers, returnType, name, | 246 library.addProcedure(metadata, modifiers, returnType, name, |
| 242 typeVariables, formals, asyncModifier, computeProcedureKind(getOrSet), | 247 typeVariables, formals, asyncModifier, computeProcedureKind(getOrSet), |
| 243 beginToken.charOffset, isTopLevel: true); | 248 beginToken.charOffset, nativeMethodName, isTopLevel: true); |
| 249 nativeMethodName = null; |
| 244 } | 250 } |
| 245 | 251 |
| 246 @override | 252 @override |
| 247 void handleNoFunctionBody(Token token) { | 253 void handleNoFunctionBody(Token token) { |
| 248 debugEvent("NoFunctionBody"); | 254 debugEvent("NoFunctionBody"); |
| 249 push(MethodBody.Abstract); | 255 push(MethodBody.Abstract); |
| 250 } | 256 } |
| 251 | 257 |
| 252 @override | 258 @override |
| 253 void handleFunctionBodySkipped(Token token) { | 259 void handleFunctionBodySkipped(Token token) { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 282 kind = ProcedureKind.Operator; | 288 kind = ProcedureKind.Operator; |
| 283 } else { | 289 } else { |
| 284 name = nameOrOperator; | 290 name = nameOrOperator; |
| 285 kind = computeProcedureKind(getOrSet); | 291 kind = computeProcedureKind(getOrSet); |
| 286 } | 292 } |
| 287 TypeBuilder returnType = pop(); | 293 TypeBuilder returnType = pop(); |
| 288 int modifiers = Modifier.validate(pop(), | 294 int modifiers = Modifier.validate(pop(), |
| 289 isAbstract: bodyKind == MethodBody.Abstract); | 295 isAbstract: bodyKind == MethodBody.Abstract); |
| 290 List<MetadataBuilder> metadata = pop(); | 296 List<MetadataBuilder> metadata = pop(); |
| 291 library.addProcedure(metadata, modifiers, returnType, name, typeVariables, | 297 library.addProcedure(metadata, modifiers, returnType, name, typeVariables, |
| 292 formals, asyncModifier, kind, beginToken.charOffset, isTopLevel: false); | 298 formals, asyncModifier, kind, beginToken.charOffset, nativeMethodName, |
| 299 isTopLevel: false); |
| 300 nativeMethodName = null; |
| 293 } | 301 } |
| 294 | 302 |
| 295 @override | 303 @override |
| 296 void endMixinApplication() { | 304 void endMixinApplication() { |
| 297 debugEvent("MixinApplication"); | 305 debugEvent("MixinApplication"); |
| 298 List<TypeBuilder> mixins = pop(); | 306 List<TypeBuilder> mixins = pop(); |
| 299 TypeBuilder supertype = pop(); | 307 TypeBuilder supertype = pop(); |
| 300 push(library.addMixinApplication(supertype, mixins, -1)); | 308 push(library.addMixinApplication(supertype, mixins, -1)); |
| 301 } | 309 } |
| 302 | 310 |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 510 MethodBody kind = pop(); | 518 MethodBody kind = pop(); |
| 511 ConstructorReferenceBuilder redirectionTarget; | 519 ConstructorReferenceBuilder redirectionTarget; |
| 512 if (kind == MethodBody.RedirectingFactoryBody) { | 520 if (kind == MethodBody.RedirectingFactoryBody) { |
| 513 redirectionTarget = pop(); | 521 redirectionTarget = pop(); |
| 514 } | 522 } |
| 515 AsyncMarker asyncModifier = pop(); | 523 AsyncMarker asyncModifier = pop(); |
| 516 List<FormalParameterBuilder> formals = pop(); | 524 List<FormalParameterBuilder> formals = pop(); |
| 517 var name = pop(); | 525 var name = pop(); |
| 518 List<MetadataBuilder> metadata = pop(); | 526 List<MetadataBuilder> metadata = pop(); |
| 519 library.addFactoryMethod(metadata, name, formals, asyncModifier, | 527 library.addFactoryMethod(metadata, name, formals, asyncModifier, |
| 520 redirectionTarget, beginToken.charOffset); | 528 redirectionTarget, beginToken.charOffset, nativeMethodName); |
| 529 nativeMethodName = null; |
| 521 } | 530 } |
| 522 | 531 |
| 523 @override | 532 @override |
| 524 void endRedirectingFactoryBody(Token beginToken, Token endToken) { | 533 void endRedirectingFactoryBody(Token beginToken, Token endToken) { |
| 525 debugEvent("RedirectingFactoryBody"); | 534 debugEvent("RedirectingFactoryBody"); |
| 526 push(MethodBody.RedirectingFactoryBody); | 535 push(MethodBody.RedirectingFactoryBody); |
| 527 } | 536 } |
| 528 | 537 |
| 529 @override | 538 @override |
| 530 void endFieldInitializer(Token assignmentOperator) { | 539 void endFieldInitializer(Token assignmentOperator) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 545 | 554 |
| 546 @override | 555 @override |
| 547 void handleNoInitializers() { | 556 void handleNoInitializers() { |
| 548 debugEvent("NoInitializers"); | 557 debugEvent("NoInitializers"); |
| 549 // This is a constructor initializer and it's ignored for now. | 558 // This is a constructor initializer and it's ignored for now. |
| 550 } | 559 } |
| 551 | 560 |
| 552 @override | 561 @override |
| 553 void endMember() { | 562 void endMember() { |
| 554 debugEvent("Member"); | 563 debugEvent("Member"); |
| 564 assert(nativeMethodName == null); |
| 555 } | 565 } |
| 556 | 566 |
| 557 @override | 567 @override |
| 558 void endClassBody(int memberCount, Token beginToken, Token endToken) { | 568 void endClassBody(int memberCount, Token beginToken, Token endToken) { |
| 559 debugEvent("ClassBody"); | 569 debugEvent("ClassBody"); |
| 560 } | 570 } |
| 561 | 571 |
| 562 @override | 572 @override |
| 563 void handleAsyncModifier(Token asyncToken, Token starToken) { | 573 void handleAsyncModifier(Token asyncToken, Token starToken) { |
| 564 debugEvent("AsyncModifier"); | 574 debugEvent("AsyncModifier"); |
| 565 push(asyncMarkerFromTokens(asyncToken, starToken)); | 575 push(asyncMarkerFromTokens(asyncToken, starToken)); |
| 566 } | 576 } |
| 567 | 577 |
| 568 @override | 578 @override |
| 569 void handleModifier(Token token) { | 579 void handleModifier(Token token) { |
| 570 debugEvent("Modifier"); | 580 debugEvent("Modifier"); |
| 571 push(new Modifier.fromString(token.stringValue)); | 581 push(new Modifier.fromString(token.stringValue)); |
| 572 } | 582 } |
| 573 | 583 |
| 574 @override | 584 @override |
| 575 void handleModifiers(int count) { | 585 void handleModifiers(int count) { |
| 576 debugEvent("Modifiers"); | 586 debugEvent("Modifiers"); |
| 577 push(popList(count) ?? NullValue.Modifiers); | 587 push(popList(count) ?? NullValue.Modifiers); |
| 578 } | 588 } |
| 579 | 589 |
| 580 @override | 590 @override |
| 581 Token handleUnrecoverableError(Token token, ErrorKind kind, Map arguments) { | 591 Token handleUnrecoverableError(Token token, ErrorKind kind, Map arguments) { |
| 582 if (isDartLibrary && kind == ErrorKind.ExpectedBlockToSkip) { | 592 if (isDartLibrary && kind == ErrorKind.ExpectedBlockToSkip) { |
| 583 Token recover = skipNativeClause(token); | 593 Token recover = skipNativeClause(token); |
| 584 if (recover != null) return recover; | 594 if (recover != null) { |
| 595 nativeMethodName = unescapeString(token.next.value); |
| 596 return recover; |
| 597 } |
| 585 } | 598 } |
| 586 return super.handleUnrecoverableError(token, kind, arguments); | 599 return super.handleUnrecoverableError(token, kind, arguments); |
| 587 } | 600 } |
| 588 | 601 |
| 589 @override | 602 @override |
| 590 Link<Token> handleMemberName(Link<Token> identifiers) { | 603 Link<Token> handleMemberName(Link<Token> identifiers) { |
| 591 if (!isDartLibrary || identifiers.isEmpty) return identifiers; | 604 if (!isDartLibrary || identifiers.isEmpty) return identifiers; |
| 592 return removeNativeClause(identifiers); | 605 return removeNativeClause(identifiers); |
| 593 } | 606 } |
| 594 | 607 |
| 595 @override | 608 @override |
| 596 void debugEvent(String name) { | 609 void debugEvent(String name) { |
| 597 // printEvent(name); | 610 // printEvent(name); |
| 598 } | 611 } |
| 599 } | 612 } |
| OLD | NEW |