clang  12.0.0git
HeaderMap.h
Go to the documentation of this file.
1 //===--- HeaderMap.h - A file that acts like dir of symlinks ----*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines the HeaderMap interface.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_CLANG_LEX_HEADERMAP_H
14 #define LLVM_CLANG_LEX_HEADERMAP_H
15 
17 #include "clang/Basic/LLVM.h"
18 #include "llvm/ADT/Optional.h"
19 #include "llvm/Support/Compiler.h"
20 #include "llvm/Support/MemoryBuffer.h"
21 #include <memory>
22 
23 namespace clang {
24 
25 struct HMapBucket;
26 struct HMapHeader;
27 
28 /// Implementation for \a HeaderMap that doesn't depend on \a FileManager.
30  std::unique_ptr<const llvm::MemoryBuffer> FileBuffer;
31  bool NeedsBSwap;
32 
33 public:
34  HeaderMapImpl(std::unique_ptr<const llvm::MemoryBuffer> File, bool NeedsBSwap)
35  : FileBuffer(std::move(File)), NeedsBSwap(NeedsBSwap) {}
36 
37  // Check for a valid header and extract the byte swap.
38  static bool checkHeader(const llvm::MemoryBuffer &File, bool &NeedsByteSwap);
39 
40  /// If the specified relative filename is located in this HeaderMap return
41  /// the filename it is mapped to, otherwise return an empty StringRef.
42  StringRef lookupFilename(StringRef Filename,
43  SmallVectorImpl<char> &DestPath) const;
44 
45  /// Return the filename of the headermap.
46  StringRef getFileName() const;
47 
48  /// Print the contents of this headermap to stderr.
49  void dump() const;
50 
51 private:
52  unsigned getEndianAdjustedWord(unsigned X) const;
53  const HMapHeader &getHeader() const;
54  HMapBucket getBucket(unsigned BucketNo) const;
55 
56  /// Look up the specified string in the string table. If the string index is
57  /// not valid, return None.
58  Optional<StringRef> getString(unsigned StrTabIdx) const;
59 };
60 
61 /// This class represents an Apple concept known as a 'header map'. To the
62 /// \#include file resolution process, it basically acts like a directory of
63 /// symlinks to files. Its advantages are that it is dense and more efficient
64 /// to create and process than a directory of symlinks.
65 class HeaderMap : private HeaderMapImpl {
66  HeaderMap(std::unique_ptr<const llvm::MemoryBuffer> File, bool BSwap)
67  : HeaderMapImpl(std::move(File), BSwap) {}
68 
69 public:
70  /// This attempts to load the specified file as a header map. If it doesn't
71  /// look like a HeaderMap, it gives up and returns null.
72  static std::unique_ptr<HeaderMap> Create(const FileEntry *FE,
73  FileManager &FM);
74 
75  /// Check to see if the specified relative filename is located in this
76  /// HeaderMap. If so, open it and return its FileEntry. If RawPath is not
77  /// NULL and the file is found, RawPath will be set to the raw path at which
78  /// the file was found in the file system. For example, for a search path
79  /// ".." and a filename "../file.h" this would be "../../file.h".
81 
84  using HeaderMapImpl::dump;
85 };
86 
87 } // end namespace clang.
88 
89 #endif
Implements support for file system lookup, file system caching, and directory search management.
Definition: FileManager.h:53
Defines the clang::FileManager interface and associated types.
static bool checkHeader(const llvm::MemoryBuffer &File, bool &NeedsByteSwap)
Definition: HeaderMap.cpp:65
Optional< FileEntryRef > LookupFile(StringRef Filename, FileManager &FM) const
Check to see if the specified relative filename is located in this HeaderMap.
Definition: HeaderMap.cpp:199
StringRef lookupFilename(StringRef Filename, SmallVectorImpl< char > &DestPath) const
If the specified relative filename is located in this HeaderMap return the filename it is mapped to,...
Definition: HeaderMap.cpp:210
This class represents an Apple concept known as a 'header map'.
Definition: HeaderMap.h:65
Definition: Format.h:2835
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
void dump() const
Print the contents of this headermap to stderr.
Definition: HeaderMap.cpp:172
HeaderMapImpl(std::unique_ptr< const llvm::MemoryBuffer > File, bool NeedsBSwap)
Definition: HeaderMap.h:34
StringRef Filename
Definition: Format.cpp:2070
Cached information about one file (either on disk or in the virtual file system).
Definition: FileEntry.h:276
Dataflow Directional Tag Classes.
Implementation for HeaderMap that doesn't depend on FileManager.
Definition: HeaderMap.h:29
X
Add a minimal nested name specifier fixit hint to allow lookup of a tag name from an outer enclosing ...
Definition: SemaDecl.cpp:15282
StringRef getFileName() const
Return the filename of the headermap.
Definition: HeaderMap.cpp:109
static std::unique_ptr< HeaderMap > Create(const FileEntry *FE, FileManager &FM)
This attempts to load the specified file as a header map.
Definition: HeaderMap.cpp:50