clang-tools  14.0.0git
HeaderMapCollector.cpp
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 #include "HeaderMapCollector.h"
10 #include "llvm/Support/Regex.h"
11 
12 namespace clang {
13 namespace find_all_symbols {
14 
16  const RegexHeaderMap *RegexHeaderMappingTable) {
17  assert(RegexHeaderMappingTable);
18  this->RegexHeaderMappingTable.reserve(RegexHeaderMappingTable->size());
19  for (const auto &Entry : *RegexHeaderMappingTable) {
20  this->RegexHeaderMappingTable.emplace_back(llvm::Regex(Entry.first),
21  Entry.second);
22  }
23 }
24 
25 llvm::StringRef
26 HeaderMapCollector::getMappedHeader(llvm::StringRef Header) const {
27  auto Iter = HeaderMappingTable.find(Header);
28  if (Iter != HeaderMappingTable.end())
29  return Iter->second;
30  // If there is no complete header name mapping for this header, check the
31  // regex header mapping.
32  for (auto &Entry : RegexHeaderMappingTable) {
33 #ifndef NDEBUG
34  std::string Dummy;
35  assert(Entry.first.isValid(Dummy) && "Regex should never be invalid!");
36 #endif
37  if (Entry.first.match(Header))
38  return Entry.second;
39  }
40  return Header;
41 }
42 
43 } // namespace find_all_symbols
44 } // namespace clang
clang::find_all_symbols::HeaderMapCollector::RegexHeaderMap
std::vector< std::pair< const char *, const char * > > RegexHeaderMap
Definition: HeaderMapCollector.h:25
HeaderMapCollector.h
clang::find_all_symbols::HeaderMapCollector::getMappedHeader
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.
Definition: HeaderMapCollector.cpp:26
Entry
Definition: Modularize.cpp:428
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ApplyReplacements.h:27
clang::find_all_symbols::HeaderMapCollector::HeaderMapCollector
HeaderMapCollector()=default