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_INSTALLAPI_HEADERFILE_H
0014 #define LLVM_CLANG_INSTALLAPI_HEADERFILE_H
0015
0016 #include "clang/Basic/FileManager.h"
0017 #include "clang/Basic/LangStandard.h"
0018 #include "clang/InstallAPI/MachO.h"
0019 #include "llvm/ADT/StringRef.h"
0020 #include "llvm/Support/ErrorHandling.h"
0021 #include "llvm/Support/Regex.h"
0022 #include <optional>
0023 #include <string>
0024
0025 namespace clang::installapi {
0026 enum class HeaderType {
0027
0028 Public,
0029
0030 Private,
0031
0032
0033 Project,
0034
0035 Unknown,
0036 };
0037
0038 inline StringRef getName(const HeaderType T) {
0039 switch (T) {
0040 case HeaderType::Public:
0041 return "Public";
0042 case HeaderType::Private:
0043 return "Private";
0044 case HeaderType::Project:
0045 return "Project";
0046 case HeaderType::Unknown:
0047 return "Unknown";
0048 }
0049 llvm_unreachable("unexpected header type");
0050 }
0051
0052 class HeaderFile {
0053
0054 std::string FullPath;
0055
0056 HeaderType Type;
0057
0058 std::string IncludeName;
0059
0060 std::optional<clang::Language> Language;
0061
0062 bool Excluded{false};
0063
0064 bool Extra{false};
0065
0066 bool Umbrella{false};
0067
0068 public:
0069 HeaderFile() = delete;
0070 HeaderFile(StringRef FullPath, HeaderType Type,
0071 StringRef IncludeName = StringRef(),
0072 std::optional<clang::Language> Language = std::nullopt)
0073 : FullPath(FullPath), Type(Type), IncludeName(IncludeName),
0074 Language(Language) {}
0075
0076 static llvm::Regex getFrameworkIncludeRule();
0077
0078 HeaderType getType() const { return Type; }
0079 StringRef getIncludeName() const { return IncludeName; }
0080 StringRef getPath() const { return FullPath; }
0081
0082 void setExtra(bool V = true) { Extra = V; }
0083 void setExcluded(bool V = true) { Excluded = V; }
0084 void setUmbrellaHeader(bool V = true) { Umbrella = V; }
0085 bool isExtra() const { return Extra; }
0086 bool isExcluded() const { return Excluded; }
0087 bool isUmbrellaHeader() const { return Umbrella; }
0088
0089 bool useIncludeName() const {
0090 return Type != HeaderType::Project && !IncludeName.empty();
0091 }
0092
0093 bool operator==(const HeaderFile &Other) const {
0094 return std::tie(Type, FullPath, IncludeName, Language, Excluded, Extra,
0095 Umbrella) == std::tie(Other.Type, Other.FullPath,
0096 Other.IncludeName, Other.Language,
0097 Other.Excluded, Other.Extra,
0098 Other.Umbrella);
0099 }
0100
0101 bool operator<(const HeaderFile &Other) const {
0102
0103
0104
0105
0106
0107 if (isExtra() && Other.isExtra())
0108 return std::tie(Type, Umbrella) < std::tie(Other.Type, Other.Umbrella);
0109
0110 return std::tie(Type, Umbrella, Extra, FullPath) <
0111 std::tie(Other.Type, Other.Umbrella, Other.Extra, Other.FullPath);
0112 }
0113 };
0114
0115
0116 class HeaderGlob {
0117 private:
0118 std::string GlobString;
0119 llvm::Regex Rule;
0120 HeaderType Type;
0121 bool FoundMatch{false};
0122
0123 public:
0124 HeaderGlob(StringRef GlobString, llvm::Regex &&, HeaderType Type);
0125
0126
0127 static llvm::Expected<std::unique_ptr<HeaderGlob>>
0128 create(StringRef GlobString, HeaderType Type);
0129
0130
0131 bool match(const HeaderFile &Header);
0132
0133
0134
0135 bool didMatch() { return FoundMatch; }
0136
0137
0138 StringRef str() { return GlobString; }
0139 };
0140
0141
0142
0143
0144
0145
0146
0147
0148
0149 std::optional<std::string> createIncludeHeaderName(const StringRef FullPath);
0150 using HeaderSeq = std::vector<HeaderFile>;
0151
0152
0153
0154
0155
0156 bool isHeaderFile(StringRef Path);
0157
0158
0159
0160
0161
0162 llvm::Expected<PathSeq> enumerateFiles(clang::FileManager &FM,
0163 StringRef Directory);
0164
0165 }
0166
0167 #endif