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

Side by Side Diff: lib/compiler/implementation/dart_backend/backend.dart

Issue 10826234: Support some usages of empty classes. (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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | tests/compiler/dart2js/unparser_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 class DartBackend extends Backend { 5 class DartBackend extends Backend {
6 final List<CompilerTask> tasks; 6 final List<CompilerTask> tasks;
7 final UnparseValidator unparseValidator; 7 final UnparseValidator unparseValidator;
8 8
9 Map<Element, TreeElements> get resolvedElements() => 9 Map<Element, TreeElements> get resolvedElements() =>
10 compiler.enqueuer.resolution.resolvedElements; 10 compiler.enqueuer.resolution.resolvedElements;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 final LIBS_TO_IGNORE = [ 52 final LIBS_TO_IGNORE = [
53 compiler.jsHelperLibrary, 53 compiler.jsHelperLibrary,
54 compiler.interceptorsLibrary, 54 compiler.interceptorsLibrary,
55 ]; 55 ];
56 bool shouldOutput(Element element) => 56 bool shouldOutput(Element element) =>
57 element.kind !== ElementKind.VOID && 57 element.kind !== ElementKind.VOID &&
58 LIBS_TO_IGNORE.indexOf(element.getLibrary()) == -1 && 58 LIBS_TO_IGNORE.indexOf(element.getLibrary()) == -1 &&
59 !isDartCoreLib(compiler, element.getLibrary()); 59 !isDartCoreLib(compiler, element.getLibrary());
60 60
61 Set<TypedefElement> typedefs = new Set<TypedefElement>(); 61 Set<TypedefElement> typedefs = new Set<TypedefElement>();
62 Set<ClassElement> classes = new Set<ClassElement>();
62 PlaceholderCollector collector = new PlaceholderCollector(compiler); 63 PlaceholderCollector collector = new PlaceholderCollector(compiler);
63 resolvedElements.forEach((element, treeElements) { 64 resolvedElements.forEach((element, treeElements) {
64 if (!shouldOutput(element)) return; 65 if (!shouldOutput(element)) return;
65 if (element is AbstractFieldElement) return; 66 if (element is AbstractFieldElement) return;
66 collector.collect(element, treeElements); 67 collector.collect(element, treeElements);
67 new ReferencedElementCollector( 68 new ReferencedElementCollector(
68 compiler, element, treeElements, typedefs) 69 compiler, element, treeElements, typedefs, classes)
69 .collect(); 70 .collect();
70 }); 71 });
71 72
72 ConflictingRenamer renamer = 73 ConflictingRenamer renamer =
73 new ConflictingRenamer(compiler, collector.placeholders); 74 new ConflictingRenamer(compiler, collector.placeholders);
74 Emitter emitter = new Emitter(compiler, renamer); 75 Emitter emitter = new Emitter(compiler, renamer);
75 resolvedElements.forEach((element, treeElements) { 76 resolvedElements.forEach((element, treeElements) {
76 if (!shouldOutput(element)) return; 77 if (!shouldOutput(element)) return;
77 if (element.isMember()) { 78 if (element.isMember()) {
78 ClassElement enclosingClass = element.getEnclosingClass(); 79 ClassElement enclosingClass = element.getEnclosingClass();
79 assert(enclosingClass.isClass()); 80 assert(enclosingClass.isClass());
80 assert(enclosingClass.isTopLevel()); 81 assert(enclosingClass.isTopLevel());
81 addMemberToClass(element, enclosingClass); 82 addMemberToClass(element, enclosingClass);
82 return; 83 return;
83 } 84 }
84 if (!element.isTopLevel()) { 85 if (!element.isTopLevel()) {
85 compiler.cancel(reason: 'Cannot process $element', element: element); 86 compiler.cancel(reason: 'Cannot process $element', element: element);
86 } 87 }
87 88
88 emitter.outputElement(element); 89 emitter.outputElement(element);
89 }); 90 });
90 91
91 typedefs.forEach(emitter.outputElement); 92 typedefs.forEach(emitter.outputElement);
93 final emptySet = new Set<Element>();
94 classes.forEach((classElement) {
95 if (!shouldOutput(classElement)) return;
96 if (resolvedClassMembers.containsKey(classElement)) return;
97 emitter.outputClass(classElement, emptySet);
98 });
92 99
93 // Now output resolved classes with inner elements we met before. 100 // Now output resolved classes with inner elements we met before.
94 resolvedClassMembers.forEach(emitter.outputClass); 101 resolvedClassMembers.forEach(emitter.outputClass);
95 compiler.assembledCode = emitter.toString(); 102 compiler.assembledCode = emitter.toString();
96 } 103 }
97 104
98 log(String message) => compiler.log('[DartBackend] $message'); 105 log(String message) => compiler.log('[DartBackend] $message');
99 } 106 }
100 107
101 /** 108 /**
(...skipping 14 matching lines...) Expand all
116 * Some elements are not recorded by resolver now, 123 * Some elements are not recorded by resolver now,
117 * for example, typedefs or classes which are only 124 * for example, typedefs or classes which are only
118 * used in signatures, as/is operators or in super clauses 125 * used in signatures, as/is operators or in super clauses
119 * (just to name a few). Retraverse AST to pick those up. 126 * (just to name a few). Retraverse AST to pick those up.
120 */ 127 */
121 class ReferencedElementCollector extends AbstractVisitor { 128 class ReferencedElementCollector extends AbstractVisitor {
122 final Compiler compiler; 129 final Compiler compiler;
123 final Element element; 130 final Element element;
124 final TreeElements treeElements; 131 final TreeElements treeElements;
125 final Set<TypedefElement> typedefs; 132 final Set<TypedefElement> typedefs;
133 final Set<ClassElement> classes;
126 134
127 ReferencedElementCollector( 135 ReferencedElementCollector(
128 this.compiler, 136 this.compiler,
129 this.element, this.treeElements, 137 this.element, this.treeElements,
130 this.typedefs); 138 this.typedefs, this.classes);
131 139
132 visitNode(Node node) { node.visitChildren(this); } 140 visitNode(Node node) { node.visitChildren(this); }
133 141
134 visitTypeAnnotation(TypeAnnotation typeAnnotation) { 142 visitTypeAnnotation(TypeAnnotation typeAnnotation) {
135 Element element = treeElements[typeAnnotation]; 143 final type = compiler.resolveTypeAnnotation(element, typeAnnotation);
136 if (element !== null) { 144 Element typeElement = type.element;
137 if (element.isTypedef()) typedefs.add(element); 145 if (typeElement.isTypedef()) typedefs.add(typeElement);
138 } 146 if (typeElement.isClass()) classes.add(typeElement);
139 typeAnnotation.visitChildren(this); 147 typeAnnotation.visitChildren(this);
140 } 148 }
141 149
142 void collect() { 150 void collect() {
143 element.parseNode(compiler).accept(this); 151 element.parseNode(compiler).accept(this);
144 } 152 }
145 } 153 }
OLDNEW
« no previous file with comments | « no previous file | tests/compiler/dart2js/unparser_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698