HeaderSearchOptions.h revision d44d2872b2ebe58237de4dbc350b82cab944ccc5
1cf2cfa174ca878c144e17e9fc60ca8e9070d7dededisonn@google.com//===--- HeaderSearchOptions.h ----------------------------------*- C++ -*-===//
2cf2cfa174ca878c144e17e9fc60ca8e9070d7dededisonn@google.com//
38cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com//                     The LLVM Compiler Infrastructure
4cf2cfa174ca878c144e17e9fc60ca8e9070d7dededisonn@google.com//
5cf2cfa174ca878c144e17e9fc60ca8e9070d7dededisonn@google.com// This file is distributed under the University of Illinois Open Source
6cf2cfa174ca878c144e17e9fc60ca8e9070d7dededisonn@google.com// License. See LICENSE.TXT for details.
78cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com//
8cf2cfa174ca878c144e17e9fc60ca8e9070d7dededisonn@google.com//===----------------------------------------------------------------------===//
98cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com
10cf2cfa174ca878c144e17e9fc60ca8e9070d7dededisonn@google.com#ifndef LLVM_CLANG_LEX_HEADERSEARCHOPTIONS_H
118cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com#define LLVM_CLANG_LEX_HEADERSEARCHOPTIONS_H
128cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com
138cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com#include "clang/Basic/LLVM.h"
148cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com#include "llvm/ADT/IntrusiveRefCntPtr.h"
158cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com#include "llvm/ADT/SetVector.h"
168cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com#include "llvm/ADT/StringRef.h"
178cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com#include <string>
188cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com#include <vector>
198cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com
208cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.comnamespace clang {
218cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com
228cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.comnamespace frontend {
238cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  /// IncludeDirGroup - Identifiers the group a include entry belongs to, which
248cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  /// represents its relative positive in the search list.  A \#include of a ""
258cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  /// path starts at the -iquote group, then searches the Angled group, then
268cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  /// searches the system group, etc.
278cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  enum IncludeDirGroup {
288cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com    Quoted = 0,     ///< '\#include ""' paths, added by 'gcc -iquote'.
298cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com    Angled,         ///< Paths for '\#include <>' added by '-I'.
308cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com    IndexHeaderMap, ///< Like Angled, but marks header maps used when
318cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com                       ///  building frameworks.
328cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com    System,         ///< Like Angled, but marks system directories.
338cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com    ExternCSystem,  ///< Like System, but headers are implicitly wrapped in
348cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com                    ///  extern "C".
358cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com    CSystem,        ///< Like System, but only used for C.
368cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com    CXXSystem,      ///< Like System, but only used for C++.
378cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com    ObjCSystem,     ///< Like System, but only used for ObjC.
388cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com    ObjCXXSystem,   ///< Like System, but only used for ObjC++.
398cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com    After           ///< Like System, but searched after the system directories.
408cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  };
418cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com}
428cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com
438cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com/// HeaderSearchOptions - Helper class for storing options related to the
448cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com/// initialization of the HeaderSearch object.
458cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.comclass HeaderSearchOptions : public RefCountedBase<HeaderSearchOptions> {
468cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.compublic:
478cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com  struct Entry {
488cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com    std::string Path;
498cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com    frontend::IncludeDirGroup Group;
508cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com    unsigned IsFramework : 1;
518cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com
528cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com    /// IgnoreSysRoot - This is false if an absolute path should be treated
538cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com    /// relative to the sysroot, or true if it should always be the absolute
548cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com    /// path.
558cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com    unsigned IgnoreSysRoot : 1;
568cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com
578cee797901763ab0922eb9ef484cfdcbc94bee54edisonn@google.com    Entry(StringRef path, frontend::IncludeDirGroup group, bool isFramework,
58          bool ignoreSysRoot)
59      : Path(path), Group(group), IsFramework(isFramework),
60        IgnoreSysRoot(ignoreSysRoot) {}
61  };
62
63  struct SystemHeaderPrefix {
64    /// A prefix to be matched against paths in \#include directives.
65    std::string Prefix;
66
67    /// True if paths beginning with this prefix should be treated as system
68    /// headers.
69    bool IsSystemHeader;
70
71    SystemHeaderPrefix(StringRef Prefix, bool IsSystemHeader)
72      : Prefix(Prefix), IsSystemHeader(IsSystemHeader) {}
73  };
74
75  /// If non-empty, the directory to use as a "virtual system root" for include
76  /// paths.
77  std::string Sysroot;
78
79  /// User specified include entries.
80  std::vector<Entry> UserEntries;
81
82  /// User-specified system header prefixes.
83  std::vector<SystemHeaderPrefix> SystemHeaderPrefixes;
84
85  /// The directory which holds the compiler resource files (builtin includes,
86  /// etc.).
87  std::string ResourceDir;
88
89  /// \brief The directory used for the module cache.
90  std::string ModuleCachePath;
91
92  /// \brief Whether we should disable the use of the hash string within the
93  /// module cache.
94  ///
95  /// Note: Only used for testing!
96  unsigned DisableModuleHash : 1;
97
98  /// \brief The interval (in seconds) between pruning operations.
99  ///
100  /// This operation is expensive, because it requires Clang to walk through
101  /// the directory structure of the module cache, stat()'ing and removing
102  /// files.
103  ///
104  /// The default value is large, e.g., the operation runs once a week.
105  unsigned ModuleCachePruneInterval;
106
107  /// \brief The time (in seconds) after which an unused module file will be
108  /// considered unused and will, therefore, be pruned.
109  ///
110  /// When the module cache is pruned, any module file that has not been
111  /// accessed in this many seconds will be removed. The default value is
112  /// large, e.g., a month, to avoid forcing infrequently-used modules to be
113  /// regenerated often.
114  unsigned ModuleCachePruneAfter;
115
116  /// \brief The set of macro names that should be ignored for the purposes
117  /// of computing the module hash.
118  llvm::SetVector<std::string> ModulesIgnoreMacros;
119
120  /// Include the compiler builtin includes.
121  unsigned UseBuiltinIncludes : 1;
122
123  /// Include the system standard include search directories.
124  unsigned UseStandardSystemIncludes : 1;
125
126  /// Include the system standard C++ library include search directories.
127  unsigned UseStandardCXXIncludes : 1;
128
129  /// Use libc++ instead of the default libstdc++.
130  unsigned UseLibcxx : 1;
131
132  /// Whether header search information should be output as for -v.
133  unsigned Verbose : 1;
134
135public:
136  HeaderSearchOptions(StringRef _Sysroot = "/")
137    : Sysroot(_Sysroot), DisableModuleHash(0),
138      ModuleCachePruneInterval(7*24*60*60),
139      ModuleCachePruneAfter(31*24*60*60),
140      UseBuiltinIncludes(true),
141      UseStandardSystemIncludes(true), UseStandardCXXIncludes(true),
142      UseLibcxx(false), Verbose(false) {}
143
144  /// AddPath - Add the \p Path path to the specified \p Group list.
145  void AddPath(StringRef Path, frontend::IncludeDirGroup Group,
146               bool IsFramework, bool IgnoreSysRoot) {
147    UserEntries.push_back(Entry(Path, Group, IsFramework, IgnoreSysRoot));
148  }
149
150  /// AddSystemHeaderPrefix - Override whether \#include directives naming a
151  /// path starting with \p Prefix should be considered as naming a system
152  /// header.
153  void AddSystemHeaderPrefix(StringRef Prefix, bool IsSystemHeader) {
154    SystemHeaderPrefixes.push_back(SystemHeaderPrefix(Prefix, IsSystemHeader));
155  }
156};
157
158} // end namespace clang
159
160#endif
161