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

Unified Diff: lib/unresolved.dart

Issue 2108193002: Change error handling. (Closed) Base URL: git@github.com:dart-lang/rasta.git@master
Patch Set: Address comments Created 4 years, 6 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
« no previous file with comments | « lib/kernel.dart ('k') | test/kernel/regression/type_with_parse_error.dart.txt » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/unresolved.dart
diff --git a/lib/unresolved.dart b/lib/unresolved.dart
index d358ca3a80d692694fb68428d97c715adb9a6eae..8abc85e88ea6b1c0a6311e0ed682e46fa83d65cb 100644
--- a/lib/unresolved.dart
+++ b/lib/unresolved.dart
@@ -16,9 +16,11 @@ import "package:compiler/src/universe/call_structure.dart" show
CallStructure;
import "package:compiler/src/elements/elements.dart" show
+ AstElement,
ConstructorElement,
Element,
ErroneousElement,
+ FunctionElement,
MethodElement;
import "package:compiler/src/dart_types.dart" show
@@ -37,72 +39,6 @@ import "package:compiler/src/universe/selector.dart" show
import "kernel.dart" show
Kernel;
-enum ErrorKind {
- /// See [SemanticSendVisitor.visitUnresolvedClassConstructorInvoke].
- ///
- /// A "dynamic error occurs".
- ///
- /// Arguments are `(String message)`.
- unresolvedClassConstructorInvoke,
-
- unresolvedCompound,
- unresolvedConstructorInvoke,
- unresolvedGet,
- unresolvedInvoke,
- unresolvedPostfix,
- unresolvedPrefix,
- unresolvedRedirectingFactoryConstructorInvoke,
- unresolvedSet,
- unresolvedSetIfNull,
- unresolvedStaticGetterCompound,
- unresolvedStaticGetterPostfix,
- unresolvedStaticGetterPrefix,
- unresolvedStaticGetterSetIfNull,
- unresolvedStaticSetterCompound,
- unresolvedStaticSetterPostfix,
- unresolvedStaticSetterPrefix,
- unresolvedStaticSetterSetIfNull,
- unresolvedSuperBinary,
- unresolvedSuperCompound,
- unresolvedSuperCompoundIndexSet,
- unresolvedSuperGet,
- unresolvedSuperGetterCompound,
- unresolvedSuperGetterCompoundIndexSet,
- unresolvedSuperGetterIndexPostfix,
- unresolvedSuperGetterIndexPrefix,
- unresolvedSuperGetterPostfix,
- unresolvedSuperGetterPrefix,
- unresolvedSuperGetterSetIfNull,
- unresolvedSuperIndex,
- unresolvedSuperIndexPostfix,
- unresolvedSuperIndexPrefix,
- unresolvedSuperIndexSet,
- unresolvedSuperInvoke,
- unresolvedSuperPostfix,
- unresolvedSuperPrefix,
- unresolvedSuperSetIfNull,
- unresolvedSuperSetterCompound,
- unresolvedSuperSetterCompoundIndexSet,
- unresolvedSuperSetterIndexPostfix,
- unresolvedSuperSetterIndexPrefix,
- unresolvedSuperSetterPostfix,
- unresolvedSuperSetterPrefix,
- unresolvedSuperSetterSetIfNull,
- unresolvedSuperUnary,
- unresolvedTopLevelGetterCompound,
- unresolvedTopLevelGetterPostfix,
- unresolvedTopLevelGetterPrefix,
- unresolvedTopLevelGetterSetIfNull,
- unresolvedTopLevelSetterCompound,
- unresolvedTopLevelSetterPostfix,
- unresolvedTopLevelSetterPrefix,
- unresolvedTopLevelSetterSetIfNull,
- unresolvedSuperGetterIndexSetIfNull,
- unresolvedSuperSetterIndexSetIfNull,
- unresolvedSuperIndexSetIfNull,
- unresolvedSuperSet,
-}
-
ir.Arguments buildStringArgument(String argument) {
return new ir.Arguments(<ir.Expression>[new ir.StringLiteral(argument)]);
}
@@ -111,26 +47,67 @@ ir.Arguments buildIntArgument(int argument) {
return new ir.Arguments(<ir.Expression>[new ir.IntLiteral(argument)]);
}
-class ErrorExpression extends ir.InvalidExpression {
- final ErrorKind kind;
- final ir.Arguments arguments;
-
- ErrorExpression(this.kind, this.arguments);
-
- ir.Expression toDynamicError(Kernel kernel) {
- return new ir.MethodInvocation(
- new ir.StaticInvocation(
- kernel.getDynamicErrorHandler(), buildIntArgument(kind.index)),
- new ir.Name("call"), arguments);
- }
-}
-
abstract class RastaUnresolved {
Kernel get kernel;
+ // Implemented in KernelVisitor
+ AstElement get currentElement;
+ ir.Arguments buildArguments(NodeList arguments);
+
// TODO(ahe): Delete this method.
ir.InvalidExpression handleUnresolved(Node node);
+ /// Throws a [NoSuchMethodError] corresponding to a call to
+ /// [receiver].[memberName] with the arguments [callArguments].
+ ///
+ /// The exception object is built by calling [exceptionBuilder]. This should
+ /// take the same arguments as the default constructor to [NoSuchMethodError],
+ /// but the method itself may encode additional details about the call than
+ /// is possible through the public interface of NoSuchMethodError.
+ ///
+ /// Note that [callArguments] are the arguments as they occur in the attempted
+ /// call in user code -- they are not the arguments to [exceptionBuilder].
+ ///
+ /// If [candidateTarget] is given, it will provide the expected parameter
+ /// names.
+ ir.Expression buildThrowNoSuchMethodError(
+ ir.Procedure exceptionBuilder,
+ ir.Expression receiver,
+ String memberName,
+ ir.Arguments callArguments,
+ [Element candidateTarget]) {
+ ir.Expression memberNameArg = new ir.SymbolLiteral(memberName);
+ ir.Expression positional = new ir.ListLiteral(callArguments.positional);
+ ir.Expression named = new ir.MapLiteral(callArguments.named.map((e) {
+ return new ir.MapEntry(new ir.SymbolLiteral(e.name), e.value);
+ }).toList());
+ ir.Expression existingArguments;
+ if (candidateTarget is FunctionElement && !candidateTarget.isError) {
+ List<ir.Expression> existingArgumentsList = <ir.Expression>[];
+ candidateTarget.functionSignature.forEachParameter((param) {
+ existingArgumentsList.add(new ir.StringLiteral(param.name));
+ });
+ existingArguments = new ir.ListLiteral(existingArgumentsList);
+ } else {
+ existingArguments = new ir.NullLiteral();
+ }
+ return new ir.Throw(new ir.StaticInvocation(
+ exceptionBuilder,
+ new ir.Arguments(<ir.Expression>[
+ receiver,
+ memberNameArg,
+ positional,
+ named,
+ existingArguments
+ ])));
+ }
+
+ ir.Expression buildThrowSingleArgumentError(
+ ir.Procedure exceptionBuilder, String errorMessage) {
+ return new ir.Throw(new ir.StaticInvocation(exceptionBuilder,
+ new ir.Arguments(<ir.Expression>[new ir.StringLiteral(errorMessage)])));
+ }
+
ir.Expression visitUnresolvedClassConstructorInvoke(
NewExpression node,
ErroneousElement element,
@@ -138,27 +115,37 @@ abstract class RastaUnresolved {
NodeList arguments,
Selector selector,
_) {
- return new ErrorExpression(
- ErrorKind.unresolvedClassConstructorInvoke,
- buildStringArgument(element.message)).toDynamicError(kernel);
- }
-
- ir.InvalidExpression visitUnresolvedCompound(
- Send node,
- Element element,
- AssignmentOperator operator,
- Node rhs,
- _) {
- return handleUnresolved(node);
+ // TODO(asgerf): The VM includes source information as part of the error
+ // message. We could do the same when we add source maps.
+ return buildThrowSingleArgumentError(kernel.getMalformedTypeErrorBuilder(),
+ element.message);
}
- ir.InvalidExpression visitUnresolvedConstructorInvoke(
+ ir.Expression visitUnresolvedConstructorInvoke(
NewExpression node,
Element constructor,
DartType type,
NodeList arguments,
Selector selector,
_) {
+ ir.Expression receiver = new ir.TypeLiteral(kernel.interfaceTypeToIr(type));
+ String methodName = node.send.selector != null
+ ? '${node.send.selector}'
+ : type.name;
+ return buildThrowNoSuchMethodError(
+ kernel.getUnresolvedConstructorBuilder(),
+ receiver,
+ methodName,
+ buildArguments(arguments),
+ constructor);
+ }
+
+ ir.InvalidExpression visitUnresolvedCompound(
+ Send node,
+ Element element,
+ AssignmentOperator operator,
+ Node rhs,
+ _) {
return handleUnresolved(node);
}
« no previous file with comments | « lib/kernel.dart ('k') | test/kernel/regression/type_with_parse_error.dart.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698