15 #include "llvm/ADT/StringMap.h"
16 #include "llvm/Support/FileSystem.h"
17 #include "llvm/Support/Path.h"
18 #include "llvm/Support/raw_ostream.h"
20 using namespace clang;
21 using namespace tooling;
26 bool equivalent(StringRef FileA, StringRef FileB)
const override {
27 return FileA == FileB || llvm::sys::fs::equivalent(FileA, FileB);
54 void insert(StringRef NewPath,
unsigned ConsumedLength = 0) {
57 if (llvm::sys::path::is_relative(NewPath))
64 if (Children.empty()) {
69 StringRef Element(llvm::sys::path::filename(
70 StringRef(Path).drop_back(ConsumedLength)));
71 Children[Element].Path = Path;
73 StringRef Element(llvm::sys::path::filename(
74 StringRef(NewPath).drop_back(ConsumedLength)));
75 Children[Element].insert(NewPath, ConsumedLength + Element.size() + 1);
102 unsigned ConsumedLength = 0)
const {
103 if (Children.empty()) {
104 if (Comparator.
equivalent(StringRef(Path), FileName))
105 return StringRef(Path);
108 StringRef Element(llvm::sys::path::filename(FileName.drop_back(
110 llvm::StringMap<FileMatchTrieNode>::const_iterator MatchingChild =
111 Children.find(Element);
112 if (MatchingChild != Children.end()) {
113 StringRef
Result = MatchingChild->getValue().findEquivalent(
114 Comparator, FileName, IsAmbiguous,
115 ConsumedLength + Element.size() + 1);
116 if (!Result.empty() || IsAmbiguous)
119 std::vector<StringRef> AllChildren;
120 getAll(AllChildren, MatchingChild);
122 for (
unsigned i = 0; i < AllChildren.size(); i++) {
123 if (Comparator.
equivalent(AllChildren[i], FileName)) {
124 if (Result.empty()) {
125 Result = AllChildren[i];
137 void getAll(std::vector<StringRef> &Results,
138 llvm::StringMap<FileMatchTrieNode>::const_iterator Except)
const {
141 if (Children.empty()) {
142 Results.push_back(StringRef(Path));
145 for (llvm::StringMap<FileMatchTrieNode>::const_iterator
146 It = Children.begin(),
E = Children.end();
150 It->getValue().getAll(Results, Children.end());
159 llvm::StringMap<FileMatchTrieNode> Children;
179 raw_ostream &Error)
const {
180 if (llvm::sys::path::is_relative(FileName)) {
181 Error <<
"Cannot resolve relative paths";
184 bool IsAmbiguous =
false;
187 Error <<
"Path is ambiguous";
The result type of a method or function.
detail::InMemoryDirectory::const_iterator E