1 //===-- HeaderMapCoolector.h - find all symbols------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
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
12 #include "llvm/ADT/StringMap.h"
13 #include "llvm/Support/Regex.h"
18 namespace find_all_symbols
{
20 /// HeaderMappCollector collects all remapping header files. This maps
21 /// complete header names or header name regex patterns to header names.
22 class HeaderMapCollector
{
24 typedef llvm::StringMap
<std::string
> HeaderMap
;
25 typedef std::vector
<std::pair
<const char *, const char *>> RegexHeaderMap
;
27 HeaderMapCollector() = default;
28 explicit HeaderMapCollector(const RegexHeaderMap
*RegexHeaderMappingTable
);
30 void addHeaderMapping(llvm::StringRef OrignalHeaderPath
,
31 llvm::StringRef MappingHeaderPath
) {
32 HeaderMappingTable
[OrignalHeaderPath
] = std::string(MappingHeaderPath
);
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;
43 /// A string-to-string map saving the mapping relationship.
44 HeaderMap HeaderMappingTable
;
46 // A map from header patterns to header names.
47 // The header names are not owned. This is only threadsafe because the regexes
49 mutable std::vector
<std::pair
<llvm::Regex
, const char *>>
50 RegexHeaderMappingTable
;
53 } // namespace find_all_symbols
56 #endif // LLVM_CLANG_TOOLS_EXTRA_FIND_ALL_SYMBOLS_HEADER_MAP_COLLECTOR_H