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

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 BailoutException { 5 class BailoutException {
6 final String reason; 6 final String reason;
7 7
8 const BailoutException(this.reason); 8 const BailoutException(this.reason);
9 } 9 }
10 10
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 compiler.jsHelperLibrary, 64 compiler.jsHelperLibrary,
65 compiler.interceptorsLibrary, 65 compiler.interceptorsLibrary,
66 ]; 66 ];
67 bool shouldOutput(Element element) => 67 bool shouldOutput(Element element) =>
68 element.kind !== ElementKind.VOID && 68 element.kind !== ElementKind.VOID &&
69 LIBS_TO_IGNORE.indexOf(element.getLibrary()) == -1 && 69 LIBS_TO_IGNORE.indexOf(element.getLibrary()) == -1 &&
70 !isDartCoreLib(compiler, element.getLibrary()); 70 !isDartCoreLib(compiler, element.getLibrary());
71 71
72 try { 72 try {
73 Set<TypedefElement> typedefs = new Set<TypedefElement>(); 73 Set<TypedefElement> typedefs = new Set<TypedefElement>();
74 Set<ClassElement> classes = new Set<ClassElement>();
74 PlaceholderCollector collector = new PlaceholderCollector(compiler); 75 PlaceholderCollector collector = new PlaceholderCollector(compiler);
75 resolvedElements.forEach((element, treeElements) { 76 resolvedElements.forEach((element, treeElements) {
76 if (!shouldOutput(element)) return; 77 if (!shouldOutput(element)) return;
77 if (element is AbstractFieldElement) return; 78 if (element is AbstractFieldElement) return;
78 collector.collect(element, treeElements); 79 collector.collect(element, treeElements);
79 new ReferencedElementCollector( 80 new ReferencedElementCollector(
Roman 2012/08/10 07:27:40 This is probably controversial, but I think "typed
Anton Muhin 2012/08/10 08:33:37 Indeed. For example, I really don't like that you
80 compiler, element, treeElements, typedefs) 81 compiler, element, treeElements, typedefs, classes)
81 .collect(); 82 .collect();
82 }); 83 });
83 84
84 ConflictingRenamer renamer = 85 ConflictingRenamer renamer =
85 new ConflictingRenamer(compiler, collector.placeholders); 86 new ConflictingRenamer(compiler, collector.placeholders);
86 Emitter emitter = new Emitter(compiler, renamer); 87 Emitter emitter = new Emitter(compiler, renamer);
87 resolvedElements.forEach((element, treeElements) { 88 resolvedElements.forEach((element, treeElements) {
88 if (!shouldOutput(element)) return; 89 if (!shouldOutput(element)) return;
89 if (element.isMember()) { 90 if (element.isMember()) {
90 ClassElement enclosingClass = element.getEnclosingClass(); 91 ClassElement enclosingClass = element.getEnclosingClass();
91 assert(enclosingClass.isClass()); 92 assert(enclosingClass.isClass());
92 assert(enclosingClass.isTopLevel()); 93 assert(enclosingClass.isTopLevel());
93 addMemberToClass(element, enclosingClass); 94 addMemberToClass(element, enclosingClass);
94 return; 95 return;
95 } 96 }
96 if (!element.isTopLevel()) { 97 if (!element.isTopLevel()) {
97 bailout('Cannot process non top-level $element'); 98 bailout('Cannot process non top-level $element');
98 } 99 }
99 100
100 emitter.outputElement(element); 101 emitter.outputElement(element);
101 }); 102 });
102 103
103 typedefs.forEach(emitter.outputElement); 104 typedefs.forEach(emitter.outputElement);
105 final emptySet = new Set<Element>();
106 classes.forEach((classElement) {
107 if (!shouldOutput(classElement)) return;
108 if (resolvedClassMembers.containsKey(classElement)) return;
Roman 2012/08/10 07:27:40 Why not unify "classes" collection and "resolvedCl
Anton Muhin 2012/08/10 08:33:37 I am considering this too. But for now I'd prefer
Roman 2012/08/10 08:46:01 "Not knowing about the rest of system" is not quit
Anton Muhin 2012/08/10 08:56:48 I meant pretty simple thing: ReferencedElementColl
109 emitter.outputClass(classElement, emptySet);
110 });
104 111
105 // Now output resolved classes with inner elements we met before. 112 // Now output resolved classes with inner elements we met before.
106 resolvedClassMembers.forEach(emitter.outputClass); 113 resolvedClassMembers.forEach(emitter.outputClass);
107 compiler.assembledCode = emitter.toString(); 114 compiler.assembledCode = emitter.toString();
108 } catch (BailoutException e) { 115 } catch (BailoutException e) {
109 compiler.assembledCode = ''' 116 compiler.assembledCode = '''
110 main() { 117 main() {
111 final bailout_reason = "${e.reason}"; 118 final bailout_reason = "${e.reason}";
112 } 119 }
113 '''; 120 ''';
(...skipping 21 matching lines...) Expand all
135 * Some elements are not recorded by resolver now, 142 * Some elements are not recorded by resolver now,
136 * for example, typedefs or classes which are only 143 * for example, typedefs or classes which are only
137 * used in signatures, as/is operators or in super clauses 144 * used in signatures, as/is operators or in super clauses
138 * (just to name a few). Retraverse AST to pick those up. 145 * (just to name a few). Retraverse AST to pick those up.
139 */ 146 */
140 class ReferencedElementCollector extends AbstractVisitor { 147 class ReferencedElementCollector extends AbstractVisitor {
141 final Compiler compiler; 148 final Compiler compiler;
142 final Element element; 149 final Element element;
143 final TreeElements treeElements; 150 final TreeElements treeElements;
144 final Set<TypedefElement> typedefs; 151 final Set<TypedefElement> typedefs;
152 final Set<ClassElement> classes;
145 153
146 ReferencedElementCollector( 154 ReferencedElementCollector(
147 this.compiler, 155 this.compiler,
148 this.element, this.treeElements, 156 this.element, this.treeElements,
149 this.typedefs); 157 this.typedefs, this.classes);
150 158
151 visitNode(Node node) { node.visitChildren(this); } 159 visitNode(Node node) { node.visitChildren(this); }
152 160
153 visitTypeAnnotation(TypeAnnotation typeAnnotation) { 161 visitTypeAnnotation(TypeAnnotation typeAnnotation) {
154 Element element = treeElements[typeAnnotation]; 162 Element element = treeElements[typeAnnotation];
155 if (element !== null) { 163 if (element !== null) {
Roman 2012/08/10 07:27:40 This IF may be changed to just "compiler.resolveTy
Anton Muhin 2012/08/10 08:33:37 Good point, done. On 2012/08/10 07:27:40, Roman w
156 if (element.isTypedef()) typedefs.add(element); 164 addElement(element);
165 } else {
166 final type = compiler.resolveTypeAnnotation(this.element, typeAnnotation);
167 addElement(type.element);
157 } 168 }
158 typeAnnotation.visitChildren(this); 169 typeAnnotation.visitChildren(this);
159 } 170 }
160 171
172 addElement(Element element) {
173 if (element.isTypedef()) typedefs.add(element);
174 if (element.isClass()) classes.add(element);
175 }
176
161 void collect() { 177 void collect() {
162 element.parseNode(compiler).accept(this); 178 element.parseNode(compiler).accept(this);
163 } 179 }
164 } 180 }
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