|
19 | 19 | #include "swift/AST/SimpleRequest.h"
|
20 | 20 | #include "swift/AST/ASTTypeIDs.h"
|
21 | 21 | #include "swift/AST/EvaluatorDependencies.h"
|
| 22 | +#include "swift/AST/FileUnit.h" |
| 23 | +#include "swift/AST/Identifier.h" |
| 24 | +#include "swift/AST/NameLookup.h" |
| 25 | +#include "swift/Basic/Statistic.h" |
| 26 | +#include "llvm/ADT/Hashing.h" |
| 27 | +#include "llvm/ADT/TinyPtrVector.h" |
22 | 28 |
|
23 | 29 | namespace swift {
|
| 30 | +class Decl; |
| 31 | +class DeclName; |
| 32 | +class EnumDecl; |
| 33 | + |
| 34 | +/// The input type for a clang direct lookup request. |
| 35 | +struct ClangDirectLookupDescriptor final { |
| 36 | + Decl *decl; |
| 37 | + DeclName name; |
| 38 | + |
| 39 | + ClangDirectLookupDescriptor(Decl *decl, DeclName name) |
| 40 | + : decl(decl), name(name) {} |
| 41 | + |
| 42 | + friend llvm::hash_code hash_value(const ClangDirectLookupDescriptor &desc) { |
| 43 | + return llvm::hash_combine(desc.name, desc.decl); |
| 44 | + } |
| 45 | + |
| 46 | + friend bool operator==(const ClangDirectLookupDescriptor &lhs, |
| 47 | + const ClangDirectLookupDescriptor &rhs) { |
| 48 | + return lhs.name == rhs.name && lhs.decl == rhs.decl; |
| 49 | + } |
| 50 | + |
| 51 | + friend bool operator!=(const ClangDirectLookupDescriptor &lhs, |
| 52 | + const ClangDirectLookupDescriptor &rhs) { |
| 53 | + return !(lhs == rhs); |
| 54 | + } |
| 55 | +}; |
| 56 | + |
| 57 | +void simple_display(llvm::raw_ostream &out, |
| 58 | + const ClangDirectLookupDescriptor &desc); |
| 59 | +SourceLoc extractNearestSourceLoc(const ClangDirectLookupDescriptor &desc); |
| 60 | + |
| 61 | +/// This matches SwiftLookupTable::SingleEntry; |
| 62 | +using SingleEntry = llvm::PointerUnion<clang::NamedDecl *, clang::MacroInfo *, |
| 63 | + clang::ModuleMacro *>; |
| 64 | +/// Uses the appropriate SwiftLookupTable to find a set of clang decls given |
| 65 | +/// their name. |
| 66 | +class ClangDirectLookupRequest |
| 67 | + : public SimpleRequest<ClangDirectLookupRequest, |
| 68 | + SmallVector<SingleEntry, 4>( |
| 69 | + ClangDirectLookupDescriptor), |
| 70 | + RequestFlags::Uncached> { |
| 71 | +public: |
| 72 | + using SimpleRequest::SimpleRequest; |
| 73 | + |
| 74 | +private: |
| 75 | + friend SimpleRequest; |
| 76 | + |
| 77 | + // Evaluation. |
| 78 | + SmallVector<SingleEntry, 4> evaluate(Evaluator &evaluator, |
| 79 | + ClangDirectLookupDescriptor desc) const; |
| 80 | +}; |
| 81 | + |
| 82 | +/// The input type for a namespace member lookup request. |
| 83 | +struct CXXNamespaceMemberLookupDescriptor final { |
| 84 | + EnumDecl *namespaceDecl; |
| 85 | + DeclName name; |
| 86 | + |
| 87 | + CXXNamespaceMemberLookupDescriptor(EnumDecl *namespaceDecl, DeclName name) |
| 88 | + : namespaceDecl(namespaceDecl), name(name) { |
| 89 | + assert(isa<clang::NamespaceDecl>(namespaceDecl->getClangDecl())); |
| 90 | + } |
| 91 | + |
| 92 | + friend llvm::hash_code |
| 93 | + hash_value(const CXXNamespaceMemberLookupDescriptor &desc) { |
| 94 | + return llvm::hash_combine(desc.name, desc.namespaceDecl); |
| 95 | + } |
| 96 | + |
| 97 | + friend bool operator==(const CXXNamespaceMemberLookupDescriptor &lhs, |
| 98 | + const CXXNamespaceMemberLookupDescriptor &rhs) { |
| 99 | + return lhs.name == rhs.name && lhs.namespaceDecl == rhs.namespaceDecl; |
| 100 | + } |
| 101 | + |
| 102 | + friend bool operator!=(const CXXNamespaceMemberLookupDescriptor &lhs, |
| 103 | + const CXXNamespaceMemberLookupDescriptor &rhs) { |
| 104 | + return !(lhs == rhs); |
| 105 | + } |
| 106 | +}; |
| 107 | + |
| 108 | +void simple_display(llvm::raw_ostream &out, |
| 109 | + const CXXNamespaceMemberLookupDescriptor &desc); |
| 110 | +SourceLoc |
| 111 | +extractNearestSourceLoc(const CXXNamespaceMemberLookupDescriptor &desc); |
| 112 | + |
| 113 | +/// Uses ClangDirectLookup to find a named member inside of the given namespace. |
| 114 | +class CXXNamespaceMemberLookup |
| 115 | + : public SimpleRequest<CXXNamespaceMemberLookup, |
| 116 | + TinyPtrVector<ValueDecl *>( |
| 117 | + CXXNamespaceMemberLookupDescriptor), |
| 118 | + RequestFlags::Uncached> { |
| 119 | +public: |
| 120 | + using SimpleRequest::SimpleRequest; |
| 121 | + |
| 122 | +private: |
| 123 | + friend SimpleRequest; |
| 124 | + |
| 125 | + // Evaluation. |
| 126 | + TinyPtrVector<ValueDecl *> |
| 127 | + evaluate(Evaluator &evaluator, CXXNamespaceMemberLookupDescriptor desc) const; |
| 128 | +}; |
| 129 | + |
| 130 | +/// The input type for a record member lookup request. |
| 131 | +struct ClangRecordMemberLookupDescriptor final { |
| 132 | + StructDecl *recordDecl; |
| 133 | + DeclName name; |
| 134 | + |
| 135 | + ClangRecordMemberLookupDescriptor(StructDecl *recordDecl, DeclName name) |
| 136 | + : recordDecl(recordDecl), name(name) { |
| 137 | + assert(isa<clang::RecordDecl>(recordDecl->getClangDecl())); |
| 138 | + } |
| 139 | + |
| 140 | + friend llvm::hash_code |
| 141 | + hash_value(const ClangRecordMemberLookupDescriptor &desc) { |
| 142 | + return llvm::hash_combine(desc.name, desc.recordDecl); |
| 143 | + } |
| 144 | + |
| 145 | + friend bool operator==(const ClangRecordMemberLookupDescriptor &lhs, |
| 146 | + const ClangRecordMemberLookupDescriptor &rhs) { |
| 147 | + return lhs.name == rhs.name && lhs.recordDecl == rhs.recordDecl; |
| 148 | + } |
| 149 | + |
| 150 | + friend bool operator!=(const ClangRecordMemberLookupDescriptor &lhs, |
| 151 | + const ClangRecordMemberLookupDescriptor &rhs) { |
| 152 | + return !(lhs == rhs); |
| 153 | + } |
| 154 | +}; |
| 155 | + |
| 156 | +void simple_display(llvm::raw_ostream &out, |
| 157 | + const ClangRecordMemberLookupDescriptor &desc); |
| 158 | +SourceLoc |
| 159 | +extractNearestSourceLoc(const ClangRecordMemberLookupDescriptor &desc); |
| 160 | + |
| 161 | +/// Uses ClangDirectLookup to find a named member inside of the given record. |
| 162 | +class ClangRecordMemberLookup |
| 163 | + : public SimpleRequest<ClangRecordMemberLookup, |
| 164 | + TinyPtrVector<ValueDecl *>( |
| 165 | + ClangRecordMemberLookupDescriptor), |
| 166 | + RequestFlags::Uncached> { |
| 167 | +public: |
| 168 | + using SimpleRequest::SimpleRequest; |
| 169 | + |
| 170 | +private: |
| 171 | + friend SimpleRequest; |
| 172 | + |
| 173 | + // Evaluation. |
| 174 | + TinyPtrVector<ValueDecl *> |
| 175 | + evaluate(Evaluator &evaluator, ClangRecordMemberLookupDescriptor desc) const; |
| 176 | +}; |
24 | 177 |
|
25 | 178 | #define SWIFT_TYPEID_ZONE ClangImporter
|
26 | 179 | #define SWIFT_TYPEID_HEADER "swift/ClangImporter/ClangImporterTypeIDZone.def"
|
|
0 commit comments