Chromium Code Reviews| Index: sdk/lib/_internal/compiler/implementation/mirror_renamer/renamer.dart |
| diff --git a/sdk/lib/_internal/compiler/implementation/mirror_renamer/renamer.dart b/sdk/lib/_internal/compiler/implementation/mirror_renamer/renamer.dart |
| index 003dda44768370e4daaa8994d6ab2ca587f32386..122840502d9474f55a6d993337ab5f887e430b42 100644 |
| --- a/sdk/lib/_internal/compiler/implementation/mirror_renamer/renamer.dart |
| +++ b/sdk/lib/_internal/compiler/implementation/mirror_renamer/renamer.dart |
| @@ -5,28 +5,72 @@ |
| part of mirror_renamer; |
| class MirrorRenamer { |
| - static const String MIRROR_HELPER_CLASS = 'MirrorHelper'; |
| - static const String MIRROR_HELPER_GET_NAME_FUNCTION = 'getName'; |
| - static const String MIRROR_HELPER_LIBRARY_NAME = 'mirror_helper.dart'; |
| - static const String MIRROR_HELPER_LIBRARY_PREFIX = 'm'; |
| - static const String MIRROR_HELPER_CLASS_FULLY_QUALIFIED_NAME = |
| - '$MIRROR_HELPER_LIBRARY_PREFIX.$MIRROR_HELPER_CLASS'; |
| - |
| - static void handleStaticSend(Map<Node, String> renames, Element element, |
| - Send node, Compiler compiler) { |
| + static const String MIRROR_HELPER_GET_NAME_FUNCTION = 'helperGetName'; |
| + static const String MIRROR_HELPER_LIBRARY_NAME = '_mirror_helper'; |
| + static const String MIRROR_HELPER_SYMBOLS_MAP_NAME = '_SYMBOLS'; |
| + |
| + static Map<String, String> inverseRenames = new Map<String, String>(); |
|
ahe
2013/08/19 15:34:06
Inverse of what?
ahe
2013/08/19 15:34:06
No static state please.
zarah
2013/08/20 14:08:17
Done.
zarah
2013/08/20 14:08:17
Inverse of the renames. Changed the name to symbol
|
| + static List<Node> mirrorSystemGetNameNodes = <Node>[]; |
|
ahe
2013/08/19 15:34:06
Document.
zarah
2013/08/20 14:08:17
Done.
|
| + static FunctionExpression mirrorHelperFunctionNode; |
|
ahe
2013/08/19 15:34:06
Name too general?
zarah
2013/08/20 14:08:17
Done.
|
| + |
| + static void registerStaticSend(Element element, Send node, |
| + Compiler compiler) { |
| if (element == compiler.mirrorSystemGetNameFunction) { |
| - renames[node.selector] = MIRROR_HELPER_GET_NAME_FUNCTION; |
| - renames[node.receiver] = MIRROR_HELPER_CLASS_FULLY_QUALIFIED_NAME; |
| - } |
| + mirrorSystemGetNameNodes.add(node); |
| + } |
| } |
| - static void addMirrorHelperImport(Map<LibraryElement, String> imports) { |
| - Uri mirrorHelperUri = new Uri(path: MIRROR_HELPER_LIBRARY_NAME); |
| - // TODO(zarah): Remove this hack! LibraryElementX should not be created |
| - // outside the library loader. When actual mirror helper library |
| - // is created, change to load that. |
| - LibraryElement mirrorHelperLib = new LibraryElementX( |
| - new Script(mirrorHelperUri, null)); |
| - imports.putIfAbsent(mirrorHelperLib, () => MIRROR_HELPER_LIBRARY_PREFIX); |
| + static void registerHelperFunction(Element element, Node node, |
| + Compiler compiler) { |
| + if (element == compiler.mirrorHelperFunction) { |
| + mirrorHelperFunctionNode = node; |
| + } |
| + } |
| + |
| + static void addRenames(Map<Node, String> renames, List<Node> topLevelNodes, |
|
ahe
2013/08/19 15:34:06
Document.
zarah
2013/08/20 14:08:17
Done.
|
| + Compiler compiler) { |
| + inverseRenames = new Map<String, String>(); |
| + String renameMapName; |
| + FunctionElement getNameElement; |
| + |
| + Node parse(String text) { |
| + Token tokens = compiler.scanner.tokenize(text); |
| + return compiler.parser.parseCompilationUnit(tokens); |
| + } |
| + |
| + //Add toplevel map containing all renames. |
|
ahe
2013/08/19 15:34:06
Add space after //.
zarah
2013/08/20 14:08:17
Done.
|
| + for (Node node in renames.keys) { |
| + if (node is Identifier) { |
|
ahe
2013/08/19 15:34:06
Identifier identifier = node.asIdentifier();
if (n
zarah
2013/08/20 14:08:17
Done.
|
| + var stringValue = node.asIdentifier().source.stringValue; |
| + if (stringValue == MIRROR_HELPER_SYMBOLS_MAP_NAME) { |
|
ahe
2013/08/19 15:34:06
Accessing stringValue in general won't work. See B
zarah
2013/08/20 14:08:17
Done.
|
| + renameMapName = renames[node]; |
| + } else if (stringValue != renames[node]) { |
|
ahe
2013/08/19 15:34:06
Could you put SourceStrings in the 'renames' map?
zarah
2013/08/20 14:08:17
Not really, since it is used in renamePlaceHolders
|
| + inverseRenames.putIfAbsent(renames[node], () => stringValue); |
| + } |
| + } |
| + } |
| + |
| + StringBuffer sb = new StringBuffer('const Map<String, String> ' |
| + '$renameMapName = const<String, String>{'); |
| + bool first = true; |
| + for (String mangledName in inverseRenames.keys) { |
| + if (!first) { |
| + sb.write(','); |
| + } else { |
| + first = false; |
| + } |
| + sb.write("'$mangledName' : '${inverseRenames[mangledName]}'"); |
| + } |
| + sb.write('};'); |
| + topLevelNodes.add(parse(sb.toString())); |
| + |
| + //Replace calls to Mirrorsystem.getName with calls to helper function. |
|
ahe
2013/08/19 15:34:06
Add space after //.
zarah
2013/08/20 14:08:17
Done.
|
| + getNameElement = compiler.mirrorHelperLibrary.find(const |
| + SourceString(MIRROR_HELPER_GET_NAME_FUNCTION)); |
| + Node getNameNode = getNameElement.parseNode(compiler); |
| + mirrorSystemGetNameNodes.forEach((node) { |
| + renames[node.selector] = renames[mirrorHelperFunctionNode.name]; |
| + renames[node.receiver] = ''; |
| + }); |
| } |
| -} |
| +} |