| 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 part of dart2js; | 5 part of dart2js; |
| 6 | 6 |
| 7 class World { | 7 class World { |
| 8 final Compiler compiler; | 8 final Compiler compiler; |
| 9 final Map<ClassElement, Set<MixinApplicationElement>> mixinUses; | 9 final Map<ClassElement, Set<MixinApplicationElement>> mixinUses; |
| 10 final Map<ClassElement, Set<ClassElement>> typesImplementedBySubclasses; | 10 final Map<ClassElement, Set<ClassElement>> typesImplementedBySubclasses; |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 allFunctions.add(element); | 141 allFunctions.add(element); |
| 142 } | 142 } |
| 143 } | 143 } |
| 144 | 144 |
| 145 VariableElement locateSingleField(Selector selector) { | 145 VariableElement locateSingleField(Selector selector) { |
| 146 Element result = locateSingleElement(selector); | 146 Element result = locateSingleElement(selector); |
| 147 return (result != null && result.isField()) ? result : null; | 147 return (result != null && result.isField()) ? result : null; |
| 148 } | 148 } |
| 149 | 149 |
| 150 Element locateSingleElement(Selector selector) { | 150 Element locateSingleElement(Selector selector) { |
| 151 Iterable<Element> targets = allFunctions.filter(selector); | 151 ti.TypeMask mask = selector.mask == null |
| 152 if (targets.length != 1) return null; | 152 ? new ti.TypeMask.subclass(compiler.objectClass.rawType) |
| 153 Element result = targets.first; | 153 : selector.mask; |
| 154 ClassElement enclosing = result.getEnclosingClass(); | 154 return mask.locateSingleElement(selector, compiler); |
| 155 // TODO(kasperl): Move this code to the type mask. | |
| 156 ti.TypeMask mask = selector.mask; | |
| 157 ClassElement receiverTypeElement = (mask == null || mask.base == null) | |
| 158 ? compiler.objectClass | |
| 159 : mask.base.element; | |
| 160 // We only return the found element if it is guaranteed to be | |
| 161 // implemented on the exact receiver type. It could be found in a | |
| 162 // subclass or in an inheritance-wise unrelated class in case of | |
| 163 // subtype selectors. | |
| 164 return (receiverTypeElement.isSubclassOf(enclosing)) ? result : null; | |
| 165 } | 155 } |
| 166 | 156 |
| 167 bool hasSingleMatch(Selector selector) { | 157 bool hasSingleMatch(Selector selector) { |
| 168 Iterable<Element> targets = allFunctions.filter(selector); | 158 Iterable<Element> targets = allFunctions.filter(selector); |
| 169 return targets.length == 1; | 159 return targets.length == 1; |
| 170 } | 160 } |
| 171 | 161 |
| 172 Iterable<ClassElement> locateNoSuchMethodHolders(Selector selector) { | 162 Iterable<ClassElement> locateNoSuchMethodHolders(Selector selector) { |
| 173 Selector noSuchMethodSelector = compiler.noSuchMethodSelector; | 163 Selector noSuchMethodSelector = compiler.noSuchMethodSelector; |
| 174 ti.TypeMask mask = selector.mask; | 164 ti.TypeMask mask = selector.mask; |
| 175 if (mask != null) { | 165 if (mask != null) { |
| 176 noSuchMethodSelector = new TypedSelector(mask, noSuchMethodSelector); | 166 noSuchMethodSelector = new TypedSelector(mask, noSuchMethodSelector); |
| 177 } | 167 } |
| 178 ClassElement objectClass = compiler.objectClass; | 168 ClassElement objectClass = compiler.objectClass; |
| 179 return allFunctions | 169 return allFunctions |
| 180 .filter(noSuchMethodSelector) | 170 .filter(noSuchMethodSelector) |
| 181 .map((Element member) => member.getEnclosingClass()) | 171 .map((Element member) => member.getEnclosingClass()) |
| 182 .where((ClassElement holder) => !identical(holder, objectClass)); | 172 .where((ClassElement holder) => !identical(holder, objectClass)); |
| 183 } | 173 } |
| 184 | 174 |
| 185 void addFunctionCalledInLoop(Element element) { | 175 void addFunctionCalledInLoop(Element element) { |
| 186 functionsCalledInLoop.add(element); | 176 functionsCalledInLoop.add(element); |
| 187 } | 177 } |
| 188 | 178 |
| 189 bool isCalledInLoop(Element element) { | 179 bool isCalledInLoop(Element element) { |
| 190 return functionsCalledInLoop.contains(element); | 180 return functionsCalledInLoop.contains(element); |
| 191 } | 181 } |
| 192 } | 182 } |
| OLD | NEW |