|
12 | 12 |
|
13 | 13 | #include "swift/SILOptimizer/Analysis/ClassHierarchyAnalysis.h"
|
14 | 14 | #include "swift/AST/ASTContext.h"
|
15 |
| -#include "swift/AST/ASTWalker.h" |
16 | 15 | #include "swift/AST/Module.h"
|
17 | 16 | #include "swift/SIL/SILInstruction.h"
|
18 | 17 | #include "swift/SIL/SILValue.h"
|
19 | 18 | #include "swift/SIL/SILModule.h"
|
20 | 19 |
|
21 | 20 | using namespace swift;
|
22 | 21 |
|
23 |
| -namespace { |
24 |
| -/// A helper class to collect all nominal type declarations. |
25 |
| -class NominalTypeWalker: public ASTWalker { |
26 |
| - ClassHierarchyAnalysis::ProtocolImplementations &ProtocolImplementationsCache; |
27 |
| -public: |
28 |
| - NominalTypeWalker(ClassHierarchyAnalysis::ProtocolImplementations |
29 |
| - &ProtocolImplementationsCache) |
30 |
| - :ProtocolImplementationsCache(ProtocolImplementationsCache) { |
31 |
| - } |
32 |
| - |
33 |
| - bool walkToDeclPre(Decl *D) override { |
34 |
| - auto *NTD = dyn_cast<NominalTypeDecl>(D); |
35 |
| - if (!NTD || !NTD->hasInterfaceType()) |
36 |
| - return true; |
37 |
| - auto Protocols = NTD->getAllProtocols(); |
38 |
| - // We are only interested in types implementing protocols. |
39 |
| - if (!Protocols.empty()) { |
40 |
| - for (auto &Protocol : Protocols) { |
41 |
| - auto &K = ProtocolImplementationsCache[Protocol]; |
42 |
| - K.push_back(NTD); |
43 |
| - } |
44 |
| - } |
45 |
| - return true; |
46 |
| - } |
47 |
| -}; |
48 |
| -} // end anonymous namespace |
49 |
| - |
50 | 22 | void ClassHierarchyAnalysis::init() {
|
51 |
| - // Process all types implementing protocols. |
52 |
| - SmallVector<Decl *, 32> Decls; |
53 |
| - // TODO: It would be better if we could get all declarations |
54 |
| - // from a given module, not only the top-level ones. |
55 |
| - M->getSwiftModule()->getTopLevelDecls(Decls); |
56 |
| - |
57 |
| - NominalTypeWalker Walker(ProtocolImplementationsCache); |
58 |
| - for (auto *D: Decls) { |
59 |
| - D->walk(Walker); |
60 |
| - } |
61 |
| - |
62 | 23 | // For each class declaration in our V-table list:
|
63 | 24 | for (auto &VT : M->getVTableList()) {
|
64 | 25 | ClassDecl *C = VT.getClass();
|
|
0 commit comments