clang  9.0.0svn
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 
16 #include "clang/Basic/LLVM.h"
17 #include "llvm/ADT/Optional.h"
18 #include "llvm/Support/Compiler.h"
19 #include "llvm/Support/MemoryBuffer.h"
20 #include <memory>
21 
22 namespace clang {
23 
24 class FileEntry;
25 class FileManager;
26 struct HMapBucket;
27 struct HMapHeader;
28 
29 /// Implementation for \a HeaderMap that doesn't depend on \a FileManager.
31  std::unique_ptr<const llvm::MemoryBuffer> FileBuffer;
32  bool NeedsBSwap;
33 
34 public:
35  HeaderMapImpl(std::unique_ptr<const llvm::MemoryBuffer> File, bool NeedsBSwap)
36  : FileBuffer(std::move(File)), NeedsBSwap(NeedsBSwap) {}
37 
38  // Check for a valid header and extract the byte swap.
39  static bool checkHeader(const llvm::MemoryBuffer &File, bool &NeedsByteSwap);
40 
41  /// If the specified relative filename is located in this HeaderMap return
42  /// the filename it is mapped to, otherwise return an empty StringRef.
43  StringRef lookupFilename(StringRef Filename,
44  SmallVectorImpl<char> &DestPath) const;
45 
46  /// Return the filename of the headermap.
47  StringRef getFileName() const;
48 
49  /// Print the contents of this headermap to stderr.
50  void dump() const;
51 
52 private:
53  unsigned getEndianAdjustedWord(unsigned X) const;
54  const HMapHeader &getHeader() const;
55  HMapBucket getBucket(unsigned BucketNo) const;
56 
57  /// Look up the specified string in the string table. If the string index is
58  /// not valid, return None.
59  Optional<StringRef> getString(unsigned StrTabIdx) const;
60 };
61 
62 /// This class represents an Apple concept known as a 'header map'. To the
63 /// \#include file resolution process, it basically acts like a directory of
64 /// symlinks to files. Its advantages are that it is dense and more efficient
65 /// to create and process than a directory of symlinks.
66 class HeaderMap : private HeaderMapImpl {
67  HeaderMap(std::unique_ptr<const llvm::MemoryBuffer> File, bool BSwap)
68  : HeaderMapImpl(std::move(File), BSwap) {}
69 
70 public:
71  /// This attempts to load the specified file as a header map. If it doesn't
72  /// look like a HeaderMap, it gives up and returns null.
73  static std::unique_ptr<HeaderMap> Create(const FileEntry *FE,
74  FileManager &FM);
75 
76  /// Check to see if the specified relative filename is located in this
77  /// HeaderMap. If so, open it and return its FileEntry. If RawPath is not
78  /// NULL and the file is found, RawPath will be set to the raw path at which
79  /// the file was found in the file system. For example, for a search path
80  /// ".." and a filename "../file.h" this would be "../../file.h".
81  const FileEntry *LookupFile(StringRef Filename, FileManager &FM) const;
82 
85  using HeaderMapImpl::dump;
86 };
87 
88 } // end namespace clang.
89 
90 #endif
Implements support for file system lookup, file system caching, and directory search management...
Definition: FileManager.h:116
static bool checkHeader(const llvm::MemoryBuffer &File, bool &NeedsByteSwap)
Definition: HeaderMap.cpp:65
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 &#39;header map&#39;.
Definition: HeaderMap.h:66
Definition: Format.h:2261
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:35
StringRef Filename
Definition: Format.cpp:1709
Cached information about one file (either on disk or in the virtual file system). ...
Definition: FileManager.h:59
Dataflow Directional Tag Classes.
Implementation for HeaderMap that doesn&#39;t depend on FileManager.
Definition: HeaderMap.h:30
X
Add a minimal nested name specifier fixit hint to allow lookup of a tag name from an outer enclosing ...
Definition: SemaDecl.cpp:14125
StringRef getFileName() const
Return the filename of the headermap.
Definition: HeaderMap.cpp:109
static OMPLinearClause * Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc, SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef< Expr *> VL, ArrayRef< Expr *> PL, ArrayRef< Expr *> IL, Expr *Step, Expr *CalcStep, Stmt *PreInit, Expr *PostUpdate)
Creates clause with a list of variables VL and a linear step Step.