| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 library dart2js.resolution; | 5 library dart2js.resolution; |
| 6 | 6 |
| 7 import 'dart:collection' show Queue; | 7 import 'dart:collection' show Queue; |
| 8 | 8 |
| 9 import '../common.dart'; | 9 import '../common.dart'; |
| 10 import '../common/names.dart' show Identifiers; | 10 import '../common/names.dart' show Identifiers; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 | 51 |
| 52 import 'class_hierarchy.dart'; | 52 import 'class_hierarchy.dart'; |
| 53 import 'class_members.dart' show MembersCreator; | 53 import 'class_members.dart' show MembersCreator; |
| 54 import 'constructors.dart'; | 54 import 'constructors.dart'; |
| 55 import 'members.dart'; | 55 import 'members.dart'; |
| 56 import 'registry.dart'; | 56 import 'registry.dart'; |
| 57 import 'signatures.dart'; | 57 import 'signatures.dart'; |
| 58 import 'tree_elements.dart'; | 58 import 'tree_elements.dart'; |
| 59 import 'typedefs.dart'; | 59 import 'typedefs.dart'; |
| 60 | 60 |
| 61 // TODO(ahe): This should be a compiler option or something like that. |
| 62 const bool allowSuperInMixin = true; |
| 63 |
| 61 class ResolverTask extends CompilerTask { | 64 class ResolverTask extends CompilerTask { |
| 62 final ConstantCompiler constantCompiler; | 65 final ConstantCompiler constantCompiler; |
| 63 | 66 |
| 64 ResolverTask(Compiler compiler, this.constantCompiler) : super(compiler); | 67 ResolverTask(Compiler compiler, this.constantCompiler) : super(compiler); |
| 65 | 68 |
| 66 String get name => 'Resolver'; | 69 String get name => 'Resolver'; |
| 67 | 70 |
| 68 Resolution get resolution => compiler.resolution; | 71 Resolution get resolution => compiler.resolution; |
| 69 | 72 |
| 70 Parsing get parsing => compiler.parsing; | 73 Parsing get parsing => compiler.parsing; |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 visitor.visit(tree.body); | 259 visitor.visit(tree.body); |
| 257 } | 260 } |
| 258 | 261 |
| 259 // Get the resolution tree and check that the resolved | 262 // Get the resolution tree and check that the resolved |
| 260 // function doesn't use 'super' if it is mixed into another | 263 // function doesn't use 'super' if it is mixed into another |
| 261 // class. This is the part of the 'super' mixin check that | 264 // class. This is the part of the 'super' mixin check that |
| 262 // happens when a function is resolved after the mixin | 265 // happens when a function is resolved after the mixin |
| 263 // application has been performed. | 266 // application has been performed. |
| 264 TreeElements resolutionTree = registry.mapping; | 267 TreeElements resolutionTree = registry.mapping; |
| 265 ClassElement enclosingClass = element.enclosingClass; | 268 ClassElement enclosingClass = element.enclosingClass; |
| 266 if (enclosingClass != null) { | 269 if (!allowSuperInMixin && enclosingClass != null) { |
| 267 // TODO(johnniwinther): Find another way to obtain mixin uses. | 270 // TODO(johnniwinther): Find another way to obtain mixin uses. |
| 268 Iterable<MixinApplicationElement> mixinUses = | 271 Iterable<MixinApplicationElement> mixinUses = |
| 269 compiler.world.allMixinUsesOf(enclosingClass); | 272 compiler.world.allMixinUsesOf(enclosingClass); |
| 270 ClassElement mixin = enclosingClass; | 273 ClassElement mixin = enclosingClass; |
| 271 for (MixinApplicationElement mixinApplication in mixinUses) { | 274 for (MixinApplicationElement mixinApplication in mixinUses) { |
| 272 checkMixinSuperUses(resolutionTree, mixinApplication, mixin); | 275 checkMixinSuperUses(resolutionTree, mixinApplication, mixin); |
| 273 } | 276 } |
| 274 } | 277 } |
| 275 | 278 |
| 276 // TODO(9631): support noSuchMethod on native classes. | 279 // TODO(9631): support noSuchMethod on native classes. |
| (...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 719 if (!mixin.superclass.isObject) { | 722 if (!mixin.superclass.isObject) { |
| 720 reporter.reportErrorMessage(mixin, MessageKind.ILLEGAL_MIXIN_SUPERCLASS); | 723 reporter.reportErrorMessage(mixin, MessageKind.ILLEGAL_MIXIN_SUPERCLASS); |
| 721 } | 724 } |
| 722 | 725 |
| 723 // Check that the mixed in class doesn't have any constructors and | 726 // Check that the mixed in class doesn't have any constructors and |
| 724 // make sure we aren't mixing in methods that use 'super'. | 727 // make sure we aren't mixing in methods that use 'super'. |
| 725 mixin.forEachLocalMember((AstElement member) { | 728 mixin.forEachLocalMember((AstElement member) { |
| 726 if (member.isGenerativeConstructor && !member.isSynthesized) { | 729 if (member.isGenerativeConstructor && !member.isSynthesized) { |
| 727 reporter.reportErrorMessage( | 730 reporter.reportErrorMessage( |
| 728 member, MessageKind.ILLEGAL_MIXIN_CONSTRUCTOR); | 731 member, MessageKind.ILLEGAL_MIXIN_CONSTRUCTOR); |
| 729 } else { | 732 } else if (!allowSuperInMixin) { |
| 730 // Get the resolution tree and check that the resolved member | 733 // Get the resolution tree and check that the resolved member |
| 731 // doesn't use 'super'. This is the part of the 'super' mixin | 734 // doesn't use 'super'. This is the part of the 'super' mixin |
| 732 // check that happens when a function is resolved before the | 735 // check that happens when a function is resolved before the |
| 733 // mixin application has been performed. | 736 // mixin application has been performed. |
| 734 // TODO(johnniwinther): Obtain the [TreeElements] for [member] | 737 // TODO(johnniwinther): Obtain the [TreeElements] for [member] |
| 735 // differently. | 738 // differently. |
| 736 if (compiler.enqueuer.resolution.hasBeenProcessed(member)) { | 739 if (compiler.enqueuer.resolution.hasBeenProcessed(member)) { |
| 737 checkMixinSuperUses( | 740 checkMixinSuperUses( |
| 738 member.resolvedAst.elements, mixinApplication, mixin); | 741 member.resolvedAst.elements, mixinApplication, mixin); |
| 739 } | 742 } |
| (...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1098 TreeElements get treeElements { | 1101 TreeElements get treeElements { |
| 1099 assert(invariant(this, _treeElements != null, | 1102 assert(invariant(this, _treeElements != null, |
| 1100 message: "TreeElements have not been computed for $this.")); | 1103 message: "TreeElements have not been computed for $this.")); |
| 1101 return _treeElements; | 1104 return _treeElements; |
| 1102 } | 1105 } |
| 1103 | 1106 |
| 1104 void reuseElement() { | 1107 void reuseElement() { |
| 1105 _treeElements = null; | 1108 _treeElements = null; |
| 1106 } | 1109 } |
| 1107 } | 1110 } |
| OLD | NEW |