Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:36:56

0001 //===- HeaderSearchOptions.h ------------------------------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLVM_CLANG_LEX_HEADERSEARCHOPTIONS_H
0010 #define LLVM_CLANG_LEX_HEADERSEARCHOPTIONS_H
0011 
0012 #include "clang/Basic/LLVM.h"
0013 #include "llvm/ADT/CachedHashString.h"
0014 #include "llvm/ADT/SetVector.h"
0015 #include "llvm/ADT/StringRef.h"
0016 #include "llvm/Support/HashBuilder.h"
0017 #include <cstdint>
0018 #include <map>
0019 #include <string>
0020 #include <vector>
0021 
0022 namespace clang {
0023 
0024 namespace frontend {
0025 
0026 /// IncludeDirGroup - Identifies the group an include Entry belongs to,
0027 /// representing its relative positive in the search list.
0028 /// \#include directives whose paths are enclosed by string quotes ("")
0029 /// start searching at the Quoted group (specified by '-iquote'),
0030 /// then search the Angled group, then the System group, etc.
0031 enum IncludeDirGroup {
0032   /// '\#include ""' paths, added by 'gcc -iquote'.
0033   Quoted = 0,
0034 
0035   /// Paths for '\#include <>' added by '-I'.
0036   Angled,
0037 
0038   /// Like Angled, but marks system directories.
0039   System,
0040 
0041   /// Like System, but headers are implicitly wrapped in extern "C".
0042   ExternCSystem,
0043 
0044   /// Like System, but only used for C.
0045   CSystem,
0046 
0047   /// Like System, but only used for C++.
0048   CXXSystem,
0049 
0050   /// Like System, but only used for ObjC.
0051   ObjCSystem,
0052 
0053   /// Like System, but only used for ObjC++.
0054   ObjCXXSystem,
0055 
0056   /// Like System, but searched after the system directories.
0057   After
0058 };
0059 
0060 } // namespace frontend
0061 
0062 /// HeaderSearchOptions - Helper class for storing options related to the
0063 /// initialization of the HeaderSearch object.
0064 class HeaderSearchOptions {
0065 public:
0066   struct Entry {
0067     std::string Path;
0068     frontend::IncludeDirGroup Group;
0069     LLVM_PREFERRED_TYPE(bool)
0070     unsigned IsFramework : 1;
0071 
0072     /// IgnoreSysRoot - This is false if an absolute path should be treated
0073     /// relative to the sysroot, or true if it should always be the absolute
0074     /// path.
0075     LLVM_PREFERRED_TYPE(bool)
0076     unsigned IgnoreSysRoot : 1;
0077 
0078     Entry(StringRef path, frontend::IncludeDirGroup group, bool isFramework,
0079           bool ignoreSysRoot)
0080         : Path(path), Group(group), IsFramework(isFramework),
0081           IgnoreSysRoot(ignoreSysRoot) {}
0082   };
0083 
0084   struct SystemHeaderPrefix {
0085     /// A prefix to be matched against paths in \#include directives.
0086     std::string Prefix;
0087 
0088     /// True if paths beginning with this prefix should be treated as system
0089     /// headers.
0090     bool IsSystemHeader;
0091 
0092     SystemHeaderPrefix(StringRef Prefix, bool IsSystemHeader)
0093         : Prefix(Prefix), IsSystemHeader(IsSystemHeader) {}
0094   };
0095 
0096   /// If non-empty, the directory to use as a "virtual system root" for include
0097   /// paths.
0098   std::string Sysroot;
0099 
0100   /// User specified include entries.
0101   std::vector<Entry> UserEntries;
0102 
0103   /// User-specified system header prefixes.
0104   std::vector<SystemHeaderPrefix> SystemHeaderPrefixes;
0105 
0106   /// The directory which holds the compiler resource files (builtin includes,
0107   /// etc.).
0108   std::string ResourceDir;
0109 
0110   /// The directory used for the module cache.
0111   std::string ModuleCachePath;
0112 
0113   /// The directory used for a user build.
0114   std::string ModuleUserBuildPath;
0115 
0116   /// The mapping of module names to prebuilt module files.
0117   std::map<std::string, std::string, std::less<>> PrebuiltModuleFiles;
0118 
0119   /// The directories used to load prebuilt module files.
0120   std::vector<std::string> PrebuiltModulePaths;
0121 
0122   /// The module/pch container format.
0123   std::string ModuleFormat;
0124 
0125   /// Whether we should disable the use of the hash string within the
0126   /// module cache.
0127   ///
0128   /// Note: Only used for testing!
0129   LLVM_PREFERRED_TYPE(bool)
0130   unsigned DisableModuleHash : 1;
0131 
0132   /// Implicit module maps.  This option is enabld by default when
0133   /// modules is enabled.
0134   LLVM_PREFERRED_TYPE(bool)
0135   unsigned ImplicitModuleMaps : 1;
0136 
0137   /// Set the 'home directory' of a module map file to the current
0138   /// working directory (or the home directory of the module map file that
0139   /// contained the 'extern module' directive importing this module map file
0140   /// if any) rather than the directory containing the module map file.
0141   //
0142   /// The home directory is where we look for files named in the module map
0143   /// file.
0144   LLVM_PREFERRED_TYPE(bool)
0145   unsigned ModuleMapFileHomeIsCwd : 1;
0146 
0147   /// Set the base path of a built module file to be the current working
0148   /// directory. This is useful for sharing module files across machines
0149   /// that build with different paths without having to rewrite all
0150   /// modulemap files to have working directory relative paths.
0151   LLVM_PREFERRED_TYPE(bool)
0152   unsigned ModuleFileHomeIsCwd : 1;
0153 
0154   /// Also search for prebuilt implicit modules in the prebuilt module cache
0155   /// path.
0156   LLVM_PREFERRED_TYPE(bool)
0157   unsigned EnablePrebuiltImplicitModules : 1;
0158 
0159   /// The interval (in seconds) between pruning operations.
0160   ///
0161   /// This operation is expensive, because it requires Clang to walk through
0162   /// the directory structure of the module cache, stat()'ing and removing
0163   /// files.
0164   ///
0165   /// The default value is large, e.g., the operation runs once a week.
0166   unsigned ModuleCachePruneInterval = 7 * 24 * 60 * 60;
0167 
0168   /// The time (in seconds) after which an unused module file will be
0169   /// considered unused and will, therefore, be pruned.
0170   ///
0171   /// When the module cache is pruned, any module file that has not been
0172   /// accessed in this many seconds will be removed. The default value is
0173   /// large, e.g., a month, to avoid forcing infrequently-used modules to be
0174   /// regenerated often.
0175   unsigned ModuleCachePruneAfter = 31 * 24 * 60 * 60;
0176 
0177   /// The time in seconds when the build session started.
0178   ///
0179   /// This time is used by other optimizations in header search and module
0180   /// loading.
0181   uint64_t BuildSessionTimestamp = 0;
0182 
0183   /// The set of macro names that should be ignored for the purposes
0184   /// of computing the module hash.
0185   llvm::SmallSetVector<llvm::CachedHashString, 16> ModulesIgnoreMacros;
0186 
0187   /// The set of user-provided virtual filesystem overlay files.
0188   std::vector<std::string> VFSOverlayFiles;
0189 
0190   /// Include the compiler builtin includes.
0191   LLVM_PREFERRED_TYPE(bool)
0192   unsigned UseBuiltinIncludes : 1;
0193 
0194   /// Include the system standard include search directories.
0195   LLVM_PREFERRED_TYPE(bool)
0196   unsigned UseStandardSystemIncludes : 1;
0197 
0198   /// Include the system standard C++ library include search directories.
0199   LLVM_PREFERRED_TYPE(bool)
0200   unsigned UseStandardCXXIncludes : 1;
0201 
0202   /// Use libc++ instead of the default libstdc++.
0203   LLVM_PREFERRED_TYPE(bool)
0204   unsigned UseLibcxx : 1;
0205 
0206   /// Whether header search information should be output as for -v.
0207   LLVM_PREFERRED_TYPE(bool)
0208   unsigned Verbose : 1;
0209 
0210   /// If true, skip verifying input files used by modules if the
0211   /// module was already verified during this build session (see
0212   /// \c BuildSessionTimestamp).
0213   LLVM_PREFERRED_TYPE(bool)
0214   unsigned ModulesValidateOncePerBuildSession : 1;
0215 
0216   /// Whether to validate system input files when a module is loaded.
0217   LLVM_PREFERRED_TYPE(bool)
0218   unsigned ModulesValidateSystemHeaders : 1;
0219 
0220   // Whether the content of input files should be hashed and used to
0221   // validate consistency.
0222   LLVM_PREFERRED_TYPE(bool)
0223   unsigned ValidateASTInputFilesContent : 1;
0224 
0225   // Whether the input files from C++20 Modules should be checked.
0226   LLVM_PREFERRED_TYPE(bool)
0227   unsigned ForceCheckCXX20ModulesInputFiles : 1;
0228 
0229   /// Whether the module includes debug information (-gmodules).
0230   LLVM_PREFERRED_TYPE(bool)
0231   unsigned UseDebugInfo : 1;
0232 
0233   LLVM_PREFERRED_TYPE(bool)
0234   unsigned ModulesValidateDiagnosticOptions : 1;
0235 
0236   /// Whether to entirely skip writing diagnostic options.
0237   /// Primarily used to speed up deserialization during dependency scanning.
0238   LLVM_PREFERRED_TYPE(bool)
0239   unsigned ModulesSkipDiagnosticOptions : 1;
0240 
0241   /// Whether to entirely skip writing header search paths.
0242   /// Primarily used to speed up deserialization during dependency scanning.
0243   LLVM_PREFERRED_TYPE(bool)
0244   unsigned ModulesSkipHeaderSearchPaths : 1;
0245 
0246   /// Whether to entirely skip writing pragma diagnostic mappings.
0247   /// Primarily used to speed up deserialization during dependency scanning.
0248   LLVM_PREFERRED_TYPE(bool)
0249   unsigned ModulesSkipPragmaDiagnosticMappings : 1;
0250 
0251   /// Whether to prune non-affecting module map files from PCM files.
0252   LLVM_PREFERRED_TYPE(bool)
0253   unsigned ModulesPruneNonAffectingModuleMaps : 1;
0254 
0255   LLVM_PREFERRED_TYPE(bool)
0256   unsigned ModulesHashContent : 1;
0257 
0258   /// Whether AST files should only contain the preprocessor information.
0259   LLVM_PREFERRED_TYPE(bool)
0260   unsigned ModulesSerializeOnlyPreprocessor : 1;
0261 
0262   /// Whether we should include all things that could impact the module in the
0263   /// hash.
0264   ///
0265   /// This includes things like the full header search path, and enabled
0266   /// diagnostics.
0267   LLVM_PREFERRED_TYPE(bool)
0268   unsigned ModulesStrictContextHash : 1;
0269 
0270   /// Whether to include ivfsoverlay usage information in written AST files.
0271   LLVM_PREFERRED_TYPE(bool)
0272   unsigned ModulesIncludeVFSUsage : 1;
0273 
0274   /// Whether we should look for a module in module maps only in provided
0275   /// header search paths or if we are allowed to look for module maps in
0276   /// subdirectories of provided paths too.
0277   LLVM_PREFERRED_TYPE(bool)
0278   unsigned AllowModuleMapSubdirectorySearch : 1;
0279 
0280   HeaderSearchOptions(StringRef _Sysroot = "/")
0281       : Sysroot(_Sysroot), ModuleFormat("raw"), DisableModuleHash(false),
0282         ImplicitModuleMaps(false), ModuleMapFileHomeIsCwd(false),
0283         ModuleFileHomeIsCwd(false), EnablePrebuiltImplicitModules(false),
0284         UseBuiltinIncludes(true), UseStandardSystemIncludes(true),
0285         UseStandardCXXIncludes(true), UseLibcxx(false), Verbose(false),
0286         ModulesValidateOncePerBuildSession(false),
0287         ModulesValidateSystemHeaders(false),
0288         ValidateASTInputFilesContent(false),
0289         ForceCheckCXX20ModulesInputFiles(false), UseDebugInfo(false),
0290         ModulesValidateDiagnosticOptions(true),
0291         ModulesSkipDiagnosticOptions(false),
0292         ModulesSkipHeaderSearchPaths(false),
0293         ModulesSkipPragmaDiagnosticMappings(false),
0294         ModulesPruneNonAffectingModuleMaps(true), ModulesHashContent(false),
0295         ModulesSerializeOnlyPreprocessor(false),
0296         ModulesStrictContextHash(false), ModulesIncludeVFSUsage(false),
0297         AllowModuleMapSubdirectorySearch(true) {}
0298 
0299   /// AddPath - Add the \p Path path to the specified \p Group list.
0300   void AddPath(StringRef Path, frontend::IncludeDirGroup Group,
0301                bool IsFramework, bool IgnoreSysRoot) {
0302     UserEntries.emplace_back(Path, Group, IsFramework, IgnoreSysRoot);
0303   }
0304 
0305   /// AddSystemHeaderPrefix - Override whether \#include directives naming a
0306   /// path starting with \p Prefix should be considered as naming a system
0307   /// header.
0308   void AddSystemHeaderPrefix(StringRef Prefix, bool IsSystemHeader) {
0309     SystemHeaderPrefixes.emplace_back(Prefix, IsSystemHeader);
0310   }
0311 
0312   void AddVFSOverlayFile(StringRef Name) {
0313     VFSOverlayFiles.push_back(std::string(Name));
0314   }
0315 
0316   void AddPrebuiltModulePath(StringRef Name) {
0317     PrebuiltModulePaths.push_back(std::string(Name));
0318   }
0319 };
0320 
0321 template <typename HasherT, llvm::endianness Endianness>
0322 inline void addHash(llvm::HashBuilder<HasherT, Endianness> &HBuilder,
0323                     const HeaderSearchOptions::Entry &E) {
0324   HBuilder.add(E.Path, E.Group, E.IsFramework, E.IgnoreSysRoot);
0325 }
0326 
0327 template <typename HasherT, llvm::endianness Endianness>
0328 inline void addHash(llvm::HashBuilder<HasherT, Endianness> &HBuilder,
0329                     const HeaderSearchOptions::SystemHeaderPrefix &SHP) {
0330   HBuilder.add(SHP.Prefix, SHP.IsSystemHeader);
0331 }
0332 
0333 } // namespace clang
0334 
0335 #endif // LLVM_CLANG_LEX_HEADERSEARCHOPTIONS_H