Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Unified Diff: pkg/front_end/lib/src/fasta/kernel/body_builder.dart

Issue 2906253004: Avoid using Invalid{Statement,Expression,Initializer}. (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 8d5af76f94e9ec17721c2db0c325a668d1f8c4d8..4530a30d2b14c9f92a5b68fd3bed1fa6d01e0337 100644
--- a/pkg/front_end/lib/src/fasta/kernel/body_builder.dart
+++ b/pkg/front_end/lib/src/fasta/kernel/body_builder.dart
@@ -24,7 +24,8 @@ import 'package:front_end/src/fasta/type_inference/type_inferrer.dart'
import 'package:front_end/src/fasta/type_inference/type_promotion.dart'
show TypePromoter;
-import 'package:kernel/ast.dart';
+import 'package:kernel/ast.dart'
+ hide InvalidExpression, InvalidInitializer, InvalidStatement;
import 'package:kernel/clone.dart' show CloneVisitor;
@@ -463,10 +464,9 @@ class BodyBuilder extends ScopeListener<JumpTarget> implements BuilderHelper {
initializer =
buildSuperInitializer(node.target, node.arguments, token.charOffset);
} else {
+ Expression value = toValue(node);
if (node is! Throw) {
- // TODO(ahe): This is probably an internal error.
- needsImplicitSuperInitializer = false;
- node = wrapInvalid(node);
+ value = wrapInCompileTimeError(value, "Expected an initializer.");
}
initializer = buildInvalidIntializer(node, token.charOffset);
}
@@ -1233,10 +1233,7 @@ class BodyBuilder extends ScopeListener<JumpTarget> implements BuilderHelper {
debugEvent("AssignmentExpression");
Expression value = popForValue();
var accessor = pop();
- if (accessor is TypeDeclarationBuilder) {
- push(wrapInvalid(new KernelTypeLiteral(
- accessor.buildTypesWithBuiltArguments(library, null))));
- } else if (accessor is! FastaAccessor) {
+ if (accessor is TypeDeclarationBuilder || accessor is! FastaAccessor) {
ahe 2017/05/29 13:14:47 This change is what's causing the new compile-time
push(buildCompileTimeError("Can't assign to this.", token.charOffset));
} else {
push(new DelayedAssignment(
@@ -1767,9 +1764,10 @@ class BodyBuilder extends ScopeListener<JumpTarget> implements BuilderHelper {
}
if (catchParameters.required.length > 2 ||
catchParameters.optional != null) {
- body = new Block(<Statement>[new InvalidStatement()]);
- compileTimeErrorInTry ??= buildCompileTimeErrorStatement(
- "Invalid catch arguments.", catchKeyword.next.charOffset);
+ body = new Block(<Statement>[
+ compileTimeErrorInTry ??= buildCompileTimeErrorStatement(
+ "Invalid catch arguments.", catchKeyword.next.charOffset)
+ ]);
}
}
push(new Catch(exception, body, guard: type, stackTrace: stackTrace));
@@ -1855,7 +1853,7 @@ class BodyBuilder extends ScopeListener<JumpTarget> implements BuilderHelper {
push(accessor.buildPrefixIncrement(incrementOperator(token),
offset: token.charOffset));
} else {
- push(wrapInvalid(toValue(accessor)));
+ push(wrapInCompileTimeError(toValue(accessor), "Can't assign to this."));
}
}
@@ -1867,7 +1865,7 @@ class BodyBuilder extends ScopeListener<JumpTarget> implements BuilderHelper {
push(new DelayedPostfixIncrement(
this, token, accessor, incrementOperator(token), null));
} else {
- push(wrapInvalid(toValue(accessor)));
+ push(wrapInCompileTimeError(toValue(accessor), "Can't assign to this."));
}
}
@@ -2137,7 +2135,9 @@ class BodyBuilder extends ScopeListener<JumpTarget> implements BuilderHelper {
isFinal: true, isLocalFunction: true)
..fileOffset = offsetForToken(name.token);
push(new KernelFunctionDeclaration(
- variable, new FunctionNode(new InvalidStatement()))
+ variable,
+ // The function node is created later.
+ null)
..fileOffset = beginToken.charOffset);
declareVariable(variable);
enterLocalScope();
@@ -2658,7 +2658,16 @@ class BodyBuilder extends ScopeListener<JumpTarget> implements BuilderHelper {
String message = formatUnexpected(uri, charOffset, error);
Builder constructor = library.loader.getCompileTimeError();
return new Throw(buildStaticInvocation(constructor.target,
- new KernelArguments(<Expression>[new StringLiteral(message)])));
+ new KernelArguments(<Expression>[new StringLiteral(message)]),
+ charOffset: charOffset));
+ }
+
+ Expression wrapInCompileTimeError(Expression expression, String message) {
+ return new Let(
+ new VariableDeclaration.forValue(expression)
+ ..fileOffset = expression.fileOffset,
+ buildCompileTimeError(message, expression.fileOffset))
+ ..fileOffset = expression.fileOffset;
}
Expression buildAbstractClassInstantiationError(String className,
@@ -2709,7 +2718,7 @@ class BodyBuilder extends ScopeListener<JumpTarget> implements BuilderHelper {
@override
void handleOperator(Token token) {
debugEvent("Operator");
- push(new Operator(token.stringValue)..fileOffset = token.charOffset);
+ push(new Operator(token.stringValue, token.charOffset));
}
@override
@@ -2731,7 +2740,9 @@ class BodyBuilder extends ScopeListener<JumpTarget> implements BuilderHelper {
if (member.isNative) {
push(NullValue.FunctionBody);
} else {
- push(new Block(<Statement>[new InvalidStatement()]));
+ push(new Block(<Statement>[
+ buildCompileTimeErrorStatement("Expected '{'.", token.charOffset)
+ ]));
}
}
@@ -2800,11 +2811,12 @@ class Identifier {
String toString() => "identifier($name)";
}
-// TODO(ahe): Shouldn't need to be an expression.
-class Operator extends InvalidExpression {
+class Operator {
final String name;
- Operator(this.name);
+ final int charOffset;
+
+ Operator(this.name, this.charOffset);
String toString() => "operator($name)";
}
@@ -2817,8 +2829,7 @@ class InitializedIdentifier extends Identifier {
String toString() => "initialized-identifier($name, $initializer)";
}
-// TODO(ahe): Shouldn't need to be an expression.
-class Label extends InvalidExpression {
+class Label {
String name;
Label(this.name);
« no previous file with comments | « pkg/compiler/lib/src/kernel/fasta_support.dart ('k') | pkg/front_end/lib/src/fasta/kernel/fasta_accessors.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698