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

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: rebase 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 // TODO(ahe): Don't use string replacement here.
176 name = new SourceString(constructor.name.slowToString().replaceFirst(
177 intrface.name.slowToString(),
178 defaultClass.name.slowToString()));
179 } else {
180 name = constructor.name;
181 }
182 constructor.defaultImplementation = defaultClass.lookupConstructor(name);
173 183
174 // If that fails, try looking up "MyClass.name".
175 if (constructor.defaultImplementation === null) { 184 if (constructor.defaultImplementation === null) {
176 SourceString name = 185 // We failed to find a constructor named either
177 new SourceString(constructor.name.slowToString().replaceFirst( 186 // "MyInterface.name" or "MyClass.name".
178 intrface.name.slowToString(), 187 error(node,
179 defaultClass.name.slowToString())); 188 MessageKind.CANNOT_FIND_CONSTRUCTOR2,
180 constructor.defaultImplementation = defaultClass.lookupConstructor(name); 189 [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 } 190 }
189 } 191 }
190 192
191 TreeElements resolveField(Element element) { 193 TreeElements resolveField(Element element) {
192 Node tree = element.parseNode(compiler); 194 Node tree = element.parseNode(compiler);
193 ResolverVisitor visitor = new ResolverVisitor(compiler, element); 195 ResolverVisitor visitor = new ResolverVisitor(compiler, element);
194 initializerDo(tree, visitor.visit); 196 initializerDo(tree, visitor.visit);
195 return visitor.mapping; 197 return visitor.mapping;
196 } 198 }
197 199
(...skipping 1594 matching lines...) Expand 10 before | Expand all | Expand 10 after
1792 1794
1793 TopScope(LibraryElement library) : super(null, library); 1795 TopScope(LibraryElement library) : super(null, library);
1794 Element lookup(SourceString name) { 1796 Element lookup(SourceString name) {
1795 return library.find(name); 1797 return library.find(name);
1796 } 1798 }
1797 1799
1798 Element add(Element element) { 1800 Element add(Element element) {
1799 throw "Cannot add an element in the top scope"; 1801 throw "Cannot add an element in the top scope";
1800 } 1802 }
1801 } 1803 }
OLDNEW
« no previous file with comments | « lib/compiler/implementation/lib/mockimpl.dart ('k') | lib/compiler/implementation/warnings.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698