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

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

Issue 10947024: Made dart2js constructor lookup logic "private"-aware, fixed 4740 bug. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fixed indentation. 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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 // A synthetic constructor does not have a node. 82 // A synthetic constructor does not have a node.
83 if (node === null) return null; 83 if (node === null) return null;
84 if (node.initializers === null) return null; 84 if (node.initializers === null) return null;
85 Link<Node> initializers = node.initializers.nodes; 85 Link<Node> initializers = node.initializers.nodes;
86 if (!initializers.isEmpty() && 86 if (!initializers.isEmpty() &&
87 Initializers.isConstructorRedirect(initializers.head)) { 87 Initializers.isConstructorRedirect(initializers.head)) {
88 final ClassElement classElement = constructor.getEnclosingClass(); 88 final ClassElement classElement = constructor.getEnclosingClass();
89 final SourceString constructorName = 89 final SourceString constructorName =
90 getConstructorName(initializers.head); 90 getConstructorName(initializers.head);
91 final SourceString className = classElement.name; 91 final SourceString className = classElement.name;
92 return classElement.lookupConstructor(className, constructorName); 92
93 return classElement.lookupConstructor(
94 new Selector.callConstructor(
95 new SelectorName.namedConstructor(className, constructorName),
96 constructor.getLibrary())
97 );
93 } 98 }
94 return null; 99 return null;
95 } 100 }
96 101
97 void resolveRedirectingConstructor(InitializerResolver resolver, 102 void resolveRedirectingConstructor(InitializerResolver resolver,
98 Node node, 103 Node node,
99 FunctionElement constructor, 104 FunctionElement constructor,
100 FunctionElement redirection) { 105 FunctionElement redirection) {
101 Set<FunctionElement> seen = new Set<FunctionElement>(); 106 Set<FunctionElement> seen = new Set<FunctionElement>();
102 seen.add(constructor); 107 seen.add(constructor);
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 // of the interface. 183 // of the interface.
179 SourceString name; 184 SourceString name;
180 if (defaultClass.implementsInterface(intrface)) { 185 if (defaultClass.implementsInterface(intrface)) {
181 // TODO(ahe): Don't use string replacement here. 186 // TODO(ahe): Don't use string replacement here.
182 name = new SourceString(constructor.name.slowToString().replaceFirst( 187 name = new SourceString(constructor.name.slowToString().replaceFirst(
183 intrface.name.slowToString(), 188 intrface.name.slowToString(),
184 defaultClass.name.slowToString())); 189 defaultClass.name.slowToString()));
185 } else { 190 } else {
186 name = constructor.name; 191 name = constructor.name;
187 } 192 }
188 constructor.defaultImplementation = defaultClass.lookupConstructor(name); 193 constructor.defaultImplementation = defaultClass.lookupConstructor(
194 new Selector.callConstructor(
195 new SelectorName.namedClass(name),
196 defaultClass.getLibrary()));
189 197
190 if (constructor.defaultImplementation === null) { 198 if (constructor.defaultImplementation === null) {
191 // We failed to find a constructor named either 199 // We failed to find a constructor named either
192 // "MyInterface.name" or "MyClass.name". 200 // "MyInterface.name" or "MyClass.name".
193 error(node, 201 error(node,
194 MessageKind.CANNOT_FIND_CONSTRUCTOR2, 202 MessageKind.CANNOT_FIND_CONSTRUCTOR2,
195 [name, defaultClass.name]); 203 [name, defaultClass.name]);
196 } 204 }
197 } 205 }
198 206
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 if (lookupTarget === visitor.compiler.objectClass) { 593 if (lookupTarget === visitor.compiler.objectClass) {
586 error(diagnosticNode, MessageKind.SUPER_INITIALIZER_IN_OBJECT); 594 error(diagnosticNode, MessageKind.SUPER_INITIALIZER_IN_OBJECT);
587 } else { 595 } else {
588 lookupTarget = lookupTarget.supertype.element; 596 lookupTarget = lookupTarget.supertype.element;
589 } 597 }
590 } 598 }
591 599
592 // Lookup constructor and try to match it to the selector. 600 // Lookup constructor and try to match it to the selector.
593 ResolverTask resolver = visitor.compiler.resolver; 601 ResolverTask resolver = visitor.compiler.resolver;
594 final SourceString className = lookupTarget.name; 602 final SourceString className = lookupTarget.name;
595 result = lookupTarget.lookupConstructor(className, constructorName); 603 result = lookupTarget.lookupConstructor(
604 new Selector.callConstructor(
605 new SelectorName.namedConstructor(className, constructorName),
606 constructor.getLibrary()));
596 if (result === null || !result.isGenerativeConstructor()) { 607 if (result === null || !result.isGenerativeConstructor()) {
597 String classNameString = className.slowToString(); 608 String classNameString = className.slowToString();
598 String constructorNameString = constructorName.slowToString(); 609 String constructorNameString = constructorName.slowToString();
599 String name = (constructorName === const SourceString('')) 610 String name = (constructorName === const SourceString(''))
600 ? classNameString 611 ? classNameString
601 : "$classNameString.$constructorNameString"; 612 : "$classNameString.$constructorNameString";
602 MessageKind kind = isImplicitSuperCall 613 MessageKind kind = isImplicitSuperCall
603 ? MessageKind.CANNOT_RESOLVE_CONSTRUCTOR_FOR_IMPLICIT 614 ? MessageKind.CANNOT_RESOLVE_CONSTRUCTOR_FOR_IMPLICIT
604 : MessageKind.CANNOT_RESOLVE_CONSTRUCTOR; 615 : MessageKind.CANNOT_RESOLVE_CONSTRUCTOR;
605 error(diagnosticNode, kind, [name]); 616 error(diagnosticNode, kind, [name]);
(...skipping 1991 matching lines...) Expand 10 before | Expand all | Expand 10 after
2597 compiler.reportWarning(diagnosticNode, warning); 2608 compiler.reportWarning(diagnosticNode, warning);
2598 return new ErroneousFunctionElement(warning.message, targetName, 2609 return new ErroneousFunctionElement(warning.message, targetName,
2599 enclosing); 2610 enclosing);
2600 } 2611 }
2601 } 2612 }
2602 2613
2603 FunctionElement lookupConstructor(ClassElement cls, 2614 FunctionElement lookupConstructor(ClassElement cls,
2604 Node diagnosticNode, 2615 Node diagnosticNode,
2605 SourceString constructorName) { 2616 SourceString constructorName) {
2606 cls.ensureResolved(compiler); 2617 cls.ensureResolved(compiler);
2607 Element result = cls.lookupConstructor(cls.name, constructorName); 2618 Element result = cls.lookupConstructor(
2619 new Selector.callConstructor(
2620 new SelectorName.namedConstructor(cls.name, constructorName),
2621 resolver.enclosingElement.getLibrary()));
2608 if (result === null) { 2622 if (result === null) {
2609 String fullConstructorName = cls.name.slowToString(); 2623 String fullConstructorName = cls.name.slowToString();
2610 if (constructorName !== const SourceString('')) { 2624 if (constructorName !== const SourceString('')) {
2611 fullConstructorName = '$fullConstructorName' 2625 fullConstructorName = '$fullConstructorName'
2612 '.${constructorName.slowToString()}'; 2626 '.${constructorName.slowToString()}';
2613 } 2627 }
2614 return failOrReturnErroneousElement(cls, diagnosticNode, 2628 return failOrReturnErroneousElement(cls, diagnosticNode,
2615 new SourceString(fullConstructorName), 2629 new SourceString(fullConstructorName),
2616 MessageKind.CANNOT_FIND_CONSTRUCTOR, 2630 MessageKind.CANNOT_FIND_CONSTRUCTOR,
2617 [fullConstructorName]); 2631 [fullConstructorName]);
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
2825 2839
2826 Element localLookup(SourceString name) => library.find(name); 2840 Element localLookup(SourceString name) => library.find(name);
2827 Element lookup(SourceString name) => localLookup(name); 2841 Element lookup(SourceString name) => localLookup(name);
2828 Element lexicalLookup(SourceString name) => localLookup(name); 2842 Element lexicalLookup(SourceString name) => localLookup(name);
2829 2843
2830 Element add(Element newElement) { 2844 Element add(Element newElement) {
2831 throw "Cannot add an element in the top scope"; 2845 throw "Cannot add an element in the top scope";
2832 } 2846 }
2833 String toString() => '$element'; 2847 String toString() => '$element';
2834 } 2848 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698