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

Unified Diff: lib/compiler/implementation/dart_backend/renamer.dart

Issue 10829076: Support imports for dart: libs. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Better version Created 8 years, 5 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 | « lib/compiler/implementation/dart_backend/emitter.dart ('k') | tests/language/language.status » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/compiler/implementation/dart_backend/renamer.dart
diff --git a/lib/compiler/implementation/dart_backend/renamer.dart b/lib/compiler/implementation/dart_backend/renamer.dart
index 47bdbee52bb044974c9c3df49c5bbab42e0a1d7c..94cbfd9a9da7c475eb026bdfc71694b9cfbaa928 100644
--- a/lib/compiler/implementation/dart_backend/renamer.dart
+++ b/lib/compiler/implementation/dart_backend/renamer.dart
@@ -10,6 +10,7 @@ class ConflictingRenamer extends Renamer {
final Compiler compiler;
final Map<Element, String> renamed;
final Set<String> usedTopLevelIdentifiers;
+ final Map<LibraryElement, String> imports;
TreeElements contextElements;
Element context;
@@ -18,7 +19,8 @@ class ConflictingRenamer extends Renamer {
ConflictingRenamer(this.compiler) :
renamed = new Map<Element, String>(),
- usedTopLevelIdentifiers = new Set<String>();
+ usedTopLevelIdentifiers = new Set<String>(),
+ imports = new Map<LibraryElement, String>();
void setContext(Element element) {
this.context = element;
@@ -82,9 +84,22 @@ class ConflictingRenamer extends Renamer {
}
String renameElement(Element element) {
+ generateUniqueName(name) {
+ while (usedTopLevelIdentifiers.contains(name)) {
+ name = "x$name";
+ }
+ usedTopLevelIdentifiers.add(name);
+ return name;
+ }
+
String originalName = element.name.slowToString();
- if (element.getLibrary() == compiler.coreLibrary || !element.isTopLevel()) {
- return originalName;
+ // TODO(antonm): we should rename lib private names as well.
+ if (!element.isTopLevel()) return originalName;
+ final library = element.getLibrary();
+ if (library === compiler.coreLibrary) return originalName;
+ if (isDartCoreLib(compiler, library)) {
+ final prefix = imports.putIfAbsent(library, () => generateUniqueName('p'));
Roman 2012/07/30 14:43:30 >80 chars
+ return '$prefix.$originalName';
}
if (renamed[element] !== null) {
return renamed[element];
@@ -93,12 +108,6 @@ class ConflictingRenamer extends Renamer {
// Not renamed and top element.
// TODO(smok): Make sure that the new name does not conflict with existing
// local identifiers.
- String name = originalName;
- while (usedTopLevelIdentifiers.contains(name)) {
- name = "_$name";
- }
- usedTopLevelIdentifiers.add(name);
- renamed[element] = name;
- return name;
+ return renamed[element] = generateUniqueName(originalName);
}
}
« no previous file with comments | « lib/compiler/implementation/dart_backend/emitter.dart ('k') | tests/language/language.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698