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

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

Issue 10870037: Throw a NoSuchMethodException when attempting to call an undefined constructor. (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 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 Type getType(TypeAnnotation annotation); 8 Type getType(TypeAnnotation annotation);
9 } 9 }
10 10
(...skipping 1512 matching lines...) Expand 10 before | Expand all | Expand 10 after
1523 compiler.internalError("malformed send in new expression"); 1523 compiler.internalError("malformed send in new expression");
1524 } 1524 }
1525 } 1525 }
1526 1526
1527 /** 1527 /**
1528 * Try to resolve the constructor that is referred to by [node]. 1528 * Try to resolve the constructor that is referred to by [node].
1529 * Note: this function may return an ErroneousFunctionElement instead of 1529 * Note: this function may return an ErroneousFunctionElement instead of
1530 * [null], if there is no corresponding constructor, class or library. 1530 * [null], if there is no corresponding constructor, class or library.
1531 */ 1531 */
1532 FunctionElement resolveConstructor(NewExpression node) { 1532 FunctionElement resolveConstructor(NewExpression node) {
1533 FunctionElement constructor =
1534 node.accept(new ConstructorResolver(compiler, this));
1535 TypeAnnotation annotation = getTypeAnnotationFromSend(node.send); 1533 TypeAnnotation annotation = getTypeAnnotationFromSend(node.send);
1536 // TODO(karlklose): clean up: the type should be resolved in the 1534 // TODO(karlklose): clean up: the type should be resolved in the
1537 // constructor resolver visitor to avoid visiting the node twice. 1535 // constructor resolver visitor to avoid visiting the node twice.
1538 resolveTypeRequired(annotation); 1536 resolveTypeRequired(annotation);
1539 return constructor; 1537 var visitor = new ConstructorResolver(compiler, this, node.isConst());
ngeoffray 2012/08/23 10:25:05 var -> ConstructorResolver
karlklose 2012/08/23 11:05:56 Done.
1538 return node.accept(visitor);
1540 } 1539 }
1541 1540
1542 Type resolveTypeRequired(TypeAnnotation node) { 1541 Type resolveTypeRequired(TypeAnnotation node) {
1543 bool old = typeRequired; 1542 bool old = typeRequired;
1544 typeRequired = true; 1543 typeRequired = true;
1545 Type result = resolveTypeAnnotation(node); 1544 Type result = resolveTypeAnnotation(node);
1546 typeRequired = old; 1545 typeRequired = old;
1547 return result; 1546 return result;
1548 } 1547 }
1549 1548
(...skipping 795 matching lines...) Expand 10 before | Expand all | Expand 10 after
2345 2344
2346 // TODO(ahe): This is temporary. 2345 // TODO(ahe): This is temporary.
2347 ClassElement get currentClass { 2346 ClassElement get currentClass {
2348 return enclosingElement.isMember() 2347 return enclosingElement.isMember()
2349 ? enclosingElement.getEnclosingClass() : null; 2348 ? enclosingElement.getEnclosingClass() : null;
2350 } 2349 }
2351 } 2350 }
2352 2351
2353 class ConstructorResolver extends CommonResolverVisitor<Element> { 2352 class ConstructorResolver extends CommonResolverVisitor<Element> {
2354 final ResolverVisitor resolver; 2353 final ResolverVisitor resolver;
2354 final bool inConstContext;
2355 2355
2356 ConstructorResolver(Compiler compiler, this.resolver) : super(compiler); 2356 ConstructorResolver(Compiler compiler, this.resolver,
2357 [bool this.inConstContext = false])
2358 : super(compiler);
2357 2359
2358 visitNode(Node node) { 2360 visitNode(Node node) {
2359 throw 'not supported'; 2361 throw 'not supported';
2360 } 2362 }
2361 2363
2362 FunctionElement lookupConstructor(ClassElement cls, 2364 FunctionElement lookupConstructor(ClassElement cls,
2363 Node diagnosticNode, 2365 Node diagnosticNode,
2364 SourceString constructorName) { 2366 SourceString constructorName) {
2365 cls.ensureResolved(compiler); 2367 cls.ensureResolved(compiler);
2366 Element result = cls.lookupConstructor(cls.name, constructorName); 2368 Element result = cls.lookupConstructor(cls.name, constructorName);
2367 if (result === null) { 2369 if (result === null) {
2368 String fullConstructorName = cls.name.slowToString(); 2370 String fullConstructorName = cls.name.slowToString();
2369 if (constructorName !== const SourceString('')) { 2371 if (constructorName !== const SourceString('')) {
2370 fullConstructorName = '$fullConstructorName' 2372 fullConstructorName = '$fullConstructorName'
2371 '.${constructorName.slowToString()}'; 2373 '.${constructorName.slowToString()}';
2372 } 2374 }
2373 ResolutionWarning warning = 2375 if (inConstContext) {
2374 new ResolutionWarning(MessageKind.CANNOT_FIND_CONSTRUCTOR, 2376 error(diagnosticNode, MessageKind.CANNOT_FIND_CONSTRUCTOR,
2375 [fullConstructorName]); 2377 [fullConstructorName]);
2376 compiler.reportWarning(diagnosticNode, warning); 2378 } else {
2377 return new ErroneousFunctionElement(warning.message, cls); 2379 ResolutionWarning warning =
2380 new ResolutionWarning(MessageKind.CANNOT_FIND_CONSTRUCTOR,
2381 [fullConstructorName]);
2382 compiler.reportWarning(diagnosticNode, warning);
2383 return new ErroneousFunctionElement(warning.message, cls);
2384 }
2378 } 2385 }
2379 return result; 2386 return result;
2380 } 2387 }
2381 2388
2382 visitNewExpression(NewExpression node) { 2389 visitNewExpression(NewExpression node) {
2383 Node selector = node.send.selector; 2390 Node selector = node.send.selector;
2384 Element e = visit(selector); 2391 Element e = visit(selector);
2385 if (!Element.isInvalid(e) && e.kind === ElementKind.CLASS) { 2392 if (!Element.isInvalid(e) && e.kind === ElementKind.CLASS) {
2386 ClassElement cls = e; 2393 ClassElement cls = e;
2387 cls.ensureResolved(compiler); 2394 cls.ensureResolved(compiler);
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
2558 TopScope(LibraryElement library) : super(null, library); 2565 TopScope(LibraryElement library) : super(null, library);
2559 Element lookup(SourceString name) { 2566 Element lookup(SourceString name) {
2560 return library.find(name); 2567 return library.find(name);
2561 } 2568 }
2562 2569
2563 Element add(Element newElement) { 2570 Element add(Element newElement) {
2564 throw "Cannot add an element in the top scope"; 2571 throw "Cannot add an element in the top scope";
2565 } 2572 }
2566 String toString() => '$element'; 2573 String toString() => '$element';
2567 } 2574 }
OLDNEW
« no previous file with comments | « no previous file | lib/compiler/implementation/ssa/builder.dart » ('j') | lib/compiler/implementation/ssa/builder.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698