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