1 //===--- HeaderSearchOptions.h ----------------------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #ifndef LLVM_CLANG_LEX_HEADERSEARCHOPTIONS_H 11 #define LLVM_CLANG_LEX_HEADERSEARCHOPTIONS_H 12 13 #include "clang/Basic/LLVM.h" 14 #include "llvm/ADT/IntrusiveRefCntPtr.h" 15 #include "llvm/ADT/SetVector.h" 16 #include "llvm/ADT/StringRef.h" 17 #include <string> 18 #include <vector> 19 20 namespace clang { 21 22 namespace frontend { 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 35 /// extern "C". 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. 41 }; 42 } 43 44 /// HeaderSearchOptions - Helper class for storing options related to the 45 /// initialization of the HeaderSearch object. 46 class HeaderSearchOptions : public RefCountedBase<HeaderSearchOptions> { 47 public: 48 struct Entry { 49 std::string Path; 50 frontend::IncludeDirGroup Group; 51 unsigned IsFramework : 1; 52 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 55 /// path. 56 unsigned IgnoreSysRoot : 1; 57 EntryEntry58 Entry(StringRef path, frontend::IncludeDirGroup group, bool isFramework, 59 bool ignoreSysRoot) 60 : Path(path), Group(group), IsFramework(isFramework), 61 IgnoreSysRoot(ignoreSysRoot) {} 62 }; 63 64 struct SystemHeaderPrefix { 65 /// A prefix to be matched against paths in \#include directives. 66 std::string Prefix; 67 68 /// True if paths beginning with this prefix should be treated as system 69 /// headers. 70 bool IsSystemHeader; 71 SystemHeaderPrefixSystemHeaderPrefix72 SystemHeaderPrefix(StringRef Prefix, bool IsSystemHeader) 73 : Prefix(Prefix), IsSystemHeader(IsSystemHeader) {} 74 }; 75 76 /// If non-empty, the directory to use as a "virtual system root" for include 77 /// paths. 78 std::string Sysroot; 79 80 /// User specified include entries. 81 std::vector<Entry> UserEntries; 82 83 /// User-specified system header prefixes. 84 std::vector<SystemHeaderPrefix> SystemHeaderPrefixes; 85 86 /// The directory which holds the compiler resource files (builtin includes, 87 /// etc.). 88 std::string ResourceDir; 89 90 /// \brief The directory used for the module cache. 91 std::string ModuleCachePath; 92 93 /// \brief The directory used for a user build. 94 std::string ModuleUserBuildPath; 95 96 /// The module/pch container format. 97 std::string ModuleFormat; 98 99 /// \brief Whether we should disable the use of the hash string within the 100 /// module cache. 101 /// 102 /// Note: Only used for testing! 103 unsigned DisableModuleHash : 1; 104 105 /// \brief Implicit module maps. This option is enabld by default when 106 /// modules is enabled. 107 unsigned ImplicitModuleMaps : 1; 108 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. 113 // 114 /// The home directory is where we look for files named in the module map 115 /// file. 116 unsigned ModuleMapFileHomeIsCwd : 1; 117 118 /// \brief The interval (in seconds) between pruning operations. 119 /// 120 /// This operation is expensive, because it requires Clang to walk through 121 /// the directory structure of the module cache, stat()'ing and removing 122 /// files. 123 /// 124 /// The default value is large, e.g., the operation runs once a week. 125 unsigned ModuleCachePruneInterval; 126 127 /// \brief The time (in seconds) after which an unused module file will be 128 /// considered unused and will, therefore, be pruned. 129 /// 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; 135 136 /// \brief The time in seconds when the build session started. 137 /// 138 /// This time is used by other optimizations in header search and module 139 /// loading. 140 uint64_t BuildSessionTimestamp; 141 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; 145 146 /// \brief The set of user-provided virtual filesystem overlay files. 147 std::vector<std::string> VFSOverlayFiles; 148 149 /// Include the compiler builtin includes. 150 unsigned UseBuiltinIncludes : 1; 151 152 /// Include the system standard include search directories. 153 unsigned UseStandardSystemIncludes : 1; 154 155 /// Include the system standard C++ library include search directories. 156 unsigned UseStandardCXXIncludes : 1; 157 158 /// Use libc++ instead of the default libstdc++. 159 unsigned UseLibcxx : 1; 160 161 /// Whether header search information should be output as for -v. 162 unsigned Verbose : 1; 163 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; 168 169 /// \brief Whether to validate system input files when a module is loaded. 170 unsigned ModulesValidateSystemHeaders : 1; 171 172 /// Whether the module includes debug information (-gmodules). 173 unsigned UseDebugInfo : 1; 174 175 HeaderSearchOptions(StringRef _Sysroot = "/") Sysroot(_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) {} 185 186 /// AddPath - Add the \p Path path to the specified \p Group list. AddPath(StringRef Path,frontend::IncludeDirGroup Group,bool IsFramework,bool IgnoreSysRoot)187 void AddPath(StringRef Path, frontend::IncludeDirGroup Group, 188 bool IsFramework, bool IgnoreSysRoot) { 189 UserEntries.emplace_back(Path, Group, IsFramework, IgnoreSysRoot); 190 } 191 192 /// AddSystemHeaderPrefix - Override whether \#include directives naming a 193 /// path starting with \p Prefix should be considered as naming a system 194 /// header. AddSystemHeaderPrefix(StringRef Prefix,bool IsSystemHeader)195 void AddSystemHeaderPrefix(StringRef Prefix, bool IsSystemHeader) { 196 SystemHeaderPrefixes.emplace_back(Prefix, IsSystemHeader); 197 } 198 AddVFSOverlayFile(StringRef Name)199 void AddVFSOverlayFile(StringRef Name) { 200 VFSOverlayFiles.push_back(Name); 201 } 202 }; 203 204 } // end namespace clang 205 206 #endif 207