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

Unified Diff: sdk/lib/_internal/compiler/implementation/dart_backend/backend.dart

Issue 22791002: Add renames in output when using the mirror helper library. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Added an assert. Created 7 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | sdk/lib/_internal/compiler/implementation/dart_backend/dart_backend.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..95ee0d1edc556dded18368b2dc31b16183ca4af2 100644
--- a/sdk/lib/_internal/compiler/implementation/dart_backend/backend.dart
+++ b/sdk/lib/_internal/compiler/implementation/dart_backend/backend.dart
@@ -129,6 +129,19 @@ 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;
+ /// Initialized when dart:mirrors is loaded if the useMirrorHelperLibrary
+ /// field is set.
+ Element mirrorHelperSymbolsMap;
+
Map<Element, TreeElements> get resolvedElements =>
compiler.enqueuer.resolution.resolvedElements;
@@ -264,15 +277,22 @@ class DartBackend extends Backend {
fixedMemberNames.add('srcType');
fixedMemberNames.add('dstType');
+ if (useMirrorHelperLibrary && compiler.mirrorsLibrary != null) {
+ 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.getLibrary() == mirrorHelperLibrary;
}
final elementAsts = new Map<Element, ElementAst>();
@@ -397,7 +417,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 +475,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 +505,33 @@ 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));
+ mirrorHelperSymbolsMap = mirrorHelperLibrary.find(
+ const SourceString(MirrorRenamer.MIRROR_HELPER_SYMBOLS_MAP_NAME));
+ }
+ }
+
void registerStaticSend(Element element, Node node) {
- if (useMirrorHelperLibrary && compiler.mirrorsLibrary != null) {
- MirrorRenamer.handleStaticSend(renames, element, node, compiler);
+ if (useMirrorHelperLibrary) {
+ mirrorRenamer.registerStaticSend(element, node);
+ }
+ }
+
+ void registerMirrorHelperElement(Element element, Node node) {
+ if (element.getLibrary() == mirrorHelperLibrary) {
+ mirrorRenamer.registerHelperElement(element, node);
+ }
+ }
+
+ void registerStaticUse(Element element, Enqueuer enqueuer) {
+ if (useMirrorHelperLibrary &&
+ element == compiler.mirrorSystemGetNameFunction) {
+ enqueuer.addToWorkList(mirrorHelperGetNameFunction);
}
}
}
« no previous file with comments | « no previous file | sdk/lib/_internal/compiler/implementation/dart_backend/dart_backend.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698