Add Forest support for creating try statements

Change-Id: Ib0241b929fa4c9eda533beec1e3f902973340821
Reviewed-on: https://dart-review.googlesource.com/55520
Reviewed-by: Dan Rubel <danrubel@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
Brian Wilkerson 2018-05-16 20:15:02 +00:00 committed by commit-bot@chromium.org
parent 757ef3979c
commit 338a423416
5 changed files with 40 additions and 13 deletions

View file

@ -243,6 +243,16 @@ class AstBuildingForest
Expression throwExpression(Token throwKeyword, Expression expression) =>
astFactory.throwExpression(throwKeyword, expression);
@override
Statement tryStatement(
Token tryKeyword,
Statement body,
List<CatchClause> catchClauses,
Token finallyKeyword,
Statement finallyBlock) =>
astFactory.tryStatement(
tryKeyword, body, catchClauses, finallyKeyword, finallyBlock);
@override
Statement yieldStatement(Token yieldKeyword, Token star,
Expression expression, Token semicolon) =>

View file

@ -2384,19 +2384,11 @@ abstract class BodyBuilder<Expression, Statement, Arguments>
@override
void endTryStatement(int catchCount, Token tryKeyword, Token finallyKeyword) {
Statement finallyBlock = popStatementIfNotNull(finallyKeyword);
List<Catch> catches = popList(catchCount);
Object catches = popList(catchCount);
Statement tryBlock = popStatement();
kernel.Statement kernelFinallyBlock = toKernelStatement(finallyBlock);
kernel.Statement kernelTryBlock = toKernelStatement(tryBlock);
if (compileTimeErrorInTry == null) {
if (catches != null) {
kernelTryBlock = new ShadowTryCatch(kernelTryBlock, catches);
}
if (kernelFinallyBlock != null) {
kernelTryBlock =
new ShadowTryFinally(kernelTryBlock, kernelFinallyBlock);
}
push(kernelTryBlock);
push(forest.tryStatement(
tryKeyword, tryBlock, catches, finallyKeyword, finallyBlock));
} else {
push(compileTimeErrorInTry);
compileTimeErrorInTry = null;

View file

@ -9,6 +9,7 @@ import 'dart:core' hide MapEntry;
import 'package:kernel/ast.dart'
show
Arguments,
Catch,
DartType,
EmptyStatement,
Expression,
@ -53,6 +54,8 @@ import 'kernel_shadow_ast.dart'
ShadowSyntheticExpression,
ShadowThisExpression,
ShadowThrow,
ShadowTryCatch,
ShadowTryFinally,
ShadowTypeLiteral,
ShadowYieldStatement;
@ -274,6 +277,19 @@ class Fangorn extends Forest<Expression, Statement, Token, Arguments> {
..fileOffset = offsetForToken(throwKeyword);
}
@override
Statement tryStatement(Token tryKeyword, Statement body,
List<Catch> catchClauses, Token finallyKeyword, Statement finallyBlock) {
Statement tryStatement = body;
if (catchClauses != null) {
tryStatement = new ShadowTryCatch(tryStatement, catchClauses);
}
if (finallyBlock != null) {
tryStatement = new ShadowTryFinally(tryStatement, finallyBlock);
}
return tryStatement;
}
@override
Statement yieldStatement(
Token yieldKeyword, Token star, Expression expression, Token semicolon) {

View file

@ -176,6 +176,17 @@ abstract class Forest<Expression, Statement, Location, Arguments> {
/// [throwKeyword].
Expression throwExpression(Location throwKeyword, Expression expression);
/// Return a representation of a try statement. The statement is introduced by
/// the [tryKeyword] and the given [body]. If catch clauses were included,
/// then the [catchClauses] will represent them, otherwise it will be `null`.
/// Similarly, if a finally block was included, then the [finallyKeyword] and
/// [finallyBlock] will be non-`null`, otherwise both will be `null`. If there
/// was an error in some part of the try statement, then an [errorReplacement]
/// might be provided, in which case it could be returned instead of the
/// representation of the try statement.
Statement tryStatement(Location tryKeyword, Statement body,
covariant catchClauses, Location finallyKeyword, Statement finallyBlock);
/// Return a representation of a yield statement consisting of the
/// [yieldKeyword], [star], [expression], and [semicolon]. The [star] is null
/// when no star was included in the source code.

View file

@ -105,8 +105,6 @@ export 'kernel_shadow_ast.dart'
ShadowSuperPropertyGet,
ShadowSwitchStatement,
ShadowSyntheticExpression,
ShadowTryCatch,
ShadowTryFinally,
ShadowVariableAssignment,
ShadowVariableDeclaration,
ShadowVariableGet,