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