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

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

Issue 10915083: Change assert implementation to not depend on a top-level function called 'assert'. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address review comments. 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
11 static Set<String> _jsReserved = null; 11 static Set<String> _jsReserved = null;
12 Set<String> get jsReserved { 12 Set<String> get jsReserved {
13 if (_jsReserved === null) { 13 if (_jsReserved === null) {
14 _jsReserved = new Set<String>(); 14 _jsReserved = new Set<String>();
15 _jsReserved.addAll(JsNames.javaScriptKeywords); 15 _jsReserved.addAll(JsNames.javaScriptKeywords);
16 _jsReserved.addAll(JsNames.reservedPropertySymbols); 16 _jsReserved.addAll(JsNames.reservedPropertySymbols);
17 } 17 }
18 return _jsReserved; 18 return _jsReserved;
19 } 19 }
20 20
21 final Map<Element, String> globals; 21 Map<Element, String> globals;
22 final Map<String, int> usedGlobals; 22 Map<String, int> usedGlobals;
23 final Map<String, LibraryElement> shortPrivateNameOwners; 23 Map<String, LibraryElement> shortPrivateNameOwners;
24
25 final Map<Constant, String> constantNames;
26 24
27 Namer(this.compiler) 25 Namer(this.compiler)
28 : globals = new Map<Element, String>(), 26 : globals = new Map<Element, String>(),
29 usedGlobals = new Map<String, int>(), 27 usedGlobals = new Map<String, int>(),
30 shortPrivateNameOwners = new Map<String, LibraryElement>(), 28 shortPrivateNameOwners = new Map<String, LibraryElement>();
31 constantNames = new Map<Constant, String>();
32 29
33 final String CURRENT_ISOLATE = @'$'; 30 final String CURRENT_ISOLATE = @'$';
34 final String ISOLATE = 'Isolate'; 31 final String ISOLATE = 'Isolate';
35 final String ISOLATE_PROPERTIES = @"$isolateProperties"; 32 final String ISOLATE_PROPERTIES = @"$isolateProperties";
36 /** Some closures must contain their name. The name is stored in 33 /** Some closures must contain their name. The name is stored in
37 * [STATIC_CLOSURE_NAME_NAME]. */ 34 * [STATIC_CLOSURE_NAME_NAME]. */
38 final String STATIC_CLOSURE_NAME_NAME = @'$name'; 35 final String STATIC_CLOSURE_NAME_NAME = @'$name';
39 static const SourceString CLOSURE_INVOCATION_NAME = 36 static const SourceString CLOSURE_INVOCATION_NAME =
40 Compiler.CALL_OPERATOR_NAME; 37 Compiler.CALL_OPERATOR_NAME;
41 38
42 String constantName(Constant constant) {
43 // In the current implementation it doesn't make sense to give names to
44 // function constants since the function-implementation itself serves as
45 // constant and can be accessed directly.
46 assert(!constant.isFunction());
47 String result = constantNames[constant];
48 if (result === null) {
49 result = getFreshGlobalName("CTC");
50 constantNames[constant] = result;
51 }
52 return result;
53 }
54 39
55 String closureInvocationName(Selector selector) { 40 String closureInvocationName(Selector selector) {
56 // TODO(floitsch): mangle, while not conflicting with instance names. 41 // TODO(floitsch): mangle, while not conflicting with instance names.
57 return instanceMethodInvocationName(null, CLOSURE_INVOCATION_NAME, 42 return instanceMethodInvocationName(null, CLOSURE_INVOCATION_NAME,
58 selector); 43 selector);
59 } 44 }
60 45
61 String breakLabelName(LabelElement label) { 46 String breakLabelName(LabelElement label) {
62 return '\$${label.labelName}\$${label.target.nestingLevel}'; 47 return '\$${label.labelName}\$${label.target.nestingLevel}';
63 } 48 }
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 } 272 }
288 273
289 String safeName(String name) { 274 String safeName(String name) {
290 if (jsReserved.contains(name) || name.startsWith('\$')) { 275 if (jsReserved.contains(name) || name.startsWith('\$')) {
291 name = "\$$name"; 276 name = "\$$name";
292 assert(!jsReserved.contains(name)); 277 assert(!jsReserved.contains(name));
293 } 278 }
294 return name; 279 return name;
295 } 280 }
296 } 281 }
OLDNEW
« no previous file with comments | « lib/compiler/implementation/js_backend/js_backend.dart ('k') | lib/compiler/implementation/lib/js_helper.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698