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

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

Issue 10837025: Properly emit variable declarations. (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 | lib/compiler/implementation/elements/elements.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 /** 5 /**
6 * Dart backend helper for converting program IR back to source code. 6 * Dart backend helper for converting program IR back to source code.
7 */ 7 */
8 class Emitter { 8 class Emitter {
9 9
10 final Compiler compiler; 10 final Compiler compiler;
11 final StringBuffer sb; 11 final StringBuffer sb;
12 final ConflictingRenamer renamer; 12 final ConflictingRenamer renamer;
13 final Set<VariableListElement> processedVariableLists;
13 14
14 Emitter(Compiler compiler) : 15 Emitter(Compiler compiler) :
15 this.compiler = compiler, 16 this.compiler = compiler,
16 sb = new StringBuffer(), 17 sb = new StringBuffer(),
17 renamer = new ConflictingRenamer(compiler); 18 renamer = new ConflictingRenamer(compiler),
19 processedVariableLists = new Set<VariableListElement>();
18 20
19 /** 21 /**
20 * Outputs given class element with selected inner elements. 22 * Outputs given class element with selected inner elements.
21 */ 23 */
22 void outputClass(ClassElement classElement, Set<Element> innerElements) { 24 void outputClass(ClassElement classElement, Set<Element> innerElements) {
23 Unparser unparser = new Unparser(renamer); 25 Unparser unparser = new Unparser(renamer);
24 renamer.setContext(classElement.getCompilationUnit()); 26 renamer.setContext(classElement.getCompilationUnit());
25 ClassNode classNode = classElement.parseNode(compiler); 27 ClassNode classNode = classElement.parseNode(compiler);
26 // classElement.beginToken is 'class', 'interface', or 'abstract'. 28 // classElement.beginToken is 'class', 'interface', or 'abstract'.
27 sb.add(classElement.beginToken.slowToString()); 29 sb.add(classElement.beginToken.slowToString());
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 61
60 void outputElement(Element element) { 62 void outputElement(Element element) {
61 Unparser unparser = new Unparser(renamer); 63 Unparser unparser = new Unparser(renamer);
62 renamer.setContext(element); 64 renamer.setContext(element);
63 // TODO(smok): Figure out why AbstractFieldElement appears here, 65 // TODO(smok): Figure out why AbstractFieldElement appears here,
64 // we have used getters/setters resolved instead of it. 66 // we have used getters/setters resolved instead of it.
65 if (element is SynthesizedConstructorElement 67 if (element is SynthesizedConstructorElement
66 || element is AbstractFieldElement) return; 68 || element is AbstractFieldElement) return;
67 if (element.isField()) { 69 if (element.isField()) {
68 assert(element is VariableElement); 70 assert(element is VariableElement);
69 sb.add(unparser.unparse(element.variables.parseNode(compiler))); 71 // Different VariableElement's may refer to the same VariableListElement.
72 // Output this list only once.
73 final variableList = element.variables;
74 if (!processedVariableLists.contains(variableList)) {
Roman 2012/07/31 18:45:03 Hmm, I just thought about it in another way - we o
Anton Muhin 2012/07/31 18:55:37 Good point, todo added. On 2012/07/31 18:45:03, R
75 processedVariableLists.add(variableList);
76 sb.add(unparser.unparse(variableList.parseNode(compiler)));
77 }
70 } else { 78 } else {
71 sb.add(unparser.unparse(element.parseNode(compiler))); 79 sb.add(unparser.unparse(element.parseNode(compiler)));
72 } 80 }
73 } 81 }
74 82
75 String toString() { 83 String toString() {
76 final result = new StringBuffer(); 84 final result = new StringBuffer();
77 final libraries = compiler.libraries; 85 final libraries = compiler.libraries;
78 for (final uri in libraries.getKeys()) { 86 for (final uri in libraries.getKeys()) {
79 // Same library element may be a value for different uris as of now 87 // Same library element may be a value for different uris as of now
80 // e.g., core libraryElement is a value for both keys 'dart:core' 88 // e.g., core libraryElement is a value for both keys 'dart:core'
81 // and full file name. Only care about uris with dart scheme. 89 // and full file name. Only care about uris with dart scheme.
82 if (!uri.startsWith('dart:')) continue; 90 if (!uri.startsWith('dart:')) continue;
83 final lib = libraries[uri]; 91 final lib = libraries[uri];
84 if (renamer.imports.containsKey(lib)) { 92 if (renamer.imports.containsKey(lib)) {
85 result.add('#import("$uri", prefix: "${renamer.imports[lib]}");'); 93 result.add('#import("$uri", prefix: "${renamer.imports[lib]}");');
86 } 94 }
87 } 95 }
88 result.add(sb); 96 result.add(sb);
89 return result.toString(); 97 return result.toString();
90 } 98 }
91 } 99 }
OLDNEW
« no previous file with comments | « no previous file | lib/compiler/implementation/elements/elements.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698