clang-tools 20.0.0git
HeaderMapCollector.h
Go to the documentation of this file.
1//===-- HeaderMapCoolector.h - find all symbols------------------*- 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#ifndef LLVM_CLANG_TOOLS_EXTRA_FIND_ALL_SYMBOLS_HEADER_MAP_COLLECTOR_H
10#define LLVM_CLANG_TOOLS_EXTRA_FIND_ALL_SYMBOLS_HEADER_MAP_COLLECTOR_H
11
12#include "llvm/ADT/StringMap.h"
13#include "llvm/Support/Regex.h"
14#include <string>
15#include <vector>
16
17namespace clang {
18namespace find_all_symbols {
19
20/// HeaderMappCollector collects all remapping header files. This maps
21/// complete header names or header name regex patterns to header names.
23public:
24 typedef llvm::StringMap<std::string> HeaderMap;
25 typedef std::vector<std::pair<const char *, const char *>> RegexHeaderMap;
26
27 HeaderMapCollector() = default;
28 explicit HeaderMapCollector(const RegexHeaderMap *RegexHeaderMappingTable);
29
30 void addHeaderMapping(llvm::StringRef OrignalHeaderPath,
31 llvm::StringRef MappingHeaderPath) {
32 HeaderMappingTable[OrignalHeaderPath] = std::string(MappingHeaderPath);
33 };
34
35 /// Check if there is a mapping from \p Header or a regex pattern that matches
36 /// it to another header name.
37 /// \param Header A header name.
38 /// \return \p Header itself if there is no mapping for it; otherwise, return
39 /// a mapped header name.
40 llvm::StringRef getMappedHeader(llvm::StringRef Header) const;
41
42private:
43 /// A string-to-string map saving the mapping relationship.
44 HeaderMap HeaderMappingTable;
45
46 // A map from header patterns to header names.
47 // The header names are not owned. This is only threadsafe because the regexes
48 // never fail.
49 mutable std::vector<std::pair<llvm::Regex, const char *>>
50 RegexHeaderMappingTable;
51};
52
53} // namespace find_all_symbols
54} // namespace clang
55
56#endif // LLVM_CLANG_TOOLS_EXTRA_FIND_ALL_SYMBOLS_HEADER_MAP_COLLECTOR_H
HeaderMappCollector collects all remapping header files.
llvm::StringRef getMappedHeader(llvm::StringRef Header) const
Check if there is a mapping from Header or a regex pattern that matches it to another header name.
std::vector< std::pair< const char *, const char * > > RegexHeaderMap
llvm::StringMap< std::string > HeaderMap
void addHeaderMapping(llvm::StringRef OrignalHeaderPath, llvm::StringRef MappingHeaderPath)
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//