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