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

Side by Side Diff: dart/sdk/lib/_internal/compiler/implementation/js_backend/namer.dart

Issue 10905211: Clean up operator names. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Address review comments Created 8 years, 1 month 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 part of js_backend; 5 part of js_backend;
6 6
7 /** 7 /**
8 * Assigns JavaScript identifiers to Dart variables, class-names and members. 8 * Assigns JavaScript identifiers to Dart variables, class-names and members.
9 */ 9 */
10 class Namer { 10 class Namer {
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 // If a library name does not start with the [LIBRARY_PREFIX] then our 104 // If a library name does not start with the [LIBRARY_PREFIX] then our
105 // assumptions about clashing with mangled private members do not hold. 105 // assumptions about clashing with mangled private members do not hold.
106 assert(libName.startsWith(LIBRARY_PREFIX)); 106 assert(libName.startsWith(LIBRARY_PREFIX));
107 return '_$libName$nameString'; 107 return '_$libName$nameString';
108 } else { 108 } else {
109 return name.slowToString(); 109 return name.slowToString();
110 } 110 }
111 } 111 }
112 112
113 String instanceMethodName(FunctionElement element) { 113 String instanceMethodName(FunctionElement element) {
114 SourceString name = element.name; 114 SourceString name = Elements.operatorNameToIdentifier(element.name);
115 LibraryElement lib = element.getLibrary(); 115 LibraryElement lib = element.getLibrary();
116 if (element.kind == ElementKind.GENERATIVE_CONSTRUCTOR_BODY) { 116 if (element.kind == ElementKind.GENERATIVE_CONSTRUCTOR_BODY) {
117 ConstructorBodyElement bodyElement = element; 117 ConstructorBodyElement bodyElement = element;
118 name = bodyElement.constructor.name; 118 name = bodyElement.constructor.name;
119 } 119 }
120 FunctionSignature signature = element.computeSignature(compiler); 120 FunctionSignature signature = element.computeSignature(compiler);
121 String methodName = 121 String methodName =
122 '${privateName(lib, name)}\$${signature.parameterCount}'; 122 '${privateName(lib, name)}\$${signature.parameterCount}';
123 if (!signature.optionalParametersAreNamed) { 123 if (!signature.optionalParametersAreNamed) {
124 return methodName; 124 return methodName;
125 } else if (!signature.optionalParameters.isEmpty) { 125 } else if (!signature.optionalParameters.isEmpty) {
126 StringBuffer buffer = new StringBuffer(); 126 StringBuffer buffer = new StringBuffer();
127 signature.orderedOptionalParameters.forEach((Element element) { 127 signature.orderedOptionalParameters.forEach((Element element) {
128 buffer.add('\$${JsNames.getValid(element.name.slowToString())}'); 128 buffer.add('\$${JsNames.getValid(element.name.slowToString())}');
129 }); 129 });
130 return '$methodName$buffer'; 130 return '$methodName$buffer';
131 } 131 }
132 } 132 }
133 133
134 String publicInstanceMethodNameByArity(SourceString name, int arity) { 134 String publicInstanceMethodNameByArity(SourceString name, int arity) {
135 name = Elements.operatorNameToIdentifier(name);
135 assert(!name.isPrivate()); 136 assert(!name.isPrivate());
136 return '${name.slowToString()}\$$arity'; 137 return '${name.slowToString()}\$$arity';
137 } 138 }
138 139
139 String instanceMethodInvocationName(LibraryElement lib, SourceString name, 140 String instanceMethodInvocationName(LibraryElement lib, SourceString name,
140 Selector selector) { 141 Selector selector) {
142 name = Elements.operatorNameToIdentifier(name);
141 // TODO(floitsch): mangle, while preserving uniqueness. 143 // TODO(floitsch): mangle, while preserving uniqueness.
142 StringBuffer buffer = new StringBuffer(); 144 StringBuffer buffer = new StringBuffer();
143 List<SourceString> names = selector.getOrderedNamedArguments(); 145 List<SourceString> names = selector.getOrderedNamedArguments();
144 for (SourceString argumentName in names) { 146 for (SourceString argumentName in names) {
145 buffer.add(r'$'); 147 buffer.add(r'$');
146 argumentName.printOn(buffer); 148 argumentName.printOn(buffer);
147 } 149 }
148 return '${privateName(lib, name)}\$${selector.argumentCount}$buffer'; 150 return '${privateName(lib, name)}\$${selector.argumentCount}$buffer';
149 } 151 }
150 152
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 } 326 }
325 327
326 String safeName(String name) { 328 String safeName(String name) {
327 if (jsReserved.contains(name) || name.startsWith('\$')) { 329 if (jsReserved.contains(name) || name.startsWith('\$')) {
328 name = "\$$name"; 330 name = "\$$name";
329 assert(!jsReserved.contains(name)); 331 assert(!jsReserved.contains(name));
330 } 332 }
331 return name; 333 return name;
332 } 334 }
333 } 335 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698