clang 24.0.0git
DirectoryLookup.h
Go to the documentation of this file.
1//===--- DirectoryLookup.h - Info for searching for headers -----*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines the DirectoryLookup interface.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_CLANG_LEX_DIRECTORYLOOKUP_H
14#define LLVM_CLANG_LEX_DIRECTORYLOOKUP_H
15
16#include "clang/Basic/LLVM.h"
19#include "clang/Lex/ModuleMap.h"
20
21namespace clang {
22class HeaderMap;
23class HeaderSearch;
24class Module;
25
26/// DirectoryLookup - This class represents one entry in the search list that
27/// specifies the search order for directories in \#include directives. It
28/// represents either a directory, a framework, or a headermap.
29///
31public:
37private:
38 union DLU { // This union is discriminated by isHeaderMap.
39 /// Dir - This is the actual directory that we're referring to for a normal
40 /// directory or a framework.
42
43 /// Map - This is the HeaderMap if this is a headermap lookup.
44 ///
45 const HeaderMap *Map;
46
47 DLU(DirectoryEntryRef Dir) : Dir(Dir) {}
48 DLU(const HeaderMap *Map) : Map(Map) {}
49 } u;
50
51 /// DirCharacteristic - The type of directory this is: this is an instance of
52 /// SrcMgr::CharacteristicKind.
53 LLVM_PREFERRED_TYPE(SrcMgr::CharacteristicKind)
54 unsigned DirCharacteristic : 3;
55
56 /// LookupType - This indicates whether this DirectoryLookup object is a
57 /// normal directory, a framework, or a headermap.
58 LLVM_PREFERRED_TYPE(LookupType_t)
59 unsigned LookupType : 2;
60
61 /// Whether we've performed an exhaustive search and loaded all of the module
62 /// maps within the subdirectories of this directory.
63 LLVM_PREFERRED_TYPE(bool)
64 unsigned LoadedAllModuleMaps : 1;
65
66public:
67 /// This ctor *does not take ownership* of 'Dir'.
69 bool isFramework)
70 : u(Dir), DirCharacteristic(DT),
72 LoadedAllModuleMaps(false) {}
73
74 /// This ctor *does not take ownership* of 'Map'.
76 : u(Map), DirCharacteristic(DT), LookupType(LT_HeaderMap),
77 LoadedAllModuleMaps(false) {}
78
79 /// getLookupType - Return the kind of directory lookup that this is: either a
80 /// normal directory, a framework path, or a HeaderMap.
81 LookupType_t getLookupType() const { return (LookupType_t)LookupType; }
82
83 /// getName - Return the directory or filename corresponding to this lookup
84 /// object.
85 StringRef getName() const;
86
87 /// getDir - Return the directory that this entry refers to.
88 ///
89 const DirectoryEntry *getDir() const {
90 return isNormalDir() ? &u.Dir.getDirEntry() : nullptr;
91 }
92
94 return isNormalDir() ? OptionalDirectoryEntryRef(u.Dir) : std::nullopt;
95 }
96
97 /// getFrameworkDir - Return the directory that this framework refers to.
98 ///
100 return isFramework() ? &u.Dir.getDirEntry() : nullptr;
101 }
102
104 return isFramework() ? OptionalDirectoryEntryRef(u.Dir) : std::nullopt;
105 }
106
107 /// getHeaderMap - Return the directory that this entry refers to.
108 ///
109 const HeaderMap *getHeaderMap() const {
110 return isHeaderMap() ? u.Map : nullptr;
111 }
112
113 /// isNormalDir - Return true if this is a normal directory, not a header map.
114 bool isNormalDir() const { return getLookupType() == LT_NormalDir; }
115
116 /// isFramework - True if this is a framework directory.
117 ///
118 bool isFramework() const { return getLookupType() == LT_Framework; }
119
120 /// isHeaderMap - Return true if this is a header map, not a normal directory.
121 bool isHeaderMap() const { return getLookupType() == LT_HeaderMap; }
122
123 /// Determine whether we have already searched and loaded all of the module
124 /// maps within this entire directory.
125 bool haveLoadedAllModuleMaps() const { return LoadedAllModuleMaps; }
126
127 /// Specify whether we have already loaded all of the module maps within the
128 /// subdirectories of this directory.
129 void setLoadedAllModuleMaps(bool LAMM) { LoadedAllModuleMaps = LAMM; }
130
131 /// DirCharacteristic - The type of directory this is, one of the DirType enum
132 /// values.
134 return (SrcMgr::CharacteristicKind)DirCharacteristic;
135 }
136
137 /// Whether this describes a system header directory.
140 }
141
142 /// LookupFile - Lookup the specified file in this search path, returning it
143 /// if it exists or returning null if not.
144 ///
145 /// \param Filename The file to look up relative to the search paths.
146 ///
147 /// \param HS The header search instance to search with.
148 ///
149 /// \param IncludeLoc the source location of the #include or #import
150 /// directive.
151 ///
152 /// \param SearchPath If not NULL, will be set to the search path relative
153 /// to which the file was found.
154 ///
155 /// \param RelativePath If not NULL, will be set to the path relative to
156 /// SearchPath at which the file was found. This only differs from the
157 /// Filename for framework includes.
158 ///
159 /// \param RequestingModule The module in which the lookup was performed.
160 ///
161 /// \param SuggestedModule If non-null, and the file found is semantically
162 /// part of a known module, this will be set to the module that should
163 /// be imported instead of preprocessing/parsing the file found.
164 ///
165 /// \param [out] InUserSpecifiedSystemFramework If the file is found,
166 /// set to true if the file is located in a framework that has been
167 /// user-specified to be treated as a system framework.
168 ///
169 /// \param [out] IsFrameworkFound For a framework directory set to true if
170 /// specified '.framework' directory is found.
171 ///
172 /// \param [out] MappedName if this is a headermap which maps the filename to
173 /// a framework include ("Foo.h" -> "Foo/Foo.h"), set the new name to this
174 /// vector and point Filename to it.
176 LookupFile(StringRef &Filename, HeaderSearch &HS, SourceLocation IncludeLoc,
177 SmallVectorImpl<char> *SearchPath,
178 SmallVectorImpl<char> *RelativePath, Module *RequestingModule,
179 ModuleMap::KnownHeader *SuggestedModule,
180 bool &InUserSpecifiedSystemFramework, bool &IsFrameworkFound,
181 bool &IsInHeaderMap, SmallVectorImpl<char> &MappedName,
182 bool OpenFile = true) const;
183
184private:
185 OptionalFileEntryRef DoFrameworkLookup(
186 StringRef Filename, HeaderSearch &HS, SmallVectorImpl<char> *SearchPath,
187 SmallVectorImpl<char> *RelativePath, Module *RequestingModule,
188 ModuleMap::KnownHeader *SuggestedModule,
189 bool &InUserSpecifiedSystemFramework, bool &IsFrameworkFound) const;
190};
191
192} // end namespace clang
193
194#endif
Defines the clang::FileManager interface and associated types.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
Defines the SourceManager interface.
A reference to a DirectoryEntry that includes the name of the directory as it was accessed by the Fil...
Cached information about one directory (either on disk or in the virtual file system).
SrcMgr::CharacteristicKind getDirCharacteristic() const
DirCharacteristic - The type of directory this is, one of the DirType enum values.
const DirectoryEntry * getFrameworkDir() const
getFrameworkDir - Return the directory that this framework refers to.
bool haveLoadedAllModuleMaps() const
Determine whether we have already searched and loaded all of the module maps within this entire direc...
OptionalFileEntryRef LookupFile(StringRef &Filename, HeaderSearch &HS, SourceLocation IncludeLoc, SmallVectorImpl< char > *SearchPath, SmallVectorImpl< char > *RelativePath, Module *RequestingModule, ModuleMap::KnownHeader *SuggestedModule, bool &InUserSpecifiedSystemFramework, bool &IsFrameworkFound, bool &IsInHeaderMap, SmallVectorImpl< char > &MappedName, bool OpenFile=true) const
LookupFile - Lookup the specified file in this search path, returning it if it exists or returning nu...
void setLoadedAllModuleMaps(bool LAMM)
Specify whether we have already loaded all of the module maps within the subdirectories of this direc...
bool isFramework() const
isFramework - True if this is a framework directory.
bool isSystemHeaderDirectory() const
Whether this describes a system header directory.
OptionalDirectoryEntryRef getFrameworkDirRef() const
DirectoryLookup(DirectoryEntryRef Dir, SrcMgr::CharacteristicKind DT, bool isFramework)
This ctor does not take ownership of 'Dir'.
bool isHeaderMap() const
isHeaderMap - Return true if this is a header map, not a normal directory.
StringRef getName() const
getName - Return the directory or filename corresponding to this lookup object.
LookupType_t getLookupType() const
getLookupType - Return the kind of directory lookup that this is: either a normal directory,...
OptionalDirectoryEntryRef getDirRef() const
DirectoryLookup(const HeaderMap *Map, SrcMgr::CharacteristicKind DT)
This ctor does not take ownership of 'Map'.
const DirectoryEntry * getDir() const
getDir - Return the directory that this entry refers to.
bool isNormalDir() const
isNormalDir - Return true if this is a normal directory, not a header map.
const HeaderMap * getHeaderMap() const
getHeaderMap - Return the directory that this entry refers to.
This class represents an Apple concept known as a 'header map'.
Definition HeaderMap.h:84
Encapsulates the information needed to find the file referenced by a #include or #include_next,...
A header that is known to reside within a given module, whether it was included or excluded.
Definition ModuleMap.h:158
Describes a module or submodule.
Definition Module.h:340
Encodes a location in the source.
CharacteristicKind
Indicates whether a file or directory holds normal user code, system code, or system code which is im...
Top level wrappers for InstallAPI frontend operations.
CustomizableOptional< FileEntryRef > OptionalFileEntryRef
Definition FileEntry.h:196
CustomizableOptional< DirectoryEntryRef > OptionalDirectoryEntryRef
#define false
Definition stdbool.h:26