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

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
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 an element matching this selector.
kasperl 2012/09/11 07:39:11 has any elements matching the given [selector].
ngeoffray 2012/09/11 08:51:08 Done.
51 */
52 bool hasOneElementMatchingSelector(Selector selector) {
kasperl 2012/09/11 07:39:11 hasAnyElementsMatchingSelector would be more corre
ngeoffray 2012/09/11 08:51:08 Done.
53 // TODO(kasperl): For now, we use a different implementation for
54 // filtering if the tree contains interface subtypes.
55 return containsInterfaceSubtypes
56 ? hasOneInAll(selector)
57 : hasOneInHierarchy(selector);
58 }
59
49 Set<Element> filterAllBySelector(Selector selector) { 60 Set<Element> filterAllBySelector(Selector selector) {
50 Set<Element> result = new Set<Element>(); 61 Set<Element> result = new Set<Element>();
51 if (root === null) return result; 62 if (root === null) return result;
52 root.visitRecursively((FunctionSetNode node) { 63 root.visitRecursively((FunctionSetNode node) {
53 Element member = node.membersByName[selector.name]; 64 Element member = node.membersByName[selector.name];
54 // Since we're running through the entire tree we have to use 65 // Since we're running through the entire tree we have to use
55 // the applies method that takes types into account. 66 // the applies method that takes types into account.
56 if (member !== null && selector.applies(member, compiler)) { 67 if (member !== null && selector.applies(member, compiler)) {
57 result.add(member); 68 result.add(member);
58 } 69 }
59 return true; 70 return true;
60 }); 71 });
61 return result; 72 return result;
62 } 73 }
63 74
64 Set<Element> filterHierarchyBySelector(Selector selector) { 75 Set<Element> filterHierarchyBySelector(Selector selector) {
65 Set<Element> result = new Set<Element>(); 76 Set<Element> result = new Set<Element>();
66 if (root === null) return result; 77 if (root === null) return result;
67 visitHierarchy(selectorType(selector), (FunctionSetNode node) { 78 visitHierarchy(selectorType(selector), (FunctionSetNode node) {
68 Element member = node.membersByName[selector.name]; 79 Element member = node.membersByName[selector.name];
69 if (member !== null && selector.appliesUntyped(member, compiler)) { 80 if (member !== null && selector.appliesUntyped(member, compiler)) {
70 result.add(member); 81 result.add(member);
71 } 82 }
72 return true; 83 return true;
73 }); 84 });
74 return result; 85 return result;
75 } 86 }
76 87
88 bool hasOneInAll(Selector selector) {
89 bool result = false;
90 if (root === null) return result;
91 root.visitRecursively((FunctionSetNode node) {
92 Element member = node.membersByName[selector.name];
93 // Since we're running through the entire tree we have to use
94 // the applies method that takes types into account.
95 if (member !== null && selector.applies(member, compiler)) {
96 result = true;
97 // End the traversal.
98 return false;
99 }
100 return true;
101 });
102 return result;
103 }
104
105 bool hasOneInHierarchy(Selector selector) {
106 bool result = false;
107 if (root === null) return result;
108 visitHierarchy(selectorType(selector), (FunctionSetNode node) {
109 Element member = node.membersByName[selector.name];
110 if (member !== null && selector.appliesUntyped(member, compiler)) {
111 result = true;
112 // End the traversal.
113 return false;
114 }
115 return true;
116 });
117 return result;
118 }
119
77 } 120 }
78 121
79 class FunctionSetNode extends PartialTypeTreeNode { 122 class FunctionSetNode extends PartialTypeTreeNode {
80 123
81 final Map<SourceString, Element> membersByName; 124 final Map<SourceString, Element> membersByName;
82 125
83 FunctionSetNode(ClassElement type) : super(type), 126 FunctionSetNode(ClassElement type) : super(type),
84 membersByName = new Map<SourceString, Element>(); 127 membersByName = new Map<SourceString, Element>();
85 128
86 } 129 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698