DirectoryLookup.h revision df772336655fd84ee2c0ce514c93cef0b29d60d4
1//===--- DirectoryLookup.h - Info for searching for headers -----*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file was developed by Chris Lattner and is distributed under 6// the University of Illinois Open Source 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 17namespace clang { 18class HeaderMap; 19class DirectoryEntry; 20class FileEntry; 21class FileManager; 22 23/// DirectoryLookup - This class represents one entry in the search list that 24/// specifies the search order for directories in #include directives. It 25/// represents either a directory, a framework, or a headermap. 26/// 27class DirectoryLookup { 28public: 29 enum DirType { 30 NormalHeaderDir, 31 SystemHeaderDir, 32 ExternCSystemHeaderDir 33 }; 34 35 enum LookupType_t { 36 LT_NormalDir, 37 LT_Framework, 38 LT_HeaderMap 39 }; 40private: 41 union { // This union is discriminated by isHeaderMap. 42 /// Dir - This is the actual directory that we're referring to for a normal 43 /// directory or a framework. 44 const DirectoryEntry *Dir; 45 46 /// Map - This is the HeaderMap if this is a headermap lookup. 47 /// 48 const HeaderMap *Map; 49 } u; 50 51 /// DirCharacteristic - The type of directory this is, one of the DirType enum 52 /// values. 53 DirType DirCharacteristic : 2; 54 55 /// UserSupplied - True if this is a user-supplied directory. 56 /// 57 bool UserSupplied : 1; 58 59 /// LookupType - This indicates whether this DirectoryLookup object is a 60 /// normal directory, a framework, or a headermap. 61 unsigned LookupType : 2; 62public: 63 /// DirectoryLookup ctor - Note that this ctor *does not take ownership* of 64 /// 'dir'. 65 DirectoryLookup(const DirectoryEntry *dir, DirType DT, bool isUser, 66 bool isFramework) 67 : DirCharacteristic(DT), UserSupplied(isUser), 68 LookupType(isFramework ? LT_Framework : LT_NormalDir) { 69 u.Dir = dir; 70 } 71 72 /// DirectoryLookup ctor - Note that this ctor *does not take ownership* of 73 /// 'map'. 74 DirectoryLookup(const HeaderMap *map, DirType DT, bool isUser) 75 : DirCharacteristic(DT), UserSupplied(isUser), LookupType(LT_HeaderMap) { 76 u.Map = map; 77 } 78 79 /// LookupFile - Lookup the specified file in this search path, returning it 80 /// if it exists or returning null if not. 81 const FileEntry *LookupFile(const char *FilenameStart, 82 const char *FilenameEnd, 83 FileManager &FileMgr) const; 84 85 /// getDir - Return the directory that this entry refers to. 86 /// 87 const DirectoryEntry *getDir() const { return isNormalDir() ? u.Dir : 0; } 88 89 /// getFrameworkDir - Return the directory that this framework refers to. 90 /// 91 const DirectoryEntry *getFrameworkDir() const { 92 return isFramework() ? u.Dir : 0; 93 } 94 95 /// getHeaderMap - Return the directory that this entry refers to. 96 /// 97 const HeaderMap *getHeaderMap() const { return isHeaderMap() ? u.Map : 0; } 98 99 LookupType_t getLookupType() const { return (LookupType_t)LookupType; } 100 101 /// isNormalDir - Return true if this is a normal directory, not a header map. 102 bool isNormalDir() const { return getLookupType() == LT_NormalDir; } 103 104 /// isFramework - True if this is a framework directory. 105 /// 106 bool isFramework() const { return getLookupType() == LT_Framework; } 107 108 /// isHeaderMap - Return true if this is a header map, not a normal directory. 109 bool isHeaderMap() const { return getLookupType() == LT_HeaderMap; } 110 111 /// DirCharacteristic - The type of directory this is, one of the DirType enum 112 /// values. 113 DirType getDirCharacteristic() const { return DirCharacteristic; } 114 115 /// isUserSupplied - True if this is a user-supplied directory. 116 /// 117 bool isUserSupplied() const { return UserSupplied; } 118 119}; 120 121} // end namespace clang 122 123#endif 124