clang
20.0.0git
include
clang
Lex
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/FileManager.h
"
17
#include "
clang/Basic/LLVM.h
"
18
#include "
clang/Lex/HeaderMapTypes.h
"
19
#include "llvm/ADT/StringMap.h"
20
#include "llvm/Support/Compiler.h"
21
#include "llvm/Support/MemoryBuffer.h"
22
#include <memory>
23
#include <optional>
24
25
namespace
clang
{
26
27
struct
HMapBucket;
28
struct
HMapHeader;
29
30
/// Implementation for \a HeaderMap that doesn't depend on \a FileManager.
31
class
HeaderMapImpl
{
32
std::unique_ptr<const llvm::MemoryBuffer> FileBuffer;
33
bool
NeedsBSwap;
34
mutable
llvm::StringMap<StringRef> ReverseMap;
35
36
public
:
37
HeaderMapImpl
(std::unique_ptr<const llvm::MemoryBuffer>
File
,
bool
NeedsBSwap)
38
: FileBuffer(
std
::move(
File
)), NeedsBSwap(NeedsBSwap) {}
39
40
// Check for a valid header and extract the byte swap.
41
static
bool
checkHeader
(
const
llvm::MemoryBuffer &
File
,
bool
&NeedsByteSwap);
42
43
// Make a call for every Key in the map.
44
template
<
typename
Func>
void
forEachKey
(
Func
Callback)
const
{
45
const
HMapHeader
&Hdr = getHeader();
46
unsigned
NumBuckets = getEndianAdjustedWord(Hdr.
NumBuckets
);
47
48
for
(
unsigned
Bucket = 0; Bucket < NumBuckets; ++Bucket) {
49
HMapBucket
B = getBucket(Bucket);
50
if
(B.
Key
!=
HMAP_EmptyBucketKey
)
51
if
(std::optional<StringRef> Key = getString(B.
Key
))
52
Callback(*Key);
53
}
54
}
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
/// Return the filename of the headermap.
62
StringRef
getFileName
()
const
;
63
64
/// Print the contents of this headermap to stderr.
65
void
dump
()
const
;
66
67
/// Return key for specifed path.
68
StringRef
reverseLookupFilename
(StringRef DestPath)
const
;
69
70
private
:
71
unsigned
getEndianAdjustedWord(
unsigned
X
)
const
;
72
const
HMapHeader
&getHeader()
const
;
73
HMapBucket
getBucket(
unsigned
BucketNo)
const
;
74
75
/// Look up the specified string in the string table. If the string index is
76
/// not valid, return std::nullopt.
77
std::optional<StringRef> getString(
unsigned
StrTabIdx)
const
;
78
};
79
80
/// This class represents an Apple concept known as a 'header map'. To the
81
/// \#include file resolution process, it basically acts like a directory of
82
/// symlinks to files. Its advantages are that it is dense and more efficient
83
/// to create and process than a directory of symlinks.
84
class
HeaderMap
:
private
HeaderMapImpl
{
85
HeaderMap
(std::unique_ptr<const llvm::MemoryBuffer>
File
,
bool
BSwap)
86
:
HeaderMapImpl
(std::move(
File
), BSwap) {}
87
88
public
:
89
/// This attempts to load the specified file as a header map. If it doesn't
90
/// look like a HeaderMap, it gives up and returns null.
91
static
std::unique_ptr<HeaderMap>
Create
(
FileEntryRef
FE,
FileManager
&FM);
92
93
using
HeaderMapImpl::dump
;
94
using
HeaderMapImpl::forEachKey
;
95
using
HeaderMapImpl::getFileName
;
96
using
HeaderMapImpl::lookupFilename
;
97
using
HeaderMapImpl::reverseLookupFilename
;
98
};
99
100
}
// end namespace clang.
101
102
#endif
FileManager.h
Defines the clang::FileManager interface and associated types.
Filename
StringRef Filename
Definition:
Format.cpp:3001
HeaderMapTypes.h
X
#define X(type, name)
Definition:
Value.h:143
LLVM.h
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
clang::FileEntryRef
A reference to a FileEntry that includes the name of the file as it was accessed by the FileManager's...
Definition:
FileEntry.h:57
clang::FileManager
Implements support for file system lookup, file system caching, and directory search management.
Definition:
FileManager.h:53
clang::HeaderMapImpl
Implementation for HeaderMap that doesn't depend on FileManager.
Definition:
HeaderMap.h:31
clang::HeaderMapImpl::getFileName
StringRef getFileName() const
Return the filename of the headermap.
Definition:
HeaderMap.cpp:109
clang::HeaderMapImpl::HeaderMapImpl
HeaderMapImpl(std::unique_ptr< const llvm::MemoryBuffer > File, bool NeedsBSwap)
Definition:
HeaderMap.h:37
clang::HeaderMapImpl::forEachKey
void forEachKey(Func Callback) const
Definition:
HeaderMap.h:44
clang::HeaderMapImpl::reverseLookupFilename
StringRef reverseLookupFilename(StringRef DestPath) const
Return key for specifed path.
Definition:
HeaderMap.cpp:231
clang::HeaderMapImpl::dump
void dump() const
Print the contents of this headermap to stderr.
Definition:
HeaderMap.cpp:172
clang::HeaderMapImpl::lookupFilename
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:197
clang::HeaderMapImpl::checkHeader
static bool checkHeader(const llvm::MemoryBuffer &File, bool &NeedsByteSwap)
Definition:
HeaderMap.cpp:66
clang::HeaderMap
This class represents an Apple concept known as a 'header map'.
Definition:
HeaderMap.h:84
llvm::SmallVectorImpl
Definition:
Randstruct.h:18
clang
The JSON file list parser is used to communicate input to InstallAPI.
Definition:
CalledOnceCheck.h:17
clang::OpenACCClauseKind::Create
@ Create
'create' clause, allowed on Compute and Combined constructs, plus 'data', 'enter data',...
clang::HMAP_EmptyBucketKey
@ HMAP_EmptyBucketKey
Definition:
HeaderMapTypes.h:19
clang::SourceLocIdentKind::File
@ File
clang::PredefinedIdentKind::Func
@ Func
std
Definition:
__clang_cuda_cmath.h:361
clang::HMapBucket
Definition:
HeaderMapTypes.h:22
clang::HMapBucket::Key
uint32_t Key
Definition:
HeaderMapTypes.h:23
clang::HMapHeader
Definition:
HeaderMapTypes.h:28
clang::HMapHeader::NumBuckets
uint32_t NumBuckets
Definition:
HeaderMapTypes.h:34
Generated on Fri Nov 22 2024 09:47:17 for clang by
1.9.6