DirectoryLookup.h revision 651f13cea278ec967336033dd032faef0e9fc2ec
11320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci//===--- DirectoryLookup.h - Info for searching for headers -----*- C++ -*-===// 21320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// 31320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// The LLVM Compiler Infrastructure 41320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// 51320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// This file is distributed under the University of Illinois Open Source 61320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// License. See LICENSE.TXT for details. 71320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// 81320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci//===----------------------------------------------------------------------===// 91320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// 101320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// This file defines the DirectoryLookup interface. 111320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// 121320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci//===----------------------------------------------------------------------===// 131320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 141320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#ifndef LLVM_CLANG_LEX_DIRECTORYLOOKUP_H 151320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#define LLVM_CLANG_LEX_DIRECTORYLOOKUP_H 161320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 171320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "clang/Basic/LLVM.h" 181320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "clang/Basic/SourceManager.h" 191320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "clang/Lex/ModuleMap.h" 201320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 211320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccinamespace clang { 221320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciclass HeaderMap; 231320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciclass DirectoryEntry; 241320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciclass FileEntry; 251320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciclass HeaderSearch; 261320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciclass Module; 271320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 281320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci/// DirectoryLookup - This class represents one entry in the search list that 291320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci/// specifies the search order for directories in \#include directives. It 301320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci/// represents either a directory, a framework, or a headermap. 311320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci/// 321320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciclass DirectoryLookup { 331320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccipublic: 341320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci enum LookupType_t { 351320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci LT_NormalDir, 361320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci LT_Framework, 371320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci LT_HeaderMap 381320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci }; 391320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciprivate: 401320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci union { // This union is discriminated by isHeaderMap. 411320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci /// Dir - This is the actual directory that we're referring to for a normal 421320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci /// 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 /// \brief Whether this is a header map used when building a framework. 59 unsigned IsIndexHeaderMap : 1; 60 61 /// \brief Whether we've performed an exhaustive search for module maps 62 /// within the subdirectories of this directory. 63 unsigned SearchedAllModuleMaps : 1; 64 65public: 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 const char *getName() const; 92 93 /// getDir - Return the directory that this entry refers to. 94 /// 95 const DirectoryEntry *getDir() const { return isNormalDir() ? u.Dir : 0; } 96 97 /// getFrameworkDir - Return the directory that this framework refers to. 98 /// 99 const DirectoryEntry *getFrameworkDir() const { 100 return isFramework() ? u.Dir : 0; 101 } 102 103 /// getHeaderMap - Return the directory that this entry refers to. 104 /// 105 const HeaderMap *getHeaderMap() const { return isHeaderMap() ? u.Map : 0; } 106 107 /// isNormalDir - Return true if this is a normal directory, not a header map. 108 bool isNormalDir() const { return getLookupType() == LT_NormalDir; } 109 110 /// isFramework - True if this is a framework directory. 111 /// 112 bool isFramework() const { return getLookupType() == LT_Framework; } 113 114 /// isHeaderMap - Return true if this is a header map, not a normal directory. 115 bool isHeaderMap() const { return getLookupType() == LT_HeaderMap; } 116 117 /// \brief Determine whether we have already searched this entire 118 /// directory for module maps. 119 bool haveSearchedAllModuleMaps() const { return SearchedAllModuleMaps; } 120 121 /// \brief Specify whether we have already searched all of the subdirectories 122 /// for module maps. 123 void setSearchedAllModuleMaps(bool SAMM) { 124 SearchedAllModuleMaps = SAMM; 125 } 126 127 /// DirCharacteristic - The type of directory this is, one of the DirType enum 128 /// values. 129 SrcMgr::CharacteristicKind getDirCharacteristic() const { 130 return (SrcMgr::CharacteristicKind)DirCharacteristic; 131 } 132 133 /// \brief Whether this describes a system header directory. 134 bool isSystemHeaderDirectory() const { 135 return getDirCharacteristic() != SrcMgr::C_User; 136 } 137 138 /// \brief Whether this header map is building a framework or not. 139 bool isIndexHeaderMap() const { 140 return isHeaderMap() && IsIndexHeaderMap; 141 } 142 143 /// LookupFile - Lookup the specified file in this search path, returning it 144 /// if it exists or returning null if not. 145 /// 146 /// \param Filename The file to look up relative to the search paths. 147 /// 148 /// \param HS The header search instance to search with. 149 /// 150 /// \param SearchPath If not NULL, will be set to the search path relative 151 /// to which the file was found. 152 /// 153 /// \param RelativePath If not NULL, will be set to the path relative to 154 /// SearchPath at which the file was found. This only differs from the 155 /// Filename for framework includes. 156 /// 157 /// \param SuggestedModule If non-null, and the file found is semantically 158 /// part of a known module, this will be set to the module that should 159 /// be imported instead of preprocessing/parsing the file found. 160 /// 161 /// \param [out] InUserSpecifiedSystemFramework If the file is found, 162 /// set to true if the file is located in a framework that has been 163 /// user-specified to be treated as a system framework. 164 /// 165 /// \param [out] MappedName if this is a headermap which maps the filename to 166 /// a framework include ("Foo.h" -> "Foo/Foo.h"), set the new name to this 167 /// vector and point Filename to it. 168 const FileEntry *LookupFile(StringRef &Filename, HeaderSearch &HS, 169 SmallVectorImpl<char> *SearchPath, 170 SmallVectorImpl<char> *RelativePath, 171 ModuleMap::KnownHeader *SuggestedModule, 172 bool &InUserSpecifiedSystemFramework, 173 bool &HasBeenMapped, 174 SmallVectorImpl<char> &MappedName) const; 175 176private: 177 const FileEntry *DoFrameworkLookup( 178 StringRef Filename, HeaderSearch &HS, 179 SmallVectorImpl<char> *SearchPath, 180 SmallVectorImpl<char> *RelativePath, 181 ModuleMap::KnownHeader *SuggestedModule, 182 bool &InUserSpecifiedSystemHeader) const; 183 184}; 185 186} // end namespace clang 187 188#endif 189