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 - Identifies the group an include Entry belongs to,
24 /// representing its relative positive in the search list.
25 /// \#include directives whose paths are enclosed by string quotes ("")
26 /// start searching at the Quoted group (specified by '-iquote'),
27 /// then search the Angled group, then the System group, etc.
28 enum IncludeDirGroup {
29 Quoted = 0, ///< '\#include ""' paths, added by 'gcc -iquote'.
30 Angled, ///< Paths for '\#include <>' added by '-I'.
31 IndexHeaderMap, ///< Like Angled, but marks header maps used when
32 /// building frameworks.
33 System, ///< Like Angled, but marks system directories.
34 ExternCSystem, ///< Like System, but headers are implicitly wrapped in
36 CSystem, ///< Like System, but only used for C.
37 CXXSystem, ///< Like System, but only used for C++.
38 ObjCSystem, ///< Like System, but only used for ObjC.
39 ObjCXXSystem, ///< Like System, but only used for ObjC++.
40 After ///< Like System, but searched after the system directories.
44 /// HeaderSearchOptions - Helper class for storing options related to the
45 /// initialization of the HeaderSearch object.
46 class HeaderSearchOptions : public RefCountedBase<HeaderSearchOptions> {
50 frontend::IncludeDirGroup Group;
51 unsigned IsFramework : 1;
53 /// IgnoreSysRoot - This is false if an absolute path should be treated
54 /// relative to the sysroot, or true if it should always be the absolute
56 unsigned IgnoreSysRoot : 1;
58 Entry(StringRef path, frontend::IncludeDirGroup group, bool isFramework,
60 : Path(path), Group(group), IsFramework(isFramework),
61 IgnoreSysRoot(ignoreSysRoot) {}
64 struct SystemHeaderPrefix {
65 /// A prefix to be matched against paths in \#include directives.
68 /// True if paths beginning with this prefix should be treated as system
72 SystemHeaderPrefix(StringRef Prefix, bool IsSystemHeader)
73 : Prefix(Prefix), IsSystemHeader(IsSystemHeader) {}
76 /// If non-empty, the directory to use as a "virtual system root" for include
80 /// User specified include entries.
81 std::vector<Entry> UserEntries;
83 /// User-specified system header prefixes.
84 std::vector<SystemHeaderPrefix> SystemHeaderPrefixes;
86 /// The directory which holds the compiler resource files (builtin includes,
88 std::string ResourceDir;
90 /// \brief The directory used for the module cache.
91 std::string ModuleCachePath;
93 /// \brief The directory used for a user build.
94 std::string ModuleUserBuildPath;
96 /// The module/pch container format.
97 std::string ModuleFormat;
99 /// \brief Whether we should disable the use of the hash string within the
102 /// Note: Only used for testing!
103 unsigned DisableModuleHash : 1;
105 /// \brief Implicit module maps. This option is enabld by default when
106 /// modules is enabled.
107 unsigned ImplicitModuleMaps : 1;
109 /// \brief Set the 'home directory' of a module map file to the current
110 /// working directory (or the home directory of the module map file that
111 /// contained the 'extern module' directive importing this module map file
112 /// if any) rather than the directory containing the module map file.
114 /// The home directory is where we look for files named in the module map
116 unsigned ModuleMapFileHomeIsCwd : 1;
118 /// \brief The interval (in seconds) between pruning operations.
120 /// This operation is expensive, because it requires Clang to walk through
121 /// the directory structure of the module cache, stat()'ing and removing
124 /// The default value is large, e.g., the operation runs once a week.
125 unsigned ModuleCachePruneInterval;
127 /// \brief The time (in seconds) after which an unused module file will be
128 /// considered unused and will, therefore, be pruned.
130 /// When the module cache is pruned, any module file that has not been
131 /// accessed in this many seconds will be removed. The default value is
132 /// large, e.g., a month, to avoid forcing infrequently-used modules to be
133 /// regenerated often.
134 unsigned ModuleCachePruneAfter;
136 /// \brief The time in seconds when the build session started.
138 /// This time is used by other optimizations in header search and module
140 uint64_t BuildSessionTimestamp;
142 /// \brief The set of macro names that should be ignored for the purposes
143 /// of computing the module hash.
144 llvm::SmallSetVector<std::string, 16> ModulesIgnoreMacros;
146 /// \brief The set of user-provided virtual filesystem overlay files.
147 std::vector<std::string> VFSOverlayFiles;
149 /// Include the compiler builtin includes.
150 unsigned UseBuiltinIncludes : 1;
152 /// Include the system standard include search directories.
153 unsigned UseStandardSystemIncludes : 1;
155 /// Include the system standard C++ library include search directories.
156 unsigned UseStandardCXXIncludes : 1;
158 /// Use libc++ instead of the default libstdc++.
159 unsigned UseLibcxx : 1;
161 /// Whether header search information should be output as for -v.
162 unsigned Verbose : 1;
164 /// \brief If true, skip verifying input files used by modules if the
165 /// module was already verified during this build session (see
166 /// \c BuildSessionTimestamp).
167 unsigned ModulesValidateOncePerBuildSession : 1;
169 /// \brief Whether to validate system input files when a module is loaded.
170 unsigned ModulesValidateSystemHeaders : 1;
172 /// Whether the module includes debug information (-gmodules).
173 unsigned UseDebugInfo : 1;
175 HeaderSearchOptions(StringRef _Sysroot = "/")
176 : Sysroot(_Sysroot), ModuleFormat("raw"), DisableModuleHash(0),
177 ImplicitModuleMaps(0), ModuleMapFileHomeIsCwd(0),
178 ModuleCachePruneInterval(7 * 24 * 60 * 60),
179 ModuleCachePruneAfter(31 * 24 * 60 * 60), BuildSessionTimestamp(0),
180 UseBuiltinIncludes(true), UseStandardSystemIncludes(true),
181 UseStandardCXXIncludes(true), UseLibcxx(false), Verbose(false),
182 ModulesValidateOncePerBuildSession(false),
183 ModulesValidateSystemHeaders(false),
184 UseDebugInfo(false) {}
186 /// AddPath - Add the \p Path path to the specified \p Group list.
187 void AddPath(StringRef Path, frontend::IncludeDirGroup Group,
188 bool IsFramework, bool IgnoreSysRoot) {
189 UserEntries.emplace_back(Path, Group, IsFramework, IgnoreSysRoot);
192 /// AddSystemHeaderPrefix - Override whether \#include directives naming a
193 /// path starting with \p Prefix should be considered as naming a system
195 void AddSystemHeaderPrefix(StringRef Prefix, bool IsSystemHeader) {
196 SystemHeaderPrefixes.emplace_back(Prefix, IsSystemHeader);
199 void AddVFSOverlayFile(StringRef Name) {
200 VFSOverlayFiles.push_back(Name);
204 } // end namespace clang