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

Side by Side Diff: lib/compiler/implementation/resolver.dart

Issue 9980004: Look up the correct constructor for default classes. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 8 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 interface TreeElements { 5 interface TreeElements {
6 Element operator[](Node node); 6 Element operator[](Node node);
7 Selector getSelector(Send send); 7 Selector getSelector(Send send);
8 } 8 }
9 9
10 class TreeElementMapping implements TreeElements { 10 class TreeElementMapping implements TreeElements {
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 ClassElement defaultClass = defaultType.element; 160 ClassElement defaultClass = defaultType.element;
161 defaultClass.ensureResolved(compiler); 161 defaultClass.ensureResolved(compiler);
162 if (defaultClass.isInterface()) { 162 if (defaultClass.isInterface()) {
163 error(node, MessageKind.CANNOT_INSTANTIATE_INTERFACE, 163 error(node, MessageKind.CANNOT_INSTANTIATE_INTERFACE,
164 [defaultClass.name]); 164 [defaultClass.name]);
165 } 165 }
166 // We have now established the following: 166 // We have now established the following:
167 // [intrface] is an interface, let's say "MyInterface". 167 // [intrface] is an interface, let's say "MyInterface".
168 // [defaultClass] is a class, let's say "MyClass". 168 // [defaultClass] is a class, let's say "MyClass".
169 169
170 // First look up the constructor named "MyInterface.name". 170 // If the default class implements the interface then we must use the
171 constructor.defaultImplementation = 171 // default class' name. Otherwise we look for a factory with the name
172 defaultClass.lookupConstructor(constructor.name); 172 // of the interface.
173 SourceString name;
174 if (defaultClass.implementsInterface(intrface)) {
175 name = new SourceString(constructor.name.slowToString().replaceFirst(
ahe 2012/04/10 14:30:38 Please add "TODO(ahe): Don't use string replacemen
floitsch 2012/04/11 11:40:56 Done.
176 intrface.name.slowToString(),
177 defaultClass.name.slowToString()));
178 } else {
179 name = constructor.name;
180 }
181 constructor.defaultImplementation = defaultClass.lookupConstructor(name);
173 182
174 // If that fails, try looking up "MyClass.name".
175 if (constructor.defaultImplementation === null) { 183 if (constructor.defaultImplementation === null) {
176 SourceString name = 184 // We failed to find a constructor named either
177 new SourceString(constructor.name.slowToString().replaceFirst( 185 // "MyInterface.name" or "MyClass.name".
178 intrface.name.slowToString(), 186 error(node,
179 defaultClass.name.slowToString())); 187 MessageKind.CANNOT_FIND_CONSTRUCTOR2,
180 constructor.defaultImplementation = defaultClass.lookupConstructor(name); 188 [name, defaultClass.name]);
181
182 if (constructor.defaultImplementation === null) {
183 // We failed find a constrcutor named either
184 // "MyInterface.name" or "MyClass.name".
185 error(node, MessageKind.CANNOT_FIND_CONSTRUCTOR2,
186 [constructor.name, name]);
187 }
188 } 189 }
189 } 190 }
190 191
191 TreeElements resolveField(Element element) { 192 TreeElements resolveField(Element element) {
192 Node tree = element.parseNode(compiler); 193 Node tree = element.parseNode(compiler);
193 ResolverVisitor visitor = new ResolverVisitor(compiler, element); 194 ResolverVisitor visitor = new ResolverVisitor(compiler, element);
194 initializerDo(tree, visitor.visit); 195 initializerDo(tree, visitor.visit);
195 return visitor.mapping; 196 return visitor.mapping;
196 } 197 }
197 198
(...skipping 1594 matching lines...) Expand 10 before | Expand all | Expand 10 after
1792 1793
1793 TopScope(LibraryElement library) : super(null, library); 1794 TopScope(LibraryElement library) : super(null, library);
1794 Element lookup(SourceString name) { 1795 Element lookup(SourceString name) {
1795 return library.find(name); 1796 return library.find(name);
1796 } 1797 }
1797 1798
1798 Element add(Element element) { 1799 Element add(Element element) {
1799 throw "Cannot add an element in the top scope"; 1800 throw "Cannot add an element in the top scope";
1800 } 1801 }
1801 } 1802 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698