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

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

Issue 10970006: Correctly handle const constructors with type parameters. (Closed) Base URL: http://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 abstract class TreeElements { 5 abstract class TreeElements {
6 Element operator[](Node node); 6 Element operator[](Node node);
7 Selector getSelector(Send send); 7 Selector getSelector(Send send);
8 DartType getType(TypeAnnotation annotation); 8 DartType getType(TypeAnnotation annotation);
9 bool isParameterChecked(Element element); 9 bool isParameterChecked(Element element);
10 } 10 }
(...skipping 2586 matching lines...) Expand 10 before | Expand all | Expand 10 after
2597 2597
2598 // TODO(ahe): This is temporary. 2598 // TODO(ahe): This is temporary.
2599 ClassElement get currentClass { 2599 ClassElement get currentClass {
2600 return enclosingElement.isMember() 2600 return enclosingElement.isMember()
2601 ? enclosingElement.getEnclosingClass() : null; 2601 ? enclosingElement.getEnclosingClass() : null;
2602 } 2602 }
2603 } 2603 }
2604 2604
2605 class ConstructorResolver extends CommonResolverVisitor<Element> { 2605 class ConstructorResolver extends CommonResolverVisitor<Element> {
2606 final ResolverVisitor resolver; 2606 final ResolverVisitor resolver;
2607 // TODO(ngeoffray): have this context at the call site.
2607 final bool inConstContext; 2608 final bool inConstContext;
2608 2609
2609 ConstructorResolver(Compiler compiler, this.resolver, 2610 ConstructorResolver(Compiler compiler,
2610 [bool this.inConstContext = false]) 2611 this.resolver,
2612 this.inConstContext)
2611 : super(compiler); 2613 : super(compiler);
2612 2614
2613 visitNode(Node node) { 2615 visitNode(Node node) {
2614 throw 'not supported'; 2616 throw 'not supported';
2615 } 2617 }
2616 2618
2617 failOrReturnErroneousElement(Element enclosing, Node diagnosticNode, 2619 failOrReturnErroneousElement(Element enclosing, Node diagnosticNode,
2618 SourceString targetName, MessageKind kind, 2620 SourceString targetName, MessageKind kind,
2619 List arguments) { 2621 List arguments) {
2620 if (inConstContext) { 2622 if (inConstContext) {
2621 error(diagnosticNode, kind, arguments); 2623 error(diagnosticNode, kind, arguments);
2622 } else { 2624 } else {
2623 ResolutionWarning warning = new ResolutionWarning(kind, arguments); 2625 ResolutionWarning warning = new ResolutionWarning(kind, arguments);
2624 compiler.reportWarning(diagnosticNode, warning); 2626 compiler.reportWarning(diagnosticNode, warning);
2625 return new ErroneousFunctionElement(warning.message, targetName, 2627 return new ErroneousFunctionElement(warning.message, targetName,
2626 enclosing); 2628 enclosing);
2627 } 2629 }
2628 } 2630 }
2629 2631
2632 // TODO(ngeoffray): method named lookup should not report errors.
2630 FunctionElement lookupConstructor(ClassElement cls, 2633 FunctionElement lookupConstructor(ClassElement cls,
2631 Node diagnosticNode, 2634 Node diagnosticNode,
2632 SourceString constructorName) { 2635 SourceString constructorName) {
2633 cls.ensureResolved(compiler); 2636 cls.ensureResolved(compiler);
2634 Element result = cls.lookupConstructor(cls.name, constructorName); 2637 Element result = cls.lookupConstructor(cls.name, constructorName);
2635 if (result === null) { 2638 if (result === null) {
2636 String fullConstructorName = cls.name.slowToString(); 2639 String fullConstructorName = cls.name.slowToString();
2637 if (constructorName !== const SourceString('')) { 2640 if (constructorName !== const SourceString('')) {
2638 fullConstructorName = '$fullConstructorName' 2641 fullConstructorName = '$fullConstructorName'
2639 '.${constructorName.slowToString()}'; 2642 '.${constructorName.slowToString()}';
2640 } 2643 }
2641 return failOrReturnErroneousElement(cls, diagnosticNode, 2644 return failOrReturnErroneousElement(cls, diagnosticNode,
2642 new SourceString(fullConstructorName), 2645 new SourceString(fullConstructorName),
2643 MessageKind.CANNOT_FIND_CONSTRUCTOR, 2646 MessageKind.CANNOT_FIND_CONSTRUCTOR,
2644 [fullConstructorName]); 2647 [fullConstructorName]);
2648 } else if (inConstContext &&
2649 (result.modifiers == null || !result.modifiers.isConst())) {
2650 error(diagnosticNode, MessageKind.CONSTRUCTOR_IS_NOT_CONST);
2645 } 2651 }
2646 return result; 2652 return result;
2647 } 2653 }
2648 2654
2649 visitNewExpression(NewExpression node) { 2655 visitNewExpression(NewExpression node) {
2650 Node selector = node.send.selector; 2656 Node selector = node.send.selector;
2651 Element e = visit(selector); 2657 Element e = visit(selector);
2652 if (!Elements.isUnresolved(e) && e.kind === ElementKind.CLASS) { 2658 if (!Elements.isUnresolved(e) && e.kind === ElementKind.CLASS) {
2653 ClassElement cls = e; 2659 ClassElement cls = e;
2654 cls.ensureResolved(compiler); 2660 cls.ensureResolved(compiler);
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
2852 2858
2853 Element localLookup(SourceString name) => library.find(name); 2859 Element localLookup(SourceString name) => library.find(name);
2854 Element lookup(SourceString name) => localLookup(name); 2860 Element lookup(SourceString name) => localLookup(name);
2855 Element lexicalLookup(SourceString name) => localLookup(name); 2861 Element lexicalLookup(SourceString name) => localLookup(name);
2856 2862
2857 Element add(Element newElement) { 2863 Element add(Element newElement) {
2858 throw "Cannot add an element in the top scope"; 2864 throw "Cannot add an element in the top scope";
2859 } 2865 }
2860 String toString() => '$element'; 2866 String toString() => '$element';
2861 } 2867 }
OLDNEW
« no previous file with comments | « lib/compiler/implementation/lib/math_patch.dart ('k') | lib/compiler/implementation/scanner/listener.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698