| OLD | NEW |
| 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 MirrorRenamerImpl implements MirrorRenamer { | 7 class MirrorRenamerImpl implements MirrorRenamer { |
| 8 static const String MIRROR_HELPER_GET_NAME_FUNCTION = 'helperGetName'; | 8 static const String MIRROR_HELPER_GET_NAME_FUNCTION = 'helperGetName'; |
| 9 static final Uri DART_MIRROR_HELPER = | 9 static final Uri DART_MIRROR_HELPER = |
| 10 new Uri(scheme: 'dart', path: '_mirror_helper'); | 10 new Uri(scheme: 'dart', path: '_mirror_helper'); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 * backend.mirrorHelperGetNameFunction which represents the helperGetName | 33 * backend.mirrorHelperGetNameFunction which represents the helperGetName |
| 34 * function in _mirror_helper. | 34 * function in _mirror_helper. |
| 35 */ | 35 */ |
| 36 FunctionExpression get getNameFunctionNode => getNameFunction.node; | 36 FunctionExpression get getNameFunctionNode => getNameFunction.node; |
| 37 VariableDefinitions get symbolsMapNode => symbolsMapVariable.node; | 37 VariableDefinitions get symbolsMapNode => symbolsMapVariable.node; |
| 38 Compiler compiler; | 38 Compiler compiler; |
| 39 DartBackend backend; | 39 DartBackend backend; |
| 40 | 40 |
| 41 MirrorRenamerImpl(this.compiler, this.backend, LibraryElement library) | 41 MirrorRenamerImpl(this.compiler, this.backend, LibraryElement library) |
| 42 : this.helperLibrary = library, | 42 : this.helperLibrary = library, |
| 43 getNameFunction = library.find( | 43 getNameFunction = |
| 44 MirrorRenamerImpl.MIRROR_HELPER_GET_NAME_FUNCTION), | 44 library.find(MirrorRenamerImpl.MIRROR_HELPER_GET_NAME_FUNCTION), |
| 45 symbolsMapVariable = library.find( | 45 symbolsMapVariable = |
| 46 MirrorRenamerImpl.MIRROR_HELPER_SYMBOLS_MAP_NAME); | 46 library.find(MirrorRenamerImpl.MIRROR_HELPER_SYMBOLS_MAP_NAME); |
| 47 | 47 |
| 48 bool isMirrorHelperLibrary(LibraryElement element) { | 48 bool isMirrorHelperLibrary(LibraryElement element) { |
| 49 return element == helperLibrary; | 49 return element == helperLibrary; |
| 50 } | 50 } |
| 51 | 51 |
| 52 void registerStaticSend(Element currentElement, Element target, Send node) { | 52 void registerStaticSend(Element currentElement, Element target, Send node) { |
| 53 if (target == compiler.mirrorSystemGetNameFunction && | 53 if (target == compiler.mirrorSystemGetNameFunction && |
| 54 currentElement.library != helperLibrary) { | 54 currentElement.library != helperLibrary) { |
| 55 // Access to `MirrorSystem.getName` that needs to be redirected to the | 55 // Access to `MirrorSystem.getName` that needs to be redirected to the |
| 56 // [getNameFunction]. | 56 // [getNameFunction]. |
| 57 mirrorSystemGetNameNodes.add(node); | 57 mirrorSystemGetNameNodes.add(node); |
| 58 } | 58 } |
| 59 } | 59 } |
| 60 | 60 |
| 61 /** | 61 /** |
| 62 * Adds a toplevel node to the output containing a map from the mangled | 62 * Adds a toplevel node to the output containing a map from the mangled |
| 63 * to the unmangled names and replaces calls to MirrorSystem.getName() | 63 * to the unmangled names and replaces calls to MirrorSystem.getName() |
| 64 * with calls to the corresponding wrapper from _mirror_helper which has | 64 * with calls to the corresponding wrapper from _mirror_helper which has |
| 65 * been added during resolution. [renames] is assumed to map nodes in user | 65 * been added during resolution. [renames] is assumed to map nodes in user |
| 66 * code to mangled names appearing in output code, and [topLevelNodes] should | 66 * code to mangled names appearing in output code, and [topLevelNodes] should |
| 67 * contain all the toplevel ast nodes that will be emitted in the output. | 67 * contain all the toplevel ast nodes that will be emitted in the output. |
| 68 */ | 68 */ |
| 69 void addRenames(Map<Node, String> renames, List<Node> topLevelNodes, | 69 void addRenames(Map<Node, String> renames, List<Node> topLevelNodes, |
| 70 PlaceholderCollector placeholderCollector) { | 70 PlaceholderCollector placeholderCollector) { |
| 71 // Right now we only support instances of MirrorSystem.getName, | 71 // Right now we only support instances of MirrorSystem.getName, |
| 72 // hence if there are no occurence of these we don't do anything. | 72 // hence if there are no occurence of these we don't do anything. |
| 73 if (mirrorSystemGetNameNodes.isEmpty) { | 73 if (mirrorSystemGetNameNodes.isEmpty) { |
| 74 return; | 74 return; |
| 75 } | 75 } |
| 76 | 76 |
| 77 Node parse(String text) { | 77 Node parse(String text) { |
| 78 Token tokens = compiler.scanner.tokenize(text); | 78 Token tokens = compiler.scanner.tokenize(text); |
| 79 return compiler.parser.parseCompilationUnit(tokens); | 79 return compiler.parser.parseCompilationUnit(tokens); |
| 80 } | 80 } |
| (...skipping 28 matching lines...) Expand all Loading... |
| 109 sb.writeCharCode(0); // Terminate the string with '0', see [StringScanner]. | 109 sb.writeCharCode(0); // Terminate the string with '0', see [StringScanner]. |
| 110 topLevelNodes.add(parse(sb.toString())); | 110 topLevelNodes.add(parse(sb.toString())); |
| 111 | 111 |
| 112 // Replace calls to Mirrorsystem.getName with calls to helper function. | 112 // Replace calls to Mirrorsystem.getName with calls to helper function. |
| 113 mirrorSystemGetNameNodes.forEach((node) { | 113 mirrorSystemGetNameNodes.forEach((node) { |
| 114 renames[node.selector] = renames[getNameFunctionNode.name]; | 114 renames[node.selector] = renames[getNameFunctionNode.name]; |
| 115 renames[node.receiver] = ''; | 115 renames[node.receiver] = ''; |
| 116 }); | 116 }); |
| 117 } | 117 } |
| 118 } | 118 } |
| OLD | NEW |