clang  10.0.0svn
HeaderSearchOptions.h
Go to the documentation of this file.
1 //===- HeaderSearchOptions.h ------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLVM_CLANG_LEX_HEADERSEARCHOPTIONS_H
10 #define LLVM_CLANG_LEX_HEADERSEARCHOPTIONS_H
11 
12 #include "clang/Basic/LLVM.h"
13 #include "llvm/ADT/CachedHashString.h"
14 #include "llvm/ADT/SetVector.h"
15 #include "llvm/ADT/StringRef.h"
16 #include <cstdint>
17 #include <string>
18 #include <vector>
19 #include <map>
20 
21 namespace clang {
22 
23 namespace frontend {
24 
25 /// IncludeDirGroup - Identifies the group an include Entry belongs to,
26 /// representing its relative positive in the search list.
27 /// \#include directives whose paths are enclosed by string quotes ("")
28 /// start searching at the Quoted group (specified by '-iquote'),
29 /// then search the Angled group, then the System group, etc.
31  /// '\#include ""' paths, added by 'gcc -iquote'.
32  Quoted = 0,
33 
34  /// Paths for '\#include <>' added by '-I'.
36 
37  /// Like Angled, but marks header maps used when building frameworks.
39 
40  /// Like Angled, but marks system directories.
42 
43  /// Like System, but headers are implicitly wrapped in extern "C".
45 
46  /// Like System, but only used for C.
48 
49  /// Like System, but only used for C++.
51 
52  /// Like System, but only used for ObjC.
54 
55  /// Like System, but only used for ObjC++.
57 
58  /// Like System, but searched after the system directories.
60 };
61 
62 } // namespace frontend
63 
64 /// HeaderSearchOptions - Helper class for storing options related to the
65 /// initialization of the HeaderSearch object.
67 public:
68  struct Entry {
69  std::string Path;
71  unsigned IsFramework : 1;
72 
73  /// IgnoreSysRoot - This is false if an absolute path should be treated
74  /// relative to the sysroot, or true if it should always be the absolute
75  /// path.
76  unsigned IgnoreSysRoot : 1;
77 
78  Entry(StringRef path, frontend::IncludeDirGroup group, bool isFramework,
79  bool ignoreSysRoot)
80  : Path(path), Group(group), IsFramework(isFramework),
81  IgnoreSysRoot(ignoreSysRoot) {}
82  };
83 
85  /// A prefix to be matched against paths in \#include directives.
86  std::string Prefix;
87 
88  /// True if paths beginning with this prefix should be treated as system
89  /// headers.
91 
92  SystemHeaderPrefix(StringRef Prefix, bool IsSystemHeader)
93  : Prefix(Prefix), IsSystemHeader(IsSystemHeader) {}
94  };
95 
96  /// If non-empty, the directory to use as a "virtual system root" for include
97  /// paths.
98  std::string Sysroot;
99 
100  /// User specified include entries.
101  std::vector<Entry> UserEntries;
102 
103  /// User-specified system header prefixes.
104  std::vector<SystemHeaderPrefix> SystemHeaderPrefixes;
105 
106  /// The directory which holds the compiler resource files (builtin includes,
107  /// etc.).
108  std::string ResourceDir;
109 
110  /// The directory used for the module cache.
111  std::string ModuleCachePath;
112 
113  /// The directory used for a user build.
114  std::string ModuleUserBuildPath;
115 
116  /// The mapping of module names to prebuilt module files.
117  std::map<std::string, std::string> PrebuiltModuleFiles;
118 
119  /// The directories used to load prebuilt module files.
120  std::vector<std::string> PrebuiltModulePaths;
121 
122  /// The module/pch container format.
123  std::string ModuleFormat;
124 
125  /// Whether we should disable the use of the hash string within the
126  /// module cache.
127  ///
128  /// Note: Only used for testing!
129  unsigned DisableModuleHash : 1;
130 
131  /// Implicit module maps. This option is enabld by default when
132  /// modules is enabled.
133  unsigned ImplicitModuleMaps : 1;
134 
135  /// Set the 'home directory' of a module map file to the current
136  /// working directory (or the home directory of the module map file that
137  /// contained the 'extern module' directive importing this module map file
138  /// if any) rather than the directory containing the module map file.
139  //
140  /// The home directory is where we look for files named in the module map
141  /// file.
143 
144  /// The interval (in seconds) between pruning operations.
145  ///
146  /// This operation is expensive, because it requires Clang to walk through
147  /// the directory structure of the module cache, stat()'ing and removing
148  /// files.
149  ///
150  /// The default value is large, e.g., the operation runs once a week.
151  unsigned ModuleCachePruneInterval = 7 * 24 * 60 * 60;
152 
153  /// The time (in seconds) after which an unused module file will be
154  /// considered unused and will, therefore, be pruned.
155  ///
156  /// When the module cache is pruned, any module file that has not been
157  /// accessed in this many seconds will be removed. The default value is
158  /// large, e.g., a month, to avoid forcing infrequently-used modules to be
159  /// regenerated often.
160  unsigned ModuleCachePruneAfter = 31 * 24 * 60 * 60;
161 
162  /// The time in seconds when the build session started.
163  ///
164  /// This time is used by other optimizations in header search and module
165  /// loading.
166  uint64_t BuildSessionTimestamp = 0;
167 
168  /// The set of macro names that should be ignored for the purposes
169  /// of computing the module hash.
171 
172  /// The set of user-provided virtual filesystem overlay files.
173  std::vector<std::string> VFSOverlayFiles;
174 
175  /// Include the compiler builtin includes.
176  unsigned UseBuiltinIncludes : 1;
177 
178  /// Include the system standard include search directories.
180 
181  /// Include the system standard C++ library include search directories.
183 
184  /// Use libc++ instead of the default libstdc++.
185  unsigned UseLibcxx : 1;
186 
187  /// Whether header search information should be output as for -v.
188  unsigned Verbose : 1;
189 
190  /// If true, skip verifying input files used by modules if the
191  /// module was already verified during this build session (see
192  /// \c BuildSessionTimestamp).
194 
195  /// Whether to validate system input files when a module is loaded.
197 
198  /// Whether the module includes debug information (-gmodules).
199  unsigned UseDebugInfo : 1;
200 
202 
203  unsigned ModulesHashContent : 1;
204 
205  HeaderSearchOptions(StringRef _Sysroot = "/")
206  : Sysroot(_Sysroot), ModuleFormat("raw"), DisableModuleHash(false),
207  ImplicitModuleMaps(false), ModuleMapFileHomeIsCwd(false),
208  UseBuiltinIncludes(true), UseStandardSystemIncludes(true),
209  UseStandardCXXIncludes(true), UseLibcxx(false), Verbose(false),
210  ModulesValidateOncePerBuildSession(false),
211  ModulesValidateSystemHeaders(false), UseDebugInfo(false),
212  ModulesValidateDiagnosticOptions(true), ModulesHashContent(false) {}
213 
214  /// AddPath - Add the \p Path path to the specified \p Group list.
215  void AddPath(StringRef Path, frontend::IncludeDirGroup Group,
216  bool IsFramework, bool IgnoreSysRoot) {
217  UserEntries.emplace_back(Path, Group, IsFramework, IgnoreSysRoot);
218  }
219 
220  /// AddSystemHeaderPrefix - Override whether \#include directives naming a
221  /// path starting with \p Prefix should be considered as naming a system
222  /// header.
223  void AddSystemHeaderPrefix(StringRef Prefix, bool IsSystemHeader) {
224  SystemHeaderPrefixes.emplace_back(Prefix, IsSystemHeader);
225  }
226 
227  void AddVFSOverlayFile(StringRef Name) {
228  VFSOverlayFiles.push_back(Name);
229  }
230 
231  void AddPrebuiltModulePath(StringRef Name) {
232  PrebuiltModulePaths.push_back(Name);
233  }
234 };
235 
236 } // namespace clang
237 
238 #endif // LLVM_CLANG_LEX_HEADERSEARCHOPTIONS_H
Paths for &#39;#include <>&#39; added by &#39;-I&#39;.
std::vector< std::string > PrebuiltModulePaths
The directories used to load prebuilt module files.
unsigned UseLibcxx
Use libc++ instead of the default libstdc++.
unsigned ImplicitModuleMaps
Implicit module maps.
std::string ModuleUserBuildPath
The directory used for a user build.
Like System, but headers are implicitly wrapped in extern "C".
Like System, but only used for C++.
Like System, but only used for ObjC++.
llvm::SmallSetVector< llvm::CachedHashString, 16 > ModulesIgnoreMacros
The set of macro names that should be ignored for the purposes of computing the module hash...
void AddPath(StringRef Path, frontend::IncludeDirGroup Group, bool IsFramework, bool IgnoreSysRoot)
AddPath - Add the Path path to the specified Group list.
Like System, but searched after the system directories.
std::string ModuleCachePath
The directory used for the module cache.
bool IsSystemHeader
True if paths beginning with this prefix should be treated as system headers.
void AddSystemHeaderPrefix(StringRef Prefix, bool IsSystemHeader)
AddSystemHeaderPrefix - Override whether #include directives naming a path starting with Prefix shoul...
std::vector< Entry > UserEntries
User specified include entries.
std::vector< SystemHeaderPrefix > SystemHeaderPrefixes
User-specified system header prefixes.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
std::vector< std::string > VFSOverlayFiles
The set of user-provided virtual filesystem overlay files.
std::string ResourceDir
The directory which holds the compiler resource files (builtin includes, etc.).
unsigned DisableModuleHash
Whether we should disable the use of the hash string within the module cache.
void AddVFSOverlayFile(StringRef Name)
unsigned IgnoreSysRoot
IgnoreSysRoot - This is false if an absolute path should be treated relative to the sysroot...
IncludeDirGroup
IncludeDirGroup - Identifies the group an include Entry belongs to, representing its relative positiv...
void AddPrebuiltModulePath(StringRef Name)
unsigned UseBuiltinIncludes
Include the compiler builtin includes.
unsigned ModulesValidateOncePerBuildSession
If true, skip verifying input files used by modules if the module was already verified during this bu...
#define false
Definition: stdbool.h:17
unsigned UseStandardSystemIncludes
Include the system standard include search directories.
SystemHeaderPrefix(StringRef Prefix, bool IsSystemHeader)
unsigned ModulesValidateSystemHeaders
Whether to validate system input files when a module is loaded.
HeaderSearchOptions(StringRef _Sysroot="/")
unsigned Verbose
Whether header search information should be output as for -v.
frontend::IncludeDirGroup Group
Like System, but only used for ObjC.
std::string Prefix
A prefix to be matched against paths in #include directives.
&#39;#include ""&#39; paths, added by &#39;gcc -iquote&#39;.
Like Angled, but marks system directories.
unsigned UseDebugInfo
Whether the module includes debug information (-gmodules).
Dataflow Directional Tag Classes.
Like System, but only used for C.
HeaderSearchOptions - Helper class for storing options related to the initialization of the HeaderSea...
unsigned ModuleMapFileHomeIsCwd
Set the &#39;home directory&#39; of a module map file to the current working directory (or the home directory...
Like Angled, but marks header maps used when building frameworks.
std::string Sysroot
If non-empty, the directory to use as a "virtual system root" for include paths.
#define true
Definition: stdbool.h:16
unsigned UseStandardCXXIncludes
Include the system standard C++ library include search directories.
std::map< std::string, std::string > PrebuiltModuleFiles
The mapping of module names to prebuilt module files.
Entry(StringRef path, frontend::IncludeDirGroup group, bool isFramework, bool ignoreSysRoot)
std::string ModuleFormat
The module/pch container format.