Chromium Code Reviews| 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 universe; | 5 part of universe; |
| 6 | 6 |
| 7 // TODO(kasperl): This actually holds getters and setters just fine | 7 // TODO(kasperl): This actually holds getters and setters just fine |
| 8 // too and stricly they aren't functions. Maybe this needs a better | 8 // too and stricly they aren't functions. Maybe this needs a better |
| 9 // name -- something like ElementSet seems a bit too generic. | 9 // name -- something like ElementSet seems a bit too generic. |
| 10 class FunctionSet { | 10 class FunctionSet { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 42 return (node != null) | 42 return (node != null) |
| 43 ? node.contains(element) | 43 ? node.contains(element) |
| 44 : false; | 44 : false; |
| 45 } | 45 } |
| 46 | 46 |
| 47 /** | 47 /** |
| 48 * Returns an object that allows iterating over all the functions | 48 * Returns an object that allows iterating over all the functions |
| 49 * that may be invoked with the given [selector]. | 49 * that may be invoked with the given [selector]. |
| 50 */ | 50 */ |
| 51 Iterable<Element> filter(Selector selector) { | 51 Iterable<Element> filter(Selector selector) { |
| 52 return query(selector).functions; | |
| 53 } | |
| 54 | |
| 55 TypeMask receiverType(Selector selector) { | |
| 56 return query(selector).computeMask(compiler); | |
| 57 } | |
| 58 | |
| 59 FunctionSetQuery query(Selector selector) { | |
| 52 SourceString name = selector.name; | 60 SourceString name = selector.name; |
| 53 FunctionSetNode node = nodes[name]; | 61 FunctionSetNode node = nodes[name]; |
| 54 FunctionSetNode noSuchMethods = nodes[Compiler.NO_SUCH_METHOD]; | 62 FunctionSetNode noSuchMethods = nodes[Compiler.NO_SUCH_METHOD]; |
| 55 if (node != null) { | 63 if (node != null) { |
| 56 return node.query(selector, compiler, noSuchMethods).functions; | 64 return node.query(selector, compiler, noSuchMethods); |
| 57 } | 65 } |
| 58 // If there is no method that matches [selector] we know we can | 66 // If there is no method that matches [selector] we know we can |
| 59 // only hit [:noSuchMethod:]. | 67 // only hit [:noSuchMethod:]. |
| 60 if (noSuchMethods == null) return const <Element>[]; | 68 if (noSuchMethods == null) return const FunctionSetQuery(const <Element>[]); |
| 61 selector = (selector.mask == null) | 69 selector = (selector.mask == null) |
| 62 ? compiler.noSuchMethodSelector | 70 ? compiler.noSuchMethodSelector |
| 63 : new TypedSelector(selector.mask, compiler.noSuchMethodSelector); | 71 : new TypedSelector(selector.mask, compiler.noSuchMethodSelector); |
| 64 | 72 |
| 65 return noSuchMethods.query(selector, compiler, null).functions; | 73 return noSuchMethods.query(selector, compiler, null); |
| 66 } | 74 } |
| 67 | 75 |
| 68 void forEach(Function action) { | 76 void forEach(Function action) { |
| 69 nodes.forEach((SourceString name, FunctionSetNode node) { | 77 nodes.forEach((SourceString name, FunctionSetNode node) { |
| 70 node.forEach(action); | 78 node.forEach(action); |
| 71 }); | 79 }); |
| 72 } | 80 } |
| 73 } | 81 } |
| 74 | 82 |
| 75 | 83 |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 179 } | 187 } |
| 180 cache[selector] = result = (functions != null) | 188 cache[selector] = result = (functions != null) |
| 181 ? newQuery(functions, selector, compiler) | 189 ? newQuery(functions, selector, compiler) |
| 182 : const FunctionSetQuery(const <Element>[]); | 190 : const FunctionSetQuery(const <Element>[]); |
| 183 return result; | 191 return result; |
| 184 } | 192 } |
| 185 | 193 |
| 186 FunctionSetQuery newQuery(Iterable<Element> functions, | 194 FunctionSetQuery newQuery(Iterable<Element> functions, |
| 187 Selector selector, | 195 Selector selector, |
| 188 Compiler compiler) { | 196 Compiler compiler) { |
| 189 return new FunctionSetQuery(functions); | 197 return new FullFunctionSetQuery(functions); |
| 190 } | 198 } |
| 191 } | 199 } |
| 192 | 200 |
| 193 class FunctionSetQuery { | 201 class FunctionSetQuery { |
| 194 final Iterable<Element> functions; | 202 final Iterable<Element> functions; |
| 203 TypeMask computeMask(Compiler compiler) => const TypeMask.nonNullEmpty(); | |
| 195 const FunctionSetQuery(this.functions); | 204 const FunctionSetQuery(this.functions); |
| 196 } | 205 } |
| 206 | |
| 207 class FullFunctionSetQuery extends FunctionSetQuery { | |
| 208 TypeMask _mask; | |
| 209 | |
| 210 TypeMask computeMask(Compiler compiler) { | |
|
karlklose
2013/08/19 10:52:33
Please add a comment to describe what this functio
ngeoffray
2013/08/20 08:00:48
Done.
| |
| 211 if (_mask != null) return _mask; | |
| 212 return _mask = new TypeMask.unionOf(functions | |
| 213 .map((element) => element.getEnclosingClass()) | |
| 214 .expand((cls) { | |
| 215 return compiler.world.isUsedAsMixin(cls) | |
| 216 ? [[cls], compiler.world.mixinUses[cls]].expand((x) => x) | |
|
karlklose
2013/08/19 10:52:33
How about writing this as
'new List.from(compile
ngeoffray
2013/08/20 08:00:48
I did not want to create a new list again. By usin
ngeoffray
2013/08/20 09:13:34
After further discussions and talking to the libra
| |
| 217 : [cls]; | |
| 218 }) | |
| 219 .map((cls) { | |
| 220 Set<ClassElement> subclasses = compiler.world.subclassesOf(cls); | |
|
karlklose
2013/08/19 10:52:33
Consider adding a helper for this test:
hasSubcla
ngeoffray
2013/08/20 08:00:48
Done.
| |
| 221 return subclasses == null || subclasses.isEmpty | |
| 222 ? new TypeMask.nonNullExact(cls.rawType) | |
| 223 : new TypeMask.nonNullSubclass(cls.rawType); | |
| 224 }), | |
| 225 compiler); | |
| 226 } | |
| 227 | |
| 228 FullFunctionSetQuery(functions) : super(functions); | |
| 229 } | |
| OLD | NEW |