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

Side by Side Diff: sdk/lib/_internal/compiler/implementation/mirror_renamer/renamer.dart

Issue 23593002: Only emit members in mirror helper symbolsmap. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Changed comment. Created 7 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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 mirror_renamer; 5 part of mirror_renamer;
6 6
7 class MirrorRenamer { 7 class MirrorRenamer {
8 static const String MIRROR_HELPER_GET_NAME_FUNCTION = 'helperGetName'; 8 static const String MIRROR_HELPER_GET_NAME_FUNCTION = 'helperGetName';
9 static const String MIRROR_HELPER_LIBRARY_NAME = '_mirror_helper'; 9 static const String MIRROR_HELPER_LIBRARY_NAME = '_mirror_helper';
10 static const String MIRROR_HELPER_SYMBOLS_MAP_NAME = '_SYMBOLS'; 10 static const String MIRROR_HELPER_SYMBOLS_MAP_NAME = '_SYMBOLS';
(...skipping 29 matching lines...) Expand all
40 } 40 }
41 41
42 /** 42 /**
43 * Adds a toplevel node to the output containing a map from the mangled 43 * Adds a toplevel node to the output containing a map from the mangled
44 * to the unmangled names and replaces calls to MirrorSystem.getName() 44 * to the unmangled names and replaces calls to MirrorSystem.getName()
45 * with calls to the corresponding wrapper from _mirror_helper which has 45 * with calls to the corresponding wrapper from _mirror_helper which has
46 * been added during resolution. [renames] is assumed to map nodes in user 46 * been added during resolution. [renames] is assumed to map nodes in user
47 * code to mangled names appearing in output code, and [topLevelNodes] should 47 * code to mangled names appearing in output code, and [topLevelNodes] should
48 * contain all the toplevel ast nodes that will be emitted in the output. 48 * contain all the toplevel ast nodes that will be emitted in the output.
49 */ 49 */
50 void addRenames(Map<Node, String> renames, List<Node> topLevelNodes) { 50 void addRenames(Map<Node, String> renames, List<Node> topLevelNodes,
51 PlaceholderCollector placeholderCollector) {
51 // Right now we only support instances of MirrorSystem.getName, 52 // Right now we only support instances of MirrorSystem.getName,
52 // hence if there are no occurence of these we don't do anything. 53 // hence if there are no occurence of these we don't do anything.
53 if (mirrorSystemGetNameNodes.isEmpty) { 54 if (mirrorSystemGetNameNodes.isEmpty) {
54 return; 55 return;
55 } 56 }
56 57
57 Node parse(String text) { 58 Node parse(String text) {
58 Token tokens = compiler.scanner.tokenize(text); 59 Token tokens = compiler.scanner.tokenize(text);
59 return compiler.parser.parseCompilationUnit(tokens); 60 return compiler.parser.parseCompilationUnit(tokens);
60 } 61 }
61 62
62 // Add toplevel map containing all renames. 63 // Add toplevel map containing all renames of members.
63 symbols = new Map<String, SourceString>(); 64 symbols = new Map<String, SourceString>();
64 for (Node node in renames.keys) { 65 for (Set<Identifier> s in placeholderCollector.memberPlaceholders.values) {
65 Identifier identifier = node.asIdentifier(); 66 // All members in a set have the same name so we only need to look at one.
66 if (identifier != null) { 67 Identifier sampleNode = s.first;
67 symbols.putIfAbsent(renames[node], () => identifier.source); 68 symbols.putIfAbsent(renames[sampleNode], () => sampleNode.source);
68 }
69 } 69 }
70 70
71 Identifier symbolsMapIdentifier = 71 Identifier symbolsMapIdentifier =
72 mirrorHelperSymbolsMapNode.definitions.nodes.head.asSend().selector; 72 mirrorHelperSymbolsMapNode.definitions.nodes.head.asSend().selector;
73 assert(symbolsMapIdentifier != null); 73 assert(symbolsMapIdentifier != null);
74 topLevelNodes.remove(mirrorHelperSymbolsMapNode); 74 topLevelNodes.remove(mirrorHelperSymbolsMapNode);
75 75
76 StringBuffer sb = new StringBuffer( 76 StringBuffer sb = new StringBuffer(
77 'const ${renames[symbolsMapIdentifier]} = const<String,SourceString>{'); 77 'const ${renames[symbolsMapIdentifier]} = const<String,SourceString>{');
78 bool first = true; 78 bool first = true;
(...skipping 10 matching lines...) Expand all
89 sb.write('};'); 89 sb.write('};');
90 topLevelNodes.add(parse(sb.toString())); 90 topLevelNodes.add(parse(sb.toString()));
91 91
92 // Replace calls to Mirrorsystem.getName with calls to helper function. 92 // Replace calls to Mirrorsystem.getName with calls to helper function.
93 mirrorSystemGetNameNodes.forEach((node) { 93 mirrorSystemGetNameNodes.forEach((node) {
94 renames[node.selector] = renames[mirrorHelperGetNameFunctionNode.name]; 94 renames[node.selector] = renames[mirrorHelperGetNameFunctionNode.name];
95 renames[node.receiver] = ''; 95 renames[node.receiver] = '';
96 }); 96 });
97 } 97 }
98 } 98 }
OLDNEW
« no previous file with comments | « sdk/lib/_internal/compiler/implementation/mirror_renamer/mirror_renamer.dart ('k') | sdk/lib/_internal/lib/mirror_helper.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698