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

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

Issue 10854067: Process typedefs, referenced from the program. (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/placeholder_collector.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 f64cc13d349566cde41f450b1fd8458559d471ba..24d77a7b073d6b532c7faba2a1e612ca573e54d4 100644
--- a/lib/compiler/implementation/dart_backend/backend.dart
+++ b/lib/compiler/implementation/dart_backend/backend.dart
@@ -70,10 +70,15 @@ class DartBackend extends Backend {
!isDartCoreLib(compiler, element.getLibrary());
try {
+ Set<TypedefElement> typedefs = new Set<TypedefElement>();
PlaceholderCollector collector = new PlaceholderCollector(compiler);
resolvedElements.forEach((element, treeElements) {
if (!shouldOutput(element)) return;
+ if (element is AbstractFieldElement) return;
collector.collect(element, treeElements);
+ new ReferencedElementCollector(
+ compiler, element, treeElements, typedefs)
+ .collect();
});
ConflictingRenamer renamer =
@@ -95,6 +100,8 @@ class DartBackend extends Backend {
emitter.outputElement(element);
});
+ typedefs.forEach(emitter.outputElement);
+
// Now output resolved classes with inner elements we met before.
resolvedClassMembers.forEach(emitter.outputClass);
compiler.assembledCode = emitter.toString();
@@ -123,3 +130,35 @@ bool isDartCoreLib(Compiler compiler, LibraryElement libraryElement) {
}
return false;
}
+
+/**
+ * Some elements are not recorded by resolver now,
+ * for example, typedefs or classes which are only
+ * used in signatures, as/is operators or in super clauses
+ * (just to name a few). Retraverse AST to pick those up.
+ */
+class ReferencedElementCollector extends AbstractVisitor {
+ final Compiler compiler;
+ final Element element;
+ final TreeElements treeElements;
+ final Set<TypedefElement> typedefs;
+
+ ReferencedElementCollector(
+ this.compiler,
+ this.element, this.treeElements,
+ this.typedefs);
+
+ visitNode(Node node) { node.visitChildren(this); }
+
+ visitTypeAnnotation(TypeAnnotation typeAnnotation) {
+ Element element = treeElements[typeAnnotation];
+ if (element !== null) {
+ if (element.isTypedef()) typedefs.add(element);
+ }
+ typeAnnotation.visitChildren(this);
+ }
+
+ void collect() {
+ element.parseNode(compiler).accept(this);
+ }
+}
« no previous file with comments | « no previous file | lib/compiler/implementation/dart_backend/placeholder_collector.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698