• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/IntrusiveRefCntPtr.h"
15 #include "llvm/ADT/SetVector.h"
16 #include "llvm/ADT/StringRef.h"
17 #include <string>
18 #include <vector>
19 
20 namespace clang {
21 
22 namespace frontend {
23   /// IncludeDirGroup - Identifiers the group a include entry belongs to, which
24   /// represents its relative positive in the search list.  A \#include of a ""
25   /// path starts at the -iquote group, then searches the Angled group, then
26   /// searches the system group, etc.
27   enum IncludeDirGroup {
28     Quoted = 0,     ///< '\#include ""' paths, added by 'gcc -iquote'.
29     Angled,         ///< Paths for '\#include <>' added by '-I'.
30     IndexHeaderMap, ///< Like Angled, but marks header maps used when
31                        ///  building frameworks.
32     System,         ///< Like Angled, but marks system directories.
33     ExternCSystem,  ///< Like System, but headers are implicitly wrapped in
34                     ///  extern "C".
35     CSystem,        ///< Like System, but only used for C.
36     CXXSystem,      ///< Like System, but only used for C++.
37     ObjCSystem,     ///< Like System, but only used for ObjC.
38     ObjCXXSystem,   ///< Like System, but only used for ObjC++.
39     After           ///< Like System, but searched after the system directories.
40   };
41 }
42 
43 /// HeaderSearchOptions - Helper class for storing options related to the
44 /// initialization of the HeaderSearch object.
45 class HeaderSearchOptions : public RefCountedBase<HeaderSearchOptions> {
46 public:
47   struct Entry {
48     std::string Path;
49     frontend::IncludeDirGroup Group;
50     unsigned IsFramework : 1;
51 
52     /// IgnoreSysRoot - This is false if an absolute path should be treated
53     /// relative to the sysroot, or true if it should always be the absolute
54     /// path.
55     unsigned IgnoreSysRoot : 1;
56 
EntryEntry57     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 
SystemHeaderPrefixSystemHeaderPrefix71     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 set of macro names that should be ignored for the purposes
99   /// of computing the module hash.
100   llvm::SetVector<std::string> ModulesIgnoreMacros;
101 
102   /// Include the compiler builtin includes.
103   unsigned UseBuiltinIncludes : 1;
104 
105   /// Include the system standard include search directories.
106   unsigned UseStandardSystemIncludes : 1;
107 
108   /// Include the system standard C++ library include search directories.
109   unsigned UseStandardCXXIncludes : 1;
110 
111   /// Use libc++ instead of the default libstdc++.
112   unsigned UseLibcxx : 1;
113 
114   /// Whether header search information should be output as for -v.
115   unsigned Verbose : 1;
116 
117 public:
118   HeaderSearchOptions(StringRef _Sysroot = "/")
Sysroot(_Sysroot)119     : Sysroot(_Sysroot), DisableModuleHash(0), UseBuiltinIncludes(true),
120       UseStandardSystemIncludes(true), UseStandardCXXIncludes(true),
121       UseLibcxx(false), Verbose(false) {}
122 
123   /// AddPath - Add the \p Path path to the specified \p Group list.
AddPath(StringRef Path,frontend::IncludeDirGroup Group,bool IsFramework,bool IgnoreSysRoot)124   void AddPath(StringRef Path, frontend::IncludeDirGroup Group,
125                bool IsFramework, bool IgnoreSysRoot) {
126     UserEntries.push_back(Entry(Path, Group, IsFramework, IgnoreSysRoot));
127   }
128 
129   /// AddSystemHeaderPrefix - Override whether \#include directives naming a
130   /// path starting with \p Prefix should be considered as naming a system
131   /// header.
AddSystemHeaderPrefix(StringRef Prefix,bool IsSystemHeader)132   void AddSystemHeaderPrefix(StringRef Prefix, bool IsSystemHeader) {
133     SystemHeaderPrefixes.push_back(SystemHeaderPrefix(Prefix, IsSystemHeader));
134   }
135 };
136 
137 } // end namespace clang
138 
139 #endif
140