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/CachedHashString.h"
15 #include "llvm/ADT/IntrusiveRefCntPtr.h"
16 #include "llvm/ADT/SetVector.h"
17 #include "llvm/ADT/StringRef.h"
24 /// IncludeDirGroup - Identifies the group an include Entry belongs to,
25 /// representing its relative positive in the search list.
26 /// \#include directives whose paths are enclosed by string quotes ("")
27 /// start searching at the Quoted group (specified by '-iquote'),
28 /// then search the Angled group, then the System group, etc.
29 enum IncludeDirGroup {
30 Quoted = 0, ///< '\#include ""' paths, added by 'gcc -iquote'.
31 Angled, ///< Paths for '\#include <>' added by '-I'.
32 IndexHeaderMap, ///< Like Angled, but marks header maps used when
33 /// building frameworks.
34 System, ///< Like Angled, but marks system directories.
35 ExternCSystem, ///< Like System, but headers are implicitly wrapped in
37 CSystem, ///< Like System, but only used for C.
38 CXXSystem, ///< Like System, but only used for C++.
39 ObjCSystem, ///< Like System, but only used for ObjC.
40 ObjCXXSystem, ///< Like System, but only used for ObjC++.
41 After ///< Like System, but searched after the system directories.
45 /// HeaderSearchOptions - Helper class for storing options related to the
46 /// initialization of the HeaderSearch object.
47 class HeaderSearchOptions {
51 frontend::IncludeDirGroup Group;
52 unsigned IsFramework : 1;
54 /// IgnoreSysRoot - This is false if an absolute path should be treated
55 /// relative to the sysroot, or true if it should always be the absolute
57 unsigned IgnoreSysRoot : 1;
59 Entry(StringRef path, frontend::IncludeDirGroup group, bool isFramework,
61 : Path(path), Group(group), IsFramework(isFramework),
62 IgnoreSysRoot(ignoreSysRoot) {}
65 struct SystemHeaderPrefix {
66 /// A prefix to be matched against paths in \#include directives.
69 /// True if paths beginning with this prefix should be treated as system
73 SystemHeaderPrefix(StringRef Prefix, bool IsSystemHeader)
74 : Prefix(Prefix), IsSystemHeader(IsSystemHeader) {}
77 /// If non-empty, the directory to use as a "virtual system root" for include
81 /// User specified include entries.
82 std::vector<Entry> UserEntries;
84 /// User-specified system header prefixes.
85 std::vector<SystemHeaderPrefix> SystemHeaderPrefixes;
87 /// The directory which holds the compiler resource files (builtin includes,
89 std::string ResourceDir;
91 /// \brief The directory used for the module cache.
92 std::string ModuleCachePath;
94 /// \brief The directory used for a user build.
95 std::string ModuleUserBuildPath;
97 /// \brief The directories used to load prebuilt module files.
98 std::vector<std::string> PrebuiltModulePaths;
100 /// The module/pch container format.
101 std::string ModuleFormat;
103 /// \brief Whether we should disable the use of the hash string within the
106 /// Note: Only used for testing!
107 unsigned DisableModuleHash : 1;
109 /// \brief Implicit module maps. This option is enabld by default when
110 /// modules is enabled.
111 unsigned ImplicitModuleMaps : 1;
113 /// \brief Set the 'home directory' of a module map file to the current
114 /// working directory (or the home directory of the module map file that
115 /// contained the 'extern module' directive importing this module map file
116 /// if any) rather than the directory containing the module map file.
118 /// The home directory is where we look for files named in the module map
120 unsigned ModuleMapFileHomeIsCwd : 1;
122 /// \brief The interval (in seconds) between pruning operations.
124 /// This operation is expensive, because it requires Clang to walk through
125 /// the directory structure of the module cache, stat()'ing and removing
128 /// The default value is large, e.g., the operation runs once a week.
129 unsigned ModuleCachePruneInterval;
131 /// \brief The time (in seconds) after which an unused module file will be
132 /// considered unused and will, therefore, be pruned.
134 /// When the module cache is pruned, any module file that has not been
135 /// accessed in this many seconds will be removed. The default value is
136 /// large, e.g., a month, to avoid forcing infrequently-used modules to be
137 /// regenerated often.
138 unsigned ModuleCachePruneAfter;
140 /// \brief The time in seconds when the build session started.
142 /// This time is used by other optimizations in header search and module
144 uint64_t BuildSessionTimestamp;
146 /// \brief The set of macro names that should be ignored for the purposes
147 /// of computing the module hash.
148 llvm::SmallSetVector<llvm::CachedHashString, 16> ModulesIgnoreMacros;
150 /// \brief The set of user-provided virtual filesystem overlay files.
151 std::vector<std::string> VFSOverlayFiles;
153 /// Include the compiler builtin includes.
154 unsigned UseBuiltinIncludes : 1;
156 /// Include the system standard include search directories.
157 unsigned UseStandardSystemIncludes : 1;
159 /// Include the system standard C++ library include search directories.
160 unsigned UseStandardCXXIncludes : 1;
162 /// Use libc++ instead of the default libstdc++.
163 unsigned UseLibcxx : 1;
165 /// Whether header search information should be output as for -v.
166 unsigned Verbose : 1;
168 /// \brief If true, skip verifying input files used by modules if the
169 /// module was already verified during this build session (see
170 /// \c BuildSessionTimestamp).
171 unsigned ModulesValidateOncePerBuildSession : 1;
173 /// \brief Whether to validate system input files when a module is loaded.
174 unsigned ModulesValidateSystemHeaders : 1;
176 /// Whether the module includes debug information (-gmodules).
177 unsigned UseDebugInfo : 1;
179 unsigned ModulesValidateDiagnosticOptions : 1;
181 unsigned ModulesHashContent : 1;
183 HeaderSearchOptions(StringRef _Sysroot = "/")
184 : Sysroot(_Sysroot), ModuleFormat("raw"), DisableModuleHash(0),
185 ImplicitModuleMaps(0), ModuleMapFileHomeIsCwd(0),
186 ModuleCachePruneInterval(7 * 24 * 60 * 60),
187 ModuleCachePruneAfter(31 * 24 * 60 * 60), BuildSessionTimestamp(0),
188 UseBuiltinIncludes(true), UseStandardSystemIncludes(true),
189 UseStandardCXXIncludes(true), UseLibcxx(false), Verbose(false),
190 ModulesValidateOncePerBuildSession(false),
191 ModulesValidateSystemHeaders(false), UseDebugInfo(false),
192 ModulesValidateDiagnosticOptions(true), ModulesHashContent(false) {}
194 /// AddPath - Add the \p Path path to the specified \p Group list.
195 void AddPath(StringRef Path, frontend::IncludeDirGroup Group,
196 bool IsFramework, bool IgnoreSysRoot) {
197 UserEntries.emplace_back(Path, Group, IsFramework, IgnoreSysRoot);
200 /// AddSystemHeaderPrefix - Override whether \#include directives naming a
201 /// path starting with \p Prefix should be considered as naming a system
203 void AddSystemHeaderPrefix(StringRef Prefix, bool IsSystemHeader) {
204 SystemHeaderPrefixes.emplace_back(Prefix, IsSystemHeader);
207 void AddVFSOverlayFile(StringRef Name) {
208 VFSOverlayFiles.push_back(Name);
211 void AddPrebuiltModulePath(StringRef Name) {
212 PrebuiltModulePaths.push_back(Name);
216 } // end namespace clang