Changed FrontendActionFactory::create to return a std::unique_ptr
[lldb.git] / clang-tools-extra / clang-include-fixer / find-all-symbols / PathConfig.cpp
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,
17                            const HeaderMapCollector *Collector) {
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