HeaderMap.h revision 7412494982c8b50c90961302c3a718633b2c3ab7
1//===--- HeaderMap.h - A file that acts like dir of symlinks ----*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9// 10// This file defines the HeaderMap interface. 11// 12//===----------------------------------------------------------------------===// 13 14#ifndef LLVM_CLANG_LEX_HEADERMAP_H 15#define LLVM_CLANG_LEX_HEADERMAP_H 16 17namespace llvm { 18 class MemoryBuffer; 19 class StringRef; 20 template <typename T> class SmallVectorImpl; 21} 22namespace clang { 23 class FileEntry; 24 class FileManager; 25 struct HMapBucket; 26 struct HMapHeader; 27 28/// This class represents an Apple concept known as a 'header map'. To the 29/// #include file resolution process, it basically acts like a directory of 30/// symlinks to files. Its advantages are that it is dense and more efficient 31/// to create and process than a directory of symlinks. 32class HeaderMap { 33 HeaderMap(const HeaderMap&); // DO NOT IMPLEMENT 34 void operator=(const HeaderMap&); // DO NOT IMPLEMENT 35 36 const llvm::MemoryBuffer *FileBuffer; 37 bool NeedsBSwap; 38 39 HeaderMap(const llvm::MemoryBuffer *File, bool BSwap) 40 : FileBuffer(File), NeedsBSwap(BSwap) { 41 } 42public: 43 ~HeaderMap(); 44 45 /// HeaderMap::Create - This attempts to load the specified file as a header 46 /// map. If it doesn't look like a HeaderMap, it gives up and returns null. 47 static const HeaderMap *Create(const FileEntry *FE, FileManager &FM); 48 49 /// LookupFile - Check to see if the specified relative filename is located in 50 /// this HeaderMap. If so, open it and return its FileEntry. 51 /// If RawPath is not NULL and the file is found, RawPath will be set to the 52 /// raw path at which the file was found in the file system. For example, 53 /// for a search path ".." and a filename "../file.h" this would be 54 /// "../../file.h". 55 const FileEntry *LookupFile(llvm::StringRef Filename, FileManager &FM) const; 56 57 /// getFileName - Return the filename of the headermap. 58 const char *getFileName() const; 59 60 /// dump - Print the contents of this headermap to stderr. 61 void dump() const; 62 63private: 64 unsigned getEndianAdjustedWord(unsigned X) const; 65 const HMapHeader &getHeader() const; 66 HMapBucket getBucket(unsigned BucketNo) const; 67 const char *getString(unsigned StrTabIdx) const; 68}; 69 70} // end namespace clang. 71 72#endif 73