1 //===--- DirectoryLookup.h - Info for searching for headers -----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines the DirectoryLookup interface.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_CLANG_LEX_DIRECTORYLOOKUP_H
15 #define LLVM_CLANG_LEX_DIRECTORYLOOKUP_H
17 #include "clang/Basic/LLVM.h"
18 #include "clang/Basic/SourceManager.h"
19 #include "clang/Lex/ModuleMap.h"
28 /// DirectoryLookup - This class represents one entry in the search list that
29 /// specifies the search order for directories in \#include directives. It
30 /// represents either a directory, a framework, or a headermap.
32 class DirectoryLookup {
40 union { // This union is discriminated by isHeaderMap.
41 /// Dir - This is the actual directory that we're referring to for a normal
42 /// directory or a framework.
43 const DirectoryEntry *Dir;
45 /// Map - This is the HeaderMap if this is a headermap lookup.
50 /// DirCharacteristic - The type of directory this is: this is an instance of
51 /// SrcMgr::CharacteristicKind.
52 unsigned DirCharacteristic : 2;
54 /// LookupType - This indicates whether this DirectoryLookup object is a
55 /// normal directory, a framework, or a headermap.
56 unsigned LookupType : 2;
58 /// \brief Whether this is a header map used when building a framework.
59 unsigned IsIndexHeaderMap : 1;
61 /// \brief Whether we've performed an exhaustive search for module maps
62 /// within the subdirectories of this directory.
63 unsigned SearchedAllModuleMaps : 1;
66 /// DirectoryLookup ctor - Note that this ctor *does not take ownership* of
68 DirectoryLookup(const DirectoryEntry *dir, SrcMgr::CharacteristicKind DT,
70 : DirCharacteristic(DT),
71 LookupType(isFramework ? LT_Framework : LT_NormalDir),
72 IsIndexHeaderMap(false), SearchedAllModuleMaps(false) {
76 /// DirectoryLookup ctor - Note that this ctor *does not take ownership* of
78 DirectoryLookup(const HeaderMap *map, SrcMgr::CharacteristicKind DT,
79 bool isIndexHeaderMap)
80 : DirCharacteristic(DT), LookupType(LT_HeaderMap),
81 IsIndexHeaderMap(isIndexHeaderMap), SearchedAllModuleMaps(false) {
85 /// getLookupType - Return the kind of directory lookup that this is: either a
86 /// normal directory, a framework path, or a HeaderMap.
87 LookupType_t getLookupType() const { return (LookupType_t)LookupType; }
89 /// getName - Return the directory or filename corresponding to this lookup
91 const char *getName() const;
93 /// getDir - Return the directory that this entry refers to.
95 const DirectoryEntry *getDir() const {
96 return isNormalDir() ? u.Dir : nullptr;
99 /// getFrameworkDir - Return the directory that this framework refers to.
101 const DirectoryEntry *getFrameworkDir() const {
102 return isFramework() ? u.Dir : nullptr;
105 /// getHeaderMap - Return the directory that this entry refers to.
107 const HeaderMap *getHeaderMap() const {
108 return isHeaderMap() ? u.Map : nullptr;
111 /// isNormalDir - Return true if this is a normal directory, not a header map.
112 bool isNormalDir() const { return getLookupType() == LT_NormalDir; }
114 /// isFramework - True if this is a framework directory.
116 bool isFramework() const { return getLookupType() == LT_Framework; }
118 /// isHeaderMap - Return true if this is a header map, not a normal directory.
119 bool isHeaderMap() const { return getLookupType() == LT_HeaderMap; }
121 /// \brief Determine whether we have already searched this entire
122 /// directory for module maps.
123 bool haveSearchedAllModuleMaps() const { return SearchedAllModuleMaps; }
125 /// \brief Specify whether we have already searched all of the subdirectories
127 void setSearchedAllModuleMaps(bool SAMM) {
128 SearchedAllModuleMaps = SAMM;
131 /// DirCharacteristic - The type of directory this is, one of the DirType enum
133 SrcMgr::CharacteristicKind getDirCharacteristic() const {
134 return (SrcMgr::CharacteristicKind)DirCharacteristic;
137 /// \brief Whether this describes a system header directory.
138 bool isSystemHeaderDirectory() const {
139 return getDirCharacteristic() != SrcMgr::C_User;
142 /// \brief Whether this header map is building a framework or not.
143 bool isIndexHeaderMap() const {
144 return isHeaderMap() && IsIndexHeaderMap;
147 /// LookupFile - Lookup the specified file in this search path, returning it
148 /// if it exists or returning null if not.
150 /// \param Filename The file to look up relative to the search paths.
152 /// \param HS The header search instance to search with.
154 /// \param IncludeLoc the source location of the #include or #import
157 /// \param SearchPath If not NULL, will be set to the search path relative
158 /// to which the file was found.
160 /// \param RelativePath If not NULL, will be set to the path relative to
161 /// SearchPath at which the file was found. This only differs from the
162 /// Filename for framework includes.
164 /// \param RequestingModule The module in which the lookup was performed.
166 /// \param SuggestedModule If non-null, and the file found is semantically
167 /// part of a known module, this will be set to the module that should
168 /// be imported instead of preprocessing/parsing the file found.
170 /// \param [out] InUserSpecifiedSystemFramework If the file is found,
171 /// set to true if the file is located in a framework that has been
172 /// user-specified to be treated as a system framework.
174 /// \param [out] MappedName if this is a headermap which maps the filename to
175 /// a framework include ("Foo.h" -> "Foo/Foo.h"), set the new name to this
176 /// vector and point Filename to it.
177 const FileEntry *LookupFile(StringRef &Filename, HeaderSearch &HS,
178 SourceLocation IncludeLoc,
179 SmallVectorImpl<char> *SearchPath,
180 SmallVectorImpl<char> *RelativePath,
181 Module *RequestingModule,
182 ModuleMap::KnownHeader *SuggestedModule,
183 bool &InUserSpecifiedSystemFramework,
185 SmallVectorImpl<char> &MappedName) const;
188 const FileEntry *DoFrameworkLookup(
189 StringRef Filename, HeaderSearch &HS,
190 SmallVectorImpl<char> *SearchPath,
191 SmallVectorImpl<char> *RelativePath,
192 Module *RequestingModule,
193 ModuleMap::KnownHeader *SuggestedModule,
194 bool &InUserSpecifiedSystemHeader) const;
198 } // end namespace clang