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

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

Issue 10919003: Fix issue with the partial type tree and implemented interfaces. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix comment. 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 | « no previous file | lib/compiler/implementation/js_backend/partial_type_tree.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);
11 11
12 FunctionSetNode newNode(ClassElement type) 12 FunctionSetNode newSpecializedNode(ClassElement type)
13 => new FunctionSetNode(type); 13 => new FunctionSetNode(type);
14 14
15 // TODO(kasperl): Allow static members too? 15 // TODO(kasperl): Allow static members too?
16 void add(Element element) { 16 void add(Element element) {
17 assert(element.isMember()); 17 assert(element.isMember());
18 FunctionSetNode node = findNode(element.getEnclosingClass(), true); 18 FunctionSetNode node = findNode(element.getEnclosingClass(), true);
19 node.membersByName[element.name] = element; 19 node.membersByName[element.name] = element;
20 } 20 }
21 21
22 // TODO(kasperl): Allow static members too? 22 // TODO(kasperl): Allow static members too?
23 void remove(Element element) { 23 void remove(Element element) {
24 assert(element.isMember()); 24 assert(element.isMember());
25 FunctionSetNode node = findNode(element.getEnclosingClass(), false); 25 FunctionSetNode node = findNode(element.getEnclosingClass(), false);
26 if (node !== null) node.membersByName.remove(element.name); 26 if (node !== null) node.membersByName.remove(element.name);
27 } 27 }
28 28
29 // TODO(kasperl): Allow static members too? 29 // TODO(kasperl): Allow static members too?
30 bool contains(Element element) { 30 bool contains(Element element) {
31 assert(element.isMember()); 31 assert(element.isMember());
32 FunctionSetNode node = findNode(element.getEnclosingClass(), false); 32 FunctionSetNode node = findNode(element.getEnclosingClass(), false);
33 return (node !== null) 33 return (node !== null)
34 ? node.membersByName.containsKey(element.name) 34 ? node.membersByName.containsKey(element.name)
35 : false; 35 : false;
36 } 36 }
37 37
38 /** 38 /**
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
43 // filtering if the tree contains interface subtypes.
44 return containsInterfaceSubtypes
45 ? filterAllBySelector(selector)
46 : filterHierarchyBySelector(selector);
47 }
48
49 Set<Element> filterAllBySelector(Selector selector) {
50 Set<Element> result = new Set<Element>();
51 if (root === null) return result;
52 root.visitRecursively((FunctionSetNode node) {
53 Element member = node.membersByName[selector.name];
54 // Since we're running through the entire tree we have to use
55 // the applies method that takes types into account.
56 if (member !== null && selector.applies(member, compiler)) {
57 result.add(member);
58 }
59 return true;
60 });
61 return result;
62 }
63
64 Set<Element> filterHierarchyBySelector(Selector selector) {
42 Set<Element> result = new Set<Element>(); 65 Set<Element> result = new Set<Element>();
43 if (root === null) return result; 66 if (root === null) return result;
44 visitHierarchy(selectorType(selector), (FunctionSetNode node) { 67 visitHierarchy(selectorType(selector), (FunctionSetNode node) {
45 Element member = node.membersByName[selector.name]; 68 Element member = node.membersByName[selector.name];
46 if (member !== null && selector.appliesUntyped(member, compiler)) { 69 if (member !== null && selector.appliesUntyped(member, compiler)) {
47 result.add(member); 70 result.add(member);
48 } 71 }
49 return true; 72 return true;
50 }); 73 });
51 return result; 74 return result;
52 } 75 }
53 76
54 } 77 }
55 78
56 class FunctionSetNode extends PartialTypeTreeNode { 79 class FunctionSetNode extends PartialTypeTreeNode {
57 80
58 final Map<SourceString, Element> membersByName; 81 final Map<SourceString, Element> membersByName;
59 82
60 FunctionSetNode(ClassElement type) : super(type), 83 FunctionSetNode(ClassElement type) : super(type),
61 membersByName = new Map<SourceString, Element>(); 84 membersByName = new Map<SourceString, Element>();
62 85
63 } 86 }
OLDNEW
« no previous file with comments | « no previous file | lib/compiler/implementation/js_backend/partial_type_tree.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698