Remove ThrowJudgment
Change-Id: I9b2dc1d1f3aa9c183119f6802a976de858c22fdc
Reviewed-on: https://dart-review.googlesource.com/c/80662
Reviewed-by: Kevin Millikin <kmillikin@google.com>
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 ab45917..1983589 100644
--- a/pkg/front_end/lib/src/fasta/kernel/body_builder.dart
+++ b/pkg/front_end/lib/src/fasta/kernel/body_builder.dart
@@ -670,7 +670,7 @@
false, node.target, node.arguments, token.charOffset);
} else {
Expression value = toValue(node);
- if (node is! Throw) {
+ if (!forest.isThrow(node)) {
value =
wrapInProblem(value, fasta.messageExpectedAnInitializer, noLength);
}
@@ -1408,13 +1408,15 @@
addProblem(message.messageObject, message.charOffset, message.length,
wasHandled: true, context: context);
return new SyntheticExpressionJudgment(
- new Throw(library.loader.instantiateNoSuchMethodError(
- receiver, name, forest.castArguments(arguments), charOffset,
- isMethod: !isGetter && !isSetter,
- isGetter: isGetter,
- isSetter: isSetter,
- isStatic: isStatic,
- isTopLevel: !isStatic && !isSuper))
+ forest.throwExpression(
+ null,
+ library.loader.instantiateNoSuchMethodError(
+ receiver, name, forest.castArguments(arguments), charOffset,
+ isMethod: !isGetter && !isSetter,
+ isGetter: isGetter,
+ isSetter: isSetter,
+ isStatic: isStatic,
+ isTopLevel: !isStatic && !isSuper))
..fileOffset = charOffset)
..fileOffset = charOffset;
}
@@ -2546,8 +2548,7 @@
throwToken.offset,
throwToken.length));
} else {
- push(new ThrowJudgment(expression)
- ..fileOffset = offsetForToken(throwToken));
+ push(forest.throwExpression(throwToken, expression));
}
}
@@ -3956,7 +3957,7 @@
lastNode is! ContinueSwitchStatement &&
lastNode is! Rethrow &&
lastNode is! ReturnStatement &&
- lastNode is! Throw) {
+ !forest.isThrow(lastNode)) {
block.addStatement(
new ExpressionStatement(buildFallThroughError(current.fileOffset)));
}
@@ -4239,14 +4240,18 @@
// TODO(ahe): Compute a LocatedMessage above instead?
Location location = messages.getLocationFromUri(uri, charOffset);
- return new Throw(buildStaticInvocation(
- library.loader.coreTypes.fallThroughErrorUrlAndLineConstructor,
- forest.arguments(<Expression>[
- forest.literalString("${location?.file ?? uri}", null)
- ..fileOffset = charOffset,
- forest.literalInt(location?.line ?? 0, null)..fileOffset = charOffset,
- ], noLocation),
- charOffset: charOffset));
+ return forest.throwExpression(
+ null,
+ buildStaticInvocation(
+ library.loader.coreTypes.fallThroughErrorUrlAndLineConstructor,
+ forest.arguments(<Expression>[
+ forest.literalString("${location?.file ?? uri}", null)
+ ..fileOffset = charOffset,
+ forest.literalInt(location?.line ?? 0, null)
+ ..fileOffset = charOffset,
+ ], noLocation),
+ charOffset: charOffset))
+ ..fileOffset = charOffset;
}
Expression buildAbstractClassInstantiationError(
@@ -4256,11 +4261,16 @@
// TODO(ahe): The following doesn't make sense to Analyzer AST.
Declaration constructor =
library.loader.getAbstractClassInstantiationError();
- return new Throw(buildStaticInvocation(
- constructor.target,
- forest.arguments(<Expression>[
- forest.literalString(className, null)..fileOffset = charOffset
- ], noLocation)));
+ return forest.throwExpression(
+ null,
+ buildStaticInvocation(
+ constructor.target,
+ forest.arguments(<Expression>[
+ forest.literalString(className, null)..fileOffset = charOffset
+ ], noLocation)
+ ..fileOffset = charOffset,
+ charOffset: charOffset))
+ ..fileOffset = charOffset;
}
Statement buildProblemStatement(Message message, int charOffset,
@@ -4349,12 +4359,16 @@
return new ShadowInvalidFieldInitializer(
builder.field,
expression,
- new VariableDeclaration.forValue(new Throw(buildStaticInvocation(
- constructor.target,
- forest.arguments(<Expression>[
- forest.literalString(name, null)..fileOffset = offset
- ], noLocation),
- charOffset: offset))))
+ new VariableDeclaration.forValue(forest.throwExpression(
+ null,
+ buildStaticInvocation(
+ constructor.target,
+ forest.arguments(<Expression>[
+ forest.literalString(name, null)..fileOffset = offset
+ ], noLocation)
+ ..fileOffset = offset,
+ charOffset: offset))
+ ..fileOffset = offset))
..fileOffset = offset;
} else {
if (library.loader.target.strongMode &&
diff --git a/pkg/front_end/lib/src/fasta/kernel/fangorn.dart b/pkg/front_end/lib/src/fasta/kernel/fangorn.dart
index 21e6178..dccc2b1 100644
--- a/pkg/front_end/lib/src/fasta/kernel/fangorn.dart
+++ b/pkg/front_end/lib/src/fasta/kernel/fangorn.dart
@@ -9,6 +9,7 @@
import 'package:kernel/ast.dart'
show
Arguments,
+ Throw,
AsExpression,
AssertInitializer,
AwaitExpression,
@@ -98,7 +99,6 @@
ShadowLargeIntLiteral,
SymbolLiteralJudgment,
SyntheticExpressionJudgment,
- ThrowJudgment,
TryCatchJudgment,
TryFinallyJudgment,
TypeLiteralJudgment,
@@ -472,11 +472,13 @@
@override
Expression throwExpression(Token throwKeyword, Expression expression) {
- return new ThrowJudgment(expression)
- ..fileOffset = offsetForToken(throwKeyword);
+ return new Throw(expression)..fileOffset = offsetForToken(throwKeyword);
}
@override
+ bool isThrow(Object o) => o is Throw;
+
+ @override
Statement tryStatement(Token tryKeyword, Statement body,
List<Catch> catchClauses, Token finallyKeyword, Statement finallyBlock) {
if (finallyBlock != null) {
diff --git a/pkg/front_end/lib/src/fasta/kernel/forest.dart b/pkg/front_end/lib/src/fasta/kernel/forest.dart
index e51a8e6..a7ab83b 100644
--- a/pkg/front_end/lib/src/fasta/kernel/forest.dart
+++ b/pkg/front_end/lib/src/fasta/kernel/forest.dart
@@ -285,6 +285,8 @@
/// [throwKeyword].
Expression throwExpression(Token throwKeyword, Expression expression);
+ bool isThrow(Object o);
+
/// 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`.
diff --git a/pkg/front_end/lib/src/fasta/kernel/inference_visitor.dart b/pkg/front_end/lib/src/fasta/kernel/inference_visitor.dart
index af744ac..e8cce27 100644
--- a/pkg/front_end/lib/src/fasta/kernel/inference_visitor.dart
+++ b/pkg/front_end/lib/src/fasta/kernel/inference_visitor.dart
@@ -1202,9 +1202,9 @@
void visitThisExpression(ThisExpression node, DartType typeContext) {}
- void visitThrowJudgment(ThrowJudgment node, DartType typeContext) {
- inferrer.inferExpression(node.judgment, const UnknownType(), false);
- node.inferredType = const BottomType();
+ @override
+ void visitThrow(Throw node, DartType typeContext) {
+ inferrer.inferExpression(node.expression, const UnknownType(), false);
}
void visitCatchJudgment(CatchJudgment node) {
diff --git a/pkg/front_end/lib/src/fasta/kernel/inferred_type_visitor.dart b/pkg/front_end/lib/src/fasta/kernel/inferred_type_visitor.dart
index 5d63fa1..526ce35 100644
--- a/pkg/front_end/lib/src/fasta/kernel/inferred_type_visitor.dart
+++ b/pkg/front_end/lib/src/fasta/kernel/inferred_type_visitor.dart
@@ -148,4 +148,9 @@
StaticInvocation node, TypeInferrerImpl inferrer) {
return inferrer.readInferredType(node);
}
+
+ @override
+ DartType visitThrow(Throw node, TypeInferrerImpl inferrer) {
+ return const BottomType();
+ }
}
diff --git a/pkg/front_end/lib/src/fasta/kernel/kernel_ast_api.dart b/pkg/front_end/lib/src/fasta/kernel/kernel_ast_api.dart
index 9d1a203..a58158a 100644
--- a/pkg/front_end/lib/src/fasta/kernel/kernel_ast_api.dart
+++ b/pkg/front_end/lib/src/fasta/kernel/kernel_ast_api.dart
@@ -67,7 +67,6 @@
SuperPropertySet,
SwitchCase,
ThisExpression,
- Throw,
TreeNode,
TypeParameter,
TypeParameterType,
@@ -121,7 +120,6 @@
SwitchCaseJudgment,
SwitchStatementJudgment,
SyntheticExpressionJudgment,
- ThrowJudgment,
UnresolvedTargetInvocationJudgment,
UnresolvedVariableAssignmentJudgment,
VariableAssignmentJudgment,
diff --git a/pkg/front_end/lib/src/fasta/kernel/kernel_expression_generator.dart b/pkg/front_end/lib/src/fasta/kernel/kernel_expression_generator.dart
index 21477ae..5aec155 100644
--- a/pkg/front_end/lib/src/fasta/kernel/kernel_expression_generator.dart
+++ b/pkg/front_end/lib/src/fasta/kernel/kernel_expression_generator.dart
@@ -107,7 +107,6 @@
SuperPropertyGetJudgment,
SuperPropertySet,
SyntheticExpressionJudgment,
- Throw,
TreeNode,
TypeParameter,
UnresolvedVariableAssignmentJudgment,
@@ -1256,7 +1255,8 @@
helper.addProblemErrorIfConst(
declaration.message.messageObject, offset, token.length);
super.expression = new SyntheticExpressionJudgment(
- new Throw(forest.literalString(declaration.message.message, token))
+ forest.throwExpression(
+ null, forest.literalString(declaration.message.message, token))
..fileOffset = offset);
} else {
super.expression = forest.literalType(
diff --git a/pkg/front_end/lib/src/fasta/kernel/kernel_shadow_ast.dart b/pkg/front_end/lib/src/fasta/kernel/kernel_shadow_ast.dart
index ead87c5..4f91001 100644
--- a/pkg/front_end/lib/src/fasta/kernel/kernel_shadow_ast.dart
+++ b/pkg/front_end/lib/src/fasta/kernel/kernel_shadow_ast.dart
@@ -1517,19 +1517,6 @@
}
}
-class ThrowJudgment extends Throw implements ExpressionJudgment {
- DartType inferredType;
-
- Expression get judgment => expression;
-
- ThrowJudgment(Expression expression) : super(expression);
-
- @override
- void acceptInference(InferenceVistor visitor, DartType typeContext) {
- return visitor.visitThrowJudgment(this, typeContext);
- }
-}
-
/// Concrete shadow object representing a catch clause.
class CatchJudgment extends Catch {
CatchJudgment(VariableDeclaration exception, Statement body,
diff --git a/pkg/front_end/lib/src/fasta/type_inference/type_inferrer.dart b/pkg/front_end/lib/src/fasta/type_inference/type_inferrer.dart
index 145c84d..bfbb35d 100644
--- a/pkg/front_end/lib/src/fasta/type_inference/type_inferrer.dart
+++ b/pkg/front_end/lib/src/fasta/type_inference/type_inferrer.dart
@@ -97,7 +97,6 @@
import '../kernel/kernel_shadow_ast.dart'
show
- ArgumentsJudgment,
ExpressionJudgment,
ShadowClass,
ShadowField,
@@ -1227,7 +1226,7 @@
/// Performs the type inference steps that are shared by all kinds of
/// invocations (constructors, instance methods, and static methods).
ExpressionInferenceResult inferInvocation(DartType typeContext, int offset,
- FunctionType calleeType, DartType returnType, ArgumentsJudgment arguments,
+ FunctionType calleeType, DartType returnType, Arguments arguments,
{bool isOverloadedArithmeticOperator: false,
DartType receiverType,
bool skipTypeArgumentInference: false,