| 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 'dart2jslib.dart' show | 7 import 'dart2jslib.dart' show |
| 8 Backend, | 8 Backend, |
| 9 Compiler, | 9 Compiler, |
| 10 CompilerTask, | 10 CompilerTask, |
| 11 Constant, | 11 Constant, |
| 12 ConstructedConstant, | 12 ConstructedConstant, |
| 13 MessageKind, | 13 MessageKind, |
| 14 DeferredConstant, |
| 14 StringConstant, | 15 StringConstant, |
| 15 invariant, | 16 invariant; |
| 16 Backend; | |
| 17 | 17 |
| 18 import 'dart_backend/dart_backend.dart' show | 18 import 'dart_backend/dart_backend.dart' show |
| 19 DartBackend; | 19 DartBackend; |
| 20 | 20 |
| 21 import 'js_backend/js_backend.dart' show | 21 import 'js_backend/js_backend.dart' show |
| 22 JavaScriptBackend; | 22 JavaScriptBackend; |
| 23 | 23 |
| 24 import 'elements/elements.dart' show | 24 import 'elements/elements.dart' show |
| 25 Element, | 25 Element, |
| 26 ClassElement, | 26 ClassElement, |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 | 184 |
| 185 bool isDeferred(Element element) { | 185 bool isDeferred(Element element) { |
| 186 return outputUnitForElement(element) != mainOutputUnit; | 186 return outputUnitForElement(element) != mainOutputUnit; |
| 187 } | 187 } |
| 188 | 188 |
| 189 /// Returns true if e1 and e2 are in the same output unit. | 189 /// Returns true if e1 and e2 are in the same output unit. |
| 190 bool inSameOutputUnit(Element e1, Element e2) { | 190 bool inSameOutputUnit(Element e1, Element e2) { |
| 191 return outputUnitForElement(e1) == outputUnitForElement(e2); | 191 return outputUnitForElement(e1) == outputUnitForElement(e2); |
| 192 } | 192 } |
| 193 | 193 |
| 194 void registerConstantDeferredUse(DeferredConstant constant, |
| 195 PrefixElement prefix) { |
| 196 OutputUnit outputUnit = new OutputUnit(); |
| 197 outputUnit.imports.add(prefix.deferredImport); |
| 198 _constantToOutputUnit[constant] = outputUnit; |
| 199 } |
| 200 |
| 194 /// Mark that [import] is part of the [OutputputUnit] for [element]. | 201 /// Mark that [import] is part of the [OutputputUnit] for [element]. |
| 195 /// | 202 /// |
| 196 /// [element] can be either a [Constant] or an [Element]. | 203 /// [element] can be either a [Constant] or an [Element]. |
| 197 void _addImportToOutputUnitOfElement(Element element, Import import) { | 204 void _addImportToOutputUnitOfElement(Element element, Import import) { |
| 198 // Only one file should be loaded when the program starts, so make | 205 // Only one file should be loaded when the program starts, so make |
| 199 // sure that only one OutputUnit is created for [fakeMainImport]. | 206 // sure that only one OutputUnit is created for [fakeMainImport]. |
| 200 if (import == _fakeMainImport) { | 207 if (import == _fakeMainImport) { |
| 201 _elementToOutputUnit[element] = mainOutputUnit; | 208 _elementToOutputUnit[element] = mainOutputUnit; |
| 202 } | 209 } |
| 203 _elementToOutputUnit.putIfAbsent(element, () => new OutputUnit()) | 210 _elementToOutputUnit.putIfAbsent(element, () => new OutputUnit()) |
| (...skipping 673 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 877 Element maybePrefix = elements[identifier]; | 884 Element maybePrefix = elements[identifier]; |
| 878 if (maybePrefix != null && maybePrefix.isPrefix()) { | 885 if (maybePrefix != null && maybePrefix.isPrefix()) { |
| 879 PrefixElement prefixElement = maybePrefix; | 886 PrefixElement prefixElement = maybePrefix; |
| 880 if (prefixElement.isDeferred) { | 887 if (prefixElement.isDeferred) { |
| 881 return prefixElement; | 888 return prefixElement; |
| 882 } | 889 } |
| 883 } | 890 } |
| 884 return null; | 891 return null; |
| 885 } | 892 } |
| 886 } | 893 } |
| OLD | NEW |