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

Side by Side Diff: lib/compiler/implementation/world.dart

Issue 10827359: Fix field-accesses for private fields that were "shadowed" by other private fields. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Update comments. Created 8 years, 4 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') | tests/language/private1.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 class World { 5 class World {
6 Compiler compiler; // Set in populate(). 6 Compiler compiler; // Set in populate().
7 final Map<ClassElement, Set<ClassElement>> subtypes; 7 final Map<ClassElement, Set<ClassElement>> subtypes;
8 8
9 World() : subtypes = new Map<ClassElement, Set<ClassElement>>(); 9 World() : subtypes = new Map<ClassElement, Set<ClassElement>>();
10 10
(...skipping 11 matching lines...) Expand all
22 } 22 }
23 23
24 compiler.resolverWorld.instantiatedClasses.forEach(addSubtypes); 24 compiler.resolverWorld.instantiatedClasses.forEach(addSubtypes);
25 25
26 // Mark the world as populated. 26 // Mark the world as populated.
27 assert(compiler !== null); 27 assert(compiler !== null);
28 this.compiler = compiler; 28 this.compiler = compiler;
29 } 29 }
30 30
31 /** 31 /**
32 * Returns a [MemberSet] that contains the possible targets of a 32 * Returns a [MemberSet] that contains the possible targets of the given
33 * selector named [member] on a receiver whose type is [type]. 33 * [selector] on a receiver with the given [type].
34 */ 34 */
35 MemberSet _memberSetFor(Type type, SourceString member) { 35 MemberSet _memberSetFor(Type type, Selector selector) {
36 assert(compiler !== null); 36 assert(compiler !== null);
37 ClassElement cls = type.element; 37 ClassElement cls = type.element;
38 MemberSet result = new MemberSet(member); 38 SourceString name = selector.name;
39 Element element = cls.lookupMember(member); 39 LibraryElement library = selector.library;
40 MemberSet result = new MemberSet(name);
41 Element element = cls.lookupSelector(selector);
40 if (element !== null) result.add(element); 42 if (element !== null) result.add(element);
41 43
44 bool isPrivate = name.isPrivate();
42 Set<ClassElement> subtypesOfCls = subtypes[cls]; 45 Set<ClassElement> subtypesOfCls = subtypes[cls];
43 if (subtypesOfCls !== null) { 46 if (subtypesOfCls !== null) {
44 for (ClassElement sub in subtypesOfCls) { 47 for (ClassElement sub in subtypesOfCls) {
45 element = sub.lookupLocalMember(member); 48 // Private members from a different library are not visible.
49 if (isPrivate && sub.getLibrary() != library) continue;
50 element = sub.lookupLocalMember(name);
46 if (element !== null) result.add(element); 51 if (element !== null) result.add(element);
47 } 52 }
48 } 53 }
49 return result; 54 return result;
50 } 55 }
51 56
52 /** 57 /**
53 * Returns the single field with the given name, if such a field 58 * Returns the single field with the given [selector]. If there is no such
54 * exists. If there are multple fields, or none, return null. 59 * field, or there are multiple possible fields returns [:null:].
55 */ 60 */
56 VariableElement locateSingleField(Type type, SourceString member) { 61 VariableElement locateSingleField(Type type, Selector selector) {
57 MemberSet memberSet = _memberSetFor(type, member); 62 MemberSet memberSet = _memberSetFor(type, selector);
58 int fieldCount = 0; 63 int fieldCount = 0;
59 int nonFieldCount = 0; 64 int nonFieldCount = 0;
60 VariableElement field; 65 VariableElement field;
61 memberSet.elements.forEach((Element element) { 66 memberSet.elements.forEach((Element element) {
62 if (element.isField()) { 67 if (element.isField()) {
63 field = element; 68 field = element;
64 fieldCount++; 69 fieldCount++;
65 } else { 70 } else {
66 nonFieldCount++; 71 nonFieldCount++;
67 } 72 }
68 }); 73 });
69 return (fieldCount == 1 && nonFieldCount == 0) ? field : null; 74 return (fieldCount == 1 && nonFieldCount == 0) ? field : null;
70 } 75 }
71 76
72 Set<ClassElement> findNoSuchMethodHolders(Type type) { 77 Set<ClassElement> findNoSuchMethodHolders(Type type) {
73 Set<ClassElement> result = new Set<ClassElement>(); 78 Set<ClassElement> result = new Set<ClassElement>();
74 MemberSet memberSet = _memberSetFor(type, Compiler.NO_SUCH_METHOD);
75 Selector noSuchMethodSelector = new Selector.noSuchMethod(); 79 Selector noSuchMethodSelector = new Selector.noSuchMethod();
80 MemberSet memberSet = _memberSetFor(type, noSuchMethodSelector);
76 for (Element element in memberSet.elements) { 81 for (Element element in memberSet.elements) {
77 ClassElement holder = element.getEnclosingClass(); 82 ClassElement holder = element.getEnclosingClass();
78 if (holder !== compiler.objectClass && 83 if (holder !== compiler.objectClass &&
79 noSuchMethodSelector.applies(element, compiler)) { 84 noSuchMethodSelector.applies(element, compiler)) {
80 result.add(holder); 85 result.add(holder);
81 } 86 }
82 } 87 }
83 return result; 88 return result;
84 } 89 }
85 } 90 }
86 91
87 /** 92 /**
88 * A [MemberSet] contains all the possible targets for a selector. 93 * A [MemberSet] contains all the possible targets for a selector.
89 */ 94 */
90 class MemberSet { 95 class MemberSet {
91 final Set<Element> elements; 96 final Set<Element> elements;
92 final SourceString name; 97 final SourceString name;
93 98
94 MemberSet(SourceString this.name) : elements = new Set<Element>(); 99 MemberSet(SourceString this.name) : elements = new Set<Element>();
95 100
96 void add(Element element) { 101 void add(Element element) {
97 elements.add(element); 102 elements.add(element);
98 } 103 }
99 104
100 bool isEmpty() => elements.isEmpty(); 105 bool isEmpty() => elements.isEmpty();
101 } 106 }
OLDNEW
« no previous file with comments | « lib/compiler/implementation/ssa/optimize.dart ('k') | tests/language/private1.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698