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

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

Issue 10828121: Improve renaming of constructors and factories. (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
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 * Renames only top-level elements that would let to ambiguity if not renamed. 6 * Renames only top-level elements that would let to ambiguity if not renamed.
7 * TODO(smok): Make sure that top-level fields are correctly renamed. 7 * TODO(smok): Make sure that top-level fields are correctly renamed.
8 */ 8 */
9 class ConflictingRenamer extends Renamer { 9 class ConflictingRenamer extends Renamer {
10 final Compiler compiler; 10 final Compiler compiler;
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 .resolveTypeAnnotation(typeAnnotation, null, context); 71 .resolveTypeAnnotation(typeAnnotation, null, context);
72 } else { 72 } else {
73 type = compiler.resolveTypeAnnotation(context, typeAnnotation); 73 type = compiler.resolveTypeAnnotation(context, typeAnnotation);
74 } 74 }
75 return renameType(type); 75 return renameType(type);
76 } 76 }
77 77
78 String renameType(Type type) => renameElement(type.element); 78 String renameType(Type type) => renameElement(type.element);
79 79
80 String renameIdentifier(Identifier node) { 80 String renameIdentifier(Identifier node) {
81 if (context.isGenerativeConstructor()) { 81 if (context.isGenerativeConstructor() || context.isFactoryConstructor()) {
82 // This is either a named constructor or simple one. 82 // Two complicated cases for class/interface renaming:
83 // TODO(smok): Check if resolver can help us identifying named 83 // 1) class which implements constructors of other interfaces, but not
84 // constructors. 84 // implements interfaces themselves:
85 var enclosingClass = context.getEnclosingClass(); 85 // 0.dart: class C { I(); }
86 if (node.token.slowToString() == context.name.slowToString() 86 // 1.dart and 2.dart: interface I default C { I(); }
87 || enclosingClass.name.slowToString() == node.token.slowToString()) { 87 // now we have to duplicate our I() constructor in C class with
88 // proper names.
89 // 2) (even worse for us):
90 // 0.dart: class C { C(); }
91 // 1.dart: interface C default p0.C { C(); }
92 // the second case is just a bug now.
93 final enclosingClass = context.getEnclosingClass();
94 if (node.token.slowToString() == enclosingClass.name.slowToString()) {
95 // TODO: distinguish the case of constructor vs. nested named closure
96 // (see function_syntax_test).
97 // TODO: fix the bugs above and turn if into the assert.
88 return renameElement(enclosingClass); 98 return renameElement(enclosingClass);
89 } 99 }
90 } 100 }
91 if (context.isFunction() && context.cachedNode.name == node) { 101 if (context.isFunction() && context.cachedNode.name == node) {
Roman 2012/08/02 05:44:53 Can now (context.isFunction()) be false?
Anton Muhin 2012/08/03 13:57:57 Good point, but yes, getters/setters, and they sho
92 return renameElement(context); 102 return renameElement(context);
93 } 103 }
94 return null; 104 return null;
95 } 105 }
96 106
97 String renameElement(Element element) { 107 String renameElement(Element element) {
98 // TODO(smok): Make sure that the new name does not conflict with existing 108 // TODO(smok): Make sure that the new name does not conflict with existing
99 // local identifiers. 109 // local identifiers.
100 if (renamed[element] !== null) return renamed[element]; 110 if (renamed[element] !== null) return renamed[element];
101 111
(...skipping 11 matching lines...) Expand all
113 final library = element.getLibrary(); 123 final library = element.getLibrary();
114 if (library === compiler.coreLibrary) return originalName; 124 if (library === compiler.coreLibrary) return originalName;
115 if (isDartCoreLib(compiler, library)) { 125 if (isDartCoreLib(compiler, library)) {
116 final prefix = 126 final prefix =
117 imports.putIfAbsent(library, () => generateUniqueName('p')); 127 imports.putIfAbsent(library, () => generateUniqueName('p'));
118 return '$prefix.$originalName'; 128 return '$prefix.$originalName';
119 } 129 }
120 return renamed[element] = generateUniqueName(originalName); 130 return renamed[element] = generateUniqueName(originalName);
121 } 131 }
122 } 132 }
OLDNEW
« no previous file with comments | « no previous file | lib/compiler/implementation/tree/unparser.dart » ('j') | lib/compiler/implementation/tree/unparser.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698