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

Side by Side Diff: lib/compiler/implementation/universe/function_set.dart

Issue 10911181: Collect getters in a FunctionSet while resolving. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 3 months 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 | Annotate | Revision Log
« no previous file with comments | « lib/compiler/implementation/ssa/optimize.dart ('k') | lib/compiler/implementation/world.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // TODO(kasperl): This actually holds getters and setters just fine 5 // TODO(kasperl): This actually holds getters and setters just fine
6 // too and stricly they aren't functions. Maybe this needs a better 6 // too and stricly they aren't functions. Maybe this needs a better
7 // name -- something like ElementSet seems a bit too generic. 7 // name -- something like ElementSet seems a bit too generic.
8 class FunctionSet extends PartialTypeTree { 8 class FunctionSet extends PartialTypeTree {
9 9
10 FunctionSet(Compiler compiler) : super(compiler); 10 FunctionSet(Compiler compiler) : super(compiler);
(...skipping 28 matching lines...) Expand all
39 * Returns all elements that may be invoked with the given [selector]. 39 * Returns all elements that may be invoked with the given [selector].
40 */ 40 */
41 Set<Element> filterBySelector(Selector selector) { 41 Set<Element> filterBySelector(Selector selector) {
42 // TODO(kasperl): For now, we use a different implementation for 42 // TODO(kasperl): For now, we use a different implementation for
43 // filtering if the tree contains interface subtypes. 43 // filtering if the tree contains interface subtypes.
44 return containsInterfaceSubtypes 44 return containsInterfaceSubtypes
45 ? filterAllBySelector(selector) 45 ? filterAllBySelector(selector)
46 : filterHierarchyBySelector(selector); 46 : filterHierarchyBySelector(selector);
47 } 47 }
48 48
49 /**
50 * Returns whether the set has any element matching the given
51 * [selector].
52 */
53 bool hasAnyElementMatchingSelector(Selector selector) {
54 // TODO(kasperl): For now, we use a different implementation for
55 // filtering if the tree contains interface subtypes.
56 return containsInterfaceSubtypes
57 ? hasAnyInAll(selector)
58 : hasAnyInHierarchy(selector);
59 }
60
49 Set<Element> filterAllBySelector(Selector selector) { 61 Set<Element> filterAllBySelector(Selector selector) {
50 Set<Element> result = new Set<Element>(); 62 Set<Element> result = new Set<Element>();
51 if (root === null) return result; 63 if (root === null) return result;
52 root.visitRecursively((FunctionSetNode node) { 64 root.visitRecursively((FunctionSetNode node) {
53 Element member = node.membersByName[selector.name]; 65 Element member = node.membersByName[selector.name];
54 // Since we're running through the entire tree we have to use 66 // Since we're running through the entire tree we have to use
55 // the applies method that takes types into account. 67 // the applies method that takes types into account.
56 if (member !== null && selector.applies(member, compiler)) { 68 if (member !== null && selector.applies(member, compiler)) {
57 result.add(member); 69 result.add(member);
58 } 70 }
59 return true; 71 return true;
60 }); 72 });
61 return result; 73 return result;
62 } 74 }
63 75
64 Set<Element> filterHierarchyBySelector(Selector selector) { 76 Set<Element> filterHierarchyBySelector(Selector selector) {
65 Set<Element> result = new Set<Element>(); 77 Set<Element> result = new Set<Element>();
66 if (root === null) return result; 78 if (root === null) return result;
67 visitHierarchy(selectorType(selector), (FunctionSetNode node) { 79 visitHierarchy(selectorType(selector), (FunctionSetNode node) {
68 Element member = node.membersByName[selector.name]; 80 Element member = node.membersByName[selector.name];
69 if (member !== null && selector.appliesUntyped(member, compiler)) { 81 if (member !== null && selector.appliesUntyped(member, compiler)) {
70 result.add(member); 82 result.add(member);
71 } 83 }
72 return true; 84 return true;
73 }); 85 });
74 return result; 86 return result;
75 } 87 }
76 88
89 bool hasAnyInAll(Selector selector) {
90 bool result = false;
91 if (root === null) return result;
92 root.visitRecursively((FunctionSetNode node) {
93 Element member = node.membersByName[selector.name];
94 // Since we're running through the entire tree we have to use
95 // the applies method that takes types into account.
96 if (member !== null && selector.applies(member, compiler)) {
97 result = true;
98 // End the traversal.
99 return false;
100 }
101 return true;
102 });
103 return result;
104 }
105
106 bool hasAnyInHierarchy(Selector selector) {
107 bool result = false;
108 if (root === null) return result;
109 visitHierarchy(selectorType(selector), (FunctionSetNode node) {
110 Element member = node.membersByName[selector.name];
111 if (member !== null && selector.appliesUntyped(member, compiler)) {
112 result = true;
113 // End the traversal.
114 return false;
115 }
116 return true;
117 });
118 return result;
119 }
120
77 } 121 }
78 122
79 class FunctionSetNode extends PartialTypeTreeNode { 123 class FunctionSetNode extends PartialTypeTreeNode {
80 124
81 final Map<SourceString, Element> membersByName; 125 final Map<SourceString, Element> membersByName;
82 126
83 FunctionSetNode(ClassElement type) : super(type), 127 FunctionSetNode(ClassElement type) : super(type),
84 membersByName = new Map<SourceString, Element>(); 128 membersByName = new Map<SourceString, Element>();
85 129
86 } 130 }
OLDNEW
« no previous file with comments | « lib/compiler/implementation/ssa/optimize.dart ('k') | lib/compiler/implementation/world.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698