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