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

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: Address comments 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
« no previous file with comments | « lib/kernel.dart ('k') | test/kernel/regression/type_with_parse_error.dart.txt » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 /// Throws a [NoSuchMethodError] corresponding to a call to
61 /// [receiver].[memberName] with the arguments [callArguments].
62 ///
63 /// The exception object is built by calling [exceptionBuilder]. This should
64 /// take the same arguments as the default constructor to [NoSuchMethodError],
65 /// but the method itself may encode additional details about the call than
66 /// is possible through the public interface of NoSuchMethodError.
67 ///
68 /// Note that [callArguments] are the arguments as they occur in the attempted
69 /// call in user code -- they are not the arguments to [exceptionBuilder].
70 ///
71 /// If [candidateTarget] is given, it will provide the expected parameter
72 /// names.
73 ir.Expression buildThrowNoSuchMethodError(
74 ir.Procedure exceptionBuilder,
75 ir.Expression receiver,
76 String memberName,
77 ir.Arguments callArguments,
78 [Element candidateTarget]) {
79 ir.Expression memberNameArg = new ir.SymbolLiteral(memberName);
80 ir.Expression positional = new ir.ListLiteral(callArguments.positional);
81 ir.Expression named = new ir.MapLiteral(callArguments.named.map((e) {
82 return new ir.MapEntry(new ir.SymbolLiteral(e.name), e.value);
83 }).toList());
84 ir.Expression existingArguments;
85 if (candidateTarget is FunctionElement && !candidateTarget.isError) {
86 List<ir.Expression> existingArgumentsList = <ir.Expression>[];
87 candidateTarget.functionSignature.forEachParameter((param) {
88 existingArgumentsList.add(new ir.StringLiteral(param.name));
89 });
90 existingArguments = new ir.ListLiteral(existingArgumentsList);
91 } else {
92 existingArguments = new ir.NullLiteral();
93 }
94 return new ir.Throw(new ir.StaticInvocation(
95 exceptionBuilder,
96 new ir.Arguments(<ir.Expression>[
97 receiver,
98 memberNameArg,
99 positional,
100 named,
101 existingArguments
102 ])));
103 }
104
105 ir.Expression buildThrowSingleArgumentError(
106 ir.Procedure exceptionBuilder, String errorMessage) {
107 return new ir.Throw(new ir.StaticInvocation(exceptionBuilder,
108 new ir.Arguments(<ir.Expression>[new ir.StringLiteral(errorMessage)])));
109 }
110
134 ir.Expression visitUnresolvedClassConstructorInvoke( 111 ir.Expression visitUnresolvedClassConstructorInvoke(
135 NewExpression node, 112 NewExpression node,
136 ErroneousElement element, 113 ErroneousElement element,
137 DartType type, 114 DartType type,
138 NodeList arguments, 115 NodeList arguments,
139 Selector selector, 116 Selector selector,
140 _) { 117 _) {
141 return new ErrorExpression( 118 // TODO(asgerf): The VM includes source information as part of the error
142 ErrorKind.unresolvedClassConstructorInvoke, 119 // message. We could do the same when we add source maps.
143 buildStringArgument(element.message)).toDynamicError(kernel); 120 return buildThrowSingleArgumentError(kernel.getMalformedTypeErrorBuilder(),
121 element.message);
122 }
123
124 ir.Expression visitUnresolvedConstructorInvoke(
125 NewExpression node,
126 Element constructor,
127 DartType type,
128 NodeList arguments,
129 Selector selector,
130 _) {
131 ir.Expression receiver = new ir.TypeLiteral(kernel.interfaceTypeToIr(type));
132 String methodName = node.send.selector != null
133 ? '${node.send.selector}'
134 : type.name;
135 return buildThrowNoSuchMethodError(
136 kernel.getUnresolvedConstructorBuilder(),
137 receiver,
138 methodName,
139 buildArguments(arguments),
140 constructor);
144 } 141 }
145 142
146 ir.InvalidExpression visitUnresolvedCompound( 143 ir.InvalidExpression visitUnresolvedCompound(
147 Send node, 144 Send node,
148 Element element, 145 Element element,
149 AssignmentOperator operator, 146 AssignmentOperator operator,
150 Node rhs, 147 Node rhs,
151 _) { 148 _) {
152 return handleUnresolved(node); 149 return handleUnresolved(node);
153 } 150 }
154 151
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( 152 ir.InvalidExpression visitUnresolvedGet(
166 Send node, 153 Send node,
167 Element element, 154 Element element,
168 _) { 155 _) {
169 return handleUnresolved(node); 156 return handleUnresolved(node);
170 } 157 }
171 158
172 ir.InvalidExpression visitUnresolvedInvoke( 159 ir.InvalidExpression visitUnresolvedInvoke(
173 Send node, 160 Send node,
174 Element element, 161 Element element,
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 } 632 }
646 633
647 ir.InvalidExpression visitUnresolvedSuperSet( 634 ir.InvalidExpression visitUnresolvedSuperSet(
648 Send node, 635 Send node,
649 Element element, 636 Element element,
650 Node rhs, 637 Node rhs,
651 _) { 638 _) {
652 return handleUnresolved(node); 639 return handleUnresolved(node);
653 } 640 }
654 } 641 }
OLDNEW
« 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