[docs] Add LICENSE.txt to the root of the mono-repo
[llvm-project.git] / clang-tools-extra / clang-include-fixer / find-all-symbols / HeaderMapCollector.h
blob300e4f7b38e6bfd3d4c55e790d6100dddf5278f9
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 //===----------------------------------------------------------------------===//
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"
14 #include <string>
15 #include <vector>
17 namespace clang {
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 {
23 public:
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;
42 private:
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
48 // never fail.
49 mutable std::vector<std::pair<llvm::Regex, const char *>>
50 RegexHeaderMappingTable;
53 } // namespace find_all_symbols
54 } // namespace clang
56 #endif // LLVM_CLANG_TOOLS_EXTRA_FIND_ALL_SYMBOLS_HEADER_MAP_COLLECTOR_H