Chromium Code Reviews| 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.world_builder; | 5 library dart2js.kernel.world_builder; |
| 6 | 6 |
| 7 import 'package:kernel/ast.dart' as ir; | 7 import 'package:kernel/ast.dart' as ir; |
| 8 | 8 |
| 9 import '../common.dart'; | 9 import '../common.dart'; |
| 10 import '../common/resolution.dart'; | 10 import '../common/resolution.dart'; |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 98 | 98 |
| 99 @override | 99 @override |
| 100 CommonElements get commonElements => _commonElements; | 100 CommonElements get commonElements => _commonElements; |
| 101 | 101 |
| 102 @override | 102 @override |
| 103 ElementEnvironment get elementEnvironment => _elementEnvironment; | 103 ElementEnvironment get elementEnvironment => _elementEnvironment; |
| 104 | 104 |
| 105 @override | 105 @override |
| 106 native.BehaviorBuilder get nativeBehaviorBuilder => _nativeBehaviorBuilder; | 106 native.BehaviorBuilder get nativeBehaviorBuilder => _nativeBehaviorBuilder; |
| 107 | 107 |
| 108 KernelLookup get lookup => new KernelLookup._internal(_libraryMap, _classMap); | |
| 109 | |
| 108 LibraryEntity lookupLibrary(Uri uri) { | 110 LibraryEntity lookupLibrary(Uri uri) { |
| 109 KLibraryEnv libraryEnv = _env.lookupLibrary(uri); | 111 KLibraryEnv libraryEnv = _env.lookupLibrary(uri); |
| 110 return _getLibrary(libraryEnv.library, libraryEnv); | 112 return _getLibrary(libraryEnv.library, libraryEnv); |
| 111 } | 113 } |
| 112 | 114 |
| 113 KLibrary _getLibrary(ir.Library node, [KLibraryEnv libraryEnv]) { | 115 KLibrary _getLibrary(ir.Library node, [KLibraryEnv libraryEnv]) { |
| 114 return _libraryMap.putIfAbsent(node, () { | 116 return _libraryMap.putIfAbsent(node, () { |
| 115 Uri canonicalUri = node.importUri; | 117 Uri canonicalUri = node.importUri; |
| 116 _libraryEnvs.add(libraryEnv ?? _env.lookupLibrary(canonicalUri)); | 118 _libraryEnvs.add(libraryEnv ?? _env.lookupLibrary(canonicalUri)); |
| 117 String name = node.name; | 119 String name = node.name; |
| (...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 515 "KernelWorldBuilder._getConstructorConstant"); | 517 "KernelWorldBuilder._getConstructorConstant"); |
| 516 }); | 518 }); |
| 517 } | 519 } |
| 518 | 520 |
| 519 ResolutionImpact computeWorldImpact(KMember member) { | 521 ResolutionImpact computeWorldImpact(KMember member) { |
| 520 ir.Member node = _memberList[member.memberIndex]; | 522 ir.Member node = _memberList[member.memberIndex]; |
| 521 return buildKernelImpact(node, this); | 523 return buildKernelImpact(node, this); |
| 522 } | 524 } |
| 523 } | 525 } |
| 524 | 526 |
| 527 /// A glorified combination of maps for looking up the correspondence between a | |
| 528 /// particular K-Entity and its corresponding Kernel Element object. | |
| 529 class KernelLookup { | |
|
Emily Fortuna
2017/04/19 00:59:55
I'm guessing we want to have some sort of super in
Johnni Winther
2017/04/19 08:39:51
This functionality is already in KernelWorldBuilde
Siggi Cherem (dart-lang)
2017/04/19 15:36:29
Ah! some questions for Johnni...
1. is the idea t
Emily Fortuna
2017/04/19 22:35:46
Okay. You're still not exposing the ir.Library and
Johnni Winther
2017/04/20 07:19:27
1. I want IR based reasoning to be confined to the
| |
| 530 Map<KLibrary, ir.Library> _libraryMap = <KLibrary, ir.Library>{}; | |
| 531 Map<KClass, ir.Class> _classMap = <KClass, ir.Class>{}; | |
| 532 | |
| 533 KernelLookup._internal(Map<ir.Library, KLibrary> reverseLibraryMap, | |
| 534 Map<ir.Class, KClass> reverseClassMap) { | |
| 535 for (ir.Library library in reverseLibraryMap.keys) { | |
| 536 _libraryMap[reverseLibraryMap[library]] = library; | |
| 537 } | |
| 538 for (ir.Class class_entity in reverseClassMap.keys) { | |
| 539 _classMap[reverseClassMap[class_entity]] = class_entity; | |
| 540 } | |
| 541 } | |
| 542 | |
| 543 ir.Class lookupClass(KClass entity) => _classMap[entity]; | |
| 544 ir.Library lookupLibrary(KLibrary entity) => _libraryMap[entity]; | |
| 545 } | |
| 546 | |
| 525 /// Environment for fast lookup of program libraries. | 547 /// Environment for fast lookup of program libraries. |
| 526 class KEnv { | 548 class KEnv { |
| 527 final ir.Program program; | 549 final ir.Program program; |
| 528 | 550 |
| 529 Map<Uri, KLibraryEnv> _libraryMap; | 551 Map<Uri, KLibraryEnv> _libraryMap; |
| 530 | 552 |
| 531 KEnv(this.program); | 553 KEnv(this.program); |
| 532 | 554 |
| 533 /// Return the [KLibraryEnv] for the library with the canonical [uri]. | 555 /// Return the [KLibraryEnv] for the library with the canonical [uri]. |
| 534 KLibraryEnv lookupLibrary(Uri uri) { | 556 KLibraryEnv lookupLibrary(Uri uri) { |
| (...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1001 } | 1023 } |
| 1002 | 1024 |
| 1003 InterfaceType getMixinTypeForClass(KClass cls) { | 1025 InterfaceType getMixinTypeForClass(KClass cls) { |
| 1004 KClassEnv env = builder._classEnvs[cls.classIndex]; | 1026 KClassEnv env = builder._classEnvs[cls.classIndex]; |
| 1005 ir.Supertype mixedInType = env.cls.mixedInType; | 1027 ir.Supertype mixedInType = env.cls.mixedInType; |
| 1006 if (mixedInType == null) return null; | 1028 if (mixedInType == null) return null; |
| 1007 return builder.createInterfaceType( | 1029 return builder.createInterfaceType( |
| 1008 mixedInType.classNode, mixedInType.typeArguments); | 1030 mixedInType.classNode, mixedInType.typeArguments); |
| 1009 } | 1031 } |
| 1010 } | 1032 } |
| OLD | NEW |