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 2281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2292 closureEntity, | 2292 closureEntity, |
2293 thisLocal); | 2293 thisLocal); |
2294 int fieldNumber = 0; | 2294 int fieldNumber = 0; |
2295 for (ir.VariableDeclaration variable in info.freeVariables) { | 2295 for (ir.VariableDeclaration variable in info.freeVariables) { |
2296 // Make a corresponding field entity in this closure class for every | 2296 // Make a corresponding field entity in this closure class for every |
2297 // single freeVariable in the KernelScopeInfo.freeVariable. | 2297 // single freeVariable in the KernelScopeInfo.freeVariable. |
2298 _constructClosureField( | 2298 _constructClosureField( |
2299 member, | 2299 member, |
2300 cls, | 2300 cls, |
2301 memberMap, | 2301 memberMap, |
| 2302 localsMap.getLocalVariable(variable), |
2302 variable, | 2303 variable, |
| 2304 variable.isConst, |
| 2305 !(variable.isFinal || variable.isConst), |
2303 boxedCapturedVariables, | 2306 boxedCapturedVariables, |
2304 fieldNumber, | 2307 fieldNumber, |
2305 info.capturedVariablesAccessor, | 2308 info.capturedVariablesAccessor, |
| 2309 localsMap); |
| 2310 fieldNumber++; |
| 2311 } |
| 2312 if (info.thisUsedAsFreeVariable) { |
| 2313 _constructClosureField( |
| 2314 member, |
| 2315 cls, |
| 2316 memberMap, |
| 2317 cls.thisLocal, |
| 2318 getMemberDefinition(member).node, |
| 2319 true, |
| 2320 false, |
| 2321 boxedCapturedVariables, |
| 2322 fieldNumber, |
| 2323 info.capturedVariablesAccessor, |
2306 localsMap); | 2324 localsMap); |
2307 fieldNumber++; | 2325 fieldNumber++; |
2308 } | 2326 } |
2309 | 2327 |
2310 FunctionEntity callMethod = cls.callMethod = new JClosureCallMethod( | 2328 FunctionEntity callMethod = cls.callMethod = new JClosureCallMethod( |
2311 _memberData.length, | 2329 _memberData.length, |
2312 cls, | 2330 cls, |
2313 _getParameterStructure(node), | 2331 _getParameterStructure(node), |
2314 _getAsyncMarker(node)); | 2332 _getAsyncMarker(node)); |
2315 _memberList.add(cls.callMethod); | 2333 _memberList.add(cls.callMethod); |
2316 | 2334 |
2317 _memberData.add(new ClosureFunctionData( | 2335 _memberData.add(new ClosureFunctionData( |
2318 new ClosureMemberDefinition(callMethod, closureData.definition.location, | 2336 new ClosureMemberDefinition(callMethod, closureData.definition.location, |
2319 MemberKind.closureCall, node.parent), | 2337 MemberKind.closureCall, node.parent), |
2320 getFunctionType(node), | 2338 getFunctionType(node), |
2321 node)); | 2339 node)); |
2322 memberMap[cls.callMethod.name] = cls.callMethod; | 2340 memberMap[cls.callMethod.name] = cls.callMethod; |
2323 return cls; | 2341 return cls; |
2324 } | 2342 } |
2325 | 2343 |
2326 _constructClosureField( | 2344 _constructClosureField( |
2327 MemberEntity member, | 2345 MemberEntity member, |
2328 KernelClosureClass cls, | 2346 KernelClosureClass cls, |
2329 Map<String, MemberEntity> memberMap, | 2347 Map<String, MemberEntity> memberMap, |
2330 ir.VariableDeclaration variable, | 2348 Local capturedLocal, |
| 2349 ir.TreeNode sourceNode, |
| 2350 bool isConst, |
| 2351 bool isAssignable, |
2331 Map<Local, JRecordField> boxedCapturedVariables, | 2352 Map<Local, JRecordField> boxedCapturedVariables, |
2332 int fieldNumber, | 2353 int fieldNumber, |
2333 NodeBox box, | 2354 NodeBox box, |
2334 KernelToLocalsMap localsMap) { | 2355 KernelToLocalsMap localsMap) { |
2335 // NOTE: This construction order may be slightly different than the | 2356 // NOTE: This construction *order* may be slightly different than the |
2336 // old Element version. The old version did all the boxed items and then | 2357 // old Element version. The old version did all the boxed items and then |
2337 // all the others. | 2358 // all the others. |
2338 Local capturedLocal = localsMap.getLocalVariable(variable); | |
2339 JRecordField field = boxedCapturedVariables[capturedLocal]; | 2359 JRecordField field = boxedCapturedVariables[capturedLocal]; |
2340 FieldEntity closureField = new JClosureField( | 2360 FieldEntity closureField = new JClosureField( |
2341 _getClosureVariableName(capturedLocal.name, fieldNumber), | 2361 _getClosureVariableName(capturedLocal.name, fieldNumber), |
2342 _memberData.length, | 2362 _memberData.length, |
2343 cls, | 2363 cls, |
2344 variable.isConst, | 2364 isConst, |
2345 variable.isFinal || variable.isConst); | 2365 isAssignable); |
2346 _memberList.add(closureField); | 2366 _memberList.add(closureField); |
2347 _memberData.add(new ClosureFieldData(new ClosureMemberDefinition( | 2367 _memberData.add(new ClosureFieldData(new ClosureMemberDefinition( |
2348 cls.localToFieldMap[capturedLocal], | 2368 cls.localToFieldMap[capturedLocal], |
2349 computeSourceSpanFromTreeNode(variable), | 2369 computeSourceSpanFromTreeNode(sourceNode), |
2350 MemberKind.closureField, | 2370 MemberKind.closureField, |
2351 variable))); | 2371 sourceNode))); |
2352 memberMap[closureField.name] = closureField; | 2372 memberMap[closureField.name] = closureField; |
2353 if (boxedCapturedVariables.containsKey(capturedLocal)) { | 2373 if (boxedCapturedVariables.containsKey(capturedLocal)) { |
2354 cls.localToFieldMap[field.box] = closureField; | 2374 cls.localToFieldMap[field.box] = closureField; |
2355 cls.boxedVariables[capturedLocal] = field; | 2375 cls.boxedVariables[capturedLocal] = field; |
2356 } else { | 2376 } else { |
2357 cls.localToFieldMap[capturedLocal] = closureField; | 2377 cls.localToFieldMap[capturedLocal] = closureField; |
2358 } | 2378 } |
2359 } | 2379 } |
2360 | 2380 |
2361 // Returns a non-unique name for the given closure element. | 2381 // Returns a non-unique name for the given closure element. |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2406 /// | 2426 /// |
2407 /// These names are not used in generated code, just as element name. | 2427 /// These names are not used in generated code, just as element name. |
2408 String _getClosureVariableName(String name, int id) { | 2428 String _getClosureVariableName(String name, int id) { |
2409 return "_captured_${name}_$id"; | 2429 return "_captured_${name}_$id"; |
2410 } | 2430 } |
2411 | 2431 |
2412 String getDeferredUri(ir.LibraryDependency node) { | 2432 String getDeferredUri(ir.LibraryDependency node) { |
2413 throw new UnimplementedError('JsKernelToElementMap.getDeferredUri'); | 2433 throw new UnimplementedError('JsKernelToElementMap.getDeferredUri'); |
2414 } | 2434 } |
2415 } | 2435 } |
OLD | NEW |