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

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

Issue 10970038: Convert raw strings in compiler (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 3 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 12 matching lines...) Expand all
23 final Map<String, LibraryElement> shortPrivateNameOwners; 23 final Map<String, LibraryElement> shortPrivateNameOwners;
24 24
25 final Map<Constant, String> constantNames; 25 final Map<Constant, String> constantNames;
26 26
27 Namer(this.compiler) 27 Namer(this.compiler)
28 : globals = new Map<Element, String>(), 28 : globals = new Map<Element, String>(),
29 usedGlobals = new Map<String, int>(), 29 usedGlobals = new Map<String, int>(),
30 shortPrivateNameOwners = new Map<String, LibraryElement>(), 30 shortPrivateNameOwners = new Map<String, LibraryElement>(),
31 constantNames = new Map<Constant, String>(); 31 constantNames = new Map<Constant, String>();
32 32
33 final String CURRENT_ISOLATE = @'$'; 33 final String CURRENT_ISOLATE = r'$';
34 final String ISOLATE = 'Isolate'; 34 final String ISOLATE = 'Isolate';
35 final String ISOLATE_PROPERTIES = @"$isolateProperties"; 35 final String ISOLATE_PROPERTIES = r"$isolateProperties";
36 /** Some closures must contain their name. The name is stored in 36 /** Some closures must contain their name. The name is stored in
37 * [STATIC_CLOSURE_NAME_NAME]. */ 37 * [STATIC_CLOSURE_NAME_NAME]. */
38 final String STATIC_CLOSURE_NAME_NAME = @'$name'; 38 final String STATIC_CLOSURE_NAME_NAME = r'$name';
39 static const SourceString CLOSURE_INVOCATION_NAME = 39 static const SourceString CLOSURE_INVOCATION_NAME =
40 Compiler.CALL_OPERATOR_NAME; 40 Compiler.CALL_OPERATOR_NAME;
41 41
42 String constantName(Constant constant) { 42 String constantName(Constant constant) {
43 // In the current implementation it doesn't make sense to give names to 43 // In the current implementation it doesn't make sense to give names to
44 // function constants since the function-implementation itself serves as 44 // function constants since the function-implementation itself serves as
45 // constant and can be accessed directly. 45 // constant and can be accessed directly.
46 assert(!constant.isFunction()); 46 assert(!constant.isFunction());
47 String result = constantNames[constant]; 47 String result = constantNames[constant];
48 if (result === null) { 48 if (result === null) {
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 assert(!name.isPrivate()); 124 assert(!name.isPrivate());
125 return '${name.slowToString()}\$$arity'; 125 return '${name.slowToString()}\$$arity';
126 } 126 }
127 127
128 String instanceMethodInvocationName(LibraryElement lib, SourceString name, 128 String instanceMethodInvocationName(LibraryElement lib, SourceString name,
129 Selector selector) { 129 Selector selector) {
130 // TODO(floitsch): mangle, while preserving uniqueness. 130 // TODO(floitsch): mangle, while preserving uniqueness.
131 StringBuffer buffer = new StringBuffer(); 131 StringBuffer buffer = new StringBuffer();
132 List<SourceString> names = selector.getOrderedNamedArguments(); 132 List<SourceString> names = selector.getOrderedNamedArguments();
133 for (SourceString argumentName in names) { 133 for (SourceString argumentName in names) {
134 buffer.add(@'$'); 134 buffer.add(r'$');
135 argumentName.printOn(buffer); 135 argumentName.printOn(buffer);
136 } 136 }
137 return '${privateName(lib, name)}\$${selector.argumentCount}$buffer'; 137 return '${privateName(lib, name)}\$${selector.argumentCount}$buffer';
138 } 138 }
139 139
140 String instanceFieldName(LibraryElement libraryElement, SourceString name) { 140 String instanceFieldName(LibraryElement libraryElement, SourceString name) {
141 String proposedName = privateName(libraryElement, name); 141 String proposedName = privateName(libraryElement, name);
142 return safeName(proposedName); 142 return safeName(proposedName);
143 } 143 }
144 144
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 } 303 }
304 304
305 String safeName(String name) { 305 String safeName(String name) {
306 if (jsReserved.contains(name) || name.startsWith('\$')) { 306 if (jsReserved.contains(name) || name.startsWith('\$')) {
307 name = "\$$name"; 307 name = "\$$name";
308 assert(!jsReserved.contains(name)); 308 assert(!jsReserved.contains(name));
309 } 309 }
310 return name; 310 return name;
311 } 311 }
312 } 312 }
OLDNEW
« no previous file with comments | « lib/compiler/implementation/js_backend/emitter.dart ('k') | lib/compiler/implementation/lib/interceptors.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698