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

Side by Side Diff: frog/leg/namer.dart

Issue 9245002: Support getters and setters. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 8 years, 10 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 * The returned id is guaranteed to be a valid JS-id. 59 * The returned id is guaranteed to be a valid JS-id.
60 */ 60 */
61 String _computeGuess(Element element) { 61 String _computeGuess(Element element) {
62 assert(!element.isInstanceMember()); 62 assert(!element.isInstanceMember());
63 if (element.kind == ElementKind.GENERATIVE_CONSTRUCTOR) { 63 if (element.kind == ElementKind.GENERATIVE_CONSTRUCTOR) {
64 FunctionElement functionElement = element; 64 FunctionElement functionElement = element;
65 return instanceMethodName( 65 return instanceMethodName(
66 element.name, functionElement.parameterCount(compiler)); 66 element.name, functionElement.parameterCount(compiler));
67 } else { 67 } else {
68 // TODO(floitsch): deal with named constructors. 68 // TODO(floitsch): deal with named constructors.
69 String name = '${element.name}'; 69 String name;
70 if (element.kind == ElementKind.FUNCTION) { 70 if (element.kind == ElementKind.GETTER) {
71 name = getterName(element.name);
72 } else if (element.kind == ElementKind.SETTER) {
73 name = setterName(element.name);
74 } else if (element.kind == ElementKind.FUNCTION) {
71 FunctionElement functionElement = element; 75 FunctionElement functionElement = element;
72 name = '$name\$${functionElement.parameterCount(compiler)}'; 76 name = '${element.name}\$${functionElement.parameterCount(compiler)}';
77 } else {
78 name = '${element.name}';
73 } 79 }
74 // Prefix the name with '$' if it is reserved. 80 // Prefix the name with '$' if it is reserved.
75 if (jsReserved.contains(name)) { 81 if (jsReserved.contains(name)) {
76 name = "\$$name"; 82 name = "\$$name";
77 assert(!jsReserved.contains(name)); 83 assert(!jsReserved.contains(name));
78 } 84 }
79 return name; 85 return name;
80 } 86 }
81 } 87 }
82 88
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 switch (element.kind) { 125 switch (element.kind) {
120 case ElementKind.VARIABLE: 126 case ElementKind.VARIABLE:
121 case ElementKind.PARAMETER: 127 case ElementKind.PARAMETER:
122 // The name is not guaranteed to be unique. 128 // The name is not guaranteed to be unique.
123 return guess; 129 return guess;
124 130
125 case ElementKind.GENERATIVE_CONSTRUCTOR: 131 case ElementKind.GENERATIVE_CONSTRUCTOR:
126 case ElementKind.FUNCTION: 132 case ElementKind.FUNCTION:
127 case ElementKind.CLASS: 133 case ElementKind.CLASS:
128 case ElementKind.FIELD: 134 case ElementKind.FIELD:
135 case ElementKind.GETTER:
136 case ElementKind.SETTER:
129 // We need to make sure the name is unique. 137 // We need to make sure the name is unique.
130 int usedCount = usedGlobals[guess]; 138 int usedCount = usedGlobals[guess];
131 if (usedCount === null) { 139 if (usedCount === null) {
132 // No element with this name has been used before. 140 // No element with this name has been used before.
133 usedGlobals[guess] = 1; 141 usedGlobals[guess] = 1;
134 globals[element] = guess; 142 globals[element] = guess;
135 return guess; 143 return guess;
136 } else { 144 } else {
137 // Not the first time we see an element with this name. Append a 145 // Not the first time we see an element with this name. Append a
138 // number to make it unique. 146 // number to make it unique.
(...skipping 27 matching lines...) Expand all
166 } 174 }
167 175
168 String isolateBailoutAccess(Element element) { 176 String isolateBailoutAccess(Element element) {
169 return '${isolateAccess(element)}\$bailout'; 177 return '${isolateAccess(element)}\$bailout';
170 } 178 }
171 179
172 String operatorIs(ClassElement element) { 180 String operatorIs(ClassElement element) {
173 return 'is\$${getName(element)}'; 181 return 'is\$${getName(element)}';
174 } 182 }
175 } 183 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698