Chromium Code Reviews| Index: sdk/lib/_internal/compiler/implementation/dart_backend/backend.dart |
| diff --git a/sdk/lib/_internal/compiler/implementation/dart_backend/backend.dart b/sdk/lib/_internal/compiler/implementation/dart_backend/backend.dart |
| index d9a6f1bfb6f8d8f51b3a6eb7586029354e9e828e..63e70526a568c5028371f085b8b8fee34778e040 100644 |
| --- a/sdk/lib/_internal/compiler/implementation/dart_backend/backend.dart |
| +++ b/sdk/lib/_internal/compiler/implementation/dart_backend/backend.dart |
| @@ -129,6 +129,16 @@ class DartBackend extends Backend { |
| // Right now, it is set by the tests. |
| bool useMirrorHelperLibrary = false; |
| + /// Initialized if the useMirrorHelperLibrary field is set. |
| + MirrorRenamer mirrorRenamer; |
| + |
| + /// Initialized when dart:mirrors is loaded if the useMirrorHelperLibrary |
| + /// field is set. |
| + LibraryElement mirrorHelperLibrary; |
| + /// Initialized when dart:mirrors is loaded if the useMirrorHelperLibrary |
| + /// field is set. |
| + FunctionElement mirrorHelperGetNameFunction; |
| + |
| Map<Element, TreeElements> get resolvedElements => |
| compiler.enqueuer.resolution.resolvedElements; |
| @@ -264,15 +274,23 @@ class DartBackend extends Backend { |
| fixedMemberNames.add('srcType'); |
| fixedMemberNames.add('dstType'); |
| + if (useMirrorHelperLibrary && compiler.mirrorsLibrary != null) { |
|
Johnni Winther
2013/08/23 09:25:19
Logical bug here!
zarah
2013/08/23 16:16:37
Done.
|
| + useMirrorHelperLibrary = true; |
| + mirrorRenamer = new MirrorRenamer(compiler, this); |
| + } else { |
| + useMirrorHelperLibrary = false; |
| + } |
| + |
| /** |
| * Tells whether we should output given element. Corelib classes like |
| * Object should not be in the resulting code. |
| */ |
| bool shouldOutput(Element element) { |
| - return !identical(element.kind, ElementKind.VOID) |
| + return (element.kind != ElementKind.VOID |
| && isUserLibrary(element.getLibrary()) |
| && !element.isSynthesized |
| - && element is !AbstractFieldElement; |
| + && element is !AbstractFieldElement) |
| + || element == mirrorHelperGetNameFunction; |
| } |
| final elementAsts = new Map<Element, ElementAst>(); |
| @@ -397,7 +415,12 @@ class DartBackend extends Backend { |
| // some unused identifier. |
| collector.unresolvedNodes.add(synthesizedIdentifier); |
| makePlaceholders(element) { |
| + bool oldUseHelper = useMirrorHelperLibrary; |
| + useMirrorHelperLibrary = (useMirrorHelperLibrary |
| + && element.getLibrary() != mirrorHelperLibrary); |
| collector.collect(element); |
| + useMirrorHelperLibrary = oldUseHelper; |
| + |
| if (element.isClass()) { |
| classMembers[element].forEach(makePlaceholders); |
| } |
| @@ -450,8 +473,8 @@ class DartBackend extends Backend { |
| } |
| } |
| - if (useMirrorHelperLibrary && compiler.mirrorsLibrary != null) { |
| - MirrorRenamer.addMirrorHelperImport(imports); |
| + if (useMirrorHelperLibrary) { |
| + mirrorRenamer.addRenames(renames, topLevelNodes); |
| } |
| final unparser = new EmitterUnparser(renames); |
| @@ -480,9 +503,31 @@ class DartBackend extends Backend { |
| log(String message) => compiler.log('[DartBackend] $message'); |
| + void onLibraryLoaded(LibraryElement library, Uri uri) { |
| + if (useMirrorHelperLibrary && library == compiler.mirrorsLibrary) { |
| + mirrorHelperLibrary = compiler.scanBuiltinLibrary( |
| + MirrorRenamer.MIRROR_HELPER_LIBRARY_NAME); |
| + mirrorHelperGetNameFunction = mirrorHelperLibrary.find( |
| + const SourceString(MirrorRenamer.MIRROR_HELPER_GET_NAME_FUNCTION)); |
| + } |
| + } |
| + |
| void registerStaticSend(Element element, Node node) { |
| - if (useMirrorHelperLibrary && compiler.mirrorsLibrary != null) { |
| - MirrorRenamer.handleStaticSend(renames, element, node, compiler); |
| + if (useMirrorHelperLibrary) { |
| + mirrorRenamer.registerStaticSend(element, node); |
| + } |
| + } |
| + |
| + void registerHelperFunction(Element element, Node node) { |
| + if (element.getLibrary() == mirrorHelperLibrary) { |
| + mirrorRenamer.registerHelperFunction(element, node); |
| + } |
| + } |
| + |
| + void registerStaticUse(Element element, Enqueuer enqueuer) { |
| + if (useMirrorHelperLibrary && |
| + element == compiler.mirrorSystemGetNameFunction) { |
| + enqueuer.addToWorkList(mirrorHelperGetNameFunction); |
| } |
| } |
| } |