Chromium Code Reviews| Index: sdk/lib/_internal/compiler/implementation/dart_backend/mirror_collector.dart |
| diff --git a/sdk/lib/_internal/compiler/implementation/dart_backend/mirror_collector.dart b/sdk/lib/_internal/compiler/implementation/dart_backend/mirror_collector.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..e7efd86bb64f204dd71deeef2bea199969950d73 |
| --- /dev/null |
| +++ b/sdk/lib/_internal/compiler/implementation/dart_backend/mirror_collector.dart |
| @@ -0,0 +1,52 @@ |
| +// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| +// for details. All rights reserved. Use of this source code is governed by a |
| +// BSD-style license that can be found in the LICENSE file. |
| + |
| +part of dart_backend; |
| + |
| +class MirrorCollector extends Visitor { |
| + 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'; |
| + |
| + Map<Node, String> renames; |
| + TreeElements treeElements; |
| + final Compiler compiler; |
| + final Map<Element, ElementAst> elementAsts; |
| + Map<LibraryElement, String> imports ; |
| + |
| + MirrorCollector(this.renames, this.imports, this.compiler, this.elementAsts) { |
| + _addMirrorHelperImport(); |
|
ahe
2013/07/31 13:16:28
Please don't use library privacy. It doesn't work.
zarah
2013/08/02 07:53:41
Done.
|
| + } |
| + |
| + void _addMirrorHelperImport() { |
| + Uri _mirrorHelperUri = new Uri(path: MIRROR_HELPER_LIBRARY_NAME); |
|
ahe
2013/07/31 13:16:28
Why is this variable starting with an underscore?
zarah
2013/08/02 07:53:41
Done.
|
| + LibraryElement mirrorHelperLib = new LibraryElementX( |
|
ahe
2013/07/31 13:16:28
This is probably going to cause problems later on.
zarah
2013/08/02 07:53:41
Added a TODO. When the mirror helper library is co
|
| + new Script(_mirrorHelperUri, null)); |
| + imports.putIfAbsent(mirrorHelperLib, () => MIRROR_HELPER_LIBRARY_PREFIX); |
| + } |
| + |
| + void collect(Element element) { |
| + final ElementAst elementAst = elementAsts[element]; |
| + treeElements = elementAst.treeElements; |
| + Node elementNode = elementAst.ast; |
| + compiler.withCurrentElement(element, () { |
| + elementNode.accept(this); |
|
ahe
2013/07/31 13:16:28
This is somewhat unfortunate. It is a standard th
zarah
2013/08/02 07:53:41
Done.
|
| + }); |
| + } |
| + |
| + visitNode(Node node) { |
| + node.visitChildren(this); |
| + } |
| + |
| + visitSend(Send node) { |
| + final element = treeElements[node]; |
| + if (element == compiler.mirrorSystemGetNameFunction) { |
| + renames[node.selector] = MIRROR_HELPER_GET_NAME_FUNCTION; |
| + renames[node.receiver] = |
| + '$MIRROR_HELPER_LIBRARY_PREFIX.$MIRROR_HELPER_CLASS'; |
| + } |
| + node.visitChildren(this); |
| + } |
| +} |