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

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

Issue 1047673002: Add SemanticDeclVisitor. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Correct long lines 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.
(...skipping 2278 matching lines...) Expand 10 before | Expand all | Expand 10 after
2289 throw new UnimplementedError("BulkVisitor.apply unimplemented"); 2289 throw new UnimplementedError("BulkVisitor.apply unimplemented");
2290 } 2290 }
2291 2291
2292 @override 2292 @override
2293 R bulkHandleNode(Node node, String message, A arg) { 2293 R bulkHandleNode(Node node, String message, A arg) {
2294 throw new UnimplementedError("BulkVisitor.bulkHandleNode unimplemented"); 2294 throw new UnimplementedError("BulkVisitor.bulkHandleNode unimplemented");
2295 } 2295 }
2296 } 2296 }
2297 2297
2298 /// [SemanticSendVisitor] that visits subnodes. 2298 /// [SemanticSendVisitor] that visits subnodes.
2299 class TraversalMixin<R, A> implements SemanticSendVisitor<R, A> { 2299 class TraversalSendMixin<R, A> implements SemanticSendVisitor<R, A> {
2300 @override 2300 @override
2301 R apply(Node node, A arg) { 2301 R apply(Node node, A arg) {
2302 throw new UnimplementedError("TraversalMixin.apply unimplemented"); 2302 throw new UnimplementedError("TraversalMixin.apply unimplemented");
2303 } 2303 }
2304 2304
2305 @override 2305 @override
2306 R errorInvalidAssert( 2306 R errorInvalidAssert(
2307 Send node, 2307 Send node,
2308 NodeList arguments, 2308 NodeList arguments,
2309 A arg) { 2309 A arg) {
(...skipping 1825 matching lines...) Expand 10 before | Expand all | Expand 10 after
4135 Send node, 4135 Send node,
4136 FunctionElement indexFunction, 4136 FunctionElement indexFunction,
4137 FunctionElement indexSetFunction, 4137 FunctionElement indexSetFunction,
4138 Node index, 4138 Node index,
4139 IncDecOperator operator, 4139 IncDecOperator operator,
4140 A arg) { 4140 A arg) {
4141 apply(index, arg); 4141 apply(index, arg);
4142 return null; 4142 return null;
4143 } 4143 }
4144 4144
4145 @override
4146 R visitConstConstructorInvoke( 4145 R visitConstConstructorInvoke(
4147 NewExpression node, 4146 NewExpression node,
4148 ConstructedConstantExpression constant, 4147 ConstructedConstantExpression constant,
4149 A arg) { 4148 A arg) {
4150 return null; 4149 return null;
4151 } 4150 }
4152 4151
4153 @override 4152 @override
4154 R errorUnresolvedClassConstructorInvoke( 4153 R errorUnresolvedClassConstructorInvoke(
4155 NewExpression node, 4154 NewExpression node,
(...skipping 10 matching lines...) Expand all
4166 R errorUnresolvedConstructorInvoke( 4165 R errorUnresolvedConstructorInvoke(
4167 NewExpression node, 4166 NewExpression node,
4168 Element constructor, 4167 Element constructor,
4169 DartType type, 4168 DartType type,
4170 NodeList arguments, 4169 NodeList arguments,
4171 Selector selector, 4170 Selector selector,
4172 A arg) { 4171 A arg) {
4173 apply(arguments, arg); 4172 apply(arguments, arg);
4174 return null; 4173 return null;
4175 } 4174 }
4175
4176 @override
4176 R visitFactoryConstructorInvoke( 4177 R visitFactoryConstructorInvoke(
4177 NewExpression node, 4178 NewExpression node,
4178 ConstructorElement constructor, 4179 ConstructorElement constructor,
4179 InterfaceType type, 4180 InterfaceType type,
4180 NodeList arguments, 4181 NodeList arguments,
4181 Selector selector, 4182 Selector selector,
4182 A arg) { 4183 A arg) {
4183 apply(arguments, arg); 4184 apply(arguments, arg);
4184 return null; 4185 return null;
4185 } 4186 }
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
4240 ConstructorElement constructor, 4241 ConstructorElement constructor,
4241 InterfaceType type, 4242 InterfaceType type,
4242 NodeList arguments, 4243 NodeList arguments,
4243 Selector selector, 4244 Selector selector,
4244 A arg) { 4245 A arg) {
4245 apply(arguments, arg); 4246 apply(arguments, arg);
4246 return null; 4247 return null;
4247 } 4248 }
4248 } 4249 }
4249 4250
4251 /// [SemanticDeclVisitor] that visits subnodes.
4252 class TraversalDeclMixin<R, A> implements SemanticDeclVisitor<R, A> {
4253 @override
4254 R apply(Node node, A arg) {
4255 throw new UnimplementedError("TraversalMixin.apply unimplemented");
4256 }
4257
4258 @override
4259 applyInitializers(NodeList initializers, A arg) {
4260 throw new UnimplementedError(
4261 "TraversalMixin.applyInitializers unimplemented");
4262 }
4263
4264 @override
4265 applyParameters(NodeList parameters, A arg) {
4266 throw new UnimplementedError(
4267 "TraversalMixin.applyParameters unimplemented");
4268 }
4269
4270 @override
4271 R visitAbstractMethodDecl(
4272 FunctionExpression node,
4273 MethodElement method,
4274 NodeList parameters,
4275 A arg) {
4276 applyParameters(parameters, arg);
4277 return null;
4278 }
4279
4280 @override
4281 R visitClosureDecl(
4282 FunctionExpression node,
4283 LocalFunctionElement function,
4284 NodeList parameters,
4285 Node body,
4286 A arg) {
4287 applyParameters(parameters, arg);
4288 apply(body, arg);
4289 return null;
4290 }
4291
4292 @override
4293 R visitFactoryConstructorDecl(
4294 FunctionExpression node,
4295 ConstructorElement constructor,
4296 NodeList parameters,
4297 Node body,
4298 A arg) {
4299 applyParameters(parameters, arg);
4300 apply(body, arg);
4301 return null;
4302 }
4303
4304 @override
4305 R visitFieldInitializer(
4306 SendSet node,
4307 FieldElement field,
4308 Node initializer,
4309 A arg) {
4310 apply(initializer, arg);
4311 return null;
4312 }
4313
4314 @override
4315 R visitGenerativeConstructorDecl(
4316 FunctionExpression node,
4317 ConstructorElement constructor,
4318 NodeList parameters,
4319 NodeList initializers,
4320 Node body,
4321 A arg) {
4322 applyParameters(parameters, arg);
4323 applyInitializers(initializers, arg);
4324 apply(body, arg);
4325 return null;
4326 }
4327
4328 @override
4329 R visitInstanceMethodDecl(
4330 FunctionExpression node,
4331 MethodElement method,
4332 NodeList parameters,
4333 Node body,
4334 A arg) {
4335 applyParameters(parameters, arg);
4336 apply(body, arg);
4337 }
4338
4339 @override
4340 R visitLocalFunctionDecl(
4341 FunctionExpression node,
4342 LocalFunctionElement function,
4343 NodeList parameters,
4344 Node body,
4345 A arg) {
4346 applyParameters(parameters, arg);
4347 apply(body, arg);
4348 }
4349
4350 @override
4351 R visitRedirectingFactoryConstructorDecl(
4352 FunctionExpression node,
4353 ConstructorElement constructor,
4354 NodeList parameters,
4355 InterfaceType redirectionType,
4356 ConstructorElement redirectionTarget,
4357 A arg) {
4358 applyParameters(parameters, arg);
4359 return null;
4360 }
4361
4362 @override
4363 R visitRedirectingGenerativeConstructorDecl(
4364 FunctionExpression node,
4365 ConstructorElement constructor,
4366 NodeList parameters,
4367 NodeList initializers,
4368 A arg) {
4369 applyParameters(parameters, arg);
4370 applyInitializers(initializers, arg);
4371 return null;
4372 }
4373
4374 @override
4375 R visitStaticFunctionDecl(
4376 FunctionExpression node,
4377 MethodElement function,
4378 NodeList parameters,
4379 Node body,
4380 A arg) {
4381 applyParameters(parameters, arg);
4382 apply(body, arg);
4383 return null;
4384 }
4385
4386 @override
4387 R visitSuperConstructorInvoke(
4388 Send node,
4389 ConstructorElement superConstructor,
4390 InterfaceType type,
4391 NodeList arguments,
4392 Selector selector,
4393 A arg) {
4394 apply(arguments, arg);
4395 return null;
4396 }
4397
4398 @override
4399 R visitThisConstructorInvoke(
4400 Send node,
4401 ConstructorElement thisConstructor,
4402 NodeList arguments,
4403 Selector selector,
4404 A arg) {
4405 apply(arguments, arg);
4406 return null;
4407 }
4408
4409 @override
4410 R visitTopLevelFunctionDecl(
4411 FunctionExpression node,
4412 MethodElement function,
4413 NodeList parameters,
4414 Node body,
4415 A arg) {
4416 applyParameters(parameters, arg);
4417 apply(body, arg);
4418 return null;
4419 }
4420
4421 @override
4422 R errorUnresolvedFieldInitializer(
4423 SendSet node,
4424 Element element,
4425 Node initializer,
4426 A arg) {
4427 apply(initializer, arg);
4428 return null;
4429 }
4430
4431 @override
4432 R errorUnresolvedSuperConstructorInvoke(
4433 Send node,
4434 Element element,
4435 NodeList arguments,
4436 Selector selector,
4437 A arg) {
4438 apply(arguments, arg);
4439 return null;
4440 }
4441
4442 @override
4443 R errorUnresolvedThisConstructorInvoke(
4444 Send node,
4445 Element element,
4446 NodeList arguments,
4447 Selector selector,
4448 A arg) {
4449 apply(arguments, arg);
4450 return null;
4451 }
4452
4453 @override
4454 R visitLocalVariableDecl(
4455 VariableDefinitions node,
4456 Node definition,
4457 LocalVariableElement variable,
4458 Node initializer,
4459 A arg) {
4460 if (initializer != null) {
4461 apply(initializer, arg);
4462 }
4463 return null;
4464 }
4465
4466 @override
4467 R visitOptionalParameterDecl(
4468 VariableDefinitions node,
4469 Node definition,
4470 ParameterElement parameter,
4471 ConstantExpression defaultValue,
4472 int index,
4473 A arg) {
4474 return null;
4475 }
4476
4477 @override
4478 R visitParameterDecl(
4479 VariableDefinitions node,
4480 Node definition,
4481 ParameterElement parameter,
4482 int index,
4483 A arg) {
4484 return null;
4485 }
4486
4487 @override
4488 R visitInitializingFormalDecl(
4489 VariableDefinitions node,
4490 Node definition,
4491 InitializingFormalElement initializingFormal,
4492 int index,
4493 A arg) {
4494 return null;
4495 }
4496
4497 @override
4498 R visitLocalConstantDecl(
4499 VariableDefinitions node,
4500 Node definition,
4501 LocalVariableElement variable,
4502 ConstantExpression constant,
4503 A arg) {
4504 return null;
4505 }
4506
4507 @override
4508 R visitNamedInitializingFormalDecl(
4509 VariableDefinitions node,
4510 Node definition,
4511 InitializingFormalElement initializingFormal,
4512 ConstantExpression defaultValue,
4513 A arg) {
4514 return null;
4515 }
4516
4517 @override
4518 R visitNamedParameterDecl(
4519 VariableDefinitions node,
4520 Node definition,
4521 ParameterElement parameter,
4522 ConstantExpression defaultValue,
4523 A arg) {
4524 return null;
4525 }
4526
4527 @override
4528 R visitOptionalInitializingFormalDecl(
4529 VariableDefinitions node,
4530 Node definition,
4531 InitializingFormalElement initializingFormal,
4532 ConstantExpression defaultValue,
4533 int index,
4534 A arg) {
4535 return null;
4536 }
4537
4538 @override
4539 R visitInstanceFieldDecl(
4540 VariableDefinitions node,
4541 Node definition,
4542 FieldElement field,
4543 Node initializer,
4544 A arg) {
4545 if (initializer != null) {
4546 apply(initializer, arg);
4547 }
4548 return null;
4549 }
4550
4551 @override
4552 R visitStaticConstantDecl(
4553 VariableDefinitions node,
4554 Node definition,
4555 FieldElement field,
4556 ConstantExpression constant,
4557 A arg) {
4558 return null;
4559 }
4560
4561 @override
4562 R visitStaticFieldDecl(
4563 VariableDefinitions node,
4564 Node definition,
4565 FieldElement field,
4566 Node initializer,
4567 A arg) {
4568 if (initializer != null) {
4569 apply(initializer, arg);
4570 }
4571 return null;
4572 }
4573
4574 @override
4575 R visitTopLevelConstantDecl(
4576 VariableDefinitions node,
4577 Node definition,
4578 FieldElement field,
4579 ConstantExpression constant,
4580 A arg) {
4581 return null;
4582 }
4583
4584 @override
4585 R visitTopLevelFieldDecl(
4586 VariableDefinitions node,
4587 Node definition,
4588 FieldElement field,
4589 Node initializer,
4590 A arg) {
4591 if (initializer != null) {
4592 apply(initializer, arg);
4593 }
4594 return null;
4595 }
4596
4597 @override
4598 R visitAbstractGetterDecl(
4599 FunctionExpression node,
4600 MethodElement getter,
4601 A arg) {
4602 return null;
4603 }
4604
4605 @override
4606 R visitAbstractSetterDecl(
4607 FunctionExpression node,
4608 MethodElement setter,
4609 NodeList parameters,
4610 A arg) {
4611 applyParameters(parameters, arg);
4612 return null;
4613 }
4614
4615 @override
4616 R visitInstanceGetterDecl(
4617 FunctionExpression node,
4618 MethodElement getter,
4619 Node body,
4620 A arg) {
4621 apply(body, arg);
4622 return null;
4623 }
4624
4625 @override
4626 R visitInstanceSetterDecl(
4627 FunctionExpression node,
4628 MethodElement setter,
4629 NodeList parameters,
4630 Node body,
4631 A arg) {
4632 applyParameters(parameters, arg);
4633 apply(body, arg);
4634 return null;
4635 }
4636
4637 @override
4638 R visitStaticGetterDecl(
4639 FunctionExpression node,
4640 MethodElement getter,
4641 Node body,
4642 A arg) {
4643 apply(body, arg);
4644 return null;
4645 }
4646
4647 @override
4648 R visitStaticSetterDecl(
4649 FunctionExpression node,
4650 MethodElement setter,
4651 NodeList parameters,
4652 Node body,
4653 A arg) {
4654 applyParameters(parameters, arg);
4655 apply(body, arg);
4656 return null;
4657 }
4658
4659 @override
4660 R visitTopLevelGetterDecl(
4661 FunctionExpression node,
4662 MethodElement getter,
4663 Node body,
4664 A arg) {
4665 apply(body, arg);
4666 return null;
4667 }
4668
4669 @override
4670 R visitTopLevelSetterDecl(
4671 FunctionExpression node,
4672 MethodElement setter,
4673 NodeList parameters,
4674 Node body,
4675 A arg) {
4676 applyParameters(parameters, arg);
4677 apply(body, arg);
4678 return null;
4679 }
4680 }
4681
4250 /// AST visitor that visits all normal [Send] and [SendSet] nodes using the 4682 /// AST visitor that visits all normal [Send] and [SendSet] nodes using the
4251 /// [SemanticVisitor]. 4683 /// [SemanticVisitor].
4252 class TraversalVisitor<R, A> extends SemanticVisitor<R, A> 4684 class TraversalVisitor<R, A> extends SemanticVisitor<R, A>
4253 with TraversalMixin<R, A> { 4685 with TraversalSendMixin<R, A>,
4686 TraversalDeclMixin<R, A> {
4254 TraversalVisitor(TreeElements elements) : super(elements); 4687 TraversalVisitor(TreeElements elements) : super(elements);
4255 4688
4256 SemanticSendVisitor<R, A> get sendVisitor => this; 4689 SemanticSendVisitor<R, A> get sendVisitor => this;
4257 4690
4691 SemanticDeclVisitor<R, A> get declVisitor => this;
4692
4258 R apply(Node node, A arg) { 4693 R apply(Node node, A arg) {
4259 node.accept(this); 4694 node.accept(this);
4260 return null; 4695 return null;
4261 } 4696 }
4262 4697
4263 @override 4698 @override
4699 applyInitializers(NodeList initializers, A arg) {
4700 visitInitializers(initializers, arg);
4701 }
4702
4703 @override
4704 applyParameters(NodeList parameters, A arg) {
4705 visitParameters(parameters, arg);
4706 }
4707
4708 @override
4264 internalError(Spannable spannable, String message) { 4709 internalError(Spannable spannable, String message) {
4265 throw new SpannableAssertionFailure(spannable, message); 4710 throw new SpannableAssertionFailure(spannable, message);
4266 } 4711 }
4267 4712
4268 @override 4713 @override
4269 R visitNode(Node node) { 4714 R visitNode(Node node) {
4270 node.visitChildren(this); 4715 node.visitChildren(this);
4271 return null; 4716 return null;
4272 } 4717 }
4273
4274 void visitParameters(NodeList parameters) {
4275
4276 }
4277
4278 void visitInitializers(NodeList initializers) {
4279 // TODO(johnniwinther): Visit subnodes of initializers.
4280 }
4281
4282 @override
4283 R visitFunctionExpression(FunctionExpression node) {
4284 if (node.parameters != null) {
4285 visitParameters(node.parameters);
4286 }
4287 if (node.initializers != null) {
4288 visitInitializers(node.initializers);
4289 }
4290 if (node.body != null) {
4291 apply(node.body, null);
4292 }
4293 return null;
4294 }
4295 } 4718 }
4296 4719
4297 /// Mixin that groups all `visitStaticX` and `visitTopLevelX` method by 4720 /// Mixin that groups all `visitStaticX` and `visitTopLevelX` method by
4298 /// delegating calls to `handleStaticX` methods. 4721 /// delegating calls to `handleStaticX` methods.
4299 /// 4722 ///
4300 /// This mixin is useful for the cases where both top level members and static 4723 /// This mixin is useful for the cases where both top level members and static
4301 /// class members are handled uniformly. 4724 /// class members are handled uniformly.
4302 abstract class BaseImplementationOfStaticsMixin<R, A> 4725 abstract class BaseImplementationOfStaticsMixin<R, A>
4303 implements SemanticSendVisitor<R, A> { 4726 implements SemanticSendVisitor<R, A> {
4304 R handleStaticFieldCompound( 4727 R handleStaticFieldCompound(
(...skipping 1178 matching lines...) Expand 10 before | Expand all | Expand 10 after
5483 InterfaceType type, 5906 InterfaceType type,
5484 ConstructorElement effectiveTarget, 5907 ConstructorElement effectiveTarget,
5485 InterfaceType effectiveTargetType, 5908 InterfaceType effectiveTargetType,
5486 NodeList arguments, 5909 NodeList arguments,
5487 Selector selector, 5910 Selector selector,
5488 A arg) { 5911 A arg) {
5489 return handleConstructorInvoke( 5912 return handleConstructorInvoke(
5490 node, constructor, type, arguments, selector, arg); 5913 node, constructor, type, arguments, selector, arg);
5491 } 5914 }
5492 } 5915 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698