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"
27 /// DirectoryLookup - This class represents one entry in the search list that
28 /// specifies the search order for directories in \#include directives. It
29 /// represents either a directory, a framework, or a headermap.
31 class DirectoryLookup {
39 union { // This union is discriminated by isHeaderMap.
40 /// Dir - This is the actual directory that we're referring to for a normal
41 /// directory or a framework.
42 const DirectoryEntry *Dir;
44 /// Map - This is the HeaderMap if this is a headermap lookup.
49 /// DirCharacteristic - The type of directory this is: this is an instance of
50 /// SrcMgr::CharacteristicKind.
51 unsigned DirCharacteristic : 2;
53 /// LookupType - This indicates whether this DirectoryLookup object is a
54 /// normal directory, a framework, or a headermap.
55 unsigned LookupType : 2;
57 /// \brief Whether this is a header map used when building a framework.
58 unsigned IsIndexHeaderMap : 1;
60 /// \brief Whether we've performed an exhaustive search for module maps
61 /// within the subdirectories of this directory.
62 unsigned SearchedAllModuleMaps : 1;
65 /// DirectoryLookup ctor - Note that this ctor *does not take ownership* of
67 DirectoryLookup(const DirectoryEntry *dir, SrcMgr::CharacteristicKind DT,
69 : DirCharacteristic(DT),
70 LookupType(isFramework ? LT_Framework : LT_NormalDir),
71 IsIndexHeaderMap(false), SearchedAllModuleMaps(false) {
75 /// DirectoryLookup ctor - Note that this ctor *does not take ownership* of
77 DirectoryLookup(const HeaderMap *map, SrcMgr::CharacteristicKind DT,
78 bool isIndexHeaderMap)
79 : DirCharacteristic(DT), LookupType(LT_HeaderMap),
80 IsIndexHeaderMap(isIndexHeaderMap), SearchedAllModuleMaps(false) {
84 /// getLookupType - Return the kind of directory lookup that this is: either a
85 /// normal directory, a framework path, or a HeaderMap.
86 LookupType_t getLookupType() const { return (LookupType_t)LookupType; }
88 /// getName - Return the directory or filename corresponding to this lookup
90 const char *getName() const;
92 /// getDir - Return the directory that this entry refers to.
94 const DirectoryEntry *getDir() const { return isNormalDir() ? u.Dir : 0; }
96 /// getFrameworkDir - Return the directory that this framework refers to.
98 const DirectoryEntry *getFrameworkDir() const {
99 return isFramework() ? u.Dir : 0;
102 /// getHeaderMap - Return the directory that this entry refers to.
104 const HeaderMap *getHeaderMap() const { return isHeaderMap() ? u.Map : 0; }
106 /// isNormalDir - Return true if this is a normal directory, not a header map.
107 bool isNormalDir() const { return getLookupType() == LT_NormalDir; }
109 /// isFramework - True if this is a framework directory.
111 bool isFramework() const { return getLookupType() == LT_Framework; }
113 /// isHeaderMap - Return true if this is a header map, not a normal directory.
114 bool isHeaderMap() const { return getLookupType() == LT_HeaderMap; }
116 /// \brief Determine whether we have already searched this entire
117 /// directory for module maps.
118 bool haveSearchedAllModuleMaps() const { return SearchedAllModuleMaps; }
120 /// \brief Specify whether we have already searched all of the subdirectories
122 void setSearchedAllModuleMaps(bool SAMM) {
123 SearchedAllModuleMaps = SAMM;
126 /// DirCharacteristic - The type of directory this is, one of the DirType enum
128 SrcMgr::CharacteristicKind getDirCharacteristic() const {
129 return (SrcMgr::CharacteristicKind)DirCharacteristic;
132 /// \brief Whether this header map is building a framework or not.
133 bool isIndexHeaderMap() const {
134 return isHeaderMap() && IsIndexHeaderMap;
137 /// LookupFile - Lookup the specified file in this search path, returning it
138 /// if it exists or returning null if not.
140 /// \param Filename The file to look up relative to the search paths.
142 /// \param HS The header search instance to search with.
144 /// \param SearchPath If not NULL, will be set to the search path relative
145 /// to which the file was found.
147 /// \param RelativePath If not NULL, will be set to the path relative to
148 /// SearchPath at which the file was found. This only differs from the
149 /// Filename for framework includes.
151 /// \param SuggestedModule If non-null, and the file found is semantically
152 /// part of a known module, this will be set to the module that should
153 /// be imported instead of preprocessing/parsing the file found.
155 /// \param [out] InUserSpecifiedSystemFramework If the file is found,
156 /// set to true if the file is located in a framework that has been
157 /// user-specified to be treated as a system framework.
158 const FileEntry *LookupFile(StringRef Filename, HeaderSearch &HS,
159 SmallVectorImpl<char> *SearchPath,
160 SmallVectorImpl<char> *RelativePath,
161 Module **SuggestedModule,
162 bool &InUserSpecifiedSystemFramework) const;
165 const FileEntry *DoFrameworkLookup(
166 StringRef Filename, HeaderSearch &HS,
167 SmallVectorImpl<char> *SearchPath,
168 SmallVectorImpl<char> *RelativePath,
169 Module **SuggestedModule,
170 bool &InUserSpecifiedSystemHeader) const;
174 } // end namespace clang