| OLD | NEW |
| 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 part of dart2js; | 5 part of dart2js; |
| 6 | 6 |
| 7 /// A [ConstantEnvironment] provides access for constants compiled for variable | 7 /// A [ConstantEnvironment] provides access for constants compiled for variable |
| 8 /// initializers. | 8 /// initializers. |
| 9 abstract class ConstantEnvironment { | 9 abstract class ConstantEnvironment { |
| 10 /// Returns the constant for the initializer of [element]. | 10 /// Returns the constant for the initializer of [element]. |
| (...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 410 Constant makeTypeConstant(TypeDeclarationElement element) { | 410 Constant makeTypeConstant(TypeDeclarationElement element) { |
| 411 DartType elementType = element.rawType; | 411 DartType elementType = element.rawType; |
| 412 DartType constantType = | 412 DartType constantType = |
| 413 compiler.backend.typeImplementation.computeType(compiler); | 413 compiler.backend.typeImplementation.computeType(compiler); |
| 414 return new TypeConstant(elementType, constantType); | 414 return new TypeConstant(elementType, constantType); |
| 415 } | 415 } |
| 416 | 416 |
| 417 /// Returns true if the prefix of the send resolves to a deferred import | 417 /// Returns true if the prefix of the send resolves to a deferred import |
| 418 /// prefix. | 418 /// prefix. |
| 419 bool isDeferredUse(Send send) { | 419 bool isDeferredUse(Send send) { |
| 420 // We handle: | |
| 421 // 1. Send(Send(Send(null, Prefix), className), staticName) | |
| 422 // 2. Send(Send(Prefix, Classname), staticName) | |
| 423 // 3. Send(Send(null, Prefix), staticName | className) | |
| 424 // 4. Send(Send(Prefix), staticName | className) | |
| 425 // Nodes of the forms 2,4 occur in metadata. | |
| 426 if (send == null) return false; | 420 if (send == null) return false; |
| 427 while (send.receiver is Send) { | 421 return compiler.deferredLoadTask |
| 428 send = send.receiver; | 422 .deferredPrefixElement(send, elements) != null; |
| 429 } | |
| 430 Identifier prefixNode; | |
| 431 if (send.receiver is Identifier) { | |
| 432 prefixNode = send.receiver; | |
| 433 } else if (send.receiver == null && | |
| 434 send.selector is Identifier) { | |
| 435 prefixNode = send.selector; | |
| 436 } | |
| 437 if (prefixNode != null) { | |
| 438 Element maybePrefix = elements[prefixNode.asIdentifier()]; | |
| 439 if (maybePrefix != null && maybePrefix.isPrefix() && | |
| 440 (maybePrefix as PrefixElement).isDeferred) { | |
| 441 return true; | |
| 442 } | |
| 443 } | |
| 444 return false; | |
| 445 } | 423 } |
| 446 | 424 |
| 447 Constant visitIdentifier(Identifier node) { | 425 Constant visitIdentifier(Identifier node) { |
| 448 Element element = elements[node]; | 426 Element element = elements[node]; |
| 449 if (Elements.isClass(element) || Elements.isTypedef(element)) { | 427 if (Elements.isClass(element) || Elements.isTypedef(element)) { |
| 450 return makeTypeConstant(element); | 428 return makeTypeConstant(element); |
| 451 } | 429 } |
| 452 return signalNotCompileTimeConstant(node); | 430 return signalNotCompileTimeConstant(node); |
| 453 } | 431 } |
| 454 | 432 |
| (...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 989 if (fieldValue == null) { | 967 if (fieldValue == null) { |
| 990 // Use the default value. | 968 // Use the default value. |
| 991 fieldValue = handler.compileConstant(field); | 969 fieldValue = handler.compileConstant(field); |
| 992 } | 970 } |
| 993 jsNewArguments.add(fieldValue); | 971 jsNewArguments.add(fieldValue); |
| 994 }, | 972 }, |
| 995 includeSuperAndInjectedMembers: true); | 973 includeSuperAndInjectedMembers: true); |
| 996 return jsNewArguments; | 974 return jsNewArguments; |
| 997 } | 975 } |
| 998 } | 976 } |
| OLD | NEW |