Add Forest support for creating parenthesized conditions

Change-Id: I69aa15244dff20d18d7a34c6b052bd9eeed388ed
Reviewed-on: https://dart-review.googlesource.com/55761
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Dan Rubel <danrubel@google.com>
Reviewed-by: Peter von der Ahé <ahe@google.com>
diff --git a/pkg/analyzer/lib/src/fasta/ast_building_factory.dart b/pkg/analyzer/lib/src/fasta/ast_building_factory.dart
index ae79499..17c95f8 100644
--- a/pkg/analyzer/lib/src/fasta/ast_building_factory.dart
+++ b/pkg/analyzer/lib/src/fasta/ast_building_factory.dart
@@ -236,6 +236,12 @@
         ..staticType = _typeProvider?.boolType;
 
   @override
+  Object parenthesizedCondition(Token leftParenthesis, Expression expression,
+          Token rightParenthesis) =>
+      astFactory.parenthesizedExpression(
+          leftParenthesis, expression, rightParenthesis);
+
+  @override
   int readOffset(AstNode node) => node.offset;
 
   @override
diff --git a/pkg/analyzer/test/generated/parser_forest_test.dart b/pkg/analyzer/test/generated/parser_forest_test.dart
index fc7dc39..cba6d0a 100644
--- a/pkg/analyzer/test/generated/parser_forest_test.dart
+++ b/pkg/analyzer/test/generated/parser_forest_test.dart
@@ -2,6 +2,7 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
+import 'package:test/test.dart';
 import 'package:test_reflective_loader/test_reflective_loader.dart';
 
 import '../src/fasta/body_builder_test_helper.dart';
@@ -5184,6 +5185,8 @@
   @failingTest
   void test_parseIfStatement_else_emptyStatements() {
     super.test_parseIfStatement_else_emptyStatements();
+    fail(
+        'This passes under Dart 1, but fails under Dart 2 because of a cast exception');
   }
 
   @failingTest
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 64a8c0a..7dde376 100644
--- a/pkg/front_end/lib/src/fasta/kernel/body_builder.dart
+++ b/pkg/front_end/lib/src/fasta/kernel/body_builder.dart
@@ -903,8 +903,7 @@
   @override
   void handleParenthesizedCondition(Token token) {
     debugEvent("ParenthesizedCondition");
-    push(new ParenthesizedExpression(
-        this, token.endGroup, toKernelExpression(popForValue())));
+    push(forest.parenthesizedCondition(token, popForValue(), token.endGroup));
   }
 
   @override
diff --git a/pkg/front_end/lib/src/fasta/kernel/fangorn.dart b/pkg/front_end/lib/src/fasta/kernel/fangorn.dart
index aea6f0c..5b8667c 100644
--- a/pkg/front_end/lib/src/fasta/kernel/fangorn.dart
+++ b/pkg/front_end/lib/src/fasta/kernel/fangorn.dart
@@ -282,6 +282,12 @@
   }
 
   @override
+  Object parenthesizedCondition(
+      Token leftParenthesis, Expression expression, Token rightParenthesis) {
+    return expression;
+  }
+
+  @override
   Statement rethrowStatement(Token rethrowKeyword, Token semicolon) {
     return new ShadowExpressionStatement(
         new ShadowRethrow()..fileOffset = offsetForToken(rethrowKeyword));
diff --git a/pkg/front_end/lib/src/fasta/kernel/forest.dart b/pkg/front_end/lib/src/fasta/kernel/forest.dart
index 1547c7f..d686f1f 100644
--- a/pkg/front_end/lib/src/fasta/kernel/forest.dart
+++ b/pkg/front_end/lib/src/fasta/kernel/forest.dart
@@ -169,6 +169,11 @@
 
   Expression notExpression(Expression operand, Location location);
 
+  /// Return a representation of a parenthesized condition consisting of the
+  /// given [expression] between the [leftParenthesis] and [rightParenthesis].
+  Object parenthesizedCondition(Location leftParenthesis, Expression expression,
+      Location rightParenthesis);
+
   /// Return a representation of a rethrow statement consisting of the
   /// [rethrowKeyword] followed by the [semicolon].
   Statement rethrowStatement(Location rethrowKeyword, Location semicolon);