HeaderSearchOptions.h revision 527dcd47caa224b673d9af40fa422caf9d2b04fe
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 20namespace clang { 21 22namespace frontend { 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 34 /// extern "C". 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. 40 }; 41} 42 43/// HeaderSearchOptions - Helper class for storing options related to the 44/// initialization of the HeaderSearch object. 45class HeaderSearchOptions : public RefCountedBase<HeaderSearchOptions> { 46public: 47 struct Entry { 48 std::string Path; 49 frontend::IncludeDirGroup Group; 50 unsigned IsFramework : 1; 51 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 54 /// path. 55 unsigned IgnoreSysRoot : 1; 56 57 Entry(StringRef path, frontend::IncludeDirGroup group, bool isFramework, 58 bool ignoreSysRoot) 59 : Path(path), Group(group), IsFramework(isFramework), 60 IgnoreSysRoot(ignoreSysRoot) {} 61 62 Entry(const Entry& rhs) 63 : Path(rhs.Path), Group(rhs.Group), IsFramework(rhs.IsFramework), 64 IgnoreSysRoot(rhs.IgnoreSysRoot) {} 65 66 Entry& operator=(const Entry& rhs) 67 { 68 if (this == &rhs) 69 return *this; 70 Path = rhs.Path; 71 Group = rhs.Group; 72 IsFramework = rhs.IsFramework; 73 IgnoreSysRoot = rhs.IgnoreSysRoot; 74 } 75 }; 76 77 struct SystemHeaderPrefix { 78 /// A prefix to be matched against paths in \#include directives. 79 std::string Prefix; 80 81 /// True if paths beginning with this prefix should be treated as system 82 /// headers. 83 bool IsSystemHeader; 84 85 SystemHeaderPrefix(StringRef Prefix, bool IsSystemHeader) 86 : Prefix(Prefix), IsSystemHeader(IsSystemHeader) {} 87 }; 88 89 /// If non-empty, the directory to use as a "virtual system root" for include 90 /// paths. 91 std::string Sysroot; 92 93 /// User specified include entries. 94 std::vector<Entry> UserEntries; 95 96 /// User-specified system header prefixes. 97 std::vector<SystemHeaderPrefix> SystemHeaderPrefixes; 98 99 /// The directory which holds the compiler resource files (builtin includes, 100 /// etc.). 101 std::string ResourceDir; 102 103 /// \brief The directory used for the module cache. 104 std::string ModuleCachePath; 105 106 /// \brief Whether we should disable the use of the hash string within the 107 /// module cache. 108 /// 109 /// Note: Only used for testing! 110 unsigned DisableModuleHash : 1; 111 112 /// \brief Interpret module maps. This option is implied by full modules. 113 unsigned ModuleMaps : 1; 114 115 /// \brief The interval (in seconds) between pruning operations. 116 /// 117 /// This operation is expensive, because it requires Clang to walk through 118 /// the directory structure of the module cache, stat()'ing and removing 119 /// files. 120 /// 121 /// The default value is large, e.g., the operation runs once a week. 122 unsigned ModuleCachePruneInterval; 123 124 /// \brief The time (in seconds) after which an unused module file will be 125 /// considered unused and will, therefore, be pruned. 126 /// 127 /// When the module cache is pruned, any module file that has not been 128 /// accessed in this many seconds will be removed. The default value is 129 /// large, e.g., a month, to avoid forcing infrequently-used modules to be 130 /// regenerated often. 131 unsigned ModuleCachePruneAfter; 132 133 /// \brief The set of macro names that should be ignored for the purposes 134 /// of computing the module hash. 135 llvm::SetVector<std::string> ModulesIgnoreMacros; 136 137 /// Include the compiler builtin includes. 138 unsigned UseBuiltinIncludes : 1; 139 140 /// Include the system standard include search directories. 141 unsigned UseStandardSystemIncludes : 1; 142 143 /// Include the system standard C++ library include search directories. 144 unsigned UseStandardCXXIncludes : 1; 145 146 /// Use libc++ instead of the default libstdc++. 147 unsigned UseLibcxx : 1; 148 149 /// Whether header search information should be output as for -v. 150 unsigned Verbose : 1; 151 152public: 153 HeaderSearchOptions(StringRef _Sysroot = "/") 154 : Sysroot(_Sysroot), DisableModuleHash(0), ModuleMaps(0), 155 ModuleCachePruneInterval(7*24*60*60), 156 ModuleCachePruneAfter(31*24*60*60), 157 UseBuiltinIncludes(true), 158 UseStandardSystemIncludes(true), UseStandardCXXIncludes(true), 159 UseLibcxx(false), Verbose(false) {} 160 161 /// AddPath - Add the \p Path path to the specified \p Group list. 162 void AddPath(StringRef Path, frontend::IncludeDirGroup Group, 163 bool IsFramework, bool IgnoreSysRoot) { 164 UserEntries.push_back(Entry(Path, Group, IsFramework, IgnoreSysRoot)); 165 } 166 167 /// AddSystemHeaderPrefix - Override whether \#include directives naming a 168 /// path starting with \p Prefix should be considered as naming a system 169 /// header. 170 void AddSystemHeaderPrefix(StringRef Prefix, bool IsSystemHeader) { 171 SystemHeaderPrefixes.push_back(SystemHeaderPrefix(Prefix, IsSystemHeader)); 172 } 173}; 174 175} // end namespace clang 176 177#endif 178