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

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

Issue 10511008: Support overriding fields with fields. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Rebased Created 8 years, 6 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) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 /** 5 /**
6 * Assigns JavaScript identifiers to Dart variables, class-names and members. 6 * Assigns JavaScript identifiers to Dart variables, class-names and members.
7 */ 7 */
8 class Namer { 8 class Namer {
9 final Compiler compiler; 9 final Compiler compiler;
10 10
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 // TODO(floitsch): mangle, while preserving uniqueness. 73 // TODO(floitsch): mangle, while preserving uniqueness.
74 StringBuffer buffer = new StringBuffer(); 74 StringBuffer buffer = new StringBuffer();
75 List<SourceString> names = selector.getOrderedNamedArguments(); 75 List<SourceString> names = selector.getOrderedNamedArguments();
76 for (SourceString argumentName in names) { 76 for (SourceString argumentName in names) {
77 buffer.add(@'$'); 77 buffer.add(@'$');
78 argumentName.printOn(buffer); 78 argumentName.printOn(buffer);
79 } 79 }
80 return '${privateName(lib, name)}\$${selector.argumentCount}$buffer'; 80 return '${privateName(lib, name)}\$${selector.argumentCount}$buffer';
81 } 81 }
82 82
83 String instanceFieldName(LibraryElement lib, SourceString name) { 83 String instanceFieldName(ClassElement cls, SourceString name) {
84 String proposedName = privateName(lib, name); 84 String proposedName = privateName(cls.getLibrary(), name);
85 if (cls.lookupSuperMember(name) !== null) {
86 String libName = getName(cls.getLibrary());
87 String clsName = getName(cls);
88 proposedName = '$libName\$$clsName\$$proposedName';
89 }
85 return safeName(proposedName); 90 return safeName(proposedName);
86 } 91 }
87 92
88 String setterName(LibraryElement lib, SourceString name) { 93 String setterName(LibraryElement lib, SourceString name) {
89 // We dynamically create setters from the field-name. The setter name must 94 // We dynamically create setters from the field-name. The setter name must
90 // therefore be derived from the instance field-name. 95 // therefore be derived from the instance field-name.
91 return 'set\$${instanceFieldName(lib, name)}'; 96 String safeName = safeName(privateName(lib, name));
97 return 'set\$$safeName';
92 } 98 }
93 99
94 String getterName(LibraryElement lib, SourceString name) { 100 String getterName(LibraryElement lib, SourceString name) {
95 // We dynamically create getters from the field-name. The getter name must 101 // We dynamically create getters from the field-name. The getter name must
96 // therefore be derived from the instance field-name. 102 // therefore be derived from the instance field-name.
97 return 'get\$${instanceFieldName(lib, name)}'; 103 String safeName = safeName(privateName(lib, name));
104 return 'get\$$safeName';
98 } 105 }
99 106
100 String getFreshGlobalName(String proposedName) { 107 String getFreshGlobalName(String proposedName) {
101 int usedCount = usedGlobals[proposedName]; 108 int usedCount = usedGlobals[proposedName];
102 if (usedCount === null) { 109 if (usedCount === null) {
103 // No element with this name has been used before. 110 // No element with this name has been used before.
104 usedGlobals[proposedName] = 1; 111 usedGlobals[proposedName] = 1;
105 return proposedName; 112 return proposedName;
106 } else { 113 } else {
107 // Not the first time we see this name. Append a number to make it unique. 114 // Not the first time we see this name. Append a number to make it unique.
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 } else if (element.kind == ElementKind.FUNCTION) { 180 } else if (element.kind == ElementKind.FUNCTION) {
174 FunctionElement functionElement = element; 181 FunctionElement functionElement = element;
175 return instanceMethodName(element.getLibrary(), 182 return instanceMethodName(element.getLibrary(),
176 element.name, 183 element.name,
177 functionElement.parameterCount(compiler)); 184 functionElement.parameterCount(compiler));
178 } else if (element.kind == ElementKind.GETTER) { 185 } else if (element.kind == ElementKind.GETTER) {
179 return getterName(element.getLibrary(), element.name); 186 return getterName(element.getLibrary(), element.name);
180 } else if (element.kind == ElementKind.SETTER) { 187 } else if (element.kind == ElementKind.SETTER) {
181 return setterName(element.getLibrary(), element.name); 188 return setterName(element.getLibrary(), element.name);
182 } else { 189 } else {
183 return instanceFieldName(element.getLibrary(), element.name); 190 return instanceFieldName(element.getEnclosingClass(), element.name);
184 } 191 }
185 } else { 192 } else {
186 // Dealing with a top-level or static element. 193 // Dealing with a top-level or static element.
187 String cached = globals[element]; 194 String cached = globals[element];
188 if (cached !== null) return cached; 195 if (cached !== null) return cached;
189 196
190 String guess = _computeGuess(element); 197 String guess = _computeGuess(element);
191 switch (element.kind) { 198 switch (element.kind) {
192 case ElementKind.VARIABLE: 199 case ElementKind.VARIABLE:
193 case ElementKind.PARAMETER: 200 case ElementKind.PARAMETER:
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 } 241 }
235 242
236 String safeName(String name) { 243 String safeName(String name) {
237 if (jsReserved.contains(name) || name.startsWith('\$')) { 244 if (jsReserved.contains(name) || name.startsWith('\$')) {
238 name = "\$$name"; 245 name = "\$$name";
239 assert(!jsReserved.contains(name)); 246 assert(!jsReserved.contains(name));
240 } 247 }
241 return name; 248 return name;
242 } 249 }
243 } 250 }
OLDNEW
« no previous file with comments | « dart/lib/compiler/implementation/emitter.dart ('k') | dart/lib/compiler/implementation/ssa/builder.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698