HeaderMap.h revision 1eb4433ac451dc16f4133a88af2d002ac26c58ef
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}
20namespace clang {
21  class FileEntry;
22  class FileManager;
23  struct HMapBucket;
24  struct HMapHeader;
25
26/// This class represents an Apple concept known as a 'header map'.  To the
27/// #include file resolution process, it basically acts like a directory of
28/// symlinks to files.  Its advantages are that it is dense and more efficient
29/// to create and process than a directory of symlinks.
30class HeaderMap {
31  HeaderMap(const HeaderMap&); // DO NOT IMPLEMENT
32  void operator=(const HeaderMap&); // DO NOT IMPLEMENT
33
34  const llvm::MemoryBuffer *FileBuffer;
35  bool NeedsBSwap;
36
37  HeaderMap(const llvm::MemoryBuffer *File, bool BSwap)
38    : FileBuffer(File), NeedsBSwap(BSwap) {
39  }
40public:
41  ~HeaderMap();
42
43  /// HeaderMap::Create - This attempts to load the specified file as a header
44  /// map.  If it doesn't look like a HeaderMap, it gives up and returns null.
45  static const HeaderMap *Create(const FileEntry *FE);
46
47  /// LookupFile - Check to see if the specified relative filename is located in
48  /// this HeaderMap.  If so, open it and return its FileEntry.
49  const FileEntry *LookupFile(const char *FilenameStart,const char *FilenameEnd,
50                              FileManager &FM) const;
51
52  /// getFileName - Return the filename of the headermap.
53  const char *getFileName() const;
54
55  /// dump - Print the contents of this headermap to stderr.
56  void dump() const;
57
58private:
59  unsigned getEndianAdjustedWord(unsigned X) const;
60  const HMapHeader &getHeader() const;
61  HMapBucket getBucket(unsigned BucketNo) const;
62  const char *getString(unsigned StrTabIdx) const;
63};
64
65} // end namespace clang.
66
67#endif
68