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 library closureToClassMapper; | |
6 | |
7 import 'common/names.dart' show Identifiers; | 5 import 'common/names.dart' show Identifiers; |
8 import 'common/resolution.dart' show ParsingContext, Resolution; | 6 import 'common/resolution.dart' show ParsingContext, Resolution; |
9 import 'common/tasks.dart' show CompilerTask; | 7 import 'common/tasks.dart' show CompilerTask; |
10 import 'common.dart'; | 8 import 'common.dart'; |
11 import 'compiler.dart' show Compiler; | 9 import 'compiler.dart' show Compiler; |
12 import 'constants/expressions.dart'; | 10 import 'constants/expressions.dart'; |
13 import 'elements/elements.dart'; | 11 import 'elements/elements.dart'; |
14 import 'elements/entities.dart'; | 12 import 'elements/entities.dart'; |
15 import 'elements/entity_utils.dart' as utils; | 13 import 'elements/entity_utils.dart' as utils; |
16 import 'elements/modelx.dart' | 14 import 'elements/modelx.dart' |
17 show BaseFunctionElementX, ClassElementX, ElementX; | 15 show BaseFunctionElementX, ClassElementX, ElementX; |
18 import 'elements/resolution_types.dart'; | 16 import 'elements/resolution_types.dart'; |
19 import 'elements/types.dart'; | 17 import 'elements/types.dart'; |
20 import 'elements/visitor.dart' show ElementVisitor; | 18 import 'elements/visitor.dart' show ElementVisitor; |
21 import 'js_backend/js_backend.dart' show JavaScriptBackend; | 19 import 'js_backend/js_backend.dart' show JavaScriptBackend; |
22 import 'resolution/tree_elements.dart' show TreeElements; | 20 import 'resolution/tree_elements.dart' show TreeElements; |
23 import 'package:front_end/src/fasta/scanner.dart' show Token; | 21 import 'package:front_end/src/fasta/scanner.dart' show Token; |
24 import 'tree/tree.dart'; | 22 import 'tree/tree.dart'; |
25 import 'util/util.dart'; | 23 import 'util/util.dart'; |
26 import 'world.dart' show ClosedWorldRefiner; | 24 import 'world.dart' show ClosedWorldRefiner; |
27 | 25 |
28 /// Where T is ir.Node or Node. | 26 /// Class that provides information for how closures are rewritten/represented |
29 // TODO(efortuna): Rename this class. | 27 /// to preserve Dart semantics when compiled to JavaScript. Given a particular |
30 abstract class ClosureClassMaps<T> { | 28 /// node to look up, it returns a information about the internal representation |
| 29 /// of how closure conversion is implemented. T is an ir.Node or Node. |
| 30 abstract class ClosureDataLookup<T> { |
31 /// Look up information about the variables that have been mutated and are | 31 /// Look up information about the variables that have been mutated and are |
32 /// used inside the scope of [node]. | 32 /// used inside the scope of [node]. |
33 // TODO(johnniwinther): Split this up into two functions, one for members and | 33 // TODO(johnniwinther): Split this up into two functions, one for members and |
34 // one for local functions. | 34 // one for local functions. |
35 ClosureRepresentationInfo getClosureRepresentationInfo(Entity member); | 35 ClosureRepresentationInfo getClosureRepresentationInfo(Entity member); |
36 | 36 |
37 /// Look up information about a loop, in case any variables it declares need | 37 /// Look up information about a loop, in case any variables it declares need |
38 /// to be boxed/snapshotted. | 38 /// to be boxed/snapshotted. |
39 LoopClosureRepresentationInfo getClosureRepresentationInfoForLoop(T loopNode); | 39 LoopClosureRepresentationInfo getClosureRepresentationInfoForLoop(T loopNode); |
40 | 40 |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 /// Return true if [variable] has been captured and mutated (all other | 187 /// Return true if [variable] has been captured and mutated (all other |
188 /// variables do not require boxing). | 188 /// variables do not require boxing). |
189 bool isVariableBoxed(Local variable) => false; | 189 bool isVariableBoxed(Local variable) => false; |
190 | 190 |
191 // TODO(efortuna): Remove this method. The old system was using | 191 // TODO(efortuna): Remove this method. The old system was using |
192 // ClosureClassMaps for situations other than closure class maps, and that's | 192 // ClosureClassMaps for situations other than closure class maps, and that's |
193 // just confusing. | 193 // just confusing. |
194 bool get isClosure => false; | 194 bool get isClosure => false; |
195 } | 195 } |
196 | 196 |
197 class ClosureTask extends CompilerTask implements ClosureClassMaps<Node> { | 197 class ClosureTask extends CompilerTask implements ClosureDataLookup<Node> { |
198 Map<Node, ClosureScope> _closureInfoMap = <Node, ClosureScope>{}; | 198 Map<Node, ClosureScope> _closureInfoMap = <Node, ClosureScope>{}; |
199 Map<Element, ClosureClassMap> _closureMappingCache = | 199 Map<Element, ClosureClassMap> _closureMappingCache = |
200 <Element, ClosureClassMap>{}; | 200 <Element, ClosureClassMap>{}; |
201 Compiler compiler; | 201 Compiler compiler; |
202 ClosureTask(Compiler compiler) | 202 ClosureTask(Compiler compiler) |
203 : compiler = compiler, | 203 : compiler = compiler, |
204 super(compiler.measurer); | 204 super(compiler.measurer); |
205 | 205 |
206 String get name => "Closure Simplifier"; | 206 String get name => "Closure Simplifier"; |
207 | 207 |
(...skipping 1236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1444 /// | 1444 /// |
1445 /// Move the below classes to a JS model eventually. | 1445 /// Move the below classes to a JS model eventually. |
1446 /// | 1446 /// |
1447 abstract class JSEntity implements MemberEntity { | 1447 abstract class JSEntity implements MemberEntity { |
1448 Local get declaredEntity; | 1448 Local get declaredEntity; |
1449 } | 1449 } |
1450 | 1450 |
1451 abstract class PrivatelyNamedJSEntity implements JSEntity { | 1451 abstract class PrivatelyNamedJSEntity implements JSEntity { |
1452 Entity get rootOfScope; | 1452 Entity get rootOfScope; |
1453 } | 1453 } |
OLD | NEW |