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

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

Issue 10887012: Rename members and named constructors. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 3 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
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 bool minify; 7 final bool minify;
8 final bool cutDeclarationTypes; 8 final bool cutDeclarationTypes;
9 9
10 Map<Element, TreeElements> get resolvedElements => 10 Map<Element, TreeElements> get resolvedElements =>
11 compiler.enqueuer.resolution.resolvedElements; 11 compiler.enqueuer.resolution.resolvedElements;
12 12
13 DartBackend(Compiler compiler, this.minify, this.cutDeclarationTypes) 13 DartBackend(Compiler compiler, this.minify, this.cutDeclarationTypes)
14 : tasks = <CompilerTask>[], 14 : tasks = <CompilerTask>[],
15 super(compiler); 15 super(compiler);
16 16
17 void enqueueHelpers(Enqueuer world) { } 17 void enqueueHelpers(Enqueuer world) {
18 // Right now resolver doesn't always resolve interfaces needed
19 // for literals, so force them. TODO(antonm): fix in the resolver.
20 final LITERAL_TYPE_NAMES = const [
21 'Map', 'List', 'num', 'int', 'double'
Roman 2012/08/29 08:40:08 what about bool? There is also LiteralMapEntry, I
Anton Muhin 2012/08/29 09:43:46 Thanks a lot for bool, I just forgot about it, add
22 ];
23 final coreLibrary = compiler.coreLibrary;
24 for (final name in LITERAL_TYPE_NAMES) {
25 ClassElement classElement = coreLibrary.findLocal(new SourceString(name));
26 classElement.ensureResolved(compiler);
27 }
28 }
18 void codegen(WorkItem work) { } 29 void codegen(WorkItem work) { }
19 void processNativeClasses(Enqueuer world, 30 void processNativeClasses(Enqueuer world,
20 Collection<LibraryElement> libraries) { } 31 Collection<LibraryElement> libraries) { }
21 32
22 void assembleProgram() { 33 void assembleProgram() {
34 // Conservatively traverse all platform libraries and collect member names.
35 // TODO(antonm): ideally we should only collect names of used members,
36 // however as of today there are problems with names of some core library
37 // interfaces, most probably for interfaces of literals.
38 final fixedMemberNames = new Set<String>();
Roman 2012/08/29 08:40:08 do NoSuchMethodException and NoSuchMethod will be
Anton Muhin 2012/08/29 09:43:46 Yes, they get into this set. And fortunately enou
39 for (final library in compiler.libraries.getValues()) {
40 if (!library.isPlatformLibrary) continue;
41 for (final element in library.localMembers) {
42 if (element is ClassElement) {
43 ClassElement classElement = element;
44 for (final member in classElement.localMembers) {
45 final name = member.name.slowToString();
46 // Skip operator names.
47 if (name.startsWith(@'operator$')) continue;
48 // Fetch name of named constructors and factories if any,
49 // otherwise store regular name.
50 // TODO(antonm): better way to analyze the name.
51 fixedMemberNames.add(name.split(@'$').last());
52 }
53 } else {
54 fixedMemberNames.add(element.name.slowToString());
55 }
56 }
57 }
58 // TODO(antonm): TypeError along with other exceptions is defined in
59 // runtime/lib/error.dart. Overall, all DartVM specific libs should be
60 // accounted for.
61 fixedMemberNames.add('srcType');
Roman 2012/08/29 08:40:08 Reading the comment I don't understand why srcType
Anton Muhin 2012/08/29 09:43:46 Sorry, I meant that those fields are declared in h
62 fixedMemberNames.add('dstType');
63
23 /** 64 /**
24 * Tells whether we should output given element. Corelib classes like 65 * Tells whether we should output given element. Corelib classes like
25 * Object should not be in the resulting code. 66 * Object should not be in the resulting code.
26 */ 67 */
27 final LIBS_TO_IGNORE = [ 68 final LIBS_TO_IGNORE = [
28 compiler.jsHelperLibrary, 69 compiler.jsHelperLibrary,
29 compiler.interceptorsLibrary, 70 compiler.interceptorsLibrary,
30 ]; 71 ];
31 bool shouldOutput(Element element) => 72 bool shouldOutput(Element element) =>
32 element.kind !== ElementKind.VOID && 73 element.kind !== ElementKind.VOID &&
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 processElement(element, treeElements); 123 processElement(element, treeElements);
83 } else { 124 } else {
84 if (!element.isTopLevel()) { 125 if (!element.isTopLevel()) {
85 compiler.cancel(reason: 'Cannot process $element', element: element); 126 compiler.cancel(reason: 'Cannot process $element', element: element);
86 } 127 }
87 addTopLevel(element, treeElements); 128 addTopLevel(element, treeElements);
88 } 129 }
89 }); 130 });
90 131
91 // Create all necessary placeholders. 132 // Create all necessary placeholders.
92 PlaceholderCollector collector = new PlaceholderCollector(compiler); 133 PlaceholderCollector collector =
134 new PlaceholderCollector(compiler, fixedMemberNames);
93 makePlaceholders(element) { 135 makePlaceholders(element) {
94 TreeElements treeElements = resolvedElements[element]; 136 TreeElements treeElements = resolvedElements[element];
95 if (treeElements === null) treeElements = emptyTreeElements; 137 if (treeElements === null) treeElements = emptyTreeElements;
96 collector.collect(element, treeElements); 138 collector.collect(element, treeElements);
97 if (element is ClassElement) { 139 if (element is ClassElement) {
98 classMembers[element].forEach(makePlaceholders); 140 classMembers[element].forEach(makePlaceholders);
99 } 141 }
100 } 142 }
101 topLevelElements.forEach(makePlaceholders); 143 topLevelElements.forEach(makePlaceholders);
102 144
103 // Create renames. 145 // Create renames.
104 Map<Node, String> renames = new Map<Node, String>(); 146 Map<Node, String> renames = new Map<Node, String>();
105 Map<LibraryElement, String> imports = new Map<LibraryElement, String>(); 147 Map<LibraryElement, String> imports = new Map<LibraryElement, String>();
106 renamePlaceholders( 148 renamePlaceholders(
107 compiler, collector, renames, imports, minify, cutDeclarationTypes); 149 compiler, collector, renames, imports,
150 fixedMemberNames, minify, cutDeclarationTypes);
108 151
109 // Sort elements. 152 // Sort elements.
110 final sortedTopLevels = sortElements(topLevelElements); 153 final sortedTopLevels = sortElements(topLevelElements);
111 final sortedClassMembers = new Map<ClassElement, List<Element>>(); 154 final sortedClassMembers = new Map<ClassElement, List<Element>>();
112 classMembers.forEach((classElement, members) { 155 classMembers.forEach((classElement, members) {
113 sortedClassMembers[classElement] = sortElements(members); 156 sortedClassMembers[classElement] = sortElements(members);
114 }); 157 });
115 158
116 final unparser = new Unparser.withRenamer((Node node) => renames[node]); 159 final unparser = new Unparser.withRenamer((Node node) => renames[node]);
117 compiler.assembledCode = emitCode( 160 compiler.assembledCode = emitCode(
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 237
195 List<Element> sortElements(Collection<Element> elements) { 238 List<Element> sortElements(Collection<Element> elements) {
196 compareElements(e0, e1) { 239 compareElements(e0, e1) {
197 int result = compareBy((e) => e.getLibrary().uri.toString())(e0, e1); 240 int result = compareBy((e) => e.getLibrary().uri.toString())(e0, e1);
198 if (result != 0) return result; 241 if (result != 0) return result;
199 return compareBy((e) => e.position().charOffset)(e0, e1); 242 return compareBy((e) => e.position().charOffset)(e0, e1);
200 } 243 }
201 244
202 return sorted(elements, compareElements); 245 return sorted(elements, compareElements);
203 } 246 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698