Chromium Code Reviews| 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 FastaMessage, codeExpectedButGot, codeExpectedFunctionBody; | 8 show FastaMessage, codeExpectedButGot, codeExpectedFunctionBody; |
| 9 | 9 |
| 10 import '../parser/parser.dart' show FormalParameterType, MemberKind, optional; | 10 import '../parser/parser.dart' |
| 11 show Assert, FormalParameterType, MemberKind, optional; | |
| 11 | 12 |
| 12 import '../parser/identifier_context.dart' show IdentifierContext; | 13 import '../parser/identifier_context.dart' show IdentifierContext; |
| 13 | 14 |
| 14 import 'package:front_end/src/fasta/kernel/kernel_shadow_ast.dart'; | 15 import 'package:front_end/src/fasta/kernel/kernel_shadow_ast.dart'; |
| 15 | 16 |
| 16 import 'package:front_end/src/fasta/kernel/utils.dart' show offsetForToken; | 17 import 'package:front_end/src/fasta/kernel/utils.dart' show offsetForToken; |
| 17 | 18 |
| 18 import 'package:front_end/src/fasta/type_inference/type_inferrer.dart' | 19 import 'package:front_end/src/fasta/type_inference/type_inferrer.dart' |
| 19 show TypeInferrer; | 20 show TypeInferrer; |
| 20 | 21 |
| (...skipping 2421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2442 exitLoopOrSwitch(result); | 2443 exitLoopOrSwitch(result); |
| 2443 } | 2444 } |
| 2444 | 2445 |
| 2445 @override | 2446 @override |
| 2446 void handleEmptyStatement(Token token) { | 2447 void handleEmptyStatement(Token token) { |
| 2447 debugEvent("EmptyStatement"); | 2448 debugEvent("EmptyStatement"); |
| 2448 push(new EmptyStatement()); | 2449 push(new EmptyStatement()); |
| 2449 } | 2450 } |
| 2450 | 2451 |
| 2451 @override | 2452 @override |
| 2452 void handleAssertStatement(Token assertKeyword, Token leftParenthesis, | 2453 void beginAssert(Token assertKeyword, Assert kind) { |
| 2453 Token commaToken, Token rightParenthesis, Token semicolonToken) { | 2454 debugEvent("beginAssert"); |
| 2454 debugEvent("AssertStatement"); | 2455 inInitializer = false; |
|
kasperl
2017/06/08 10:23:14
Add a comment to explain why you have to turn this
ahe
2017/06/08 11:04:33
This value is never restored. I've added a comment
| |
| 2455 Expression message = popForValueIfNotNull(commaToken); | |
| 2456 Expression condition = popForValue(); | |
| 2457 push(new AssertStatement(condition, message)); | |
| 2458 } | 2456 } |
| 2459 | 2457 |
| 2460 @override | 2458 @override |
| 2459 void endAssert(Token assertKeyword, Assert kind, Token leftParenthesis, | |
| 2460 Token commaToken, Token rightParenthesis, Token semicolonToken) { | |
| 2461 debugEvent("Assert"); | |
| 2462 Expression message = popForValueIfNotNull(commaToken); | |
| 2463 Expression condition = popForValue(); | |
| 2464 AssertStatement statement = new AssertStatement(condition, message); | |
| 2465 switch (kind) { | |
| 2466 case Assert.Statement: | |
| 2467 push(statement); | |
| 2468 break; | |
| 2469 | |
| 2470 case Assert.Expression: | |
| 2471 push(buildCompileTimeError("`assert` can't be used as an expression.")); | |
| 2472 break; | |
| 2473 | |
| 2474 case Assert.Initializer: | |
| 2475 push(buildAssertInitializer(statement)); | |
| 2476 break; | |
| 2477 } | |
| 2478 } | |
| 2479 | |
| 2480 Initializer buildAssertInitializer(AssertStatement statement) { | |
| 2481 return new LocalInitializer(new VariableDeclaration.forValue( | |
|
kasperl
2017/06/08 10:23:14
It would be useful if you could explain the struct
ahe
2017/06/08 11:04:33
Done.
| |
| 2482 buildMethodInvocation( | |
| 2483 new FunctionExpression(new FunctionNode(statement)), | |
| 2484 callName, | |
| 2485 new Arguments.empty(), | |
| 2486 statement.fileOffset, | |
| 2487 isConstantExpression: true, | |
| 2488 isImplicitCall: true))); | |
| 2489 } | |
| 2490 | |
| 2491 @override | |
| 2461 void endYieldStatement(Token yieldToken, Token starToken, Token endToken) { | 2492 void endYieldStatement(Token yieldToken, Token starToken, Token endToken) { |
| 2462 debugEvent("YieldStatement"); | 2493 debugEvent("YieldStatement"); |
| 2463 push(new KernelYieldStatement(popForValue(), isYieldStar: starToken != null) | 2494 push(new KernelYieldStatement(popForValue(), isYieldStar: starToken != null) |
| 2464 ..fileOffset = yieldToken.charOffset); | 2495 ..fileOffset = yieldToken.charOffset); |
| 2465 } | 2496 } |
| 2466 | 2497 |
| 2467 @override | 2498 @override |
| 2468 void beginSwitchBlock(Token token) { | 2499 void beginSwitchBlock(Token token) { |
| 2469 debugEvent("beginSwitchBlock"); | 2500 debugEvent("beginSwitchBlock"); |
| 2470 enterLocalScope(); | 2501 enterLocalScope(); |
| (...skipping 951 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3422 if (starToken == null) { | 3453 if (starToken == null) { |
| 3423 return AsyncMarker.Async; | 3454 return AsyncMarker.Async; |
| 3424 } else { | 3455 } else { |
| 3425 assert(identical(starToken.stringValue, "*")); | 3456 assert(identical(starToken.stringValue, "*")); |
| 3426 return AsyncMarker.AsyncStar; | 3457 return AsyncMarker.AsyncStar; |
| 3427 } | 3458 } |
| 3428 } else { | 3459 } else { |
| 3429 return internalError("Unknown async modifier: $asyncToken"); | 3460 return internalError("Unknown async modifier: $asyncToken"); |
| 3430 } | 3461 } |
| 3431 } | 3462 } |
| OLD | NEW |