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

Side by Side Diff: pkg/compiler/lib/src/universe/function_set.dart

Issue 2580403002: Extract ClosedWorldImpl from WorldImpl. (Closed)
Patch Set: Created 4 years 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
OLDNEW
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 '../compiler.dart' show Compiler; 8 import '../compiler.dart' show Compiler;
9 import '../elements/elements.dart'; 9 import '../elements/elements.dart';
10 import '../types/types.dart'; 10 import '../types/types.dart';
11 import '../util/util.dart' show Hashing, Setlet; 11 import '../util/util.dart' show Hashing, Setlet;
12 import '../world.dart' show ClosedWorld; 12 import '../world.dart' show ClosedWorld;
13 import 'selector.dart' show Selector; 13 import 'selector.dart' show Selector;
14 import 'world_builder.dart' show ReceiverConstraint; 14 import 'world_builder.dart' show ReceiverConstraint;
15 15
16 // TODO(kasperl): This actually holds getters and setters just fine 16 class FunctionSetBuilder {
17 // too and stricly they aren't functions. Maybe this needs a better
18 // name -- something like ElementSet seems a bit too generic.
19 class FunctionSet {
20 final ClosedWorld closedWorld;
21 final Map<String, FunctionSetNode> nodes = new Map<String, FunctionSetNode>(); 17 final Map<String, FunctionSetNode> nodes = new Map<String, FunctionSetNode>();
22 FunctionSet(this.closedWorld);
23 18
24 FunctionSetNode newNode(String name) => new FunctionSetNode(name); 19 FunctionSetNode newNode(String name) => new FunctionSetNode(name);
25 20
26 void add(Element element) { 21 void add(Element element) {
27 assert(element.isInstanceMember); 22 assert(element.isInstanceMember);
28 assert(!element.isAbstract); 23 assert(!element.isAbstract);
29 String name = element.name; 24 String name = element.name;
30 FunctionSetNode node = nodes.putIfAbsent(name, () => newNode(name)); 25 FunctionSetNode node = nodes.putIfAbsent(name, () => newNode(name));
31 node.add(element); 26 node.add(element);
32 } 27 }
33 28
34 void remove(Element element) { 29 void remove(Element element) {
35 assert(element.isInstanceMember); 30 assert(element.isInstanceMember);
36 assert(!element.isAbstract); 31 assert(!element.isAbstract);
37 String name = element.name; 32 String name = element.name;
38 FunctionSetNode node = nodes[name]; 33 FunctionSetNode node = nodes[name];
39 if (node != null) { 34 if (node != null) {
40 node.remove(element); 35 node.remove(element);
41 } 36 }
42 } 37 }
43 38
39 FunctionSet close(ClosedWorld closedWorld) {
40 return new FunctionSet(closedWorld, nodes);
41 }
42 }
43
44 // TODO(kasperl): This actually holds getters and setters just fine
45 // too and stricly they aren't functions. Maybe this needs a better
46 // name -- something like ElementSet seems a bit too generic.
47 class FunctionSet {
48 final ClosedWorld closedWorld;
49 final Map<String, FunctionSetNode> nodes;
50
51 FunctionSet(this.closedWorld, this.nodes);
52
44 bool contains(Element element) { 53 bool contains(Element element) {
45 assert(element.isInstanceMember); 54 assert(element.isInstanceMember);
46 assert(!element.isAbstract); 55 assert(!element.isAbstract);
47 String name = element.name; 56 String name = element.name;
48 FunctionSetNode node = nodes[name]; 57 FunctionSetNode node = nodes[name];
49 return (node != null) ? node.contains(element) : false; 58 return (node != null) ? node.contains(element) : false;
50 } 59 }
51 60
52 /// Returns all the functions that may be invoked with the [selector] on a 61 /// Returns all the functions that may be invoked with the [selector] on a
53 /// receiver with the given [constraint]. The returned elements may include 62 /// receiver with the given [constraint]. The returned elements may include
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 } else if (closedWorld.isInstantiated(cls.declaration)) { 301 } else if (closedWorld.isInstantiated(cls.declaration)) {
293 return new TypeMask.nonNullSubclass(cls.declaration, closedWorld); 302 return new TypeMask.nonNullSubclass(cls.declaration, closedWorld);
294 } else { 303 } else {
295 // TODO(johnniwinther): Avoid the need for this case. 304 // TODO(johnniwinther): Avoid the need for this case.
296 return const TypeMask.empty(); 305 return const TypeMask.empty();
297 } 306 }
298 }), 307 }),
299 closedWorld); 308 closedWorld);
300 } 309 }
301 } 310 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698