163c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar//===--- HeaderSearchOptions.h ----------------------------------*- C++ -*-===//
263c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar//
363c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar//                     The LLVM Compiler Infrastructure
463c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar//
563c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar// This file is distributed under the University of Illinois Open Source
663c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar// License. See LICENSE.TXT for details.
763c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar//
863c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar//===----------------------------------------------------------------------===//
963c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar
1063c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar#ifndef LLVM_CLANG_FRONTEND_HEADERSEARCHOPTIONS_H
1163c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar#define LLVM_CLANG_FRONTEND_HEADERSEARCHOPTIONS_H
1263c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar
1363c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar#include "llvm/ADT/StringRef.h"
14a61066310d4544d6343154eb3f4448fec0b15420Douglas Gregor#include <vector>
1563c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar
1663c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbarnamespace clang {
1763c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar
182cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbarnamespace frontend {
192cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar  /// IncludeDirGroup - Identifiers the group a include entry belongs to, which
20809d1be9820039b4cf6efa48246a0d70ffa13394James Dennett  /// represents its relative positive in the search list.  A \#include of a ""
2112ee102774c747874f0a6904089100667153b0c0Chris Lattner  /// path starts at the -iquote group, then searches the Angled group, then
2212ee102774c747874f0a6904089100667153b0c0Chris Lattner  /// searches the system group, etc.
232cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar  enum IncludeDirGroup {
24809d1be9820039b4cf6efa48246a0d70ffa13394James Dennett    Quoted = 0,     ///< '\#include ""' paths, added by 'gcc -iquote'.
25809d1be9820039b4cf6efa48246a0d70ffa13394James Dennett    Angled,         ///< Paths for '\#include <>' added by '-I'.
2665e02fa80e1c185f18e5f81cefc30d75383a7301Douglas Gregor    IndexHeaderMap, ///< Like Angled, but marks header maps used when
2765e02fa80e1c185f18e5f81cefc30d75383a7301Douglas Gregor                       ///  building frameworks.
282cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar    System,         ///< Like Angled, but marks system directories.
2947adebef0df6dce752fe9a45e9190e8005b5d07cBenjamin Kramer    CSystem,        ///< Like System, but only used for C.
302df6647847af283302834dadae5d9dcefa7e0ad4Joerg Sonnenberger    CXXSystem,      ///< Like System, but only used for C++.
3147adebef0df6dce752fe9a45e9190e8005b5d07cBenjamin Kramer    ObjCSystem,     ///< Like System, but only used for ObjC.
3247adebef0df6dce752fe9a45e9190e8005b5d07cBenjamin Kramer    ObjCXXSystem,   ///< Like System, but only used for ObjC++.
332cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar    After           ///< Like System, but searched after the system directories.
342cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar  };
352cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar}
362cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar
3763c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar/// HeaderSearchOptions - Helper class for storing options related to the
3863c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar/// initialization of the HeaderSearch object.
3963c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbarclass HeaderSearchOptions {
4063c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbarpublic:
4163c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar  struct Entry {
4263c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar    std::string Path;
432cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar    frontend::IncludeDirGroup Group;
4463c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar    unsigned IsUserSupplied : 1;
4563c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar    unsigned IsFramework : 1;
4623637beead1fce7dac755890c9482bcdce538b87Chris Lattner
475dd45f13dc4463f0c18b923fe6795ce55103301dBob Wilson    /// IgnoreSysRoot - This is false if an absolute path should be treated
485dd45f13dc4463f0c18b923fe6795ce55103301dBob Wilson    /// relative to the sysroot, or true if it should always be the absolute
4923637beead1fce7dac755890c9482bcdce538b87Chris Lattner    /// path.
505dd45f13dc4463f0c18b923fe6795ce55103301dBob Wilson    unsigned IgnoreSysRoot : 1;
5123637beead1fce7dac755890c9482bcdce538b87Chris Lattner
52ac2bc4d220a6263be96b943e9162f4a11149e26dChandler Carruth    /// \brief True if this entry is an internal search path.
53ac2bc4d220a6263be96b943e9162f4a11149e26dChandler Carruth    ///
54ac2bc4d220a6263be96b943e9162f4a11149e26dChandler Carruth    /// This typically indicates that users didn't directly provide it, but
55ac2bc4d220a6263be96b943e9162f4a11149e26dChandler Carruth    /// instead it was provided by a compatibility layer for a particular
56ac2bc4d220a6263be96b943e9162f4a11149e26dChandler Carruth    /// system. This isn't redundant with IsUserSupplied (even though perhaps
57ac2bc4d220a6263be96b943e9162f4a11149e26dChandler Carruth    /// it should be) because that is false for user provided '-iwithprefix'
58ac2bc4d220a6263be96b943e9162f4a11149e26dChandler Carruth    /// header search entries.
59ac2bc4d220a6263be96b943e9162f4a11149e26dChandler Carruth    unsigned IsInternal : 1;
60ac2bc4d220a6263be96b943e9162f4a11149e26dChandler Carruth
61ac2bc4d220a6263be96b943e9162f4a11149e26dChandler Carruth    /// \brief True if this entry's headers should be wrapped in extern "C".
62ac2bc4d220a6263be96b943e9162f4a11149e26dChandler Carruth    unsigned ImplicitExternC : 1;
63ac2bc4d220a6263be96b943e9162f4a11149e26dChandler Carruth
64686775deca8b8685eb90801495880e3abdd844c2Chris Lattner    Entry(StringRef path, frontend::IncludeDirGroup group,
65ac2bc4d220a6263be96b943e9162f4a11149e26dChandler Carruth          bool isUserSupplied, bool isFramework, bool ignoreSysRoot,
66ac2bc4d220a6263be96b943e9162f4a11149e26dChandler Carruth          bool isInternal, bool implicitExternC)
6723637beead1fce7dac755890c9482bcdce538b87Chris Lattner      : Path(path), Group(group), IsUserSupplied(isUserSupplied),
68ac2bc4d220a6263be96b943e9162f4a11149e26dChandler Carruth        IsFramework(isFramework), IgnoreSysRoot(ignoreSysRoot),
69ac2bc4d220a6263be96b943e9162f4a11149e26dChandler Carruth        IsInternal(isInternal), ImplicitExternC(implicitExternC) {}
7063c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar  };
7163c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar
72f122a138e39dbb29162abfa9a3d44091d8efa7afRichard Smith  struct SystemHeaderPrefix {
732edbc98b046de22f3aba3c5142e85e7f3437fd03James Dennett    /// A prefix to be matched against paths in \#include directives.
74f122a138e39dbb29162abfa9a3d44091d8efa7afRichard Smith    std::string Prefix;
75f122a138e39dbb29162abfa9a3d44091d8efa7afRichard Smith
76f122a138e39dbb29162abfa9a3d44091d8efa7afRichard Smith    /// True if paths beginning with this prefix should be treated as system
77f122a138e39dbb29162abfa9a3d44091d8efa7afRichard Smith    /// headers.
78f122a138e39dbb29162abfa9a3d44091d8efa7afRichard Smith    bool IsSystemHeader;
79f122a138e39dbb29162abfa9a3d44091d8efa7afRichard Smith
80f122a138e39dbb29162abfa9a3d44091d8efa7afRichard Smith    SystemHeaderPrefix(StringRef Prefix, bool IsSystemHeader)
81f122a138e39dbb29162abfa9a3d44091d8efa7afRichard Smith      : Prefix(Prefix), IsSystemHeader(IsSystemHeader) {}
82f122a138e39dbb29162abfa9a3d44091d8efa7afRichard Smith  };
83f122a138e39dbb29162abfa9a3d44091d8efa7afRichard Smith
8463c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar  /// If non-empty, the directory to use as a "virtual system root" for include
8563c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar  /// paths.
8663c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar  std::string Sysroot;
8763c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar
8863c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar  /// User specified include entries.
8963c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar  std::vector<Entry> UserEntries;
9063c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar
91f122a138e39dbb29162abfa9a3d44091d8efa7afRichard Smith  /// User-specified system header prefixes.
92f122a138e39dbb29162abfa9a3d44091d8efa7afRichard Smith  std::vector<SystemHeaderPrefix> SystemHeaderPrefixes;
93f122a138e39dbb29162abfa9a3d44091d8efa7afRichard Smith
948b9adfea5e834eaee0f45d8cc7fb052d68df4a46Daniel Dunbar  /// The directory which holds the compiler resource files (builtin includes,
958b9adfea5e834eaee0f45d8cc7fb052d68df4a46Daniel Dunbar  /// etc.).
968b9adfea5e834eaee0f45d8cc7fb052d68df4a46Daniel Dunbar  std::string ResourceDir;
9763c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar
989a6da6930644b4f2dbe4885b0eb4fc1274ff56a4Douglas Gregor  /// \brief The directory used for the module cache.
999a6da6930644b4f2dbe4885b0eb4fc1274ff56a4Douglas Gregor  std::string ModuleCachePath;
1009a6da6930644b4f2dbe4885b0eb4fc1274ff56a4Douglas Gregor
1016e975c4517958bcc11c834336d340797356058dbDouglas Gregor  /// \brief Whether we should disable the use of the hash string within the
1026e975c4517958bcc11c834336d340797356058dbDouglas Gregor  /// module cache.
1036e975c4517958bcc11c834336d340797356058dbDouglas Gregor  ///
1046e975c4517958bcc11c834336d340797356058dbDouglas Gregor  /// Note: Only used for testing!
1056e975c4517958bcc11c834336d340797356058dbDouglas Gregor  unsigned DisableModuleHash : 1;
1066e975c4517958bcc11c834336d340797356058dbDouglas Gregor
1071e69fe3a9f0a42b32a3000bda51677d51416564eDaniel Dunbar  /// Include the compiler builtin includes.
1081e69fe3a9f0a42b32a3000bda51677d51416564eDaniel Dunbar  unsigned UseBuiltinIncludes : 1;
1091e69fe3a9f0a42b32a3000bda51677d51416564eDaniel Dunbar
11063c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar  /// Include the system standard include search directories.
111a268fc0f2229eb132ebc8501b140093aeb5516bfDaniel Dunbar  unsigned UseStandardSystemIncludes : 1;
11263c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar
1134c2bcad7b843c10fd4a2ffd43da40bfefb4dc8baDouglas Gregor  /// Include the system standard C++ library include search directories.
1144c2bcad7b843c10fd4a2ffd43da40bfefb4dc8baDouglas Gregor  unsigned UseStandardCXXIncludes : 1;
1154c2bcad7b843c10fd4a2ffd43da40bfefb4dc8baDouglas Gregor
11613c4f2144b35bda21746eb60ad90e52a9bd8dcdaBob Wilson  /// Use libc++ instead of the default libstdc++.
11713c4f2144b35bda21746eb60ad90e52a9bd8dcdaBob Wilson  unsigned UseLibcxx : 1;
11813c4f2144b35bda21746eb60ad90e52a9bd8dcdaBob Wilson
11963c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar  /// Whether header search information should be output as for -v.
12063c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar  unsigned Verbose : 1;
12163c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar
12263c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbarpublic:
123686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  HeaderSearchOptions(StringRef _Sysroot = "/")
1246e975c4517958bcc11c834336d340797356058dbDouglas Gregor    : Sysroot(_Sysroot), DisableModuleHash(0), UseBuiltinIncludes(true),
125a268fc0f2229eb132ebc8501b140093aeb5516bfDaniel Dunbar      UseStandardSystemIncludes(true), UseStandardCXXIncludes(true),
126a268fc0f2229eb132ebc8501b140093aeb5516bfDaniel Dunbar      UseLibcxx(false), Verbose(false) {}
12763c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar
12863c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar  /// AddPath - Add the \arg Path path to the specified \arg Group list.
129686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  void AddPath(StringRef Path, frontend::IncludeDirGroup Group,
130ac2bc4d220a6263be96b943e9162f4a11149e26dChandler Carruth               bool IsUserSupplied, bool IsFramework, bool IgnoreSysRoot,
131ac2bc4d220a6263be96b943e9162f4a11149e26dChandler Carruth               bool IsInternal = false, bool ImplicitExternC = false) {
13223637beead1fce7dac755890c9482bcdce538b87Chris Lattner    UserEntries.push_back(Entry(Path, Group, IsUserSupplied, IsFramework,
133ac2bc4d220a6263be96b943e9162f4a11149e26dChandler Carruth                                IgnoreSysRoot, IsInternal, ImplicitExternC));
13463c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar  }
135f122a138e39dbb29162abfa9a3d44091d8efa7afRichard Smith
1362edbc98b046de22f3aba3c5142e85e7f3437fd03James Dennett  /// AddSystemHeaderPrefix - Override whether \#include directives naming a
137f122a138e39dbb29162abfa9a3d44091d8efa7afRichard Smith  /// path starting with \arg Prefix should be considered as naming a system
138f122a138e39dbb29162abfa9a3d44091d8efa7afRichard Smith  /// header.
139f122a138e39dbb29162abfa9a3d44091d8efa7afRichard Smith  void AddSystemHeaderPrefix(StringRef Prefix, bool IsSystemHeader) {
140f122a138e39dbb29162abfa9a3d44091d8efa7afRichard Smith    SystemHeaderPrefixes.push_back(SystemHeaderPrefix(Prefix, IsSystemHeader));
141f122a138e39dbb29162abfa9a3d44091d8efa7afRichard Smith  }
14263c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar};
14363c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar
14463c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar} // end namespace clang
14563c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar
14663c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar#endif
147