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

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

Issue 10310060: Generate getters and setters dynamically. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Simplify by using a bool. Created 8 years, 7 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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 } 62 }
63 return '${privateName(lib, name)}\$${selector.argumentCount}$buffer'; 63 return '${privateName(lib, name)}\$${selector.argumentCount}$buffer';
64 } 64 }
65 65
66 String instanceFieldName(LibraryElement lib, SourceString name) { 66 String instanceFieldName(LibraryElement lib, SourceString name) {
67 String proposedName = privateName(lib, name); 67 String proposedName = privateName(lib, name);
68 return safeName(proposedName); 68 return safeName(proposedName);
69 } 69 }
70 70
71 String setterName(LibraryElement lib, SourceString name) { 71 String setterName(LibraryElement lib, SourceString name) {
72 return 'set\$${privateName(lib, name)}'; 72 // We dynamically create setters from the field-name. The setter name must
73 // therefore be derived from the instance field-name.
74 return 'set\$${instanceFieldName(lib, name)}';
73 } 75 }
74 76
75 String getterName(LibraryElement lib, SourceString name) { 77 String getterName(LibraryElement lib, SourceString name) {
76 return 'get\$${privateName(lib, name)}'; 78 // We dynamically create getters from the field-name. The getter name must
79 // therefore be derived from the instance field-name.
80 return 'get\$${instanceFieldName(lib, name)}';
77 } 81 }
78 82
79 String getFreshGlobalName(String proposedName) { 83 String getFreshGlobalName(String proposedName) {
80 int usedCount = usedGlobals[proposedName]; 84 int usedCount = usedGlobals[proposedName];
81 if (usedCount === null) { 85 if (usedCount === null) {
82 // No element with this name has been used before. 86 // No element with this name has been used before.
83 usedGlobals[proposedName] = 1; 87 usedGlobals[proposedName] = 1;
84 return proposedName; 88 return proposedName;
85 } else { 89 } else {
86 // Not the first time we see this name. Append a number to make it unique. 90 // Not the first time we see this name. Append a number to make it unique.
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 } 215 }
212 216
213 String safeName(String name) { 217 String safeName(String name) {
214 if (jsReserved.contains(name) || name.startsWith('\$')) { 218 if (jsReserved.contains(name) || name.startsWith('\$')) {
215 name = "\$$name"; 219 name = "\$$name";
216 assert(!jsReserved.contains(name)); 220 assert(!jsReserved.contains(name));
217 } 221 }
218 return name; 222 return name;
219 } 223 }
220 } 224 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698