1 //===--- HeaderSearchOptions.h ----------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_CLANG_LEX_HEADERSEARCHOPTIONS_H
11 #define LLVM_CLANG_LEX_HEADERSEARCHOPTIONS_H
13 #include "clang/Basic/LLVM.h"
14 #include "llvm/ADT/IntrusiveRefCntPtr.h"
15 #include "llvm/ADT/SetVector.h"
16 #include "llvm/ADT/StringRef.h"
23 /// IncludeDirGroup - Identifiers the group a include entry belongs to, which
24 /// represents its relative positive in the search list. A \#include of a ""
25 /// path starts at the -iquote group, then searches the Angled group, then
26 /// searches the system group, etc.
27 enum IncludeDirGroup {
28 Quoted = 0, ///< '\#include ""' paths, added by 'gcc -iquote'.
29 Angled, ///< Paths for '\#include <>' added by '-I'.
30 IndexHeaderMap, ///< Like Angled, but marks header maps used when
31 /// building frameworks.
32 System, ///< Like Angled, but marks system directories.
33 ExternCSystem, ///< Like System, but headers are implicitly wrapped in
35 CSystem, ///< Like System, but only used for C.
36 CXXSystem, ///< Like System, but only used for C++.
37 ObjCSystem, ///< Like System, but only used for ObjC.
38 ObjCXXSystem, ///< Like System, but only used for ObjC++.
39 After ///< Like System, but searched after the system directories.
43 /// HeaderSearchOptions - Helper class for storing options related to the
44 /// initialization of the HeaderSearch object.
45 class HeaderSearchOptions : public RefCountedBase<HeaderSearchOptions> {
49 frontend::IncludeDirGroup Group;
50 unsigned IsFramework : 1;
52 /// IgnoreSysRoot - This is false if an absolute path should be treated
53 /// relative to the sysroot, or true if it should always be the absolute
55 unsigned IgnoreSysRoot : 1;
57 Entry(StringRef path, frontend::IncludeDirGroup group, bool isFramework,
59 : Path(path), Group(group), IsFramework(isFramework),
60 IgnoreSysRoot(ignoreSysRoot) {}
63 struct SystemHeaderPrefix {
64 /// A prefix to be matched against paths in \#include directives.
67 /// True if paths beginning with this prefix should be treated as system
71 SystemHeaderPrefix(StringRef Prefix, bool IsSystemHeader)
72 : Prefix(Prefix), IsSystemHeader(IsSystemHeader) {}
75 /// If non-empty, the directory to use as a "virtual system root" for include
79 /// User specified include entries.
80 std::vector<Entry> UserEntries;
82 /// User-specified system header prefixes.
83 std::vector<SystemHeaderPrefix> SystemHeaderPrefixes;
85 /// The directory which holds the compiler resource files (builtin includes,
87 std::string ResourceDir;
89 /// \brief The directory used for the module cache.
90 std::string ModuleCachePath;
92 /// \brief The directory used for a user build.
93 std::string ModuleUserBuildPath;
95 /// \brief Whether we should disable the use of the hash string within the
98 /// Note: Only used for testing!
99 unsigned DisableModuleHash : 1;
101 /// \brief Implicit module maps. This option is enabld by default when
102 /// modules is enabled.
103 unsigned ImplicitModuleMaps : 1;
105 /// \brief Set the 'home directory' of a module map file to the current
106 /// working directory (or the home directory of the module map file that
107 /// contained the 'extern module' directive importing this module map file
108 /// if any) rather than the directory containing the module map file.
110 /// The home directory is where we look for files named in the module map
112 unsigned ModuleMapFileHomeIsCwd : 1;
114 /// \brief The interval (in seconds) between pruning operations.
116 /// This operation is expensive, because it requires Clang to walk through
117 /// the directory structure of the module cache, stat()'ing and removing
120 /// The default value is large, e.g., the operation runs once a week.
121 unsigned ModuleCachePruneInterval;
123 /// \brief The time (in seconds) after which an unused module file will be
124 /// considered unused and will, therefore, be pruned.
126 /// When the module cache is pruned, any module file that has not been
127 /// accessed in this many seconds will be removed. The default value is
128 /// large, e.g., a month, to avoid forcing infrequently-used modules to be
129 /// regenerated often.
130 unsigned ModuleCachePruneAfter;
132 /// \brief The time in seconds when the build session started.
134 /// This time is used by other optimizations in header search and module
136 uint64_t BuildSessionTimestamp;
138 /// \brief The set of macro names that should be ignored for the purposes
139 /// of computing the module hash.
140 llvm::SetVector<std::string> ModulesIgnoreMacros;
142 /// \brief The set of user-provided virtual filesystem overlay files.
143 std::vector<std::string> VFSOverlayFiles;
145 /// Include the compiler builtin includes.
146 unsigned UseBuiltinIncludes : 1;
148 /// Include the system standard include search directories.
149 unsigned UseStandardSystemIncludes : 1;
151 /// Include the system standard C++ library include search directories.
152 unsigned UseStandardCXXIncludes : 1;
154 /// Use libc++ instead of the default libstdc++.
155 unsigned UseLibcxx : 1;
157 /// Whether header search information should be output as for -v.
158 unsigned Verbose : 1;
160 /// \brief If true, skip verifying input files used by modules if the
161 /// module was already verified during this build session (see
162 /// \c BuildSessionTimestamp).
163 unsigned ModulesValidateOncePerBuildSession : 1;
165 /// \brief Whether to validate system input files when a module is loaded.
166 unsigned ModulesValidateSystemHeaders : 1;
169 HeaderSearchOptions(StringRef _Sysroot = "/")
170 : Sysroot(_Sysroot), DisableModuleHash(0), ImplicitModuleMaps(0),
171 ModuleMapFileHomeIsCwd(0),
172 ModuleCachePruneInterval(7*24*60*60),
173 ModuleCachePruneAfter(31*24*60*60),
174 BuildSessionTimestamp(0),
175 UseBuiltinIncludes(true),
176 UseStandardSystemIncludes(true), UseStandardCXXIncludes(true),
177 UseLibcxx(false), Verbose(false),
178 ModulesValidateOncePerBuildSession(false),
179 ModulesValidateSystemHeaders(false) {}
181 /// AddPath - Add the \p Path path to the specified \p Group list.
182 void AddPath(StringRef Path, frontend::IncludeDirGroup Group,
183 bool IsFramework, bool IgnoreSysRoot) {
184 UserEntries.emplace_back(Path, Group, IsFramework, IgnoreSysRoot);
187 /// AddSystemHeaderPrefix - Override whether \#include directives naming a
188 /// path starting with \p Prefix should be considered as naming a system
190 void AddSystemHeaderPrefix(StringRef Prefix, bool IsSystemHeader) {
191 SystemHeaderPrefixes.emplace_back(Prefix, IsSystemHeader);
194 void AddVFSOverlayFile(StringRef Name) {
195 VFSOverlayFiles.push_back(Name);
199 } // end namespace clang