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

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

Issue 10834270: Implement call operator. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 4 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 17 matching lines...) Expand all
28 usedGlobals = new Map<String, int>(), 28 usedGlobals = new Map<String, int>(),
29 usedPrivateNames = new Map<String, Set<LibraryElement>>(), 29 usedPrivateNames = new Map<String, Set<LibraryElement>>(),
30 shortPrivateNameOwners = new Map<String, LibraryElement>(); 30 shortPrivateNameOwners = new Map<String, LibraryElement>();
31 31
32 final String CURRENT_ISOLATE = @'$'; 32 final String CURRENT_ISOLATE = @'$';
33 final String ISOLATE = 'Isolate'; 33 final String ISOLATE = 'Isolate';
34 final String ISOLATE_PROPERTIES = @"$isolateProperties"; 34 final String ISOLATE_PROPERTIES = @"$isolateProperties";
35 /** Some closures must contain their name. The name is stored in 35 /** Some closures must contain their name. The name is stored in
36 * [STATIC_CLOSURE_NAME_NAME]. */ 36 * [STATIC_CLOSURE_NAME_NAME]. */
37 final String STATIC_CLOSURE_NAME_NAME = @'$name'; 37 final String STATIC_CLOSURE_NAME_NAME = @'$name';
38 final SourceString CLOSURE_INVOCATION_NAME = const SourceString(@'$call'); 38 final SourceString CLOSURE_INVOCATION_NAME = const SourceString('call');
39 39
40 40
41 String closureInvocationName(Selector selector) { 41 String closureInvocationName(Selector selector) {
42 // TODO(floitsch): mangle, while not conflicting with instance names. 42 // TODO(floitsch): mangle, while not conflicting with instance names.
43 return instanceMethodInvocationName(null, CLOSURE_INVOCATION_NAME, 43 return instanceMethodInvocationName(null, CLOSURE_INVOCATION_NAME,
44 selector); 44 selector);
45 } 45 }
46 46
47 /** Returns a non-unique name for the given closure element. */ 47 /** Returns a non-unique name for the given closure element. */
48 String closureName(Element element) { 48 String closureName(Element element) {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 // If a library name does not start with the [LIBRARY_PREFIX] then our 100 // If a library name does not start with the [LIBRARY_PREFIX] then our
101 // assumptions about clashing with mangled private members do not hold. 101 // assumptions about clashing with mangled private members do not hold.
102 assert(libName.startsWith(LIBRARY_PREFIX)); 102 assert(libName.startsWith(LIBRARY_PREFIX));
103 return '_$libName$nameString'; 103 return '_$libName$nameString';
104 } else { 104 } else {
105 return name.slowToString(); 105 return name.slowToString();
106 } 106 }
107 } 107 }
108 108
109 String instanceMethodName(LibraryElement lib, SourceString name, int arity) { 109 String instanceMethodName(LibraryElement lib, SourceString name, int arity) {
110 if (name == const SourceString("call")) name = CLOSURE_INVOCATION_NAME;
kasperl 2012/08/10 10:16:28 What's the intent here? If the name is already 'ca
floitsch 2012/08/10 12:19:16 Changed: CLOSURE_INVOCATION_NAME is now initialize
110 return '${privateName(lib, name)}\$$arity'; 111 return '${privateName(lib, name)}\$$arity';
111 } 112 }
112 113
113 String instanceMethodInvocationName(LibraryElement lib, SourceString name, 114 String instanceMethodInvocationName(LibraryElement lib, SourceString name,
114 Selector selector) { 115 Selector selector) {
116 if (name == const SourceString("call")) name = CLOSURE_INVOCATION_NAME;
115 // TODO(floitsch): mangle, while preserving uniqueness. 117 // TODO(floitsch): mangle, while preserving uniqueness.
116 StringBuffer buffer = new StringBuffer(); 118 StringBuffer buffer = new StringBuffer();
117 List<SourceString> names = selector.getOrderedNamedArguments(); 119 List<SourceString> names = selector.getOrderedNamedArguments();
118 for (SourceString argumentName in names) { 120 for (SourceString argumentName in names) {
119 buffer.add(@'$'); 121 buffer.add(@'$');
120 argumentName.printOn(buffer); 122 argumentName.printOn(buffer);
121 } 123 }
122 return '${privateName(lib, name)}\$${selector.argumentCount}$buffer'; 124 return '${privateName(lib, name)}\$${selector.argumentCount}$buffer';
123 } 125 }
124 126
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 } 285 }
284 286
285 String safeName(String name) { 287 String safeName(String name) {
286 if (jsReserved.contains(name) || name.startsWith('\$')) { 288 if (jsReserved.contains(name) || name.startsWith('\$')) {
287 name = "\$$name"; 289 name = "\$$name";
288 assert(!jsReserved.contains(name)); 290 assert(!jsReserved.contains(name));
289 } 291 }
290 return name; 292 return name;
291 } 293 }
292 } 294 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698