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

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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 switch (element.kind) { 128 switch (element.kind) {
123 case ElementKind.VARIABLE: 129 case ElementKind.VARIABLE:
124 case ElementKind.PARAMETER: 130 case ElementKind.PARAMETER:
125 // The name is not guaranteed to be unique. 131 // The name is not guaranteed to be unique.
126 return guess; 132 return guess;
127 133
128 case ElementKind.GENERATIVE_CONSTRUCTOR: 134 case ElementKind.GENERATIVE_CONSTRUCTOR:
129 case ElementKind.FUNCTION: 135 case ElementKind.FUNCTION:
130 case ElementKind.CLASS: 136 case ElementKind.CLASS:
131 case ElementKind.FIELD: 137 case ElementKind.FIELD:
138 case ElementKind.GETTER:
139 case ElementKind.SETTER:
132 // We need to make sure the name is unique. 140 // We need to make sure the name is unique.
133 int usedCount = usedGlobals[guess]; 141 int usedCount = usedGlobals[guess];
134 if (usedCount === null) { 142 if (usedCount === null) {
135 // No element with this name has been used before. 143 // No element with this name has been used before.
136 usedGlobals[guess] = 1; 144 usedGlobals[guess] = 1;
137 globals[element] = guess; 145 globals[element] = guess;
138 return guess; 146 return guess;
139 } else { 147 } else {
140 // Not the first time we see an element with this name. Append a 148 // Not the first time we see an element with this name. Append a
141 // number to make it unique. 149 // number to make it unique.
(...skipping 27 matching lines...) Expand all
169 } 177 }
170 178
171 String isolateBailoutAccess(Element element) { 179 String isolateBailoutAccess(Element element) {
172 return '${isolateAccess(element)}\$bailout'; 180 return '${isolateAccess(element)}\$bailout';
173 } 181 }
174 182
175 String operatorIs(ClassElement element) { 183 String operatorIs(ClassElement element) {
176 return 'is\$${getName(element)}'; 184 return 'is\$${getName(element)}';
177 } 185 }
178 } 186 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698