57 lines · c
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-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef LLVM_CLANG_TOOLS_EXTRA_FIND_ALL_SYMBOLS_HEADER_MAP_COLLECTOR_H10#define LLVM_CLANG_TOOLS_EXTRA_FIND_ALL_SYMBOLS_HEADER_MAP_COLLECTOR_H11 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 maps21/// complete header names or header name regex patterns to header names.22class HeaderMapCollector {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 matches36 /// it to another header name.37 /// \param Header A header name.38 /// \return \p Header itself if there is no mapping for it; otherwise, return39 /// 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 regexes48 // never fail.49 mutable std::vector<std::pair<llvm::Regex, const char *>>50 RegexHeaderMappingTable;51};52 53} // namespace find_all_symbols54} // namespace clang55 56#endif // LLVM_CLANG_TOOLS_EXTRA_FIND_ALL_SYMBOLS_HEADER_MAP_COLLECTOR_H57