clang-tools  10.0.0git
PathConfig.cpp
Go to the documentation of this file.
1 //===-- PathConfig.cpp - Process paths of symbols ---------------*- C++ -*-===//
2 //
3 //
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #include "PathConfig.h"
11 #include "llvm/Support/Path.h"
12 
13 namespace clang {
14 namespace find_all_symbols {
15 
16 std::string getIncludePath(const SourceManager &SM, SourceLocation Loc,
18  llvm::StringRef FilePath;
19  // Walk up the include stack to skip .inc files.
20  while (true) {
21  if (!Loc.isValid() || SM.isInMainFile(Loc))
22  return "";
23  FilePath = SM.getFilename(Loc);
24  if (FilePath.empty())
25  return "";
26  if (!FilePath.endswith(".inc"))
27  break;
28  FileID ID = SM.getFileID(Loc);
29  Loc = SM.getIncludeLoc(ID);
30  }
31 
32  if (Collector)
33  FilePath = Collector->getMappedHeader(FilePath);
34  SmallString<256> CleanedFilePath = FilePath;
35  llvm::sys::path::remove_dots(CleanedFilePath, /*remove_dot_dot=*/false);
36 
37  return CleanedFilePath.str();
38 }
39 
40 } // namespace find_all_symbols
41 } // namespace clang
SourceLocation Loc
&#39;#&#39; location in the include directive
HeaderMappCollector collects all remapping header files.
std::string getIncludePath(const SourceManager &SM, SourceLocation Loc, const HeaderMapCollector *Collector)
This calculates the include path for Loc.
Definition: PathConfig.cpp:16
std::shared_ptr< SymbolCollector > Collector
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++ -*-===//