DirectoryLookup.h revision 3af66a9335966e9114e660cf7aafbb9272190ec2
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 HeaderSearch; 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 /// 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 const char *getName() const; 86 87 /// getDir - Return the directory that this entry refers to. 88 /// 89 const DirectoryEntry *getDir() const { return isNormalDir() ? u.Dir : 0; } 90 91 /// getFrameworkDir - Return the directory that this framework refers to. 92 /// 93 const DirectoryEntry *getFrameworkDir() const { 94 return isFramework() ? u.Dir : 0; 95 } 96 97 /// getHeaderMap - Return the directory that this entry refers to. 98 /// 99 const HeaderMap *getHeaderMap() const { return isHeaderMap() ? u.Map : 0; } 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 /// LookupFile - Lookup the specified file in this search path, returning it 121 /// if it exists or returning null if not. 122 const FileEntry *LookupFile(const char *FilenameStart, 123 const char *FilenameEnd, HeaderSearch &HS) const; 124 125private: 126 const FileEntry *DoFrameworkLookup(const char *FilenameStart, 127 const char *FilenameEnd, 128 HeaderSearch &HS) const; 129 130}; 131 132} // end namespace clang 133 134#endif 135