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 17 #include "clang/Basic/LLVM.h" 18 #include "llvm/Support/Compiler.h" 19 20 namespace llvm { 21 class MemoryBuffer; 22 } 23 namespace clang { 24 class FileEntry; 25 class FileManager; 26 struct HMapBucket; 27 struct HMapHeader; 28 29 /// This class represents an Apple concept known as a 'header map'. To the 30 /// \#include file resolution process, it basically acts like a directory of 31 /// symlinks to files. Its advantages are that it is dense and more efficient 32 /// to create and process than a directory of symlinks. 33 class HeaderMap { 34 HeaderMap(const HeaderMap &) LLVM_DELETED_FUNCTION; 35 void operator=(const HeaderMap &) LLVM_DELETED_FUNCTION; 36 37 const llvm::MemoryBuffer *FileBuffer; 38 bool NeedsBSwap; 39 HeaderMap(const llvm::MemoryBuffer * File,bool BSwap)40 HeaderMap(const llvm::MemoryBuffer *File, bool BSwap) 41 : FileBuffer(File), NeedsBSwap(BSwap) { 42 } 43 public: 44 ~HeaderMap(); 45 46 /// HeaderMap::Create - This attempts to load the specified file as a header 47 /// map. If it doesn't look like a HeaderMap, it gives up and returns null. 48 static const HeaderMap *Create(const FileEntry *FE, FileManager &FM); 49 50 /// LookupFile - Check to see if the specified relative filename is located in 51 /// this HeaderMap. If so, open it and return its FileEntry. 52 /// If RawPath is not NULL and the file is found, RawPath will be set to the 53 /// raw path at which the file was found in the file system. For example, 54 /// for a search path ".." and a filename "../file.h" this would be 55 /// "../../file.h". 56 const FileEntry *LookupFile(StringRef Filename, FileManager &FM) const; 57 58 /// If the specified relative filename is located in this HeaderMap return 59 /// the filename it is mapped to, otherwise return an empty StringRef. 60 StringRef lookupFilename(StringRef Filename, 61 SmallVectorImpl<char> &DestPath) const; 62 63 /// getFileName - Return the filename of the headermap. 64 const char *getFileName() const; 65 66 /// dump - Print the contents of this headermap to stderr. 67 void dump() const; 68 69 private: 70 unsigned getEndianAdjustedWord(unsigned X) const; 71 const HMapHeader &getHeader() const; 72 HMapBucket getBucket(unsigned BucketNo) const; 73 const char *getString(unsigned StrTabIdx) const; 74 }; 75 76 } // end namespace clang. 77 78 #endif 79