15 #include "llvm/ADT/StringMap.h" 16 #include "llvm/ADT/StringRef.h" 17 #include "llvm/Support/FileSystem.h" 18 #include "llvm/Support/Path.h" 19 #include "llvm/Support/raw_ostream.h" 23 using namespace clang;
24 using namespace tooling;
30 bool equivalent(StringRef FileA, StringRef FileB)
const override {
31 return FileA == FileB || llvm::sys::fs::equivalent(FileA, FileB);
60 void insert(StringRef NewPath,
unsigned ConsumedLength = 0) {
63 if (llvm::sys::path::is_relative(NewPath))
70 if (Children.empty()) {
75 StringRef Element(llvm::sys::path::filename(
76 StringRef(Path).drop_back(ConsumedLength)));
77 Children[Element].Path = Path;
79 StringRef Element(llvm::sys::path::filename(
80 StringRef(NewPath).drop_back(ConsumedLength)));
81 Children[Element].insert(NewPath, ConsumedLength + Element.size() + 1);
108 unsigned ConsumedLength = 0)
const {
109 if (Children.empty()) {
110 if (Comparator.
equivalent(StringRef(Path), FileName))
111 return StringRef(Path);
114 StringRef Element(llvm::sys::path::filename(FileName.drop_back(
116 llvm::StringMap<FileMatchTrieNode>::const_iterator MatchingChild =
117 Children.find(Element);
118 if (MatchingChild != Children.end()) {
119 StringRef Result = MatchingChild->getValue().findEquivalent(
120 Comparator, FileName, IsAmbiguous,
121 ConsumedLength + Element.size() + 1);
122 if (!Result.empty() || IsAmbiguous)
125 std::vector<StringRef> AllChildren;
126 getAll(AllChildren, MatchingChild);
128 for (
const auto &Child : AllChildren) {
130 if (Result.empty()) {
143 void getAll(std::vector<StringRef> &Results,
144 llvm::StringMap<FileMatchTrieNode>::const_iterator Except)
const {
147 if (Children.empty()) {
148 Results.push_back(StringRef(Path));
151 for (llvm::StringMap<FileMatchTrieNode>::const_iterator
152 It = Children.begin(), E = Children.end();
156 It->getValue().getAll(Results, Children.end());
165 llvm::StringMap<FileMatchTrieNode> Children;
186 raw_ostream &Error)
const {
187 if (llvm::sys::path::is_relative(FileName)) {
188 Error <<
"Cannot resolve relative paths";
191 bool IsAmbiguous =
false;
192 StringRef Result = Root->
findEquivalent(*Comparator, FileName, IsAmbiguous);
194 Error <<
"Path is ambiguous";
Dataflow Directional Tag Classes.