HeaderSearchOptions.h revision 2a06085281d1b6aee628f85e8676eec04542cbc9
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
10c042edd54face617a3b9d0b4b9d5a3ff229d0f48Douglas Gregor#ifndef LLVM_CLANG_LEX_HEADERSEARCHOPTIONS_H
11c042edd54face617a3b9d0b4b9d5a3ff229d0f48Douglas Gregor#define LLVM_CLANG_LEX_HEADERSEARCHOPTIONS_H
1263c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar
139946fc735d7285f2195f89635370f534afd9877eDmitri Gribenko#include "clang/Basic/LLVM.h"
14c042edd54face617a3b9d0b4b9d5a3ff229d0f48Douglas Gregor#include "llvm/ADT/IntrusiveRefCntPtr.h"
152a06085281d1b6aee628f85e8676eec04542cbc9Douglas Gregor#include "llvm/ADT/SetVector.h"
1663c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar#include "llvm/ADT/StringRef.h"
172a06085281d1b6aee628f85e8676eec04542cbc9Douglas Gregor#include <string>
18a61066310d4544d6343154eb3f4448fec0b15420Douglas Gregor#include <vector>
1963c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar
2063c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbarnamespace clang {
2163c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar
222cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbarnamespace frontend {
232cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar  /// IncludeDirGroup - Identifiers the group a include entry belongs to, which
24809d1be9820039b4cf6efa48246a0d70ffa13394James Dennett  /// represents its relative positive in the search list.  A \#include of a ""
2512ee102774c747874f0a6904089100667153b0c0Chris Lattner  /// path starts at the -iquote group, then searches the Angled group, then
2612ee102774c747874f0a6904089100667153b0c0Chris Lattner  /// searches the system group, etc.
272cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar  enum IncludeDirGroup {
28809d1be9820039b4cf6efa48246a0d70ffa13394James Dennett    Quoted = 0,     ///< '\#include ""' paths, added by 'gcc -iquote'.
29809d1be9820039b4cf6efa48246a0d70ffa13394James Dennett    Angled,         ///< Paths for '\#include <>' added by '-I'.
3065e02fa80e1c185f18e5f81cefc30d75383a7301Douglas Gregor    IndexHeaderMap, ///< Like Angled, but marks header maps used when
3165e02fa80e1c185f18e5f81cefc30d75383a7301Douglas Gregor                       ///  building frameworks.
322cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar    System,         ///< Like Angled, but marks system directories.
33ef84554239d77cc52a14b42f2bff8c2d02e7630eDaniel Dunbar    ExternCSystem,  ///< Like System, but headers are implicitly wrapped in
34ef84554239d77cc52a14b42f2bff8c2d02e7630eDaniel Dunbar                    ///  extern "C".
3547adebef0df6dce752fe9a45e9190e8005b5d07cBenjamin Kramer    CSystem,        ///< Like System, but only used for C.
362df6647847af283302834dadae5d9dcefa7e0ad4Joerg Sonnenberger    CXXSystem,      ///< Like System, but only used for C++.
3747adebef0df6dce752fe9a45e9190e8005b5d07cBenjamin Kramer    ObjCSystem,     ///< Like System, but only used for ObjC.
3847adebef0df6dce752fe9a45e9190e8005b5d07cBenjamin Kramer    ObjCXXSystem,   ///< Like System, but only used for ObjC++.
392cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar    After           ///< Like System, but searched after the system directories.
402cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar  };
412cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar}
422cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar
4363c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar/// HeaderSearchOptions - Helper class for storing options related to the
4463c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar/// initialization of the HeaderSearch object.
45cfa88f893915ceb8ae4ce2f17c46c24a4d67502fDmitri Gribenkoclass HeaderSearchOptions : public RefCountedBase<HeaderSearchOptions> {
4663c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbarpublic:
4763c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar  struct Entry {
4863c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar    std::string Path;
492cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar    frontend::IncludeDirGroup Group;
5063c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar    unsigned IsFramework : 1;
5123637beead1fce7dac755890c9482bcdce538b87Chris Lattner
525dd45f13dc4463f0c18b923fe6795ce55103301dBob Wilson    /// IgnoreSysRoot - This is false if an absolute path should be treated
535dd45f13dc4463f0c18b923fe6795ce55103301dBob Wilson    /// relative to the sysroot, or true if it should always be the absolute
5423637beead1fce7dac755890c9482bcdce538b87Chris Lattner    /// path.
555dd45f13dc4463f0c18b923fe6795ce55103301dBob Wilson    unsigned IgnoreSysRoot : 1;
5623637beead1fce7dac755890c9482bcdce538b87Chris Lattner
5759fd63581d6d572f23e82e81a50e0b940c8d1089Daniel Dunbar    Entry(StringRef path, frontend::IncludeDirGroup group, bool isFramework,
5859fd63581d6d572f23e82e81a50e0b940c8d1089Daniel Dunbar          bool ignoreSysRoot)
59eab6652b7e417c8e46b21c7d340f3a7d41492d6eDaniel Dunbar      : Path(path), Group(group), IsFramework(isFramework),
6059fd63581d6d572f23e82e81a50e0b940c8d1089Daniel Dunbar        IgnoreSysRoot(ignoreSysRoot) {}
6163c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar  };
6263c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar
63f122a138e39dbb29162abfa9a3d44091d8efa7afRichard Smith  struct SystemHeaderPrefix {
642edbc98b046de22f3aba3c5142e85e7f3437fd03James Dennett    /// A prefix to be matched against paths in \#include directives.
65f122a138e39dbb29162abfa9a3d44091d8efa7afRichard Smith    std::string Prefix;
66f122a138e39dbb29162abfa9a3d44091d8efa7afRichard Smith
67f122a138e39dbb29162abfa9a3d44091d8efa7afRichard Smith    /// True if paths beginning with this prefix should be treated as system
68f122a138e39dbb29162abfa9a3d44091d8efa7afRichard Smith    /// headers.
69f122a138e39dbb29162abfa9a3d44091d8efa7afRichard Smith    bool IsSystemHeader;
70f122a138e39dbb29162abfa9a3d44091d8efa7afRichard Smith
71f122a138e39dbb29162abfa9a3d44091d8efa7afRichard Smith    SystemHeaderPrefix(StringRef Prefix, bool IsSystemHeader)
72f122a138e39dbb29162abfa9a3d44091d8efa7afRichard Smith      : Prefix(Prefix), IsSystemHeader(IsSystemHeader) {}
73f122a138e39dbb29162abfa9a3d44091d8efa7afRichard Smith  };
74f122a138e39dbb29162abfa9a3d44091d8efa7afRichard Smith
7563c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar  /// If non-empty, the directory to use as a "virtual system root" for include
7663c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar  /// paths.
7763c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar  std::string Sysroot;
7863c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar
7963c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar  /// User specified include entries.
8063c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar  std::vector<Entry> UserEntries;
8163c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar
82f122a138e39dbb29162abfa9a3d44091d8efa7afRichard Smith  /// User-specified system header prefixes.
83f122a138e39dbb29162abfa9a3d44091d8efa7afRichard Smith  std::vector<SystemHeaderPrefix> SystemHeaderPrefixes;
84f122a138e39dbb29162abfa9a3d44091d8efa7afRichard Smith
858b9adfea5e834eaee0f45d8cc7fb052d68df4a46Daniel Dunbar  /// The directory which holds the compiler resource files (builtin includes,
868b9adfea5e834eaee0f45d8cc7fb052d68df4a46Daniel Dunbar  /// etc.).
878b9adfea5e834eaee0f45d8cc7fb052d68df4a46Daniel Dunbar  std::string ResourceDir;
8863c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar
899a6da6930644b4f2dbe4885b0eb4fc1274ff56a4Douglas Gregor  /// \brief The directory used for the module cache.
909a6da6930644b4f2dbe4885b0eb4fc1274ff56a4Douglas Gregor  std::string ModuleCachePath;
912a06085281d1b6aee628f85e8676eec04542cbc9Douglas Gregor
926e975c4517958bcc11c834336d340797356058dbDouglas Gregor  /// \brief Whether we should disable the use of the hash string within the
936e975c4517958bcc11c834336d340797356058dbDouglas Gregor  /// module cache.
946e975c4517958bcc11c834336d340797356058dbDouglas Gregor  ///
956e975c4517958bcc11c834336d340797356058dbDouglas Gregor  /// Note: Only used for testing!
966e975c4517958bcc11c834336d340797356058dbDouglas Gregor  unsigned DisableModuleHash : 1;
972a06085281d1b6aee628f85e8676eec04542cbc9Douglas Gregor
982a06085281d1b6aee628f85e8676eec04542cbc9Douglas Gregor  /// \brief The set of macro names that should be ignored for the purposes
992a06085281d1b6aee628f85e8676eec04542cbc9Douglas Gregor  /// of computing the module hash.
1002a06085281d1b6aee628f85e8676eec04542cbc9Douglas Gregor  llvm::SetVector<std::string> ModulesIgnoreMacros;
1012a06085281d1b6aee628f85e8676eec04542cbc9Douglas Gregor
1021e69fe3a9f0a42b32a3000bda51677d51416564eDaniel Dunbar  /// Include the compiler builtin includes.
1031e69fe3a9f0a42b32a3000bda51677d51416564eDaniel Dunbar  unsigned UseBuiltinIncludes : 1;
1041e69fe3a9f0a42b32a3000bda51677d51416564eDaniel Dunbar
10563c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar  /// Include the system standard include search directories.
106a268fc0f2229eb132ebc8501b140093aeb5516bfDaniel Dunbar  unsigned UseStandardSystemIncludes : 1;
10763c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar
1084c2bcad7b843c10fd4a2ffd43da40bfefb4dc8baDouglas Gregor  /// Include the system standard C++ library include search directories.
1094c2bcad7b843c10fd4a2ffd43da40bfefb4dc8baDouglas Gregor  unsigned UseStandardCXXIncludes : 1;
1104c2bcad7b843c10fd4a2ffd43da40bfefb4dc8baDouglas Gregor
11113c4f2144b35bda21746eb60ad90e52a9bd8dcdaBob Wilson  /// Use libc++ instead of the default libstdc++.
11213c4f2144b35bda21746eb60ad90e52a9bd8dcdaBob Wilson  unsigned UseLibcxx : 1;
11313c4f2144b35bda21746eb60ad90e52a9bd8dcdaBob Wilson
11463c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar  /// Whether header search information should be output as for -v.
11563c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar  unsigned Verbose : 1;
11663c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar
11763c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbarpublic:
118686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  HeaderSearchOptions(StringRef _Sysroot = "/")
1196e975c4517958bcc11c834336d340797356058dbDouglas Gregor    : Sysroot(_Sysroot), DisableModuleHash(0), UseBuiltinIncludes(true),
120a268fc0f2229eb132ebc8501b140093aeb5516bfDaniel Dunbar      UseStandardSystemIncludes(true), UseStandardCXXIncludes(true),
121a268fc0f2229eb132ebc8501b140093aeb5516bfDaniel Dunbar      UseLibcxx(false), Verbose(false) {}
12263c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar
1231824d54df85a462ada812dadda18130f951d40f3Dmitri Gribenko  /// AddPath - Add the \p Path path to the specified \p Group list.
124686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  void AddPath(StringRef Path, frontend::IncludeDirGroup Group,
12559fd63581d6d572f23e82e81a50e0b940c8d1089Daniel Dunbar               bool IsFramework, bool IgnoreSysRoot) {
12659fd63581d6d572f23e82e81a50e0b940c8d1089Daniel Dunbar    UserEntries.push_back(Entry(Path, Group, IsFramework, IgnoreSysRoot));
12763c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar  }
128f122a138e39dbb29162abfa9a3d44091d8efa7afRichard Smith
1292edbc98b046de22f3aba3c5142e85e7f3437fd03James Dennett  /// AddSystemHeaderPrefix - Override whether \#include directives naming a
1301824d54df85a462ada812dadda18130f951d40f3Dmitri Gribenko  /// path starting with \p Prefix should be considered as naming a system
131f122a138e39dbb29162abfa9a3d44091d8efa7afRichard Smith  /// header.
132f122a138e39dbb29162abfa9a3d44091d8efa7afRichard Smith  void AddSystemHeaderPrefix(StringRef Prefix, bool IsSystemHeader) {
133f122a138e39dbb29162abfa9a3d44091d8efa7afRichard Smith    SystemHeaderPrefixes.push_back(SystemHeaderPrefix(Prefix, IsSystemHeader));
134f122a138e39dbb29162abfa9a3d44091d8efa7afRichard Smith  }
13563c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar};
13663c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar
13763c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar} // end namespace clang
13863c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar
13963c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar#endif
140