OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 deferred_load; | 5 library deferred_load; |
6 | 6 |
7 import 'common/backend_api.dart' show Backend; | 7 import 'common/backend_api.dart' show Backend; |
8 import 'common/tasks.dart' show CompilerTask; | 8 import 'common/tasks.dart' show CompilerTask; |
9 import 'common.dart'; | 9 import 'common.dart'; |
10 import 'compiler.dart' show Compiler; | 10 import 'compiler.dart' show Compiler; |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 }), | 329 }), |
330 IMPACT_USE); | 330 IMPACT_USE); |
331 | 331 |
332 if (analyzableElement.resolvedAst.kind != ResolvedAstKind.PARSED) { | 332 if (analyzableElement.resolvedAst.kind != ResolvedAstKind.PARSED) { |
333 return; | 333 return; |
334 } | 334 } |
335 | 335 |
336 TreeElements treeElements = analyzableElement.resolvedAst.elements; | 336 TreeElements treeElements = analyzableElement.resolvedAst.elements; |
337 assert(treeElements != null); | 337 assert(treeElements != null); |
338 | 338 |
| 339 // TODO(johnniwinther): Add only expressions that are actually needed. |
| 340 // Currently we have some noise here: Some potential expressions are |
| 341 // seen that should never be added (for instance field initializers |
| 342 // in constant constructors, like `this.field = parameter`). And some |
| 343 // implicit constant expression are seen that we should be able to add |
| 344 // (like primitive constant literals like `true`, `"foo"` and `0`). |
| 345 // See dartbug.com/26406 for context. |
339 treeElements | 346 treeElements |
340 .forEachConstantNode((Node node, ConstantExpression expression) { | 347 .forEachConstantNode((Node node, ConstantExpression expression) { |
341 // Explicitly depend on the backend constants. | 348 // Explicitly depend on the backend constants. |
342 ConstantValue value; | 349 if (backend.constants.hasConstantValue(expression)) { |
343 value = backend.constants.getConstantValue(expression); | 350 ConstantValue value = |
344 // TODO(johnniwinther): ensure `value` is not null or use directly the | 351 backend.constants.getConstantValue(expression); |
345 // expression to calculate dependencies. See dartbug.com/26406 for | 352 assert(invariant(node, value != null, |
346 // context. | 353 message: "Constant expression without value: " |
347 if (value != null) { | 354 "${expression.toStructuredText()}.")); |
348 constants.add(value); | 355 constants.add(value); |
| 356 } else { |
| 357 assert(invariant(node, |
| 358 expression.isImplicit || expression.isPotential, |
| 359 message: "Unexpected unevaluated constant expression: " |
| 360 "${expression.toStructuredText()}.")); |
349 } | 361 } |
350 }); | 362 }); |
351 } | 363 } |
352 } | 364 } |
353 | 365 |
354 // TODO(sigurdm): How is metadata on a patch-class handled? | 366 // TODO(sigurdm): How is metadata on a patch-class handled? |
355 for (MetadataAnnotation metadata in element.metadata) { | 367 for (MetadataAnnotation metadata in element.metadata) { |
356 ConstantValue constant = | 368 ConstantValue constant = |
357 backend.constants.getConstantValueForMetadata(metadata); | 369 backend.constants.getConstantValueForMetadata(metadata); |
358 if (constant != null) { | 370 if (constant != null) { |
(...skipping 627 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
986 return result; | 998 return result; |
987 } | 999 } |
988 | 1000 |
989 bool operator ==(other) { | 1001 bool operator ==(other) { |
990 if (other is! _DeclaredDeferredImport) return false; | 1002 if (other is! _DeclaredDeferredImport) return false; |
991 return declaration == other.declaration; | 1003 return declaration == other.declaration; |
992 } | 1004 } |
993 | 1005 |
994 int get hashCode => declaration.hashCode * 17; | 1006 int get hashCode => declaration.hashCode * 17; |
995 } | 1007 } |
OLD | NEW |