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.body_builder; | 5 library fasta.body_builder; |
6 | 6 |
7 import '../fasta_codes.dart' | 7 import '../fasta_codes.dart' |
8 show | 8 show |
9 FastaMessage, | 9 FastaMessage, |
10 codeConstFieldWithoutInitializer, | 10 codeConstFieldWithoutInitializer, |
(...skipping 2394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2405 } | 2405 } |
2406 | 2406 |
2407 void exitFunction() { | 2407 void exitFunction() { |
2408 debugEvent("exitFunction"); | 2408 debugEvent("exitFunction"); |
2409 functionNestingLevel--; | 2409 functionNestingLevel--; |
2410 inCatchBlock = pop(); | 2410 inCatchBlock = pop(); |
2411 switchScope = pop(); | 2411 switchScope = pop(); |
2412 } | 2412 } |
2413 | 2413 |
2414 @override | 2414 @override |
2415 void beginFunction(Token token) { | 2415 void beginFunctionDeclaration(Token token) { |
2416 debugEvent("beginFunction"); | 2416 debugEvent("beginNamedFunctionExpression"); |
2417 enterFunction(); | 2417 enterFunction(); |
2418 } | 2418 } |
2419 | 2419 |
2420 @override | 2420 @override |
2421 void beginUnnamedFunction(Token token) { | 2421 void beginNamedFunctionExpression(Token token) { |
2422 debugEvent("beginUnnamedFunction"); | 2422 debugEvent("beginNamedFunctionExpression"); |
2423 enterFunction(); | 2423 enterFunction(); |
2424 } | 2424 } |
2425 | 2425 |
2426 @override | 2426 @override |
2427 void endFunction(Token getOrSet, Token endToken) { | 2427 void beginFunctionExpression(Token token) { |
2428 debugEvent("Function"); | 2428 debugEvent("beginFunctionExpression"); |
2429 enterFunction(); | |
2430 } | |
2431 | |
2432 @override | |
2433 void endNamedFunctionExpression(Token endToken) { | |
2434 debugEvent("NamedFunctionExpression"); | |
2429 Statement body = popStatement(); | 2435 Statement body = popStatement(); |
2430 AsyncMarker asyncModifier = pop(); | 2436 AsyncMarker asyncModifier = pop(); |
2431 if (functionNestingLevel != 0) { | 2437 if (functionNestingLevel != 0) { |
2432 exitLocalScope(); | 2438 exitLocalScope(); |
2433 } | 2439 } |
2434 FormalParameters formals = pop(); | 2440 FormalParameters formals = pop(); |
2435 List<TypeParameter> typeParameters = typeVariableBuildersToKernel(pop()); | 2441 List<TypeParameter> typeParameters = typeVariableBuildersToKernel(pop()); |
2436 push(formals.addToFunction(new FunctionNode(body, | 2442 |
2437 typeParameters: typeParameters, asyncMarker: asyncModifier) | 2443 exitLocalScope(); |
2438 ..fileOffset = formals.charOffset | 2444 KernelFunctionDeclaration declaration = pop(); |
2439 ..fileEndOffset = endToken.charOffset)); | 2445 VariableDeclaration variable = declaration.variable; |
2446 var returnType = pop(); | |
2447 returnType ??= const DynamicType(); | |
2448 pop(); // Modifiers. | |
2449 exitFunction(); | |
2450 | |
2451 variable.initializer = new KernelFunctionExpression(formals.addToFunction( | |
2452 new FunctionNode(body, | |
2453 typeParameters: typeParameters, asyncMarker: asyncModifier) | |
2454 ..fileOffset = formals.charOffset | |
2455 ..fileEndOffset = endToken.charOffset)) | |
2456 ..parent = variable | |
2457 ..fileOffset = formals.charOffset; | |
2458 push(new Let(variable, new VariableGet(variable))); | |
2440 } | 2459 } |
2441 | 2460 |
2442 @override | 2461 @override |
2443 void endFunctionDeclaration(Token token) { | 2462 void endFunctionDeclaration(Token endToken) { |
2444 debugEvent("FunctionDeclaration"); | 2463 debugEvent("FunctionDeclaration"); |
2445 FunctionNode function = pop(); | 2464 Statement body = popStatement(); |
2465 AsyncMarker asyncModifier = pop(); | |
2466 if (functionNestingLevel != 0) { | |
2467 exitLocalScope(); | |
2468 } | |
2469 FormalParameters formals = pop(); | |
2470 List<TypeParameter> typeParameters = typeVariableBuildersToKernel(pop()); | |
2471 FunctionNode function = formals.addToFunction(new FunctionNode(body, | |
2472 typeParameters: typeParameters, asyncMarker: asyncModifier) | |
2473 ..fileOffset = formals.charOffset | |
2474 ..fileEndOffset = endToken.charOffset); | |
2446 exitLocalScope(); | 2475 exitLocalScope(); |
2447 var declaration = pop(); | 2476 var declaration = pop(); |
2448 var returnType = pop(); | 2477 var returnType = pop(); |
2449 var hasImplicitReturnType = returnType == null; | 2478 var hasImplicitReturnType = returnType == null; |
2450 returnType ??= const DynamicType(); | 2479 returnType ??= const DynamicType(); |
2451 pop(); // Modifiers. | 2480 pop(); // Modifiers. |
2452 exitFunction(); | 2481 exitFunction(); |
2453 if (declaration is FunctionDeclaration) { | 2482 if (declaration is FunctionDeclaration) { |
2454 KernelFunctionDeclaration.setHasImplicitReturnType( | 2483 KernelFunctionDeclaration.setHasImplicitReturnType( |
2455 declaration, hasImplicitReturnType); | 2484 declaration, hasImplicitReturnType); |
2456 function.returnType = returnType; | 2485 function.returnType = returnType; |
2457 declaration.variable.type = function.functionType; | 2486 declaration.variable.type = function.functionType; |
2458 declaration.function = function; | 2487 declaration.function = function; |
2459 function.parent = declaration; | 2488 function.parent = declaration; |
2460 } else { | 2489 } else { |
2461 // If [declaration] isn't a [FunctionDeclaration], it must be because | 2490 // If [declaration] isn't a [FunctionDeclaration], it must be because |
2462 // there was a compile-time error. | 2491 // there was a compile-time error. |
2463 | 2492 |
2464 // TODO(paulberry): ensure that when integrating with analyzer, type | 2493 // TODO(paulberry): ensure that when integrating with analyzer, type |
2465 // inference is still performed for the dropped declaration. | 2494 // inference is still performed for the dropped declaration. |
2466 assert(library.hasCompileTimeErrors); | 2495 assert(library.hasCompileTimeErrors); |
2467 } | 2496 } |
2468 push(declaration); | 2497 push(declaration); |
2469 } | 2498 } |
2470 | 2499 |
2471 @override | 2500 @override |
2472 void endUnnamedFunction(Token beginToken, Token token) { | 2501 void endFunctionExpression(Token beginToken, Token token) { |
danrubel
2017/07/06 15:43:34
rename token to endToken? Or is it tokenAfterExpre
ahe
2017/07/06 19:54:18
Now that I think about it, I think I've been rathe
danrubel
2017/07/06 19:58:42
Naming the current token 'token' sounds good to me
Paul Berry
2017/07/06 20:06:57
Not a blocking issue, just food for thought: I hav
ahe
2017/07/06 20:58:53
That's actually what I do for type variables. And
| |
2473 debugEvent("UnnamedFunction"); | 2502 debugEvent("FunctionExpression"); |
2474 Statement body = popStatement(); | 2503 Statement body = popStatement(); |
2475 AsyncMarker asyncModifier = pop(); | 2504 AsyncMarker asyncModifier = pop(); |
2476 exitLocalScope(); | 2505 exitLocalScope(); |
2477 FormalParameters formals = pop(); | 2506 FormalParameters formals = pop(); |
2478 exitFunction(); | 2507 exitFunction(); |
2479 List<TypeParameter> typeParameters = typeVariableBuildersToKernel(pop()); | 2508 List<TypeParameter> typeParameters = typeVariableBuildersToKernel(pop()); |
2480 FunctionNode function = formals.addToFunction(new FunctionNode(body, | 2509 FunctionNode function = formals.addToFunction(new FunctionNode(body, |
2481 typeParameters: typeParameters, asyncMarker: asyncModifier) | 2510 typeParameters: typeParameters, asyncMarker: asyncModifier) |
2482 ..fileOffset = beginToken.charOffset | 2511 ..fileOffset = beginToken.charOffset |
2483 ..fileEndOffset = token.charOffset); | 2512 ..fileEndOffset = token.charOffset); |
(...skipping 1239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3723 if (starToken == null) { | 3752 if (starToken == null) { |
3724 return AsyncMarker.Async; | 3753 return AsyncMarker.Async; |
3725 } else { | 3754 } else { |
3726 assert(identical(starToken.stringValue, "*")); | 3755 assert(identical(starToken.stringValue, "*")); |
3727 return AsyncMarker.AsyncStar; | 3756 return AsyncMarker.AsyncStar; |
3728 } | 3757 } |
3729 } else { | 3758 } else { |
3730 return internalError("Unknown async modifier: $asyncToken"); | 3759 return internalError("Unknown async modifier: $asyncToken"); |
3731 } | 3760 } |
3732 } | 3761 } |
OLD | NEW |