clang 8.0.0

DirectoryLookup.h
Go to the documentation of this file.
1 //===--- DirectoryLookup.h - Info for searching for headers -----*- 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 // This file defines the DirectoryLookup interface.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_CLANG_LEX_DIRECTORYLOOKUP_H
15 #define LLVM_CLANG_LEX_DIRECTORYLOOKUP_H
16
17 #include "clang/Basic/LLVM.h"
18 #include "clang/Basic/SourceManager.h"
19 #include "clang/Lex/ModuleMap.h"
20
21 namespace clang {
22 class HeaderMap;
23 class DirectoryEntry;
24 class FileEntry;
25 class HeaderSearch;
26 class Module;
27
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.
31 ///
32 class DirectoryLookup {
33 public:
34 enum LookupType_t {
35 LT_NormalDir,
36 LT_Framework,
37 LT_HeaderMap
38 };
39 private:
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;
44
45 /// Map - This is the HeaderMap if this is a headermap lookup.
46 ///
47 const HeaderMap *Map;
48 } u;
49
50 /// DirCharacteristic - The type of directory this is: this is an instance of
51 /// SrcMgr::CharacteristicKind.
52 unsigned DirCharacteristic : 2;
53
54 /// LookupType - This indicates whether this DirectoryLookup object is a
55 /// normal directory, a framework, or a headermap.
56 unsigned LookupType : 2;
57
58 /// Whether this is a header map used when building a framework.
59 unsigned IsIndexHeaderMap : 1;
60
61 /// Whether we've performed an exhaustive search for module maps
62 /// within the subdirectories of this directory.
63 unsigned SearchedAllModuleMaps : 1;
64
65 public:
66 /// DirectoryLookup ctor - Note that this ctor *does not take ownership* of
67 /// 'dir'.
68 DirectoryLookup(const DirectoryEntry *dir, SrcMgr::CharacteristicKind DT,
69 bool isFramework)
70 : DirCharacteristic(DT),
71 LookupType(isFramework ? LT_Framework : LT_NormalDir),
72 IsIndexHeaderMap(false), SearchedAllModuleMaps(false) {
73 u.Dir = dir;
74 }
75
76 /// DirectoryLookup ctor - Note that this ctor *does not take ownership* of
77 /// 'map'.
78 DirectoryLookup(const HeaderMap *map, SrcMgr::CharacteristicKind DT,
79 bool isIndexHeaderMap)
80 : DirCharacteristic(DT), LookupType(LT_HeaderMap),
81 IsIndexHeaderMap(isIndexHeaderMap), SearchedAllModuleMaps(false) {
82 u.Map = map;
83 }
84
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; }
88
89 /// getName - Return the directory or filename corresponding to this lookup
90 /// object.
91 StringRef getName() const;
92
93 /// getDir - Return the directory that this entry refers to.
94 ///
95 const DirectoryEntry *getDir() const {
96 return isNormalDir() ? u.Dir : nullptr;
97 }
98
99 /// getFrameworkDir - Return the directory that this framework refers to.
100 ///
101 const DirectoryEntry *getFrameworkDir() const {
102 return isFramework() ? u.Dir : nullptr;
103 }
104
105 /// getHeaderMap - Return the directory that this entry refers to.
106 ///
107 const HeaderMap *getHeaderMap() const {
108 return isHeaderMap() ? u.Map : nullptr;
109 }
110
111 /// isNormalDir - Return true if this is a normal directory, not a header map.
112 bool isNormalDir() const { return getLookupType() == LT_NormalDir; }
113
114 /// isFramework - True if this is a framework directory.
115 ///
116 bool isFramework() const { return getLookupType() == LT_Framework; }
117
118 /// isHeaderMap - Return true if this is a header map, not a normal directory.
119 bool isHeaderMap() const { return getLookupType() == LT_HeaderMap; }
120
121 /// Determine whether we have already searched this entire
122 /// directory for module maps.
123 bool haveSearchedAllModuleMaps() const { return SearchedAllModuleMaps; }
124
125 /// Specify whether we have already searched all of the subdirectories
126 /// for module maps.
127 void setSearchedAllModuleMaps(bool SAMM) {
128 SearchedAllModuleMaps = SAMM;
129 }
130
131 /// DirCharacteristic - The type of directory this is, one of the DirType enum
132 /// values.
133 SrcMgr::CharacteristicKind getDirCharacteristic() const {
134 return (SrcMgr::CharacteristicKind)DirCharacteristic;
135 }
136
137 /// Whether this describes a system header directory.
138 bool isSystemHeaderDirectory() const {
139 return getDirCharacteristic() != SrcMgr::C_User;
140 }
141
142 /// Whether this header map is building a framework or not.
143 bool isIndexHeaderMap() const {
144 return isHeaderMap() && IsIndexHeaderMap;
145 }
146
147 /// LookupFile - Lookup the specified file in this search path, returning it
148 /// if it exists or returning null if not.
149 ///
150 /// \param Filename The file to look up relative to the search paths.
151 ///
152 /// \param HS The header search instance to search with.
153 ///
154 /// \param IncludeLoc the source location of the #include or #import
155 /// directive.
156 ///
157 /// \param SearchPath If not NULL, will be set to the search path relative
158 /// to which the file was found.
159 ///
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.
163 ///
164 /// \param RequestingModule The module in which the lookup was performed.
165 ///
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.
169 ///
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.
173 ///
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,
184 bool &HasBeenMapped,
185 SmallVectorImpl<char> &MappedName) const;
186
187 private:
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 &InUserSpecifiedSystemFramework) const;
195
196 };
197
198 } // end namespace clang
199
200 #endif
clang::DirectoryLookup::isIndexHeaderMap
bool isIndexHeaderMap() const
Whether this header map is building a framework or not.
Definition: DirectoryLookup.h:143
SourceManager.h
Defines the SourceManager interface.
clang::DirectoryLookup::Map
const HeaderMap * Map
Map - This is the HeaderMap if this is a headermap lookup.
Definition: DirectoryLookup.h:47
clang::DirectoryLookup::getName
StringRef getName() const
getName - Return the directory or filename corresponding to this lookup object.
Definition: HeaderSearch.cpp:299
clang::DirectoryLookup::Dir
const DirectoryEntry * Dir
Dir - This is the actual directory that we&#39;re referring to for a normal directory or a framework...
Definition: DirectoryLookup.h:43
clang::SrcMgr::CharacteristicKind
CharacteristicKind
Indicates whether a file or directory holds normal user code, system code, or system code which is im...
Definition: SourceManager.h:78
clang::HeaderMap
This class represents an Apple concept known as a &#39;header map&#39;.
Definition: HeaderMap.h:67
clang::DirectoryLookup::isHeaderMap
bool isHeaderMap() const
isHeaderMap - Return true if this is a header map, not a normal directory.
Definition: DirectoryLookup.h:119
clang::DirectoryLookup::DirectoryLookup
DirectoryLookup(const DirectoryEntry *dir, SrcMgr::CharacteristicKind DT, bool isFramework)
DirectoryLookup ctor - Note that this ctor does not take ownership of &#39;dir&#39;.
Definition: DirectoryLookup.h:68
clang::Module
Describes a module or submodule.
Definition: Module.h:65
llvm::SmallVectorImpl
Definition: LLVM.h:37
LLVM.h
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
clang::HeaderSearch
Encapsulates the information needed to find the file referenced by a #include or #include_next, (sub-)framework lookup, etc.
Definition: HeaderSearch.h:148
clang::DirectoryLookup::LT_Framework
Definition: DirectoryLookup.h:36
Filename
StringRef Filename
Definition: Format.cpp:1629
ModuleMap.h
clang::DirectoryLookup::isNormalDir
bool isNormalDir() const
isNormalDir - Return true if this is a normal directory, not a header map.
Definition: DirectoryLookup.h:112
clang::DirectoryLookup::isFramework
bool isFramework() const
isFramework - True if this is a framework directory.
Definition: DirectoryLookup.h:116
clang::DirectoryLookup::LookupFile
const FileEntry * LookupFile(StringRef &Filename, HeaderSearch &HS, SourceLocation IncludeLoc, SmallVectorImpl< char > *SearchPath, SmallVectorImpl< char > *RelativePath, Module *RequestingModule, ModuleMap::KnownHeader *SuggestedModule, bool &InUserSpecifiedSystemFramework, bool &HasBeenMapped, SmallVectorImpl< char > &MappedName) const
LookupFile - Lookup the specified file in this search path, returning it if it exists or returning nu...
Definition: HeaderSearch.cpp:329
clang::DirectoryLookup
DirectoryLookup - This class represents one entry in the search list that specifies the search order ...
Definition: DirectoryLookup.h:32
false
#define false
Definition: stdbool.h:33
clang::SourceLocation
Encodes a location in the source.
Definition: SourceLocation.h:88
clang::DirectoryLookup::isSystemHeaderDirectory
bool isSystemHeaderDirectory() const
Whether this describes a system header directory.
Definition: DirectoryLookup.h:138
clang::DirectoryLookup::getLookupType
LookupType_t getLookupType() const
getLookupType - Return the kind of directory lookup that this is: either a normal directory...
Definition: DirectoryLookup.h:87
clang::FileEntry
Cached information about one file (either on disk or in the virtual file system). ...
Definition: FileManager.h:60
clang::DirectoryLookup::getDirCharacteristic
SrcMgr::CharacteristicKind getDirCharacteristic() const
DirCharacteristic - The type of directory this is, one of the DirType enum values.
Definition: DirectoryLookup.h:133
clang::DirectoryLookup::haveSearchedAllModuleMaps
bool haveSearchedAllModuleMaps() const
Determine whether we have already searched this entire directory for module maps. ...
Definition: DirectoryLookup.h:123
clang::DirectoryLookup::getHeaderMap
const HeaderMap * getHeaderMap() const
getHeaderMap - Return the directory that this entry refers to.
Definition: DirectoryLookup.h:107
clang
Dataflow Directional Tag Classes.
Definition: CFGReachabilityAnalysis.h:22
clang::DirectoryLookup::LT_NormalDir
Definition: DirectoryLookup.h:35
clang::index::SymbolKind::Module
clang::SrcMgr::C_User
Definition: SourceManager.h:79
clang::DirectoryLookup::getDir
const DirectoryEntry * getDir() const
getDir - Return the directory that this entry refers to.
Definition: DirectoryLookup.h:95
clang::DirectoryEntry
Cached information about one directory (either on disk or in the virtual file system).
Definition: FileManager.h:46
clang::DirectoryLookup::LookupType_t
LookupType_t
Definition: DirectoryLookup.h:34
clang::DirectoryLookup::DirectoryLookup
DirectoryLookup(const HeaderMap *map, SrcMgr::CharacteristicKind DT, bool isIndexHeaderMap)
DirectoryLookup ctor - Note that this ctor does not take ownership of &#39;map&#39;.
Definition: DirectoryLookup.h:78
clang::DirectoryLookup::LT_HeaderMap
Definition: DirectoryLookup.h:37
clang::DirectoryLookup::setSearchedAllModuleMaps
void setSearchedAllModuleMaps(bool SAMM)
Specify whether we have already searched all of the subdirectories for module maps.
Definition: DirectoryLookup.h:127
clang::ModuleMap::KnownHeader
A header that is known to reside within a given module, whether it was included or excluded...
Definition: ModuleMap.h:151
clang::DirectoryLookup::getFrameworkDir
const DirectoryEntry * getFrameworkDir() const
getFrameworkDir - Return the directory that this framework refers to.
Definition: DirectoryLookup.h:101