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' show Message; | 7 import '../fasta_codes.dart' show Message; |
8 | 8 |
9 import '../fasta_codes.dart' as fasta; | 9 import '../fasta_codes.dart' as fasta; |
10 | 10 |
(...skipping 2419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2430 } | 2430 } |
2431 | 2431 |
2432 void exitFunction() { | 2432 void exitFunction() { |
2433 debugEvent("exitFunction"); | 2433 debugEvent("exitFunction"); |
2434 functionNestingLevel--; | 2434 functionNestingLevel--; |
2435 inCatchBlock = pop(); | 2435 inCatchBlock = pop(); |
2436 switchScope = pop(); | 2436 switchScope = pop(); |
2437 } | 2437 } |
2438 | 2438 |
2439 @override | 2439 @override |
2440 void beginFunction(Token token) { | 2440 void beginFunctionDeclaration(Token token) { |
2441 debugEvent("beginFunction"); | 2441 debugEvent("beginNamedFunctionExpression"); |
2442 enterFunction(); | 2442 enterFunction(); |
2443 } | 2443 } |
2444 | 2444 |
2445 @override | 2445 @override |
2446 void beginUnnamedFunction(Token token) { | 2446 void beginNamedFunctionExpression(Token token) { |
2447 debugEvent("beginUnnamedFunction"); | 2447 debugEvent("beginNamedFunctionExpression"); |
2448 enterFunction(); | 2448 enterFunction(); |
2449 } | 2449 } |
2450 | 2450 |
2451 @override | 2451 @override |
2452 void endFunction(Token getOrSet, Token endToken) { | 2452 void beginFunctionExpression(Token token) { |
2453 debugEvent("Function"); | 2453 debugEvent("beginFunctionExpression"); |
| 2454 enterFunction(); |
| 2455 } |
| 2456 |
| 2457 @override |
| 2458 void endNamedFunctionExpression(Token endToken) { |
| 2459 debugEvent("NamedFunctionExpression"); |
2454 Statement body = popStatement(); | 2460 Statement body = popStatement(); |
2455 AsyncMarker asyncModifier = pop(); | 2461 AsyncMarker asyncModifier = pop(); |
2456 if (functionNestingLevel != 0) { | 2462 if (functionNestingLevel != 0) { |
2457 exitLocalScope(); | 2463 exitLocalScope(); |
2458 } | 2464 } |
2459 FormalParameters formals = pop(); | 2465 FormalParameters formals = pop(); |
2460 List<TypeParameter> typeParameters = typeVariableBuildersToKernel(pop()); | 2466 List<TypeParameter> typeParameters = typeVariableBuildersToKernel(pop()); |
2461 push(formals.addToFunction(new FunctionNode(body, | 2467 |
2462 typeParameters: typeParameters, asyncMarker: asyncModifier) | 2468 exitLocalScope(); |
2463 ..fileOffset = formals.charOffset | 2469 KernelFunctionDeclaration declaration = pop(); |
2464 ..fileEndOffset = endToken.charOffset)); | 2470 VariableDeclaration variable = declaration.variable; |
| 2471 var returnType = pop(); |
| 2472 returnType ??= const DynamicType(); |
| 2473 pop(); // Modifiers. |
| 2474 exitFunction(); |
| 2475 |
| 2476 variable.initializer = new KernelFunctionExpression(formals.addToFunction( |
| 2477 new FunctionNode(body, |
| 2478 typeParameters: typeParameters, asyncMarker: asyncModifier) |
| 2479 ..fileOffset = formals.charOffset |
| 2480 ..fileEndOffset = endToken.charOffset)) |
| 2481 ..parent = variable |
| 2482 ..fileOffset = formals.charOffset; |
| 2483 push(new Let(variable, new VariableGet(variable))); |
2465 } | 2484 } |
2466 | 2485 |
2467 @override | 2486 @override |
2468 void endFunctionDeclaration(Token token) { | 2487 void endFunctionDeclaration(Token endToken) { |
2469 debugEvent("FunctionDeclaration"); | 2488 debugEvent("FunctionDeclaration"); |
2470 FunctionNode function = pop(); | 2489 Statement body = popStatement(); |
| 2490 AsyncMarker asyncModifier = pop(); |
| 2491 if (functionNestingLevel != 0) { |
| 2492 exitLocalScope(); |
| 2493 } |
| 2494 FormalParameters formals = pop(); |
| 2495 List<TypeParameter> typeParameters = typeVariableBuildersToKernel(pop()); |
| 2496 FunctionNode function = formals.addToFunction(new FunctionNode(body, |
| 2497 typeParameters: typeParameters, asyncMarker: asyncModifier) |
| 2498 ..fileOffset = formals.charOffset |
| 2499 ..fileEndOffset = endToken.charOffset); |
2471 exitLocalScope(); | 2500 exitLocalScope(); |
2472 var declaration = pop(); | 2501 var declaration = pop(); |
2473 var returnType = pop(); | 2502 var returnType = pop(); |
2474 var hasImplicitReturnType = returnType == null; | 2503 var hasImplicitReturnType = returnType == null; |
2475 returnType ??= const DynamicType(); | 2504 returnType ??= const DynamicType(); |
2476 pop(); // Modifiers. | 2505 pop(); // Modifiers. |
2477 exitFunction(); | 2506 exitFunction(); |
2478 if (declaration is FunctionDeclaration) { | 2507 if (declaration is FunctionDeclaration) { |
2479 KernelFunctionDeclaration.setHasImplicitReturnType( | 2508 KernelFunctionDeclaration.setHasImplicitReturnType( |
2480 declaration, hasImplicitReturnType); | 2509 declaration, hasImplicitReturnType); |
2481 function.returnType = returnType; | 2510 function.returnType = returnType; |
2482 declaration.variable.type = function.functionType; | 2511 declaration.variable.type = function.functionType; |
2483 declaration.function = function; | 2512 declaration.function = function; |
2484 function.parent = declaration; | 2513 function.parent = declaration; |
2485 } else { | 2514 } else { |
2486 // If [declaration] isn't a [FunctionDeclaration], it must be because | 2515 // If [declaration] isn't a [FunctionDeclaration], it must be because |
2487 // there was a compile-time error. | 2516 // there was a compile-time error. |
2488 | 2517 |
2489 // TODO(paulberry): ensure that when integrating with analyzer, type | 2518 // TODO(paulberry): ensure that when integrating with analyzer, type |
2490 // inference is still performed for the dropped declaration. | 2519 // inference is still performed for the dropped declaration. |
2491 assert(library.hasCompileTimeErrors); | 2520 assert(library.hasCompileTimeErrors); |
2492 } | 2521 } |
2493 push(declaration); | 2522 push(declaration); |
2494 } | 2523 } |
2495 | 2524 |
2496 @override | 2525 @override |
2497 void endUnnamedFunction(Token beginToken, Token token) { | 2526 void endFunctionExpression(Token beginToken, Token token) { |
2498 debugEvent("UnnamedFunction"); | 2527 debugEvent("FunctionExpression"); |
2499 Statement body = popStatement(); | 2528 Statement body = popStatement(); |
2500 AsyncMarker asyncModifier = pop(); | 2529 AsyncMarker asyncModifier = pop(); |
2501 exitLocalScope(); | 2530 exitLocalScope(); |
2502 FormalParameters formals = pop(); | 2531 FormalParameters formals = pop(); |
2503 exitFunction(); | 2532 exitFunction(); |
2504 List<TypeParameter> typeParameters = typeVariableBuildersToKernel(pop()); | 2533 List<TypeParameter> typeParameters = typeVariableBuildersToKernel(pop()); |
2505 FunctionNode function = formals.addToFunction(new FunctionNode(body, | 2534 FunctionNode function = formals.addToFunction(new FunctionNode(body, |
2506 typeParameters: typeParameters, asyncMarker: asyncModifier) | 2535 typeParameters: typeParameters, asyncMarker: asyncModifier) |
2507 ..fileOffset = beginToken.charOffset | 2536 ..fileOffset = beginToken.charOffset |
2508 ..fileEndOffset = token.charOffset); | 2537 ..fileEndOffset = token.charOffset); |
(...skipping 1286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3795 if (starToken == null) { | 3824 if (starToken == null) { |
3796 return AsyncMarker.Async; | 3825 return AsyncMarker.Async; |
3797 } else { | 3826 } else { |
3798 assert(identical(starToken.stringValue, "*")); | 3827 assert(identical(starToken.stringValue, "*")); |
3799 return AsyncMarker.AsyncStar; | 3828 return AsyncMarker.AsyncStar; |
3800 } | 3829 } |
3801 } else { | 3830 } else { |
3802 return deprecated_internalProblem("Unknown async modifier: $asyncToken"); | 3831 return deprecated_internalProblem("Unknown async modifier: $asyncToken"); |
3803 } | 3832 } |
3804 } | 3833 } |
OLD | NEW |