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

Side by Side Diff: lib/unresolved.dart

Issue 2108193002: Change error handling. (Closed) Base URL: git@github.com:dart-lang/rasta.git@master
Patch Set: Created 4 years, 5 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE.md file. 3 // BSD-style license that can be found in the LICENSE.md file.
4 4
5 library rasta.unresolved; 5 library rasta.unresolved;
6 6
7 import 'package:kernel/ast.dart' as ir; 7 import 'package:kernel/ast.dart' as ir;
8 8
9 import "package:compiler/src/resolution/operators.dart" show 9 import "package:compiler/src/resolution/operators.dart" show
10 AssignmentOperator, 10 AssignmentOperator,
11 BinaryOperator, 11 BinaryOperator,
12 IncDecOperator, 12 IncDecOperator,
13 UnaryOperator; 13 UnaryOperator;
14 14
15 import "package:compiler/src/universe/call_structure.dart" show 15 import "package:compiler/src/universe/call_structure.dart" show
16 CallStructure; 16 CallStructure;
17 17
18 import "package:compiler/src/elements/elements.dart" show 18 import "package:compiler/src/elements/elements.dart" show
19 AstElement,
19 ConstructorElement, 20 ConstructorElement,
20 Element, 21 Element,
21 ErroneousElement, 22 ErroneousElement,
23 FunctionElement,
22 MethodElement; 24 MethodElement;
23 25
24 import "package:compiler/src/dart_types.dart" show 26 import "package:compiler/src/dart_types.dart" show
25 DartType, 27 DartType,
26 InterfaceType; 28 InterfaceType;
27 29
28 import "package:compiler/src/tree/tree.dart" show 30 import "package:compiler/src/tree/tree.dart" show
29 NewExpression, 31 NewExpression,
30 Node, 32 Node,
31 NodeList, 33 NodeList,
32 Send; 34 Send;
33 35
34 import "package:compiler/src/universe/selector.dart" show 36 import "package:compiler/src/universe/selector.dart" show
35 Selector; 37 Selector;
36 38
37 import "kernel.dart" show 39 import "kernel.dart" show
38 Kernel; 40 Kernel;
39 41
40 enum ErrorKind {
41 /// See [SemanticSendVisitor.visitUnresolvedClassConstructorInvoke].
42 ///
43 /// A "dynamic error occurs".
44 ///
45 /// Arguments are `(String message)`.
46 unresolvedClassConstructorInvoke,
47
48 unresolvedCompound,
49 unresolvedConstructorInvoke,
50 unresolvedGet,
51 unresolvedInvoke,
52 unresolvedPostfix,
53 unresolvedPrefix,
54 unresolvedRedirectingFactoryConstructorInvoke,
55 unresolvedSet,
56 unresolvedSetIfNull,
57 unresolvedStaticGetterCompound,
58 unresolvedStaticGetterPostfix,
59 unresolvedStaticGetterPrefix,
60 unresolvedStaticGetterSetIfNull,
61 unresolvedStaticSetterCompound,
62 unresolvedStaticSetterPostfix,
63 unresolvedStaticSetterPrefix,
64 unresolvedStaticSetterSetIfNull,
65 unresolvedSuperBinary,
66 unresolvedSuperCompound,
67 unresolvedSuperCompoundIndexSet,
68 unresolvedSuperGet,
69 unresolvedSuperGetterCompound,
70 unresolvedSuperGetterCompoundIndexSet,
71 unresolvedSuperGetterIndexPostfix,
72 unresolvedSuperGetterIndexPrefix,
73 unresolvedSuperGetterPostfix,
74 unresolvedSuperGetterPrefix,
75 unresolvedSuperGetterSetIfNull,
76 unresolvedSuperIndex,
77 unresolvedSuperIndexPostfix,
78 unresolvedSuperIndexPrefix,
79 unresolvedSuperIndexSet,
80 unresolvedSuperInvoke,
81 unresolvedSuperPostfix,
82 unresolvedSuperPrefix,
83 unresolvedSuperSetIfNull,
84 unresolvedSuperSetterCompound,
85 unresolvedSuperSetterCompoundIndexSet,
86 unresolvedSuperSetterIndexPostfix,
87 unresolvedSuperSetterIndexPrefix,
88 unresolvedSuperSetterPostfix,
89 unresolvedSuperSetterPrefix,
90 unresolvedSuperSetterSetIfNull,
91 unresolvedSuperUnary,
92 unresolvedTopLevelGetterCompound,
93 unresolvedTopLevelGetterPostfix,
94 unresolvedTopLevelGetterPrefix,
95 unresolvedTopLevelGetterSetIfNull,
96 unresolvedTopLevelSetterCompound,
97 unresolvedTopLevelSetterPostfix,
98 unresolvedTopLevelSetterPrefix,
99 unresolvedTopLevelSetterSetIfNull,
100 unresolvedSuperGetterIndexSetIfNull,
101 unresolvedSuperSetterIndexSetIfNull,
102 unresolvedSuperIndexSetIfNull,
103 unresolvedSuperSet,
104 }
105
106 ir.Arguments buildStringArgument(String argument) { 42 ir.Arguments buildStringArgument(String argument) {
107 return new ir.Arguments(<ir.Expression>[new ir.StringLiteral(argument)]); 43 return new ir.Arguments(<ir.Expression>[new ir.StringLiteral(argument)]);
108 } 44 }
109 45
110 ir.Arguments buildIntArgument(int argument) { 46 ir.Arguments buildIntArgument(int argument) {
111 return new ir.Arguments(<ir.Expression>[new ir.IntLiteral(argument)]); 47 return new ir.Arguments(<ir.Expression>[new ir.IntLiteral(argument)]);
112 } 48 }
113 49
114 class ErrorExpression extends ir.InvalidExpression {
115 final ErrorKind kind;
116 final ir.Arguments arguments;
117
118 ErrorExpression(this.kind, this.arguments);
119
120 ir.Expression toDynamicError(Kernel kernel) {
121 return new ir.MethodInvocation(
122 new ir.StaticInvocation(
123 kernel.getDynamicErrorHandler(), buildIntArgument(kind.index)),
124 new ir.Name("call"), arguments);
125 }
126 }
127
128 abstract class RastaUnresolved { 50 abstract class RastaUnresolved {
129 Kernel get kernel; 51 Kernel get kernel;
130 52
53 // Implemented in KernelVisitor
54 AstElement get currentElement;
55 ir.Arguments buildArguments(NodeList arguments);
56
131 // TODO(ahe): Delete this method. 57 // TODO(ahe): Delete this method.
132 ir.InvalidExpression handleUnresolved(Node node); 58 ir.InvalidExpression handleUnresolved(Node node);
133 59
60
ahe 2016/06/29 15:53:56 Extra line.
asgerf 2016/06/30 08:47:33 Done.
61 /// Throws a [NoSuchMethodError] corresponding to a call to
62 /// [receiver].[memberName] with the arguments [callArguments].
63 ///
64 /// The exception object is built by calling [exceptionBuilder]. This should
65 /// take the same arguments as the default constructor to [NoSuchMethodError],
66 /// but the method itself may encode additional details about the call than
67 /// is possible through the public interface of NoSuchMethodError.
68 ///
69 /// Note that [callArguments] are the arguments as they occur in the attempted
70 /// call in user code -- they are not the arguments to [exceptionBuilder].
71 ///
72 /// If [candidateTarget] is given, it will provide the expected parameter
73 /// names.
74 ir.Expression buildThrowNoSuchMethodError(ir.Procedure exceptionBuilder,
ahe 2016/06/29 15:53:56 For consistency, please have one formal parameter
asgerf 2016/06/30 08:47:33 Done, though I really think we should just stick t
75 ir.Expression receiver, String memberName, ir.Arguments callArguments,
76 [Element candidateTarget]) {
77 ir.Expression memberNameArg = new ir.SymbolLiteral(memberName);
78 ir.Expression positional = new ir.ListLiteral(callArguments.positional);
79 ir.Expression named = new ir.MapLiteral(callArguments.named.map((e) {
80 return new ir.MapEntry(new ir.SymbolLiteral(e.name), e.value);
81 }).toList());
82 ir.Expression existingArguments;
83 if (candidateTarget is FunctionElement && !candidateTarget.isError) {
84 List<ir.Expression> existingArgumentsList = <ir.Expression>[];
85 candidateTarget.functionSignature.forEachParameter((param) {
86 existingArgumentsList.add(new ir.StringLiteral(param.name));
87 });
88 existingArguments = new ir.ListLiteral(existingArgumentsList);
89 } else {
90 existingArguments = new ir.NullLiteral();
91 }
92 return new ir.Throw(new ir.StaticInvocation(
93 exceptionBuilder,
94 new ir.Arguments(<ir.Expression>[
95 receiver,
96 memberNameArg,
97 positional,
98 named,
99 existingArguments
100 ])));
101 }
102
103 ir.Expression buildThrowSingleArgumentError(
104 ir.Procedure exceptionBuilder, String errorMessage) {
105 return new ir.Throw(new ir.StaticInvocation(exceptionBuilder,
106 new ir.Arguments(<ir.Expression>[new ir.StringLiteral(errorMessage)])));
107 }
108
134 ir.Expression visitUnresolvedClassConstructorInvoke( 109 ir.Expression visitUnresolvedClassConstructorInvoke(
135 NewExpression node, 110 NewExpression node,
136 ErroneousElement element, 111 ErroneousElement element,
137 DartType type, 112 DartType type,
138 NodeList arguments, 113 NodeList arguments,
139 Selector selector, 114 Selector selector,
140 _) { 115 _) {
141 return new ErrorExpression( 116 // TODO(asgerf): The VM includes source information as part of the error
142 ErrorKind.unresolvedClassConstructorInvoke, 117 // message. We could do the same when we add source maps.
143 buildStringArgument(element.message)).toDynamicError(kernel); 118 return buildThrowSingleArgumentError(kernel.getMalformedTypeErrorBuilder(),
119 element.message);
120 }
121
122 ir.Expression visitUnresolvedConstructorInvoke(
123 NewExpression node,
124 Element constructor,
125 DartType type,
126 NodeList arguments,
127 Selector selector,
128 _) {
129 ir.Expression receiver = new ir.TypeLiteral(kernel.interfaceTypeToIr(type));
130 String methodName = node.send.selector != null
131 ? '${node.send.selector}'
132 : type.name;
133 return buildThrowNoSuchMethodError(
134 kernel.getUnresolvedConstructorBuilder(),
135 receiver,
136 methodName,
137 buildArguments(arguments),
138 constructor);
144 } 139 }
145 140
146 ir.InvalidExpression visitUnresolvedCompound( 141 ir.InvalidExpression visitUnresolvedCompound(
147 Send node, 142 Send node,
148 Element element, 143 Element element,
149 AssignmentOperator operator, 144 AssignmentOperator operator,
150 Node rhs, 145 Node rhs,
151 _) { 146 _) {
152 return handleUnresolved(node); 147 return handleUnresolved(node);
153 } 148 }
154 149
155 ir.InvalidExpression visitUnresolvedConstructorInvoke(
156 NewExpression node,
157 Element constructor,
158 DartType type,
159 NodeList arguments,
160 Selector selector,
161 _) {
162 return handleUnresolved(node);
163 }
164
165 ir.InvalidExpression visitUnresolvedGet( 150 ir.InvalidExpression visitUnresolvedGet(
166 Send node, 151 Send node,
167 Element element, 152 Element element,
168 _) { 153 _) {
169 return handleUnresolved(node); 154 return handleUnresolved(node);
170 } 155 }
171 156
172 ir.InvalidExpression visitUnresolvedInvoke( 157 ir.InvalidExpression visitUnresolvedInvoke(
173 Send node, 158 Send node,
174 Element element, 159 Element element,
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 } 630 }
646 631
647 ir.InvalidExpression visitUnresolvedSuperSet( 632 ir.InvalidExpression visitUnresolvedSuperSet(
648 Send node, 633 Send node,
649 Element element, 634 Element element,
650 Node rhs, 635 Node rhs,
651 _) { 636 _) {
652 return handleUnresolved(node); 637 return handleUnresolved(node);
653 } 638 }
654 } 639 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698