1193326Sed//===--- HeaderMap.h - A file that acts like dir of symlinks ----*- C++ -*-===//
2193326Sed//
3193326Sed//                     The LLVM Compiler Infrastructure
4193326Sed//
5193326Sed// This file is distributed under the University of Illinois Open Source
6193326Sed// License. See LICENSE.TXT for details.
7193326Sed//
8193326Sed//===----------------------------------------------------------------------===//
9193326Sed//
10193326Sed// This file defines the HeaderMap interface.
11193326Sed//
12193326Sed//===----------------------------------------------------------------------===//
13193326Sed
14193326Sed#ifndef LLVM_CLANG_LEX_HEADERMAP_H
15193326Sed#define LLVM_CLANG_LEX_HEADERMAP_H
16193326Sed
17226633Sdim#include "clang/Basic/LLVM.h"
18243830Sdim#include "llvm/Support/Compiler.h"
19226633Sdim
20193326Sednamespace llvm {
21193326Sed  class MemoryBuffer;
22193326Sed}
23193326Sednamespace clang {
24193326Sed  class FileEntry;
25193326Sed  class FileManager;
26193326Sed  struct HMapBucket;
27193326Sed  struct HMapHeader;
28193326Sed
29193326Sed/// This class represents an Apple concept known as a 'header map'.  To the
30239462Sdim/// \#include file resolution process, it basically acts like a directory of
31193326Sed/// symlinks to files.  Its advantages are that it is dense and more efficient
32193326Sed/// to create and process than a directory of symlinks.
33193326Sedclass HeaderMap {
34243830Sdim  HeaderMap(const HeaderMap &) LLVM_DELETED_FUNCTION;
35243830Sdim  void operator=(const HeaderMap &) LLVM_DELETED_FUNCTION;
36198092Srdivacky
37193326Sed  const llvm::MemoryBuffer *FileBuffer;
38193326Sed  bool NeedsBSwap;
39198092Srdivacky
40193326Sed  HeaderMap(const llvm::MemoryBuffer *File, bool BSwap)
41193326Sed    : FileBuffer(File), NeedsBSwap(BSwap) {
42193326Sed  }
43193326Sedpublic:
44193326Sed  ~HeaderMap();
45198092Srdivacky
46193326Sed  /// HeaderMap::Create - This attempts to load the specified file as a header
47193326Sed  /// map.  If it doesn't look like a HeaderMap, it gives up and returns null.
48218893Sdim  static const HeaderMap *Create(const FileEntry *FE, FileManager &FM);
49198092Srdivacky
50193326Sed  /// LookupFile - Check to see if the specified relative filename is located in
51193326Sed  /// this HeaderMap.  If so, open it and return its FileEntry.
52221345Sdim  /// If RawPath is not NULL and the file is found, RawPath will be set to the
53221345Sdim  /// raw path at which the file was found in the file system. For example,
54221345Sdim  /// for a search path ".." and a filename "../file.h" this would be
55221345Sdim  /// "../../file.h".
56226633Sdim  const FileEntry *LookupFile(StringRef Filename, FileManager &FM) const;
57198092Srdivacky
58193326Sed  /// getFileName - Return the filename of the headermap.
59193326Sed  const char *getFileName() const;
60198092Srdivacky
61193326Sed  /// dump - Print the contents of this headermap to stderr.
62193326Sed  void dump() const;
63198092Srdivacky
64193326Sedprivate:
65193326Sed  unsigned getEndianAdjustedWord(unsigned X) const;
66193326Sed  const HMapHeader &getHeader() const;
67193326Sed  HMapBucket getBucket(unsigned BucketNo) const;
68193326Sed  const char *getString(unsigned StrTabIdx) const;
69193326Sed};
70193326Sed
71193326Sed} // end namespace clang.
72193326Sed
73193326Sed#endif
74