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

Side by Side Diff: pkg/compiler/lib/src/resolution/semantic_visitor_mixins.dart

Issue 1043723002: Handle NewExpression in SemanticSendVisitor. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rebased+fix modely.dart Created 5 years, 8 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part of dart2js.semantics_visitor; 5 part of dart2js.semantics_visitor;
6 6
7 /// Mixin that implements all `errorX` methods of [SemanticSendVisitor] by 7 /// Mixin that implements all `errorX` methods of [SemanticSendVisitor] by
8 /// delegating to a bulk handler. 8 /// delegating to a bulk handler.
9 /// 9 ///
10 /// Use this mixin to provide a trivial implementation for all `errorX` methods. 10 /// Use this mixin to provide a trivial implementation for all `errorX` methods.
11 abstract class ErrorBulkMixin<R, A> implements SemanticSendVisitor<R, A> { 11 abstract class ErrorBulkMixin<R, A> implements SemanticSendVisitor<R, A> {
12 R bulkHandleNode(Node node, String message, A arg); 12 R bulkHandleNode(Node node, String message, A arg);
13 13
14 R bulkHandleError(Send node, A arg) { 14 R bulkHandleError(Node node, A arg) {
15 return bulkHandleNode(node, "Error expression `$node` unhandled.", arg); 15 return bulkHandleNode(node, "Error expression `$node` unhandled.", arg);
16 } 16 }
17 17
18 @override 18 @override
19 R errorInvalidAssert( 19 R errorInvalidAssert(
20 Send node, 20 Send node,
21 NodeList arguments, 21 NodeList arguments,
22 A arg) { 22 A arg) {
23 return bulkHandleError(node, arg); 23 return bulkHandleError(node, arg);
24 } 24 }
25 25
26 @override 26 @override
27 R errorAbstractClassConstructorInvoke(
28 NewExpression node,
29 ConstructorElement element,
30 InterfaceType type,
31 NodeList arguments,
32 Selector selector,
33 A arg) {
34 return bulkHandleError(node, arg);
35 }
36
37 @override
27 R errorClassTypeLiteralCompound( 38 R errorClassTypeLiteralCompound(
28 Send node, 39 Send node,
29 ConstantExpression constant, 40 ConstantExpression constant,
30 AssignmentOperator operator, 41 AssignmentOperator operator,
31 Node rhs, 42 Node rhs,
32 A arg) { 43 A arg) {
33 return bulkHandleError(node, arg); 44 return bulkHandleError(node, arg);
34 } 45 }
35 46
36 @override 47 @override
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 R errorUnresolvedCompound( 427 R errorUnresolvedCompound(
417 Send node, 428 Send node,
418 Element element, 429 Element element,
419 AssignmentOperator operator, 430 AssignmentOperator operator,
420 Node rhs, 431 Node rhs,
421 A arg) { 432 A arg) {
422 return bulkHandleError(node, arg); 433 return bulkHandleError(node, arg);
423 } 434 }
424 435
425 @override 436 @override
437 R errorUnresolvedClassConstructorInvoke(
438 NewExpression node,
439 Element element,
440 MalformedType type,
441 NodeList arguments,
442 Selector selector,
443 A arg) {
444 return bulkHandleError(node, arg);
445 }
446
447 @override
448 R errorUnresolvedConstructorInvoke(
449 NewExpression node,
450 Element constructor,
451 DartType type,
452 NodeList arguments,
453 Selector selector,
454 A arg) {
455 return bulkHandleError(node, arg);
456 }
457
458 @override
426 R errorUnresolvedGet( 459 R errorUnresolvedGet(
427 Send node, 460 Send node,
428 Element element, 461 Element element,
429 A arg) { 462 A arg) {
430 return bulkHandleError(node, arg); 463 return bulkHandleError(node, arg);
431 } 464 }
432 465
433 @override 466 @override
434 R errorUnresolvedInvoke( 467 R errorUnresolvedInvoke(
435 Send node, 468 Send node,
(...skipping 16 matching lines...) Expand all
452 @override 485 @override
453 R errorUnresolvedPrefix( 486 R errorUnresolvedPrefix(
454 Send node, 487 Send node,
455 Element element, 488 Element element,
456 IncDecOperator operator, 489 IncDecOperator operator,
457 A arg) { 490 A arg) {
458 return bulkHandleError(node, arg); 491 return bulkHandleError(node, arg);
459 } 492 }
460 493
461 @override 494 @override
495 R errorUnresolvedRedirectingFactoryConstructorInvoke(
496 NewExpression node,
497 ConstructorElement constructor,
498 InterfaceType type,
499 NodeList arguments,
500 Selector selector,
501 A arg) {
502 return bulkHandleError(node, arg);
503 }
504
505 @override
462 R errorUnresolvedSet( 506 R errorUnresolvedSet(
463 Send node, 507 Send node,
464 Element element, 508 Element element,
465 Node rhs, 509 Node rhs,
466 A arg) { 510 A arg) {
467 return bulkHandleError(node, arg); 511 return bulkHandleError(node, arg);
468 } 512 }
469 513
470 @override 514 @override
471 R errorUnresolvedSuperCompoundIndexSet( 515 R errorUnresolvedSuperCompoundIndexSet(
(...skipping 1684 matching lines...) Expand 10 before | Expand all | Expand 10 after
2156 @override 2200 @override
2157 R visitSuperUnary( 2201 R visitSuperUnary(
2158 Send node, 2202 Send node,
2159 UnaryOperator operator, 2203 UnaryOperator operator,
2160 FunctionElement function, 2204 FunctionElement function,
2161 A arg) { 2205 A arg) {
2162 return bulkHandleSuper(node, arg); 2206 return bulkHandleSuper(node, arg);
2163 } 2207 }
2164 } 2208 }
2165 2209
2210 abstract class NewBulkMixin<R, A> implements SemanticSendVisitor<R, A> {
2211 R bulkHandleNode(Node node, String message, A arg);
2212
2213 R bulkHandleNew(NewExpression node, A arg) {
2214 return bulkHandleNode(
2215 node, "Constructor invocation `$node` unhandled.", arg);
2216 }
2217
2218 @override
2219 R visitConstConstructorInvoke(
2220 NewExpression node,
2221 ConstructedConstantExpression constant,
2222 A arg) {
2223 return bulkHandleNew(node, arg);
2224 }
2225
2226 R visitGenerativeConstructorInvoke(
2227 NewExpression node,
2228 ConstructorElement constructor,
2229 InterfaceType type,
2230 NodeList arguments,
2231 Selector selector,
2232 A arg) {
2233 return bulkHandleNew(node, arg);
2234 }
2235
2236 R visitRedirectingGenerativeConstructorInvoke(
2237 NewExpression node,
2238 ConstructorElement constructor,
2239 InterfaceType type,
2240 NodeList arguments,
2241 Selector selector,
2242 A arg) {
2243 return bulkHandleNew(node, arg);
2244 }
2245
2246 R visitFactoryConstructorInvoke(
2247 NewExpression node,
2248 ConstructorElement constructor,
2249 InterfaceType type,
2250 NodeList arguments,
2251 Selector selector,
2252 A arg) {
2253 return bulkHandleNew(node, arg);
2254 }
2255
2256 R visitRedirectingFactoryConstructorInvoke(
2257 NewExpression node,
2258 ConstructorElement constructor,
2259 InterfaceType type,
2260 ConstructorElement effectiveTarget,
2261 InterfaceType effectiveTargetType,
2262 NodeList arguments,
2263 Selector selector,
2264 A arg) {
2265 return bulkHandleNew(node, arg);
2266 }
2267 }
2268
2166 /// Visitor that implements [SemanticSendVisitor] by the use of `BulkX` mixins. 2269 /// Visitor that implements [SemanticSendVisitor] by the use of `BulkX` mixins.
2167 /// 2270 ///
2168 /// This class is useful in itself, but shows how to use the `BulkX` mixins and 2271 /// This class is useful in itself, but shows how to use the `BulkX` mixins and
2169 /// tests that the union of the `BulkX` mixins implement all `visit` and `error` 2272 /// tests that the union of the `BulkX` mixins implement all `visit` and `error`
2170 /// methods of [SemanticSendVisitor]. 2273 /// methods of [SemanticSendVisitor].
2171 class BulkVisitor<R, A> extends SemanticSendVisitor<R, A> 2274 class BulkVisitor<R, A> extends SemanticSendVisitor<R, A>
2172 with GetBulkMixin<R, A>, 2275 with GetBulkMixin<R, A>,
2173 SetBulkMixin<R, A>, 2276 SetBulkMixin<R, A>,
2174 ErrorBulkMixin<R, A>, 2277 ErrorBulkMixin<R, A>,
2175 InvokeBulkMixin<R, A>, 2278 InvokeBulkMixin<R, A>,
2176 IndexSetBulkMixin<R, A>, 2279 IndexSetBulkMixin<R, A>,
2177 CompoundBulkMixin<R, A>, 2280 CompoundBulkMixin<R, A>,
2178 UnaryBulkMixin<R, A>, 2281 UnaryBulkMixin<R, A>,
2179 BaseBulkMixin<R, A>, 2282 BaseBulkMixin<R, A>,
2180 BinaryBulkMixin<R, A>, 2283 BinaryBulkMixin<R, A>,
2181 PrefixBulkMixin<R, A>, 2284 PrefixBulkMixin<R, A>,
2182 PostfixBulkMixin<R, A> { 2285 PostfixBulkMixin<R, A>,
2286 NewBulkMixin<R, A> {
2183 @override 2287 @override
2184 R apply(Node node, A arg) { 2288 R apply(Node node, A arg) {
2185 throw new UnimplementedError("BulkVisitor.apply unimplemented"); 2289 throw new UnimplementedError("BulkVisitor.apply unimplemented");
2186 } 2290 }
2187 2291
2188 @override 2292 @override
2189 R bulkHandleNode(Node node, String message, A arg) { 2293 R bulkHandleNode(Node node, String message, A arg) {
2190 throw new UnimplementedError("BulkVisitor.bulkHandleNode unimplemented"); 2294 throw new UnimplementedError("BulkVisitor.bulkHandleNode unimplemented");
2191 } 2295 }
2192 } 2296 }
(...skipping 1837 matching lines...) Expand 10 before | Expand all | Expand 10 after
4030 R visitSuperIndexPrefix( 4134 R visitSuperIndexPrefix(
4031 Send node, 4135 Send node,
4032 FunctionElement indexFunction, 4136 FunctionElement indexFunction,
4033 FunctionElement indexSetFunction, 4137 FunctionElement indexSetFunction,
4034 Node index, 4138 Node index,
4035 IncDecOperator operator, 4139 IncDecOperator operator,
4036 A arg) { 4140 A arg) {
4037 apply(index, arg); 4141 apply(index, arg);
4038 return null; 4142 return null;
4039 } 4143 }
4144
4145 @override
4146 R visitConstConstructorInvoke(
4147 NewExpression node,
4148 ConstructedConstantExpression constant,
4149 A arg) {
4150 return null;
4151 }
4152
4153 @override
4154 R errorUnresolvedClassConstructorInvoke(
4155 NewExpression node,
4156 Element constructor,
4157 MalformedType type,
4158 NodeList arguments,
4159 Selector selector,
4160 A arg) {
4161 apply(arguments, arg);
4162 return null;
4163 }
4164
4165 @override
4166 R errorUnresolvedConstructorInvoke(
4167 NewExpression node,
4168 Element constructor,
4169 DartType type,
4170 NodeList arguments,
4171 Selector selector,
4172 A arg) {
4173 apply(arguments, arg);
4174 return null;
4175 }
4176 R visitFactoryConstructorInvoke(
4177 NewExpression node,
4178 ConstructorElement constructor,
4179 InterfaceType type,
4180 NodeList arguments,
4181 Selector selector,
4182 A arg) {
4183 apply(arguments, arg);
4184 return null;
4185 }
4186
4187 @override
4188 R visitGenerativeConstructorInvoke(
4189 NewExpression node,
4190 ConstructorElement constructor,
4191 InterfaceType type,
4192 NodeList arguments,
4193 Selector selector,
4194 A arg) {
4195 apply(arguments, arg);
4196 return null;
4197 }
4198
4199 @override
4200 R visitRedirectingFactoryConstructorInvoke(
4201 NewExpression node,
4202 ConstructorElement constructor,
4203 InterfaceType type,
4204 ConstructorElement effectiveTarget,
4205 InterfaceType effectiveTargetType,
4206 NodeList arguments,
4207 Selector selector,
4208 A arg) {
4209 apply(arguments, arg);
4210 return null;
4211 }
4212
4213 @override
4214 R visitRedirectingGenerativeConstructorInvoke(
4215 NewExpression node,
4216 ConstructorElement constructor,
4217 InterfaceType type,
4218 NodeList arguments,
4219 Selector selector,
4220 A arg) {
4221 apply(arguments, arg);
4222 return null;
4223 }
4224
4225 @override
4226 R errorAbstractClassConstructorInvoke(
4227 NewExpression node,
4228 ConstructorElement element,
4229 InterfaceType type,
4230 NodeList arguments,
4231 Selector selector,
4232 A arg) {
4233 apply(arguments, arg);
4234 return null;
4235 }
4236
4237 @override
4238 R errorUnresolvedRedirectingFactoryConstructorInvoke(
4239 NewExpression node,
4240 ConstructorElement constructor,
4241 InterfaceType type,
4242 NodeList arguments,
4243 Selector selector,
4244 A arg) {
4245 apply(arguments, arg);
4246 return null;
4247 }
4040 } 4248 }
4041 4249
4042 /// AST visitor that visits all normal [Send] and [SendSet] nodes using the 4250 /// AST visitor that visits all normal [Send] and [SendSet] nodes using the
4043 /// [SemanticVisitor]. 4251 /// [SemanticVisitor].
4044 class TraversalVisitor<R, A> extends SemanticVisitor<R, A> 4252 class TraversalVisitor<R, A> extends SemanticVisitor<R, A>
4045 with TraversalMixin<R, A> { 4253 with TraversalMixin<R, A> {
4046 TraversalVisitor(TreeElements elements) : super(elements); 4254 TraversalVisitor(TreeElements elements) : super(elements);
4047 4255
4048 SemanticSendVisitor<R, A> get sendVisitor => this; 4256 SemanticSendVisitor<R, A> get sendVisitor => this;
4049 4257
4050 R apply(Node node, A arg) { 4258 R apply(Node node, A arg) {
4051 node.accept(this); 4259 node.accept(this);
4052 return null; 4260 return null;
4053 } 4261 }
4054 4262
4055 @override 4263 @override
4056 internalError(Spannable spannable, String message) { 4264 internalError(Spannable spannable, String message) {
4057 throw new SpannableAssertionFailure(spannable, message); 4265 throw new SpannableAssertionFailure(spannable, message);
4058 } 4266 }
4059 4267
4060 @override 4268 @override
4061 R visitNode(Node node) { 4269 R visitNode(Node node) {
4062 node.visitChildren(this); 4270 node.visitChildren(this);
4063 return null; 4271 return null;
4064 } 4272 }
4065 4273
4066 @override
4067 R visitNewExpression(NewExpression node) {
4068 // Bypass the [Send] holding the class/constructor name.
4069 return apply(node.send.argumentsNode, null);
4070 }
4071
4072 void visitParameters(NodeList parameters) { 4274 void visitParameters(NodeList parameters) {
4073 4275
4074 } 4276 }
4075 4277
4076 void visitInitializers(NodeList initializers) { 4278 void visitInitializers(NodeList initializers) {
4077 // TODO(johnniwinther): Visit subnodes of initializers. 4279 // TODO(johnniwinther): Visit subnodes of initializers.
4078 } 4280 }
4079 4281
4080 @override 4282 @override
4081 R visitFunctionExpression(FunctionExpression node) { 4283 R visitFunctionExpression(FunctionExpression node) {
(...skipping 625 matching lines...) Expand 10 before | Expand all | Expand 10 after
4707 } 4909 }
4708 4910
4709 /// Mixin that groups all `visitConstantX` and `visitXTypeLiteralY` methods for 4911 /// Mixin that groups all `visitConstantX` and `visitXTypeLiteralY` methods for
4710 /// constant type literals by delegating calls to `handleConstantX` methods. 4912 /// constant type literals by delegating calls to `handleConstantX` methods.
4711 /// 4913 ///
4712 /// This mixin is useful for the cases where expressions on constants are 4914 /// This mixin is useful for the cases where expressions on constants are
4713 /// handled uniformly. 4915 /// handled uniformly.
4714 abstract class BaseImplementationOfConstantsMixin<R, A> 4916 abstract class BaseImplementationOfConstantsMixin<R, A>
4715 implements SemanticSendVisitor<R, A> { 4917 implements SemanticSendVisitor<R, A> {
4716 R handleConstantGet( 4918 R handleConstantGet(
4717 Send node, 4919 Node node,
4718 ConstantExpression constant, 4920 ConstantExpression constant,
4719 A arg); 4921 A arg);
4720 4922
4721 R handleConstantInvoke( 4923 R handleConstantInvoke(
4722 Send node, 4924 Send node,
4723 ConstantExpression constant, 4925 ConstantExpression constant,
4724 NodeList arguments, 4926 NodeList arguments,
4725 Selector selector, 4927 Selector selector,
4726 A arg); 4928 A arg);
4727 4929
4728 @override 4930 @override
4729 R visitClassTypeLiteralGet( 4931 R visitClassTypeLiteralGet(
4730 Send node, 4932 Send node,
4731 ConstantExpression constant, 4933 ConstantExpression constant,
4732 A arg) { 4934 A arg) {
4733 return handleConstantGet(node, constant, arg); 4935 return handleConstantGet(node, constant, arg);
4734 } 4936 }
4735 4937
4736 @override 4938 @override
4737 R visitClassTypeLiteralInvoke( 4939 R visitClassTypeLiteralInvoke(
4738 Send node, 4940 Send node,
4739 ConstantExpression constant, 4941 ConstantExpression constant,
4740 NodeList arguments, 4942 NodeList arguments,
4741 Selector selector, 4943 Selector selector,
4742 A arg) { 4944 A arg) {
4743 return handleConstantInvoke(node, constant, arguments, selector, arg); 4945 return handleConstantInvoke(node, constant, arguments, selector, arg);
4744 } 4946 }
4745 4947
4746 @override 4948 @override
4949 R visitConstConstructorInvoke(
4950 NewExpression node,
4951 ConstructedConstantExpression constant,
4952 A arg) {
4953 return handleConstantGet(node, constant, arg);
4954 }
4955
4956 @override
4747 R visitConstantGet( 4957 R visitConstantGet(
4748 Send node, 4958 Send node,
4749 ConstantExpression constant, 4959 ConstantExpression constant,
4750 A arg) { 4960 A arg) {
4751 return handleConstantGet(node, constant, arg); 4961 return handleConstantGet(node, constant, arg);
4752 } 4962 }
4753 4963
4754 @override 4964 @override
4755 R visitConstantInvoke( 4965 R visitConstantInvoke(
4756 Send node, 4966 Send node,
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
4998 Send node, 5208 Send node,
4999 Node receiver, 5209 Node receiver,
5000 Node index, 5210 Node index,
5001 IncDecOperator operator, 5211 IncDecOperator operator,
5002 A arg) { 5212 A arg) {
5003 return handleDynamicIndexPostfixPrefix( 5213 return handleDynamicIndexPostfixPrefix(
5004 node, receiver, index, operator, arg, isPrefix: true); 5214 node, receiver, index, operator, arg, isPrefix: true);
5005 } 5215 }
5006 } 5216 }
5007 5217
5008 /// Mixin that groups all `visitSuperXPrefix`, `visitSuperXPostfix` methods for 5218 /// Mixin that groups all `visitSuperXPrefix`, `visitSuperXPostfix` methods by
5009 /// by delegating calls to `handleSuperXPostfixPrefix` methods. 5219 /// delegating calls to `handleSuperXPostfixPrefix` methods.
5010 /// 5220 ///
5011 /// This mixin is useful for the cases where super prefix/postfix expression are 5221 /// This mixin is useful for the cases where super prefix/postfix expression are
5012 /// handled uniformly. 5222 /// handled uniformly.
5013 abstract class BaseImplementationOfSuperIncDecsMixin<R, A> 5223 abstract class BaseImplementationOfSuperIncDecsMixin<R, A>
5014 implements SemanticSendVisitor<R, A> { 5224 implements SemanticSendVisitor<R, A> {
5015 R handleSuperFieldFieldPostfixPrefix( 5225 R handleSuperFieldFieldPostfixPrefix(
5016 Send node, 5226 Send node,
5017 FieldElement readField, 5227 FieldElement readField,
5018 FieldElement writtenField, 5228 FieldElement writtenField,
5019 IncDecOperator operator, 5229 IncDecOperator operator,
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
5210 FunctionElement indexFunction, 5420 FunctionElement indexFunction,
5211 FunctionElement indexSetFunction, 5421 FunctionElement indexSetFunction,
5212 Node index, 5422 Node index,
5213 IncDecOperator operator, 5423 IncDecOperator operator,
5214 A arg) { 5424 A arg) {
5215 return handleSuperIndexPostfixPrefix( 5425 return handleSuperIndexPostfixPrefix(
5216 node, indexFunction, indexSetFunction, 5426 node, indexFunction, indexSetFunction,
5217 index, operator, arg, isPrefix: true); 5427 index, operator, arg, isPrefix: true);
5218 } 5428 }
5219 } 5429 }
5430
5431 /// Mixin that groups the non-constant `visitXConstructorInvoke` methods by
5432 /// delegating calls to the `handleConstructorInvoke` method.
5433 ///
5434 /// This mixin is useful for the cases where all constructor invocations are
5435 /// handled uniformly.
5436 abstract class BaseImplementationOfNewMixin<R, A>
5437 implements SemanticSendVisitor<R, A> {
5438
5439 R handleConstructorInvoke(
5440 NewExpression node,
5441 ConstructorElement constructor,
5442 DartType type,
5443 NodeList arguments,
5444 Selector selector,
5445 A arg);
5446
5447 R visitGenerativeConstructorInvoke(
5448 NewExpression node,
5449 ConstructorElement constructor,
5450 InterfaceType type,
5451 NodeList arguments,
5452 Selector selector,
5453 A arg) {
5454 return handleConstructorInvoke(
5455 node, constructor, type, arguments, selector, arg);
5456 }
5457
5458 R visitRedirectingGenerativeConstructorInvoke(
5459 NewExpression node,
5460 ConstructorElement constructor,
5461 InterfaceType type,
5462 NodeList arguments,
5463 Selector selector,
5464 A arg) {
5465 return handleConstructorInvoke(
5466 node, constructor, type, arguments, selector, arg);
5467 }
5468
5469 R visitFactoryConstructorInvoke(
5470 NewExpression node,
5471 ConstructorElement constructor,
5472 InterfaceType type,
5473 NodeList arguments,
5474 Selector selector,
5475 A arg) {
5476 return handleConstructorInvoke(
5477 node, constructor, type, arguments, selector, arg);
5478 }
5479
5480 R visitRedirectingFactoryConstructorInvoke(
5481 NewExpression node,
5482 ConstructorElement constructor,
5483 InterfaceType type,
5484 ConstructorElement effectiveTarget,
5485 InterfaceType effectiveTargetType,
5486 NodeList arguments,
5487 Selector selector,
5488 A arg) {
5489 return handleConstructorInvoke(
5490 node, constructor, type, arguments, selector, arg);
5491 }
5492 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/resolution/semantic_visitor.dart ('k') | pkg/compiler/lib/src/resolution/send_resolver.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698