clang 19.0.0git
HeaderFile.h
Go to the documentation of this file.
1//===- InstallAPI/HeaderFile.h ----------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8///
9/// Representations of a library's headers for InstallAPI.
10///
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_CLANG_INSTALLAPI_HEADERFILE_H
14#define LLVM_CLANG_INSTALLAPI_HEADERFILE_H
15
19#include "llvm/ADT/StringRef.h"
20#include "llvm/Support/ErrorHandling.h"
21#include "llvm/Support/Regex.h"
22#include <optional>
23#include <string>
24
25namespace clang::installapi {
26enum class HeaderType {
27 /// Represents declarations accessible to all clients.
28 Public,
29 /// Represents declarations accessible to a disclosed set of clients.
30 Private,
31 /// Represents declarations only accessible as implementation details to the
32 /// input library.
33 Project,
34 /// Unset or unknown type.
35 Unknown,
36};
37
38inline StringRef getName(const HeaderType T) {
39 switch (T) {
41 return "Public";
43 return "Private";
45 return "Project";
47 return "Unknown";
48 }
49 llvm_unreachable("unexpected header type");
50}
51
53 /// Full input path to header.
54 std::string FullPath;
55 /// Access level of header.
57 /// Expected way header will be included by clients.
58 std::string IncludeName;
59 /// Supported language mode for header.
60 std::optional<clang::Language> Language;
61 /// Exclude header file from processing.
62 bool Excluded{false};
63 /// Add header file to processing.
64 bool Extra{false};
65 /// Specify that header file is the umbrella header for library.
66 bool Umbrella{false};
67
68public:
69 HeaderFile() = delete;
70 HeaderFile(StringRef FullPath, HeaderType Type,
71 StringRef IncludeName = StringRef(),
72 std::optional<clang::Language> Language = std::nullopt)
73 : FullPath(FullPath), Type(Type), IncludeName(IncludeName),
75
76 static llvm::Regex getFrameworkIncludeRule();
77
78 HeaderType getType() const { return Type; }
79 StringRef getIncludeName() const { return IncludeName; }
80 StringRef getPath() const { return FullPath; }
81
82 void setExtra(bool V = true) { Extra = V; }
83 void setExcluded(bool V = true) { Excluded = V; }
84 void setUmbrellaHeader(bool V = true) { Umbrella = V; }
85 bool isExtra() const { return Extra; }
86 bool isExcluded() const { return Excluded; }
87 bool isUmbrellaHeader() const { return Umbrella; }
88
89 bool useIncludeName() const {
90 return Type != HeaderType::Project && !IncludeName.empty();
91 }
92
93 bool operator==(const HeaderFile &Other) const {
94 return std::tie(Type, FullPath, IncludeName, Language, Excluded, Extra,
95 Umbrella) == std::tie(Other.Type, Other.FullPath,
96 Other.IncludeName, Other.Language,
97 Other.Excluded, Other.Extra,
98 Other.Umbrella);
99 }
100};
101
102/// Glob that represents a pattern of header files to retreive.
104private:
105 std::string GlobString;
106 llvm::Regex Rule;
108 bool FoundMatch{false};
109
110public:
111 HeaderGlob(StringRef GlobString, llvm::Regex &&, HeaderType Type);
112
113 /// Create a header glob from string for the header access level.
115 create(StringRef GlobString, HeaderType Type);
116
117 /// Query if provided header matches glob.
118 bool match(const HeaderFile &Header);
119
120 /// Query if a header was matched in the glob, used primarily for error
121 /// reporting.
122 bool didMatch() { return FoundMatch; }
123
124 /// Provide back input glob string.
125 StringRef str() { return GlobString; }
126};
127
128/// Assemble expected way header will be included by clients.
129/// As in what maps inside the brackets of `#include <IncludeName.h>`
130/// For example,
131/// "/System/Library/Frameworks/Foo.framework/Headers/Foo.h" returns
132/// "Foo/Foo.h"
133///
134/// \param FullPath Path to the header file which includes the library
135/// structure.
136std::optional<std::string> createIncludeHeaderName(const StringRef FullPath);
137using HeaderSeq = std::vector<HeaderFile>;
138
139/// Determine if Path is a header file.
140/// It does not touch the file system.
141///
142/// \param Path File path to file.
143bool isHeaderFile(StringRef Path);
144
145/// Given input directory, collect all header files.
146///
147/// \param FM FileManager for finding input files.
148/// \param Directory Path to directory file.
150 StringRef Directory);
151
152} // namespace clang::installapi
153
154#endif // LLVM_CLANG_INSTALLAPI_HEADERFILE_H
#define V(N, I)
Definition: ASTContext.h:3284
Defines the clang::FileManager interface and associated types.
Implements support for file system lookup, file system caching, and directory search management.
Definition: FileManager.h:53
The base class of the type hierarchy.
Definition: Type.h:1813
bool operator==(const HeaderFile &Other) const
Definition: HeaderFile.h:93
void setExcluded(bool V=true)
Definition: HeaderFile.h:83
HeaderType getType() const
Definition: HeaderFile.h:78
void setExtra(bool V=true)
Definition: HeaderFile.h:82
StringRef getIncludeName() const
Definition: HeaderFile.h:79
void setUmbrellaHeader(bool V=true)
Definition: HeaderFile.h:84
StringRef getPath() const
Definition: HeaderFile.h:80
HeaderFile(StringRef FullPath, HeaderType Type, StringRef IncludeName=StringRef(), std::optional< clang::Language > Language=std::nullopt)
Definition: HeaderFile.h:70
static llvm::Regex getFrameworkIncludeRule()
Definition: HeaderFile.cpp:15
Glob that represents a pattern of header files to retreive.
Definition: HeaderFile.h:103
StringRef str()
Provide back input glob string.
Definition: HeaderFile.h:125
static llvm::Expected< std::unique_ptr< HeaderGlob > > create(StringRef GlobString, HeaderType Type)
Create a header glob from string for the header access level.
Definition: HeaderFile.cpp:79
bool didMatch()
Query if a header was matched in the glob, used primarily for error reporting.
Definition: HeaderFile.h:122
bool match(const HeaderFile &Header)
Query if provided header matches glob.
Definition: HeaderFile.cpp:69
Representations of a library's headers for InstallAPI.
Definition: Context.h:20
llvm::Expected< PathSeq > enumerateFiles(clang::FileManager &FM, StringRef Directory)
Given input directory, collect all header files.
Definition: HeaderFile.cpp:45
std::vector< HeaderFile > HeaderSeq
Definition: HeaderFile.h:137
@ Public
Represents declarations accessible to all clients.
@ Private
Represents declarations accessible to a disclosed set of clients.
@ Unknown
Unset or unknown type.
@ Project
Represents declarations only accessible as implementation details to the input library.
std::optional< std::string > createIncludeHeaderName(const StringRef FullPath)
Assemble expected way header will be included by clients.
Definition: HeaderFile.cpp:19
StringRef getName(const HeaderType T)
Definition: HeaderFile.h:38
bool isHeaderFile(StringRef Path)
Determine if Path is a header file.
Definition: HeaderFile.cpp:39
Language
The language for the input, used to select and validate the language standard and possible actions.
Definition: LangStandard.h:23
const FunctionProtoType * T
@ Other
Other implicit parameter.