| 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 universe.function_set; | 5 library universe.function_set; |
| 6 | 6 |
| 7 import '../common/names.dart' show Identifiers, Selectors; | 7 import '../common/names.dart' show Identifiers, Selectors; |
| 8 import '../elements/entities.dart'; | 8 import '../elements/entities.dart'; |
| 9 import '../types/types.dart'; | 9 import '../types/types.dart'; |
| 10 import '../util/util.dart' show Hashing, Setlet; | 10 import '../util/util.dart' show Hashing, Setlet; |
| 11 import '../world.dart' show ClosedWorld; | 11 import '../world.dart' show ClosedWorld; |
| 12 import 'selector.dart' show Selector; | 12 import 'selector.dart' show Selector; |
| 13 import 'world_builder.dart' show ReceiverConstraint; | 13 import 'world_builder.dart' show ReceiverConstraint; |
| 14 | 14 |
| 15 class FunctionSetBuilder { | |
| 16 final Map<String, FunctionSetNode> nodes = new Map<String, FunctionSetNode>(); | |
| 17 | |
| 18 FunctionSetNode newNode(String name) => new FunctionSetNode(name); | |
| 19 | |
| 20 void add(MemberEntity element) { | |
| 21 assert(element.isInstanceMember); | |
| 22 assert(!element.isAbstract); | |
| 23 String name = element.name; | |
| 24 FunctionSetNode node = nodes.putIfAbsent(name, () => newNode(name)); | |
| 25 node.add(element); | |
| 26 } | |
| 27 | |
| 28 void remove(MemberEntity element) { | |
| 29 assert(element.isInstanceMember); | |
| 30 assert(!element.isAbstract); | |
| 31 String name = element.name; | |
| 32 FunctionSetNode node = nodes[name]; | |
| 33 if (node != null) { | |
| 34 node.remove(element); | |
| 35 } | |
| 36 } | |
| 37 | |
| 38 FunctionSet close() { | |
| 39 return new FunctionSet(nodes); | |
| 40 } | |
| 41 } | |
| 42 | |
| 43 // TODO(kasperl): This actually holds getters and setters just fine | 15 // TODO(kasperl): This actually holds getters and setters just fine |
| 44 // too and stricly they aren't functions. Maybe this needs a better | 16 // too and stricly they aren't functions. Maybe this needs a better |
| 45 // name -- something like ElementSet seems a bit too generic. | 17 // name -- something like ElementSet seems a bit too generic. |
| 46 class FunctionSet { | 18 class FunctionSet { |
| 47 final Map<String, FunctionSetNode> _nodes; | 19 final Map<String, FunctionSetNode> _nodes; |
| 48 | 20 |
| 49 FunctionSet(this._nodes); | 21 factory FunctionSet(Iterable<MemberEntity> liveInstanceMembers) { |
| 22 Map<String, FunctionSetNode> nodes = new Map<String, FunctionSetNode>(); |
| 23 for (MemberEntity member in liveInstanceMembers) { |
| 24 String name = member.name; |
| 25 nodes.putIfAbsent(name, () => new FunctionSetNode(name)).add(member); |
| 26 } |
| 27 return new FunctionSet.internal(nodes); |
| 28 } |
| 29 |
| 30 FunctionSet.internal(this._nodes); |
| 50 | 31 |
| 51 bool contains(MemberEntity element) { | 32 bool contains(MemberEntity element) { |
| 52 assert(element.isInstanceMember); | 33 assert(element.isInstanceMember); |
| 53 assert(!element.isAbstract); | 34 assert(!element.isAbstract); |
| 54 String name = element.name; | 35 String name = element.name; |
| 55 FunctionSetNode node = _nodes[name]; | 36 FunctionSetNode node = _nodes[name]; |
| 56 return (node != null) ? node.contains(element) : false; | 37 return (node != null) ? node.contains(element) : false; |
| 57 } | 38 } |
| 58 | 39 |
| 59 /// Returns all the functions that may be invoked with the [selector] on a | 40 /// Returns all the functions that may be invoked with the [selector] on a |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 } else if (closedWorld.isInstantiated(cls)) { | 290 } else if (closedWorld.isInstantiated(cls)) { |
| 310 return new TypeMask.nonNullSubclass(cls, closedWorld); | 291 return new TypeMask.nonNullSubclass(cls, closedWorld); |
| 311 } else { | 292 } else { |
| 312 // TODO(johnniwinther): Avoid the need for this case. | 293 // TODO(johnniwinther): Avoid the need for this case. |
| 313 return const TypeMask.empty(); | 294 return const TypeMask.empty(); |
| 314 } | 295 } |
| 315 }), | 296 }), |
| 316 closedWorld); | 297 closedWorld); |
| 317 } | 298 } |
| 318 } | 299 } |
| OLD | NEW |