File indexing completed on 2026-05-10 08:36:56
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef LLVM_CLANG_LEX_DIRECTORYLOOKUP_H
0014 #define LLVM_CLANG_LEX_DIRECTORYLOOKUP_H
0015
0016 #include "clang/Basic/LLVM.h"
0017 #include "clang/Basic/FileManager.h"
0018 #include "clang/Basic/SourceManager.h"
0019 #include "clang/Lex/ModuleMap.h"
0020
0021 namespace clang {
0022 class HeaderMap;
0023 class HeaderSearch;
0024 class Module;
0025
0026
0027
0028
0029
0030 class DirectoryLookup {
0031 public:
0032 enum LookupType_t {
0033 LT_NormalDir,
0034 LT_Framework,
0035 LT_HeaderMap
0036 };
0037 private:
0038 union DLU {
0039
0040
0041 DirectoryEntryRef Dir;
0042
0043
0044
0045 const HeaderMap *Map;
0046
0047 DLU(DirectoryEntryRef Dir) : Dir(Dir) {}
0048 DLU(const HeaderMap *Map) : Map(Map) {}
0049 } u;
0050
0051
0052
0053 LLVM_PREFERRED_TYPE(SrcMgr::CharacteristicKind)
0054 unsigned DirCharacteristic : 3;
0055
0056
0057
0058 LLVM_PREFERRED_TYPE(LookupType_t)
0059 unsigned LookupType : 2;
0060
0061
0062
0063 LLVM_PREFERRED_TYPE(bool)
0064 unsigned SearchedAllModuleMaps : 1;
0065
0066 public:
0067
0068 DirectoryLookup(DirectoryEntryRef Dir, SrcMgr::CharacteristicKind DT,
0069 bool isFramework)
0070 : u(Dir), DirCharacteristic(DT),
0071 LookupType(isFramework ? LT_Framework : LT_NormalDir),
0072 SearchedAllModuleMaps(false) {}
0073
0074
0075 DirectoryLookup(const HeaderMap *Map, SrcMgr::CharacteristicKind DT)
0076 : u(Map), DirCharacteristic(DT), LookupType(LT_HeaderMap),
0077 SearchedAllModuleMaps(false) {}
0078
0079
0080
0081 LookupType_t getLookupType() const { return (LookupType_t)LookupType; }
0082
0083
0084
0085 StringRef getName() const;
0086
0087
0088
0089 const DirectoryEntry *getDir() const {
0090 return isNormalDir() ? &u.Dir.getDirEntry() : nullptr;
0091 }
0092
0093 OptionalDirectoryEntryRef getDirRef() const {
0094 return isNormalDir() ? OptionalDirectoryEntryRef(u.Dir) : std::nullopt;
0095 }
0096
0097
0098
0099 const DirectoryEntry *getFrameworkDir() const {
0100 return isFramework() ? &u.Dir.getDirEntry() : nullptr;
0101 }
0102
0103 OptionalDirectoryEntryRef getFrameworkDirRef() const {
0104 return isFramework() ? OptionalDirectoryEntryRef(u.Dir) : std::nullopt;
0105 }
0106
0107
0108
0109 const HeaderMap *getHeaderMap() const {
0110 return isHeaderMap() ? u.Map : nullptr;
0111 }
0112
0113
0114 bool isNormalDir() const { return getLookupType() == LT_NormalDir; }
0115
0116
0117
0118 bool isFramework() const { return getLookupType() == LT_Framework; }
0119
0120
0121 bool isHeaderMap() const { return getLookupType() == LT_HeaderMap; }
0122
0123
0124
0125 bool haveSearchedAllModuleMaps() const { return SearchedAllModuleMaps; }
0126
0127
0128
0129 void setSearchedAllModuleMaps(bool SAMM) {
0130 SearchedAllModuleMaps = SAMM;
0131 }
0132
0133
0134
0135 SrcMgr::CharacteristicKind getDirCharacteristic() const {
0136 return (SrcMgr::CharacteristicKind)DirCharacteristic;
0137 }
0138
0139
0140 bool isSystemHeaderDirectory() const {
0141 return getDirCharacteristic() != SrcMgr::C_User;
0142 }
0143
0144
0145
0146
0147
0148
0149
0150
0151
0152
0153
0154
0155
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165
0166
0167
0168
0169
0170
0171
0172
0173
0174
0175
0176
0177 OptionalFileEntryRef
0178 LookupFile(StringRef &Filename, HeaderSearch &HS, SourceLocation IncludeLoc,
0179 SmallVectorImpl<char> *SearchPath,
0180 SmallVectorImpl<char> *RelativePath, Module *RequestingModule,
0181 ModuleMap::KnownHeader *SuggestedModule,
0182 bool &InUserSpecifiedSystemFramework, bool &IsFrameworkFound,
0183 bool &IsInHeaderMap, SmallVectorImpl<char> &MappedName,
0184 bool OpenFile = true) const;
0185
0186 private:
0187 OptionalFileEntryRef DoFrameworkLookup(
0188 StringRef Filename, HeaderSearch &HS, SmallVectorImpl<char> *SearchPath,
0189 SmallVectorImpl<char> *RelativePath, Module *RequestingModule,
0190 ModuleMap::KnownHeader *SuggestedModule,
0191 bool &InUserSpecifiedSystemFramework, bool &IsFrameworkFound) const;
0192 };
0193
0194 }
0195
0196 #endif