OLD | NEW |
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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.kernel.element_map; | 5 library dart2js.kernel.element_map; |
6 | 6 |
7 import 'package:kernel/ast.dart' as ir; | 7 import 'package:kernel/ast.dart' as ir; |
8 | 8 |
9 import '../closure.dart' show BoxLocal, ThisLocal; | 9 import '../closure.dart' show BoxLocal, ThisLocal; |
10 import '../common.dart'; | 10 import '../common.dart'; |
(...skipping 13 matching lines...) Expand all Loading... |
24 import '../elements/types.dart'; | 24 import '../elements/types.dart'; |
25 import '../environment.dart'; | 25 import '../environment.dart'; |
26 import '../frontend_strategy.dart'; | 26 import '../frontend_strategy.dart'; |
27 import '../js_backend/backend_usage.dart'; | 27 import '../js_backend/backend_usage.dart'; |
28 import '../js_backend/constant_system_javascript.dart'; | 28 import '../js_backend/constant_system_javascript.dart'; |
29 import '../js_backend/interceptor_data.dart'; | 29 import '../js_backend/interceptor_data.dart'; |
30 import '../js_backend/native_data.dart'; | 30 import '../js_backend/native_data.dart'; |
31 import '../js_backend/no_such_method_registry.dart'; | 31 import '../js_backend/no_such_method_registry.dart'; |
32 import '../js_backend/runtime_types.dart'; | 32 import '../js_backend/runtime_types.dart'; |
33 import '../js_model/closure.dart'; | 33 import '../js_model/closure.dart'; |
| 34 import '../js_model/closure_visitors.dart' show ThisVariable; |
34 import '../js_model/elements.dart'; | 35 import '../js_model/elements.dart'; |
35 import '../js_model/locals.dart'; | 36 import '../js_model/locals.dart'; |
36 import '../native/enqueue.dart'; | 37 import '../native/enqueue.dart'; |
37 import '../native/native.dart' as native; | 38 import '../native/native.dart' as native; |
38 import '../native/resolver.dart'; | 39 import '../native/resolver.dart'; |
39 import '../ordered_typeset.dart'; | 40 import '../ordered_typeset.dart'; |
40 import '../options.dart'; | 41 import '../options.dart'; |
41 import '../ssa/kernel_impact.dart'; | 42 import '../ssa/kernel_impact.dart'; |
42 import '../universe/class_set.dart'; | 43 import '../universe/class_set.dart'; |
43 import '../universe/selector.dart'; | 44 import '../universe/selector.dart'; |
(...skipping 2268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2312 | 2313 |
2313 _constructClosureField( | 2314 _constructClosureField( |
2314 MemberEntity member, | 2315 MemberEntity member, |
2315 KernelClosureClass cls, | 2316 KernelClosureClass cls, |
2316 Map<String, MemberEntity> memberMap, | 2317 Map<String, MemberEntity> memberMap, |
2317 ir.VariableDeclaration variable, | 2318 ir.VariableDeclaration variable, |
2318 Map<Local, JRecordField> boxedCapturedVariables, | 2319 Map<Local, JRecordField> boxedCapturedVariables, |
2319 int fieldNumber, | 2320 int fieldNumber, |
2320 NodeBox box, | 2321 NodeBox box, |
2321 KernelToLocalsMap localsMap) { | 2322 KernelToLocalsMap localsMap) { |
2322 // NOTE: This construction order may be slightly different than the | 2323 // NOTE: This construction *order* may be slightly different than the |
2323 // old Element version. The old version did all the boxed items and then | 2324 // old Element version. The old version did all the boxed items and then |
2324 // all the others. | 2325 // all the others. |
2325 Local capturedLocal = localsMap.getLocalVariable(variable); | 2326 ir.Node sourceNode = variable; |
| 2327 Local capturedLocal; |
| 2328 if (variable is ThisVariable) { |
| 2329 capturedLocal = cls.thisLocal; |
| 2330 sourceNode = getMemberDefinition(member).node; |
| 2331 } else { |
| 2332 capturedLocal = localsMap.getLocalVariable(variable); |
| 2333 } |
2326 JRecordField field = boxedCapturedVariables[capturedLocal]; | 2334 JRecordField field = boxedCapturedVariables[capturedLocal]; |
2327 FieldEntity closureField = new JClosureField( | 2335 FieldEntity closureField = new JClosureField( |
2328 _getClosureVariableName(capturedLocal.name, fieldNumber), | 2336 _getClosureVariableName(capturedLocal.name, fieldNumber), |
2329 _memberData.length, | 2337 _memberData.length, |
2330 cls, | 2338 cls, |
2331 variable.isConst, | 2339 variable.isConst, |
2332 variable.isFinal || variable.isConst); | 2340 variable.isFinal || variable.isConst); |
2333 _memberList.add(closureField); | 2341 _memberList.add(closureField); |
2334 _memberData.add(new ClosureFieldData(new ClosureMemberDefinition( | 2342 _memberData.add(new ClosureFieldData(new ClosureMemberDefinition( |
2335 cls.localToFieldMap[capturedLocal], | 2343 cls.localToFieldMap[capturedLocal], |
2336 computeSourceSpanFromTreeNode(variable), | 2344 computeSourceSpanFromTreeNode(sourceNode), |
2337 MemberKind.closureField, | 2345 MemberKind.closureField, |
2338 variable))); | 2346 sourceNode))); |
2339 memberMap[closureField.name] = closureField; | 2347 memberMap[closureField.name] = closureField; |
2340 if (boxedCapturedVariables.containsKey(capturedLocal)) { | 2348 if (boxedCapturedVariables.containsKey(capturedLocal)) { |
2341 cls.localToFieldMap[field.box] = closureField; | 2349 cls.localToFieldMap[field.box] = closureField; |
2342 cls.boxedVariables[capturedLocal] = field; | 2350 cls.boxedVariables[capturedLocal] = field; |
2343 } else { | 2351 } else { |
2344 cls.localToFieldMap[capturedLocal] = closureField; | 2352 cls.localToFieldMap[capturedLocal] = closureField; |
2345 } | 2353 } |
2346 } | 2354 } |
2347 | 2355 |
2348 // Returns a non-unique name for the given closure element. | 2356 // Returns a non-unique name for the given closure element. |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2393 /// | 2401 /// |
2394 /// These names are not used in generated code, just as element name. | 2402 /// These names are not used in generated code, just as element name. |
2395 String _getClosureVariableName(String name, int id) { | 2403 String _getClosureVariableName(String name, int id) { |
2396 return "_captured_${name}_$id"; | 2404 return "_captured_${name}_$id"; |
2397 } | 2405 } |
2398 | 2406 |
2399 String getDeferredUri(ir.LibraryDependency node) { | 2407 String getDeferredUri(ir.LibraryDependency node) { |
2400 throw new UnimplementedError('JsKernelToElementMap.getDeferredUri'); | 2408 throw new UnimplementedError('JsKernelToElementMap.getDeferredUri'); |
2401 } | 2409 } |
2402 } | 2410 } |
OLD | NEW |