| 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; |
| 11 import '../constants/expressions.dart'; | 11 import '../constants/expressions.dart'; |
| 12 import '../dart_types.dart'; | 12 import '../dart_types.dart'; |
| 13 import '../diagnostics/diagnostic_listener.dart' show | 13 import '../diagnostics/diagnostic_listener.dart' show |
| 14 DiagnosticListener, | 14 DiagnosticReporter, |
| 15 DiagnosticMessage; | 15 DiagnosticMessage; |
| 16 import '../diagnostics/invariant.dart' show | 16 import '../diagnostics/invariant.dart' show |
| 17 invariant; | 17 invariant; |
| 18 import '../diagnostics/messages.dart' show | 18 import '../diagnostics/messages.dart' show |
| 19 MessageKind; | 19 MessageKind; |
| 20 import '../diagnostics/spannable.dart' show | 20 import '../diagnostics/spannable.dart' show |
| 21 Spannable; | 21 Spannable; |
| 22 import '../elements/elements.dart'; | 22 import '../elements/elements.dart'; |
| 23 import '../elements/modelx.dart' show | 23 import '../elements/modelx.dart' show |
| 24 ConstructorElementX, | 24 ConstructorElementX, |
| (...skipping 30 matching lines...) Expand all Loading... |
| 55 Link<Node> initializers; | 55 Link<Node> initializers; |
| 56 bool hasSuper = false; | 56 bool hasSuper = false; |
| 57 bool isValidAsConstant = true; | 57 bool isValidAsConstant = true; |
| 58 | 58 |
| 59 bool get isConst => constructor.isConst; | 59 bool get isConst => constructor.isConst; |
| 60 | 60 |
| 61 InitializerResolver(this.visitor, this.constructor, this.functionNode); | 61 InitializerResolver(this.visitor, this.constructor, this.functionNode); |
| 62 | 62 |
| 63 ResolutionRegistry get registry => visitor.registry; | 63 ResolutionRegistry get registry => visitor.registry; |
| 64 | 64 |
| 65 DiagnosticListener get listener => visitor.compiler; | 65 DiagnosticReporter get reporter => visitor.reporter; |
| 66 | 66 |
| 67 bool isFieldInitializer(SendSet node) { | 67 bool isFieldInitializer(SendSet node) { |
| 68 if (node.selector.asIdentifier() == null) return false; | 68 if (node.selector.asIdentifier() == null) return false; |
| 69 if (node.receiver == null) return true; | 69 if (node.receiver == null) return true; |
| 70 if (node.receiver.asIdentifier() == null) return false; | 70 if (node.receiver.asIdentifier() == null) return false; |
| 71 return node.receiver.asIdentifier().isThis(); | 71 return node.receiver.asIdentifier().isThis(); |
| 72 } | 72 } |
| 73 | 73 |
| 74 reportDuplicateInitializerError(Element field, Node init, Node existing) { | 74 reportDuplicateInitializerError(Element field, Node init, Node existing) { |
| 75 listener.reportError( | 75 reporter.reportError( |
| 76 listener.createMessage( | 76 reporter.createMessage( |
| 77 init, | 77 init, |
| 78 MessageKind.DUPLICATE_INITIALIZER, | 78 MessageKind.DUPLICATE_INITIALIZER, |
| 79 {'fieldName': field.name}), | 79 {'fieldName': field.name}), |
| 80 <DiagnosticMessage>[ | 80 <DiagnosticMessage>[ |
| 81 listener.createMessage( | 81 reporter.createMessage( |
| 82 existing, | 82 existing, |
| 83 MessageKind.ALREADY_INITIALIZED, | 83 MessageKind.ALREADY_INITIALIZED, |
| 84 {'fieldName': field.name}), | 84 {'fieldName': field.name}), |
| 85 ]); | 85 ]); |
| 86 isValidAsConstant = false; | 86 isValidAsConstant = false; |
| 87 } | 87 } |
| 88 | 88 |
| 89 void checkForDuplicateInitializers(FieldElementX field, Node init) { | 89 void checkForDuplicateInitializers(FieldElementX field, Node init) { |
| 90 // [field] can be null if it could not be resolved. | 90 // [field] can be null if it could not be resolved. |
| 91 if (field == null) return; | 91 if (field == null) return; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 104 void resolveFieldInitializer(SendSet init) { | 104 void resolveFieldInitializer(SendSet init) { |
| 105 // init is of the form [this.]field = value. | 105 // init is of the form [this.]field = value. |
| 106 final Node selector = init.selector; | 106 final Node selector = init.selector; |
| 107 final String name = selector.asIdentifier().source; | 107 final String name = selector.asIdentifier().source; |
| 108 // Lookup target field. | 108 // Lookup target field. |
| 109 Element target; | 109 Element target; |
| 110 FieldElement field; | 110 FieldElement field; |
| 111 if (isFieldInitializer(init)) { | 111 if (isFieldInitializer(init)) { |
| 112 target = constructor.enclosingClass.lookupLocalMember(name); | 112 target = constructor.enclosingClass.lookupLocalMember(name); |
| 113 if (target == null) { | 113 if (target == null) { |
| 114 listener.reportErrorMessage( | 114 reporter.reportErrorMessage( |
| 115 selector, MessageKind.CANNOT_RESOLVE, {'name': name}); | 115 selector, MessageKind.CANNOT_RESOLVE, {'name': name}); |
| 116 target = new ErroneousFieldElementX( | 116 target = new ErroneousFieldElementX( |
| 117 selector.asIdentifier(), constructor.enclosingClass); | 117 selector.asIdentifier(), constructor.enclosingClass); |
| 118 } else if (target.kind != ElementKind.FIELD) { | 118 } else if (target.kind != ElementKind.FIELD) { |
| 119 listener.reportErrorMessage( | 119 reporter.reportErrorMessage( |
| 120 selector, MessageKind.NOT_A_FIELD, {'fieldName': name}); | 120 selector, MessageKind.NOT_A_FIELD, {'fieldName': name}); |
| 121 target = new ErroneousFieldElementX( | 121 target = new ErroneousFieldElementX( |
| 122 selector.asIdentifier(), constructor.enclosingClass); | 122 selector.asIdentifier(), constructor.enclosingClass); |
| 123 } else if (!target.isInstanceMember) { | 123 } else if (!target.isInstanceMember) { |
| 124 listener.reportErrorMessage( | 124 reporter.reportErrorMessage( |
| 125 selector, MessageKind.INIT_STATIC_FIELD, {'fieldName': name}); | 125 selector, MessageKind.INIT_STATIC_FIELD, {'fieldName': name}); |
| 126 } else { | 126 } else { |
| 127 field = target; | 127 field = target; |
| 128 } | 128 } |
| 129 } else { | 129 } else { |
| 130 listener.reportErrorMessage( | 130 reporter.reportErrorMessage( |
| 131 init, MessageKind.INVALID_RECEIVER_IN_INITIALIZER); | 131 init, MessageKind.INVALID_RECEIVER_IN_INITIALIZER); |
| 132 } | 132 } |
| 133 registry.useElement(init, target); | 133 registry.useElement(init, target); |
| 134 registry.registerStaticUse(target); | 134 registry.registerStaticUse(target); |
| 135 checkForDuplicateInitializers(target, init); | 135 checkForDuplicateInitializers(target, init); |
| 136 // Resolve initializing value. | 136 // Resolve initializing value. |
| 137 ResolutionResult result = visitor.visitInStaticContext( | 137 ResolutionResult result = visitor.visitInStaticContext( |
| 138 init.arguments.head, | 138 init.arguments.head, |
| 139 inConstantInitializer: isConst); | 139 inConstantInitializer: isConst); |
| 140 if (isConst) { | 140 if (isConst) { |
| 141 if (result.isConstant && field != null) { | 141 if (result.isConstant && field != null) { |
| 142 // TODO(johnniwinther): Report error if `result.constant` is `null`. | 142 // TODO(johnniwinther): Report error if `result.constant` is `null`. |
| 143 fieldInitializers[field] = result.constant; | 143 fieldInitializers[field] = result.constant; |
| 144 } else { | 144 } else { |
| 145 isValidAsConstant = false; | 145 isValidAsConstant = false; |
| 146 } | 146 } |
| 147 } | 147 } |
| 148 } | 148 } |
| 149 | 149 |
| 150 InterfaceType getSuperOrThisLookupTarget(Node diagnosticNode, | 150 InterfaceType getSuperOrThisLookupTarget(Node diagnosticNode, |
| 151 {bool isSuperCall}) { | 151 {bool isSuperCall}) { |
| 152 if (isSuperCall) { | 152 if (isSuperCall) { |
| 153 // Calculate correct lookup target and constructor name. | 153 // Calculate correct lookup target and constructor name. |
| 154 if (identical(constructor.enclosingClass, visitor.compiler.objectClass)) { | 154 if (identical(constructor.enclosingClass, visitor.compiler.objectClass)) { |
| 155 listener.reportErrorMessage( | 155 reporter.reportErrorMessage( |
| 156 diagnosticNode, MessageKind.SUPER_INITIALIZER_IN_OBJECT); | 156 diagnosticNode, MessageKind.SUPER_INITIALIZER_IN_OBJECT); |
| 157 isValidAsConstant = false; | 157 isValidAsConstant = false; |
| 158 } else { | 158 } else { |
| 159 return constructor.enclosingClass.supertype; | 159 return constructor.enclosingClass.supertype; |
| 160 } | 160 } |
| 161 } | 161 } |
| 162 return constructor.enclosingClass.thisType; | 162 return constructor.enclosingClass.thisType; |
| 163 } | 163 } |
| 164 | 164 |
| 165 ResolutionResult resolveSuperOrThisForSend(Send call) { | 165 ResolutionResult resolveSuperOrThisForSend(Send call) { |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 String className, | 257 String className, |
| 258 Selector constructorSelector) { | 258 Selector constructorSelector) { |
| 259 if (lookedupConstructor == null || | 259 if (lookedupConstructor == null || |
| 260 !lookedupConstructor.isGenerativeConstructor) { | 260 !lookedupConstructor.isGenerativeConstructor) { |
| 261 String fullConstructorName = Elements.constructorNameForDiagnostics( | 261 String fullConstructorName = Elements.constructorNameForDiagnostics( |
| 262 className, | 262 className, |
| 263 constructorSelector.name); | 263 constructorSelector.name); |
| 264 MessageKind kind = isImplicitSuperCall | 264 MessageKind kind = isImplicitSuperCall |
| 265 ? MessageKind.CANNOT_RESOLVE_CONSTRUCTOR_FOR_IMPLICIT | 265 ? MessageKind.CANNOT_RESOLVE_CONSTRUCTOR_FOR_IMPLICIT |
| 266 : MessageKind.CANNOT_RESOLVE_CONSTRUCTOR; | 266 : MessageKind.CANNOT_RESOLVE_CONSTRUCTOR; |
| 267 listener.reportErrorMessage( | 267 reporter.reportErrorMessage( |
| 268 diagnosticNode, kind, {'constructorName': fullConstructorName}); | 268 diagnosticNode, kind, {'constructorName': fullConstructorName}); |
| 269 isValidAsConstant = false; | 269 isValidAsConstant = false; |
| 270 } else { | 270 } else { |
| 271 lookedupConstructor.computeType(visitor.resolution); | 271 lookedupConstructor.computeType(visitor.resolution); |
| 272 if (!call.signatureApplies(lookedupConstructor.functionSignature)) { | 272 if (!call.signatureApplies(lookedupConstructor.functionSignature)) { |
| 273 MessageKind kind = isImplicitSuperCall | 273 MessageKind kind = isImplicitSuperCall |
| 274 ? MessageKind.NO_MATCHING_CONSTRUCTOR_FOR_IMPLICIT | 274 ? MessageKind.NO_MATCHING_CONSTRUCTOR_FOR_IMPLICIT |
| 275 : MessageKind.NO_MATCHING_CONSTRUCTOR; | 275 : MessageKind.NO_MATCHING_CONSTRUCTOR; |
| 276 listener.reportErrorMessage(diagnosticNode, kind); | 276 reporter.reportErrorMessage(diagnosticNode, kind); |
| 277 isValidAsConstant = false; | 277 isValidAsConstant = false; |
| 278 } else if (constructor.isConst | 278 } else if (constructor.isConst |
| 279 && !lookedupConstructor.isConst) { | 279 && !lookedupConstructor.isConst) { |
| 280 MessageKind kind = isImplicitSuperCall | 280 MessageKind kind = isImplicitSuperCall |
| 281 ? MessageKind.CONST_CALLS_NON_CONST_FOR_IMPLICIT | 281 ? MessageKind.CONST_CALLS_NON_CONST_FOR_IMPLICIT |
| 282 : MessageKind.CONST_CALLS_NON_CONST; | 282 : MessageKind.CONST_CALLS_NON_CONST; |
| 283 listener.reportErrorMessage(diagnosticNode, kind); | 283 reporter.reportErrorMessage(diagnosticNode, kind); |
| 284 isValidAsConstant = false; | 284 isValidAsConstant = false; |
| 285 } | 285 } |
| 286 } | 286 } |
| 287 } | 287 } |
| 288 | 288 |
| 289 /** | 289 /** |
| 290 * Resolve all initializers of this constructor. In the case of a redirecting | 290 * Resolve all initializers of this constructor. In the case of a redirecting |
| 291 * constructor, the resolved constructor's function element is returned. | 291 * constructor, the resolved constructor's function element is returned. |
| 292 */ | 292 */ |
| 293 ConstructorElement resolveInitializers() { | 293 ConstructorElement resolveInitializers() { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 initializers = functionNode.initializers.nodes; | 343 initializers = functionNode.initializers.nodes; |
| 344 } | 344 } |
| 345 bool resolvedSuper = false; | 345 bool resolvedSuper = false; |
| 346 for (Link<Node> link = initializers; !link.isEmpty; link = link.tail) { | 346 for (Link<Node> link = initializers; !link.isEmpty; link = link.tail) { |
| 347 if (link.head.asSendSet() != null) { | 347 if (link.head.asSendSet() != null) { |
| 348 final SendSet init = link.head.asSendSet(); | 348 final SendSet init = link.head.asSendSet(); |
| 349 resolveFieldInitializer(init); | 349 resolveFieldInitializer(init); |
| 350 } else if (link.head.asSend() != null) { | 350 } else if (link.head.asSend() != null) { |
| 351 final Send call = link.head.asSend(); | 351 final Send call = link.head.asSend(); |
| 352 if (call.argumentsNode == null) { | 352 if (call.argumentsNode == null) { |
| 353 listener.reportErrorMessage( | 353 reporter.reportErrorMessage( |
| 354 link.head, MessageKind.INVALID_INITIALIZER); | 354 link.head, MessageKind.INVALID_INITIALIZER); |
| 355 continue; | 355 continue; |
| 356 } | 356 } |
| 357 if (Initializers.isSuperConstructorCall(call)) { | 357 if (Initializers.isSuperConstructorCall(call)) { |
| 358 if (resolvedSuper) { | 358 if (resolvedSuper) { |
| 359 listener.reportErrorMessage( | 359 reporter.reportErrorMessage( |
| 360 call, MessageKind.DUPLICATE_SUPER_INITIALIZER); | 360 call, MessageKind.DUPLICATE_SUPER_INITIALIZER); |
| 361 } | 361 } |
| 362 ResolutionResult result = resolveSuperOrThisForSend(call); | 362 ResolutionResult result = resolveSuperOrThisForSend(call); |
| 363 if (isConst) { | 363 if (isConst) { |
| 364 if (result.isConstant) { | 364 if (result.isConstant) { |
| 365 constructorInvocation = result.constant; | 365 constructorInvocation = result.constant; |
| 366 } else { | 366 } else { |
| 367 isValidAsConstant = false; | 367 isValidAsConstant = false; |
| 368 } | 368 } |
| 369 } | 369 } |
| 370 resolvedSuper = true; | 370 resolvedSuper = true; |
| 371 } else if (Initializers.isConstructorRedirect(call)) { | 371 } else if (Initializers.isConstructorRedirect(call)) { |
| 372 // Check that there is no body (Language specification 7.5.1). If the | 372 // Check that there is no body (Language specification 7.5.1). If the |
| 373 // constructor is also const, we already reported an error in | 373 // constructor is also const, we already reported an error in |
| 374 // [resolveMethodElement]. | 374 // [resolveMethodElement]. |
| 375 if (functionNode.hasBody() && !constructor.isConst) { | 375 if (functionNode.hasBody() && !constructor.isConst) { |
| 376 listener.reportErrorMessage( | 376 reporter.reportErrorMessage( |
| 377 functionNode, MessageKind.REDIRECTING_CONSTRUCTOR_HAS_BODY); | 377 functionNode, MessageKind.REDIRECTING_CONSTRUCTOR_HAS_BODY); |
| 378 } | 378 } |
| 379 // Check that there are no other initializers. | 379 // Check that there are no other initializers. |
| 380 if (!initializers.tail.isEmpty) { | 380 if (!initializers.tail.isEmpty) { |
| 381 listener.reportErrorMessage( | 381 reporter.reportErrorMessage( |
| 382 call, MessageKind.REDIRECTING_CONSTRUCTOR_HAS_INITIALIZER); | 382 call, MessageKind.REDIRECTING_CONSTRUCTOR_HAS_INITIALIZER); |
| 383 } else { | 383 } else { |
| 384 constructor.isRedirectingGenerative = true; | 384 constructor.isRedirectingGenerative = true; |
| 385 } | 385 } |
| 386 // Check that there are no field initializing parameters. | 386 // Check that there are no field initializing parameters. |
| 387 FunctionSignature signature = constructor.functionSignature; | 387 FunctionSignature signature = constructor.functionSignature; |
| 388 signature.forEachParameter((ParameterElement parameter) { | 388 signature.forEachParameter((ParameterElement parameter) { |
| 389 if (parameter.isInitializingFormal) { | 389 if (parameter.isInitializingFormal) { |
| 390 Node node = parameter.node; | 390 Node node = parameter.node; |
| 391 listener.reportErrorMessage( | 391 reporter.reportErrorMessage( |
| 392 node, MessageKind.INITIALIZING_FORMAL_NOT_ALLOWED); | 392 node, MessageKind.INITIALIZING_FORMAL_NOT_ALLOWED); |
| 393 isValidAsConstant = false; | 393 isValidAsConstant = false; |
| 394 } | 394 } |
| 395 }); | 395 }); |
| 396 ResolutionResult result = resolveSuperOrThisForSend(call); | 396 ResolutionResult result = resolveSuperOrThisForSend(call); |
| 397 if (isConst) { | 397 if (isConst) { |
| 398 if (result.isConstant) { | 398 if (result.isConstant) { |
| 399 constructorInvocation = result.constant; | 399 constructorInvocation = result.constant; |
| 400 } else { | 400 } else { |
| 401 isValidAsConstant = false; | 401 isValidAsConstant = false; |
| 402 } | 402 } |
| 403 if (isConst && isValidAsConstant) { | 403 if (isConst && isValidAsConstant) { |
| 404 constructor.constantConstructor = | 404 constructor.constantConstructor = |
| 405 new RedirectingGenerativeConstantConstructor( | 405 new RedirectingGenerativeConstantConstructor( |
| 406 defaultValues, | 406 defaultValues, |
| 407 constructorInvocation); | 407 constructorInvocation); |
| 408 } | 408 } |
| 409 } | 409 } |
| 410 return result.element; | 410 return result.element; |
| 411 } else { | 411 } else { |
| 412 listener.reportErrorMessage( | 412 reporter.reportErrorMessage( |
| 413 call, MessageKind.CONSTRUCTOR_CALL_EXPECTED); | 413 call, MessageKind.CONSTRUCTOR_CALL_EXPECTED); |
| 414 return null; | 414 return null; |
| 415 } | 415 } |
| 416 } else { | 416 } else { |
| 417 listener.reportErrorMessage( | 417 reporter.reportErrorMessage( |
| 418 link.head, MessageKind.INVALID_INITIALIZER); | 418 link.head, MessageKind.INVALID_INITIALIZER); |
| 419 } | 419 } |
| 420 } | 420 } |
| 421 if (!resolvedSuper) { | 421 if (!resolvedSuper) { |
| 422 constructorInvocation = resolveImplicitSuperConstructorSend(); | 422 constructorInvocation = resolveImplicitSuperConstructorSend(); |
| 423 } | 423 } |
| 424 if (isConst && isValidAsConstant) { | 424 if (isConst && isValidAsConstant) { |
| 425 constructor.constantConstructor = new GenerativeConstantConstructor( | 425 constructor.constantConstructor = new GenerativeConstantConstructor( |
| 426 constructor.enclosingClass.thisType, | 426 constructor.enclosingClass.thisType, |
| 427 defaultValues, | 427 defaultValues, |
| (...skipping 27 matching lines...) Expand all Loading... |
| 455 MessageKind kind, | 455 MessageKind kind, |
| 456 Map arguments, | 456 Map arguments, |
| 457 {bool isError: false, | 457 {bool isError: false, |
| 458 bool missingConstructor: false}) { | 458 bool missingConstructor: false}) { |
| 459 if (missingConstructor) { | 459 if (missingConstructor) { |
| 460 registry.registerThrowNoSuchMethod(); | 460 registry.registerThrowNoSuchMethod(); |
| 461 } else { | 461 } else { |
| 462 registry.registerThrowRuntimeError(); | 462 registry.registerThrowRuntimeError(); |
| 463 } | 463 } |
| 464 if (isError || inConstContext) { | 464 if (isError || inConstContext) { |
| 465 compiler.reportErrorMessage( | 465 reporter.reportErrorMessage( |
| 466 diagnosticNode, kind, arguments); | 466 diagnosticNode, kind, arguments); |
| 467 } else { | 467 } else { |
| 468 compiler.reportWarningMessage( | 468 reporter.reportWarningMessage( |
| 469 diagnosticNode, kind, arguments); | 469 diagnosticNode, kind, arguments); |
| 470 } | 470 } |
| 471 ErroneousElement error = new ErroneousConstructorElementX( | 471 ErroneousElement error = new ErroneousConstructorElementX( |
| 472 kind, arguments, name, enclosing); | 472 kind, arguments, name, enclosing); |
| 473 if (type == null) { | 473 if (type == null) { |
| 474 type = new MalformedType(error, null); | 474 type = new MalformedType(error, null); |
| 475 } | 475 } |
| 476 return new ConstructorResult(resultKind, error, type); | 476 return new ConstructorResult(resultKind, error, type); |
| 477 } | 477 } |
| 478 | 478 |
| 479 ConstructorResult resolveConstructor( | 479 ConstructorResult resolveConstructor( |
| 480 InterfaceType type, | 480 InterfaceType type, |
| 481 Node diagnosticNode, | 481 Node diagnosticNode, |
| 482 String constructorName) { | 482 String constructorName) { |
| 483 ClassElement cls = type.element; | 483 ClassElement cls = type.element; |
| 484 cls.ensureResolved(resolution); | 484 cls.ensureResolved(resolution); |
| 485 ConstructorElement constructor = findConstructor( | 485 ConstructorElement constructor = findConstructor( |
| 486 resolver.enclosingElement.library, cls, constructorName); | 486 resolver.enclosingElement.library, cls, constructorName); |
| 487 if (constructor == null) { | 487 if (constructor == null) { |
| 488 String fullConstructorName = | 488 String fullConstructorName = |
| 489 Elements.constructorNameForDiagnostics(cls.name, constructorName); | 489 Elements.constructorNameForDiagnostics(cls.name, constructorName); |
| 490 return reportAndCreateErroneousConstructorElement( | 490 return reportAndCreateErroneousConstructorElement( |
| 491 diagnosticNode, | 491 diagnosticNode, |
| 492 ConstructorResultKind.UNRESOLVED_CONSTRUCTOR, type, | 492 ConstructorResultKind.UNRESOLVED_CONSTRUCTOR, type, |
| 493 cls, constructorName, | 493 cls, constructorName, |
| 494 MessageKind.CANNOT_FIND_CONSTRUCTOR, | 494 MessageKind.CANNOT_FIND_CONSTRUCTOR, |
| 495 {'constructorName': fullConstructorName}, | 495 {'constructorName': fullConstructorName}, |
| 496 missingConstructor: true); | 496 missingConstructor: true); |
| 497 } else if (inConstContext && !constructor.isConst) { | 497 } else if (inConstContext && !constructor.isConst) { |
| 498 compiler.reportErrorMessage( | 498 reporter.reportErrorMessage( |
| 499 diagnosticNode, MessageKind.CONSTRUCTOR_IS_NOT_CONST); | 499 diagnosticNode, MessageKind.CONSTRUCTOR_IS_NOT_CONST); |
| 500 return new ConstructorResult( | 500 return new ConstructorResult( |
| 501 ConstructorResultKind.NON_CONSTANT, constructor, type); | 501 ConstructorResultKind.NON_CONSTANT, constructor, type); |
| 502 } else { | 502 } else { |
| 503 if (constructor.isGenerativeConstructor) { | 503 if (constructor.isGenerativeConstructor) { |
| 504 if (cls.isAbstract) { | 504 if (cls.isAbstract) { |
| 505 compiler.reportWarningMessage( | 505 reporter.reportWarningMessage( |
| 506 diagnosticNode, MessageKind.ABSTRACT_CLASS_INSTANTIATION); | 506 diagnosticNode, MessageKind.ABSTRACT_CLASS_INSTANTIATION); |
| 507 registry.registerAbstractClassInstantiation(); | 507 registry.registerAbstractClassInstantiation(); |
| 508 return new ConstructorResult( | 508 return new ConstructorResult( |
| 509 ConstructorResultKind.ABSTRACT, constructor, type); | 509 ConstructorResultKind.ABSTRACT, constructor, type); |
| 510 } else { | 510 } else { |
| 511 return new ConstructorResult( | 511 return new ConstructorResult( |
| 512 ConstructorResultKind.GENERATIVE, constructor, type); | 512 ConstructorResultKind.GENERATIVE, constructor, type); |
| 513 } | 513 } |
| 514 } else { | 514 } else { |
| 515 assert(invariant(diagnosticNode, constructor.isFactoryConstructor, | 515 assert(invariant(diagnosticNode, constructor.isFactoryConstructor, |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 580 message: 'No result returned for $node.receiver.')); | 580 message: 'No result returned for $node.receiver.')); |
| 581 if (receiver.kind != null) { | 581 if (receiver.kind != null) { |
| 582 assert(invariant(node, receiver.element.isErroneous, | 582 assert(invariant(node, receiver.element.isErroneous, |
| 583 message: "Unexpected prefix result: $receiver.")); | 583 message: "Unexpected prefix result: $receiver.")); |
| 584 // We have already found an error. | 584 // We have already found an error. |
| 585 return receiver; | 585 return receiver; |
| 586 } | 586 } |
| 587 | 587 |
| 588 Identifier name = node.selector.asIdentifier(); | 588 Identifier name = node.selector.asIdentifier(); |
| 589 if (name == null) { | 589 if (name == null) { |
| 590 compiler.internalError(node.selector, 'unexpected node'); | 590 reporter.internalError(node.selector, 'unexpected node'); |
| 591 } | 591 } |
| 592 | 592 |
| 593 if (receiver.type != null) { | 593 if (receiver.type != null) { |
| 594 if (receiver.type.isInterfaceType) { | 594 if (receiver.type.isInterfaceType) { |
| 595 return resolveConstructor(receiver.type, name, name.source); | 595 return resolveConstructor(receiver.type, name, name.source); |
| 596 } else { | 596 } else { |
| 597 // TODO(johnniwinther): Update the message for the different types. | 597 // TODO(johnniwinther): Update the message for the different types. |
| 598 return reportAndCreateErroneousConstructorElement( | 598 return reportAndCreateErroneousConstructorElement( |
| 599 name, | 599 name, |
| 600 ConstructorResultKind.INVALID_TYPE, null, | 600 ConstructorResultKind.INVALID_TYPE, null, |
| 601 resolver.enclosingElement, name.source, | 601 resolver.enclosingElement, name.source, |
| 602 MessageKind.NOT_A_TYPE, {'node': name}); | 602 MessageKind.NOT_A_TYPE, {'node': name}); |
| 603 } | 603 } |
| 604 } else if (receiver.element.isPrefix) { | 604 } else if (receiver.element.isPrefix) { |
| 605 PrefixElement prefix = receiver.element; | 605 PrefixElement prefix = receiver.element; |
| 606 Element member = prefix.lookupLocalMember(name.source); | 606 Element member = prefix.lookupLocalMember(name.source); |
| 607 return constructorResultForElement(node, name.source, member); | 607 return constructorResultForElement(node, name.source, member); |
| 608 } else { | 608 } else { |
| 609 return compiler.internalError( | 609 return reporter.internalError( |
| 610 node.receiver, 'unexpected receiver $receiver'); | 610 node.receiver, 'unexpected receiver $receiver'); |
| 611 } | 611 } |
| 612 } | 612 } |
| 613 | 613 |
| 614 ConstructorResult visitIdentifier(Identifier node) { | 614 ConstructorResult visitIdentifier(Identifier node) { |
| 615 String name = node.source; | 615 String name = node.source; |
| 616 Element element = resolver.reportLookupErrorIfAny( | 616 Element element = resolver.reportLookupErrorIfAny( |
| 617 lookupInScope(compiler, node, resolver.scope, name), node, name); | 617 lookupInScope(reporter, node, resolver.scope, name), node, name); |
| 618 registry.useElement(node, element); | 618 registry.useElement(node, element); |
| 619 // TODO(johnniwinther): Change errors to warnings, cf. 11.11.1. | 619 // TODO(johnniwinther): Change errors to warnings, cf. 11.11.1. |
| 620 return constructorResultForElement(node, name, element); | 620 return constructorResultForElement(node, name, element); |
| 621 } | 621 } |
| 622 | 622 |
| 623 /// Assumed to be called by [resolveRedirectingFactory]. | 623 /// Assumed to be called by [resolveRedirectingFactory]. |
| 624 ConstructorResult visitRedirectingFactoryBody(RedirectingFactoryBody node) { | 624 ConstructorResult visitRedirectingFactoryBody(RedirectingFactoryBody node) { |
| 625 Node constructorReference = node.constructorReference; | 625 Node constructorReference = node.constructorReference; |
| 626 return finishConstructorReference(visit(constructorReference), | 626 return finishConstructorReference(visit(constructorReference), |
| 627 constructorReference, node); | 627 constructorReference, node); |
| 628 } | 628 } |
| 629 | 629 |
| 630 ConstructorResult constructorResultForElement( | 630 ConstructorResult constructorResultForElement( |
| 631 Node node, String name, Element element) { | 631 Node node, String name, Element element) { |
| 632 element = Elements.unwrap(element, compiler, node); | 632 element = Elements.unwrap(element, reporter, node); |
| 633 if (element == null) { | 633 if (element == null) { |
| 634 return reportAndCreateErroneousConstructorElement( | 634 return reportAndCreateErroneousConstructorElement( |
| 635 node, | 635 node, |
| 636 ConstructorResultKind.INVALID_TYPE, null, | 636 ConstructorResultKind.INVALID_TYPE, null, |
| 637 resolver.enclosingElement, name, | 637 resolver.enclosingElement, name, |
| 638 MessageKind.CANNOT_RESOLVE, | 638 MessageKind.CANNOT_RESOLVE, |
| 639 {'name': name}); | 639 {'name': name}); |
| 640 } else if (element.isErroneous) { | 640 } else if (element.isErroneous) { |
| 641 return constructorResultForErroneous(node, element); | 641 return constructorResultForErroneous(node, element); |
| 642 } else if (element.isClass) { | 642 } else if (element.isClass) { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 692 resolver.enclosingElement, name, | 692 resolver.enclosingElement, name, |
| 693 MessageKind.CANNOT_INSTANTIATE_TYPEDEF, {'typedefName': name}); | 693 MessageKind.CANNOT_INSTANTIATE_TYPEDEF, {'typedefName': name}); |
| 694 } else if (type.isTypeVariable) { | 694 } else if (type.isTypeVariable) { |
| 695 return reportAndCreateErroneousConstructorElement( | 695 return reportAndCreateErroneousConstructorElement( |
| 696 node, | 696 node, |
| 697 ConstructorResultKind.INVALID_TYPE, type, | 697 ConstructorResultKind.INVALID_TYPE, type, |
| 698 resolver.enclosingElement, name, | 698 resolver.enclosingElement, name, |
| 699 MessageKind.CANNOT_INSTANTIATE_TYPE_VARIABLE, | 699 MessageKind.CANNOT_INSTANTIATE_TYPE_VARIABLE, |
| 700 {'typeVariableName': name}); | 700 {'typeVariableName': name}); |
| 701 } | 701 } |
| 702 return compiler.internalError(node, "Unexpected constructor type $type"); | 702 return reporter.internalError(node, "Unexpected constructor type $type"); |
| 703 } | 703 } |
| 704 | 704 |
| 705 } | 705 } |
| 706 | 706 |
| 707 enum ConstructorResultKind { | 707 enum ConstructorResultKind { |
| 708 GENERATIVE, | 708 GENERATIVE, |
| 709 FACTORY, | 709 FACTORY, |
| 710 ABSTRACT, | 710 ABSTRACT, |
| 711 INVALID_TYPE, | 711 INVALID_TYPE, |
| 712 UNRESOLVED_CONSTRUCTOR, | 712 UNRESOLVED_CONSTRUCTOR, |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 757 // constructors. | 757 // constructors. |
| 758 return null; | 758 return null; |
| 759 } | 759 } |
| 760 // TODO(johnniwinther): Use [Name] for lookup. | 760 // TODO(johnniwinther): Use [Name] for lookup. |
| 761 ConstructorElement constructor = cls.lookupConstructor(constructorName); | 761 ConstructorElement constructor = cls.lookupConstructor(constructorName); |
| 762 if (constructor != null) { | 762 if (constructor != null) { |
| 763 constructor = constructor.declaration; | 763 constructor = constructor.declaration; |
| 764 } | 764 } |
| 765 return constructor; | 765 return constructor; |
| 766 } | 766 } |
| OLD | NEW |