clang API Documentation

HeaderMap.h
Go to the documentation of this file.
00001 //===--- HeaderMap.h - A file that acts like dir of symlinks ----*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file defines the HeaderMap interface.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #ifndef LLVM_CLANG_LEX_HEADERMAP_H
00015 #define LLVM_CLANG_LEX_HEADERMAP_H
00016 
00017 #include "clang/Basic/LLVM.h"
00018 #include "llvm/Support/Compiler.h"
00019 
00020 #include <memory>
00021 
00022 namespace llvm {
00023   class MemoryBuffer;
00024 }
00025 namespace clang {
00026   class FileEntry;
00027   class FileManager;
00028   struct HMapBucket;
00029   struct HMapHeader;
00030 
00031 /// This class represents an Apple concept known as a 'header map'.  To the
00032 /// \#include file resolution process, it basically acts like a directory of
00033 /// symlinks to files.  Its advantages are that it is dense and more efficient
00034 /// to create and process than a directory of symlinks.
00035 class HeaderMap {
00036   HeaderMap(const HeaderMap &) LLVM_DELETED_FUNCTION;
00037   void operator=(const HeaderMap &) LLVM_DELETED_FUNCTION;
00038 
00039   std::unique_ptr<const llvm::MemoryBuffer> FileBuffer;
00040   bool NeedsBSwap;
00041 
00042   HeaderMap(std::unique_ptr<const llvm::MemoryBuffer> File, bool BSwap)
00043       : FileBuffer(std::move(File)), NeedsBSwap(BSwap) {}
00044 public:
00045   /// HeaderMap::Create - This attempts to load the specified file as a header
00046   /// map.  If it doesn't look like a HeaderMap, it gives up and returns null.
00047   static const HeaderMap *Create(const FileEntry *FE, FileManager &FM);
00048 
00049   /// LookupFile - Check to see if the specified relative filename is located in
00050   /// this HeaderMap.  If so, open it and return its FileEntry.
00051   /// If RawPath is not NULL and the file is found, RawPath will be set to the
00052   /// raw path at which the file was found in the file system. For example,
00053   /// for a search path ".." and a filename "../file.h" this would be
00054   /// "../../file.h".
00055   const FileEntry *LookupFile(StringRef Filename, FileManager &FM) const;
00056 
00057   /// If the specified relative filename is located in this HeaderMap return
00058   /// the filename it is mapped to, otherwise return an empty StringRef.
00059   StringRef lookupFilename(StringRef Filename,
00060                            SmallVectorImpl<char> &DestPath) const;
00061 
00062   /// getFileName - Return the filename of the headermap.
00063   const char *getFileName() const;
00064 
00065   /// dump - Print the contents of this headermap to stderr.
00066   void dump() const;
00067 
00068 private:
00069   unsigned getEndianAdjustedWord(unsigned X) const;
00070   const HMapHeader &getHeader() const;
00071   HMapBucket getBucket(unsigned BucketNo) const;
00072   const char *getString(unsigned StrTabIdx) const;
00073 };
00074 
00075 } // end namespace clang.
00076 
00077 #endif