HeaderSearchOptions.h revision ef84554239d77cc52a14b42f2bff8c2d02e7630e
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/StringRef.h"
16#include <vector>
17
18namespace clang {
19
20namespace frontend {
21  /// IncludeDirGroup - Identifiers the group a include entry belongs to, which
22  /// represents its relative positive in the search list.  A \#include of a ""
23  /// path starts at the -iquote group, then searches the Angled group, then
24  /// searches the system group, etc.
25  enum IncludeDirGroup {
26    Quoted = 0,     ///< '\#include ""' paths, added by 'gcc -iquote'.
27    Angled,         ///< Paths for '\#include <>' added by '-I'.
28    IndexHeaderMap, ///< Like Angled, but marks header maps used when
29                       ///  building frameworks.
30    System,         ///< Like Angled, but marks system directories.
31    ExternCSystem,  ///< Like System, but headers are implicitly wrapped in
32                    ///  extern "C".
33    CSystem,        ///< Like System, but only used for C.
34    CXXSystem,      ///< Like System, but only used for C++.
35    ObjCSystem,     ///< Like System, but only used for ObjC.
36    ObjCXXSystem,   ///< Like System, but only used for ObjC++.
37    After           ///< Like System, but searched after the system directories.
38  };
39}
40
41/// HeaderSearchOptions - Helper class for storing options related to the
42/// initialization of the HeaderSearch object.
43class HeaderSearchOptions : public RefCountedBase<HeaderSearchOptions> {
44public:
45  struct Entry {
46    std::string Path;
47    frontend::IncludeDirGroup Group;
48    unsigned IsFramework : 1;
49
50    /// IgnoreSysRoot - This is false if an absolute path should be treated
51    /// relative to the sysroot, or true if it should always be the absolute
52    /// path.
53    unsigned IgnoreSysRoot : 1;
54
55    /// \brief True if this entry is an internal search path.
56    ///
57    /// This typically indicates that users didn't directly provide it, but
58    /// instead it was provided by a compatibility layer for a particular
59    /// system.
60    unsigned IsInternal : 1;
61
62    /// \brief True if this entry's headers should be wrapped in extern "C".
63    unsigned ImplicitExternC : 1;
64
65    Entry(StringRef path, frontend::IncludeDirGroup group,
66          bool isFramework, bool ignoreSysRoot, bool isInternal)
67      : Path(path), Group(group), IsFramework(isFramework),
68        IgnoreSysRoot(ignoreSysRoot), IsInternal(isInternal) {}
69  };
70
71  struct SystemHeaderPrefix {
72    /// A prefix to be matched against paths in \#include directives.
73    std::string Prefix;
74
75    /// True if paths beginning with this prefix should be treated as system
76    /// headers.
77    bool IsSystemHeader;
78
79    SystemHeaderPrefix(StringRef Prefix, bool IsSystemHeader)
80      : Prefix(Prefix), IsSystemHeader(IsSystemHeader) {}
81  };
82
83  /// If non-empty, the directory to use as a "virtual system root" for include
84  /// paths.
85  std::string Sysroot;
86
87  /// User specified include entries.
88  std::vector<Entry> UserEntries;
89
90  /// User-specified system header prefixes.
91  std::vector<SystemHeaderPrefix> SystemHeaderPrefixes;
92
93  /// The directory which holds the compiler resource files (builtin includes,
94  /// etc.).
95  std::string ResourceDir;
96
97  /// \brief The directory used for the module cache.
98  std::string ModuleCachePath;
99
100  /// \brief Whether we should disable the use of the hash string within the
101  /// module cache.
102  ///
103  /// Note: Only used for testing!
104  unsigned DisableModuleHash : 1;
105
106  /// Include the compiler builtin includes.
107  unsigned UseBuiltinIncludes : 1;
108
109  /// Include the system standard include search directories.
110  unsigned UseStandardSystemIncludes : 1;
111
112  /// Include the system standard C++ library include search directories.
113  unsigned UseStandardCXXIncludes : 1;
114
115  /// Use libc++ instead of the default libstdc++.
116  unsigned UseLibcxx : 1;
117
118  /// Whether header search information should be output as for -v.
119  unsigned Verbose : 1;
120
121public:
122  HeaderSearchOptions(StringRef _Sysroot = "/")
123    : Sysroot(_Sysroot), DisableModuleHash(0), UseBuiltinIncludes(true),
124      UseStandardSystemIncludes(true), UseStandardCXXIncludes(true),
125      UseLibcxx(false), Verbose(false) {}
126
127  /// AddPath - Add the \p Path path to the specified \p Group list.
128  void AddPath(StringRef Path, frontend::IncludeDirGroup Group,
129               bool IsFramework, bool IgnoreSysRoot, bool IsInternal = false) {
130    UserEntries.push_back(Entry(Path, Group, IsFramework,
131                                IgnoreSysRoot, IsInternal));
132  }
133
134  /// AddSystemHeaderPrefix - Override whether \#include directives naming a
135  /// path starting with \p Prefix should be considered as naming a system
136  /// header.
137  void AddSystemHeaderPrefix(StringRef Prefix, bool IsSystemHeader) {
138    SystemHeaderPrefixes.push_back(SystemHeaderPrefix(Prefix, IsSystemHeader));
139  }
140};
141
142} // end namespace clang
143
144#endif
145