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

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

Issue 10830356: Fix the order in which elements are emitted. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 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 | lib/compiler/implementation/dart_backend/emitter.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/compiler/implementation/dart_backend/backend.dart
diff --git a/lib/compiler/implementation/dart_backend/backend.dart b/lib/compiler/implementation/dart_backend/backend.dart
index 5a9e0e770c95710c926f309d4e193e0ef1aea53e..ae1ef3ab787228637eb651197cf99d5f3970c1a7 100644
--- a/lib/compiler/implementation/dart_backend/backend.dart
+++ b/lib/compiler/implementation/dart_backend/backend.dart
@@ -48,7 +48,7 @@ class DartBackend extends Backend {
final emptyTreeElements = new TreeElementMapping();
Set<Element> topLevelElements = new Set<Element>();
- Map<ClassElement, Set<Element>> classes =
+ Map<ClassElement, Set<Element>> classMembers =
new Map<ClassElement, Set<Element>>();
PlaceholderCollector collector = new PlaceholderCollector(compiler);
@@ -68,9 +68,8 @@ class DartBackend extends Backend {
processElement(element, treeElements);
}
addClass(classElement) {
- if (classes.containsKey(classElement)) return;
- classes[classElement] = new Set<Element>();
- processElement(classElement, emptyTreeElements);
+ addTopLevel(classElement, emptyTreeElements);
+ classMembers.putIfAbsent(classElement, () => new Set());
}
newTypedefElementCallback = (TypedefElement element) {
@@ -91,7 +90,7 @@ class DartBackend extends Backend {
assert(enclosingClass.isTopLevel());
assert(shouldOutput(enclosingClass));
addClass(enclosingClass);
- classes[enclosingClass].add(element);
+ classMembers[enclosingClass].add(element);
processElement(element, treeElements);
} else {
if (!element.isTopLevel()) {
@@ -105,10 +104,27 @@ class DartBackend extends Backend {
Map<LibraryElement, String> imports = new Map<LibraryElement, String>();
renamePlaceholders(compiler, collector, renames, imports);
- Emitter emitter = new Emitter(compiler, renames);
+ // Sort elements.
+ compareElements(e0, e1) {
Roman 2012/08/16 15:23:14 I miss SortedSet now
+ compareBy(x, y, f) => f(x).compareTo(f(y));
+ int result = compareBy(e0, e1, (e) => e.getLibrary().uri.toString());
+ if (result != 0) return result;
+ return compareBy(e0, e1, (e) => e.position().charOffset);
+ }
+
+ final sortedTopLevels = new List<Element>.from(topLevelElements);
+ sortedTopLevels.sort(compareElements);
+
+ final sortedClassMembers = new Map<ClassElement, List<Element>>();
+ classMembers.forEach((classElement, members) {
+ final sortedMembers = new List<Element>.from(members);
+ sortedMembers.sort(compareElements);
+ sortedClassMembers[classElement] = sortedMembers;
+ });
+
+ Emitter emitter = new Emitter(compiler, renames, sortedClassMembers);
emitter.outputImports(imports);
- topLevelElements.forEach(emitter.outputElement);
- classes.forEach(emitter.outputClass);
+ sortedTopLevels.forEach(emitter.outputElement);
compiler.assembledCode = emitter.toString();
}
« no previous file with comments | « no previous file | lib/compiler/implementation/dart_backend/emitter.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698