[docs] Add LICENSE.txt to the root of the mono-repo
[llvm-project.git] / clang-tools-extra / clang-include-fixer / find-all-symbols / PathConfig.cpp
blob503fd60cb4c1b86ffb3b9e3584ad842a37e1c1d5
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 //===----------------------------------------------------------------------===//
10 #include "PathConfig.h"
11 #include "llvm/ADT/SmallString.h"
12 #include "llvm/Support/Path.h"
14 namespace clang {
15 namespace find_all_symbols {
17 std::string getIncludePath(const SourceManager &SM, SourceLocation Loc,
18 const HeaderMapCollector *Collector) {
19 llvm::StringRef FilePath;
20 // Walk up the include stack to skip .inc files.
21 while (true) {
22 if (!Loc.isValid() || SM.isInMainFile(Loc))
23 return "";
24 FilePath = SM.getFilename(Loc);
25 if (FilePath.empty())
26 return "";
27 if (!FilePath.endswith(".inc"))
28 break;
29 FileID ID = SM.getFileID(Loc);
30 Loc = SM.getIncludeLoc(ID);
33 if (Collector)
34 FilePath = Collector->getMappedHeader(FilePath);
35 SmallString<256> CleanedFilePath = FilePath;
36 llvm::sys::path::remove_dots(CleanedFilePath, /*remove_dot_dot=*/false);
38 return std::string(CleanedFilePath.str());
41 } // namespace find_all_symbols
42 } // namespace clang