Chromium Code Reviews| Index: pkg/front_end/lib/src/fasta/kernel/body_builder.dart |
| diff --git a/pkg/front_end/lib/src/fasta/kernel/body_builder.dart b/pkg/front_end/lib/src/fasta/kernel/body_builder.dart |
| index 904cd8084b9b063e179bce12afe3d3fd4cf17a4f..57af8bc55678bf9041bb2949c59a9a95c09b34ed 100644 |
| --- a/pkg/front_end/lib/src/fasta/kernel/body_builder.dart |
| +++ b/pkg/front_end/lib/src/fasta/kernel/body_builder.dart |
| @@ -7,7 +7,8 @@ library fasta.body_builder; |
| import '../fasta_codes.dart' |
| show FastaMessage, codeExpectedButGot, codeExpectedFunctionBody; |
| -import '../parser/parser.dart' show FormalParameterType, MemberKind, optional; |
| +import '../parser/parser.dart' |
| + show Assert, FormalParameterType, MemberKind, optional; |
| import '../parser/identifier_context.dart' show IdentifierContext; |
| @@ -2449,12 +2450,42 @@ class BodyBuilder extends ScopeListener<JumpTarget> implements BuilderHelper { |
| } |
| @override |
| - void handleAssertStatement(Token assertKeyword, Token leftParenthesis, |
| + void beginAssert(Token assertKeyword, Assert kind) { |
| + debugEvent("beginAssert"); |
| + 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
|
| + } |
| + |
| + @override |
| + void endAssert(Token assertKeyword, Assert kind, Token leftParenthesis, |
| Token commaToken, Token rightParenthesis, Token semicolonToken) { |
| - debugEvent("AssertStatement"); |
| + debugEvent("Assert"); |
| Expression message = popForValueIfNotNull(commaToken); |
| Expression condition = popForValue(); |
| - push(new AssertStatement(condition, message)); |
| + AssertStatement statement = new AssertStatement(condition, message); |
| + switch (kind) { |
| + case Assert.Statement: |
| + push(statement); |
| + break; |
| + |
| + case Assert.Expression: |
| + push(buildCompileTimeError("`assert` can't be used as an expression.")); |
| + break; |
| + |
| + case Assert.Initializer: |
| + push(buildAssertInitializer(statement)); |
| + break; |
| + } |
| + } |
| + |
| + Initializer buildAssertInitializer(AssertStatement statement) { |
| + 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.
|
| + buildMethodInvocation( |
| + new FunctionExpression(new FunctionNode(statement)), |
| + callName, |
| + new Arguments.empty(), |
| + statement.fileOffset, |
| + isConstantExpression: true, |
| + isImplicitCall: true))); |
| } |
| @override |