clang API Documentation
00001 //===--- DirectoryLookup.h - Info for searching for headers -----*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file defines the DirectoryLookup interface. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 #ifndef LLVM_CLANG_LEX_DIRECTORYLOOKUP_H 00015 #define LLVM_CLANG_LEX_DIRECTORYLOOKUP_H 00016 00017 #include "clang/Basic/LLVM.h" 00018 #include "clang/Basic/SourceManager.h" 00019 00020 namespace clang { 00021 class HeaderMap; 00022 class DirectoryEntry; 00023 class FileEntry; 00024 class HeaderSearch; 00025 class Module; 00026 00027 /// DirectoryLookup - This class represents one entry in the search list that 00028 /// specifies the search order for directories in #include directives. It 00029 /// represents either a directory, a framework, or a headermap. 00030 /// 00031 class DirectoryLookup { 00032 public: 00033 enum LookupType_t { 00034 LT_NormalDir, 00035 LT_Framework, 00036 LT_HeaderMap 00037 }; 00038 private: 00039 union { // This union is discriminated by isHeaderMap. 00040 /// Dir - This is the actual directory that we're referring to for a normal 00041 /// directory or a framework. 00042 const DirectoryEntry *Dir; 00043 00044 /// Map - This is the HeaderMap if this is a headermap lookup. 00045 /// 00046 const HeaderMap *Map; 00047 } u; 00048 00049 /// DirCharacteristic - The type of directory this is: this is an instance of 00050 /// SrcMgr::CharacteristicKind. 00051 unsigned DirCharacteristic : 2; 00052 00053 /// UserSupplied - True if this is a user-supplied directory. 00054 /// 00055 bool UserSupplied : 1; 00056 00057 /// LookupType - This indicates whether this DirectoryLookup object is a 00058 /// normal directory, a framework, or a headermap. 00059 unsigned LookupType : 2; 00060 00061 /// \brief Whether this is a header map used when building a framework. 00062 unsigned IsIndexHeaderMap : 1; 00063 00064 public: 00065 /// DirectoryLookup ctor - Note that this ctor *does not take ownership* of 00066 /// 'dir'. 00067 DirectoryLookup(const DirectoryEntry *dir, SrcMgr::CharacteristicKind DT, 00068 bool isUser, bool isFramework) 00069 : DirCharacteristic(DT), UserSupplied(isUser), 00070 LookupType(isFramework ? LT_Framework : LT_NormalDir), 00071 IsIndexHeaderMap(false) { 00072 u.Dir = dir; 00073 } 00074 00075 /// DirectoryLookup ctor - Note that this ctor *does not take ownership* of 00076 /// 'map'. 00077 DirectoryLookup(const HeaderMap *map, SrcMgr::CharacteristicKind DT, 00078 bool isUser, bool isIndexHeaderMap) 00079 : DirCharacteristic(DT), UserSupplied(isUser), LookupType(LT_HeaderMap), 00080 IsIndexHeaderMap(isIndexHeaderMap) { 00081 u.Map = map; 00082 } 00083 00084 /// getLookupType - Return the kind of directory lookup that this is: either a 00085 /// normal directory, a framework path, or a HeaderMap. 00086 LookupType_t getLookupType() const { return (LookupType_t)LookupType; } 00087 00088 /// getName - Return the directory or filename corresponding to this lookup 00089 /// object. 00090 const char *getName() const; 00091 00092 /// getDir - Return the directory that this entry refers to. 00093 /// 00094 const DirectoryEntry *getDir() const { return isNormalDir() ? u.Dir : 0; } 00095 00096 /// getFrameworkDir - Return the directory that this framework refers to. 00097 /// 00098 const DirectoryEntry *getFrameworkDir() const { 00099 return isFramework() ? u.Dir : 0; 00100 } 00101 00102 /// getHeaderMap - Return the directory that this entry refers to. 00103 /// 00104 const HeaderMap *getHeaderMap() const { return isHeaderMap() ? u.Map : 0; } 00105 00106 /// isNormalDir - Return true if this is a normal directory, not a header map. 00107 bool isNormalDir() const { return getLookupType() == LT_NormalDir; } 00108 00109 /// isFramework - True if this is a framework directory. 00110 /// 00111 bool isFramework() const { return getLookupType() == LT_Framework; } 00112 00113 /// isHeaderMap - Return true if this is a header map, not a normal directory. 00114 bool isHeaderMap() const { return getLookupType() == LT_HeaderMap; } 00115 00116 /// DirCharacteristic - The type of directory this is, one of the DirType enum 00117 /// values. 00118 SrcMgr::CharacteristicKind getDirCharacteristic() const { 00119 return (SrcMgr::CharacteristicKind)DirCharacteristic; 00120 } 00121 00122 /// isUserSupplied - True if this is a user-supplied directory. 00123 /// 00124 bool isUserSupplied() const { return UserSupplied; } 00125 00126 /// \brief Whether this header map is building a framework or not. 00127 bool isIndexHeaderMap() const { 00128 return isHeaderMap() && IsIndexHeaderMap; 00129 } 00130 00131 /// LookupFile - Lookup the specified file in this search path, returning it 00132 /// if it exists or returning null if not. 00133 /// 00134 /// \param Filename The file to look up relative to the search paths. 00135 /// 00136 /// \param HS The header search instance to search with. 00137 /// 00138 /// \param SearchPath If not NULL, will be set to the search path relative 00139 /// to which the file was found. 00140 /// 00141 /// \param RelativePath If not NULL, will be set to the path relative to 00142 /// SearchPath at which the file was found. This only differs from the 00143 /// Filename for framework includes. 00144 /// 00145 /// \param SuggestedModule If non-null, and the file found is semantically 00146 /// part of a known module, this will be set to the module that should 00147 /// be imported instead of preprocessing/parsing the file found. 00148 /// 00149 /// \param InUserSpecifiedSystemHeader [out] If the file is found, set to true 00150 /// if the file is located in a framework that has been user-specified to be 00151 /// treated as a system framework. 00152 const FileEntry *LookupFile(StringRef Filename, HeaderSearch &HS, 00153 SmallVectorImpl<char> *SearchPath, 00154 SmallVectorImpl<char> *RelativePath, 00155 Module **SuggestedModule, 00156 bool &InUserSpecifiedSystemHeader) const; 00157 00158 private: 00159 const FileEntry *DoFrameworkLookup( 00160 StringRef Filename, HeaderSearch &HS, 00161 SmallVectorImpl<char> *SearchPath, 00162 SmallVectorImpl<char> *RelativePath, 00163 Module **SuggestedModule, 00164 bool &InUserSpecifiedSystemHeader) const; 00165 00166 }; 00167 00168 } // end namespace clang 00169 00170 #endif