| OLD | NEW | 
|---|
| 1 // Copyright (c) 2015, the Dart project authors.  Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 library dart2js.resolution.constructors; | 5 library dart2js.resolution.constructors; | 
| 6 import '../compiler.dart' show | 6 import '../compiler.dart' show | 
| 7     Compiler; | 7     Compiler; | 
| 8 import '../constants/constructors.dart' show | 8 import '../constants/constructors.dart' show | 
| 9     GenerativeConstantConstructor, | 9     GenerativeConstantConstructor, | 
| 10     RedirectingGenerativeConstantConstructor; | 10     RedirectingGenerativeConstantConstructor; | 
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 161       visitor.resolveSelector(call, null); | 161       visitor.resolveSelector(call, null); | 
| 162       return visitor.resolveArguments(call.argumentsNode); | 162       return visitor.resolveArguments(call.argumentsNode); | 
| 163     }, inConstantInitializer: isConst); | 163     }, inConstantInitializer: isConst); | 
| 164 | 164 | 
| 165     bool isSuperCall = Initializers.isSuperConstructorCall(call); | 165     bool isSuperCall = Initializers.isSuperConstructorCall(call); | 
| 166     InterfaceType targetType = | 166     InterfaceType targetType = | 
| 167         getSuperOrThisLookupTarget(call, isSuperCall: isSuperCall); | 167         getSuperOrThisLookupTarget(call, isSuperCall: isSuperCall); | 
| 168     ClassElement lookupTarget = targetType.element; | 168     ClassElement lookupTarget = targetType.element; | 
| 169     Selector constructorSelector = | 169     Selector constructorSelector = | 
| 170         visitor.getRedirectingThisOrSuperConstructorSelector(call); | 170         visitor.getRedirectingThisOrSuperConstructorSelector(call); | 
| 171     FunctionElement calledConstructor = | 171     ConstructorElement calledConstructor = findConstructor( | 
| 172         lookupTarget.lookupConstructor(constructorSelector.name); | 172         constructor.library, lookupTarget, constructorSelector.name); | 
| 173 | 173 | 
| 174     final bool isImplicitSuperCall = false; | 174     final bool isImplicitSuperCall = false; | 
| 175     final String className = lookupTarget.name; | 175     final String className = lookupTarget.name; | 
| 176     verifyThatConstructorMatchesCall(calledConstructor, | 176     verifyThatConstructorMatchesCall(calledConstructor, | 
| 177                                      argumentsResult.callStructure, | 177                                      argumentsResult.callStructure, | 
| 178                                      isImplicitSuperCall, | 178                                      isImplicitSuperCall, | 
| 179                                      call, | 179                                      call, | 
| 180                                      className, | 180                                      className, | 
| 181                                      constructorSelector); | 181                                      constructorSelector); | 
| 182 | 182 | 
| (...skipping 25 matching lines...) Expand all  Loading... | 
| 208     ClassElement classElement = constructor.enclosingClass; | 208     ClassElement classElement = constructor.enclosingClass; | 
| 209     ClassElement superClass = classElement.superclass; | 209     ClassElement superClass = classElement.superclass; | 
| 210     if (classElement != visitor.compiler.objectClass) { | 210     if (classElement != visitor.compiler.objectClass) { | 
| 211       assert(superClass != null); | 211       assert(superClass != null); | 
| 212       assert(superClass.isResolved); | 212       assert(superClass.isResolved); | 
| 213 | 213 | 
| 214       InterfaceType targetType = | 214       InterfaceType targetType = | 
| 215           getSuperOrThisLookupTarget(functionNode, isSuperCall: true); | 215           getSuperOrThisLookupTarget(functionNode, isSuperCall: true); | 
| 216       ClassElement lookupTarget = targetType.element; | 216       ClassElement lookupTarget = targetType.element; | 
| 217       Selector constructorSelector = new Selector.callDefaultConstructor(); | 217       Selector constructorSelector = new Selector.callDefaultConstructor(); | 
| 218       Element calledConstructor = lookupTarget.lookupConstructor( | 218       ConstructorElement calledConstructor = findConstructor( | 
|  | 219           constructor.library, | 
|  | 220           lookupTarget, | 
| 219           constructorSelector.name); | 221           constructorSelector.name); | 
| 220 | 222 | 
| 221       final String className = lookupTarget.name; | 223       final String className = lookupTarget.name; | 
| 222       final bool isImplicitSuperCall = true; | 224       final bool isImplicitSuperCall = true; | 
| 223       verifyThatConstructorMatchesCall(calledConstructor, | 225       verifyThatConstructorMatchesCall(calledConstructor, | 
| 224                                        CallStructure.NO_ARGS, | 226                                        CallStructure.NO_ARGS, | 
| 225                                        isImplicitSuperCall, | 227                                        isImplicitSuperCall, | 
| 226                                        functionNode, | 228                                        functionNode, | 
| 227                                        className, | 229                                        className, | 
| 228                                        constructorSelector); | 230                                        constructorSelector); | 
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 457     } | 459     } | 
| 458     return new ConstructorResult(resultKind, error, type); | 460     return new ConstructorResult(resultKind, error, type); | 
| 459   } | 461   } | 
| 460 | 462 | 
| 461   ConstructorResult resolveConstructor( | 463   ConstructorResult resolveConstructor( | 
| 462       InterfaceType type, | 464       InterfaceType type, | 
| 463       Node diagnosticNode, | 465       Node diagnosticNode, | 
| 464       String constructorName) { | 466       String constructorName) { | 
| 465     ClassElement cls = type.element; | 467     ClassElement cls = type.element; | 
| 466     cls.ensureResolved(compiler); | 468     cls.ensureResolved(compiler); | 
| 467     ConstructorElement constructor = cls.lookupConstructor(constructorName); | 469     ConstructorElement constructor = findConstructor( | 
| 468     // TODO(johnniwinther): Use [Name] for lookup. | 470         resolver.enclosingElement.library, cls, constructorName); | 
| 469     if (Name.isPrivateName(constructorName) && |  | 
| 470         resolver.enclosingElement.library != cls.library) { |  | 
| 471       constructor = null; |  | 
| 472     } |  | 
| 473     if (constructor == null) { | 471     if (constructor == null) { | 
| 474       String fullConstructorName = | 472       String fullConstructorName = | 
| 475           Elements.constructorNameForDiagnostics(cls.name, constructorName); | 473           Elements.constructorNameForDiagnostics(cls.name, constructorName); | 
| 476       return reportAndCreateErroneousConstructorElement( | 474       return reportAndCreateErroneousConstructorElement( | 
| 477           diagnosticNode, | 475           diagnosticNode, | 
| 478           ConstructorResultKind.UNRESOLVED_CONSTRUCTOR, type, | 476           ConstructorResultKind.UNRESOLVED_CONSTRUCTOR, type, | 
| 479           cls, constructorName, | 477           cls, constructorName, | 
| 480           MessageKind.CANNOT_FIND_CONSTRUCTOR, | 478           MessageKind.CANNOT_FIND_CONSTRUCTOR, | 
| 481           {'constructorName': fullConstructorName}, | 479           {'constructorName': fullConstructorName}, | 
| 482           missingConstructor: true); | 480           missingConstructor: true); | 
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 721       sb.write('type=$type'); | 719       sb.write('type=$type'); | 
| 722     } else if (element != null) { | 720     } else if (element != null) { | 
| 723       sb.write('element=$element'); | 721       sb.write('element=$element'); | 
| 724     } else { | 722     } else { | 
| 725       sb.write('type=$type'); | 723       sb.write('type=$type'); | 
| 726     } | 724     } | 
| 727     sb.write(')'); | 725     sb.write(')'); | 
| 728     return sb.toString(); | 726     return sb.toString(); | 
| 729   } | 727   } | 
| 730 } | 728 } | 
|  | 729 | 
|  | 730 /// Lookup the [constructorName] constructor in [cls] and normalize the result | 
|  | 731 /// with respect to privacy and patching. | 
|  | 732 ConstructorElement findConstructor( | 
|  | 733     LibraryElement currentLibrary, | 
|  | 734     ClassElement cls, | 
|  | 735     String constructorName) { | 
|  | 736   if (Name.isPrivateName(constructorName) && | 
|  | 737       currentLibrary.library != cls.library) { | 
|  | 738     // TODO(johnniwinther): Report a special error on unaccessible private | 
|  | 739     // constructors. | 
|  | 740     return null; | 
|  | 741   } | 
|  | 742   // TODO(johnniwinther): Use [Name] for lookup. | 
|  | 743   ConstructorElement constructor = cls.lookupConstructor(constructorName); | 
|  | 744   if (constructor != null) { | 
|  | 745     constructor = constructor.declaration; | 
|  | 746   } | 
|  | 747   return constructor; | 
|  | 748 } | 
| OLD | NEW | 
|---|