14 #include "llvm/ADT/StringMap.h" 15 #include "llvm/ADT/StringRef.h" 16 #include "llvm/Support/FileSystem.h" 17 #include "llvm/Support/Path.h" 18 #include "llvm/Support/raw_ostream.h" 22 using namespace clang;
23 using namespace tooling;
29 bool equivalent(StringRef FileA, StringRef FileB)
const override {
30 return FileA == FileB || llvm::sys::fs::equivalent(FileA, FileB);
59 void insert(StringRef NewPath,
unsigned ConsumedLength = 0) {
62 if (llvm::sys::path::is_relative(NewPath))
69 if (Children.empty()) {
74 StringRef Element(llvm::sys::path::filename(
75 StringRef(Path).drop_back(ConsumedLength)));
76 Children[Element].Path = Path;
78 StringRef Element(llvm::sys::path::filename(
79 StringRef(NewPath).drop_back(ConsumedLength)));
80 Children[Element].insert(NewPath, ConsumedLength + Element.size() + 1);
107 unsigned ConsumedLength = 0)
const {
108 if (Children.empty()) {
109 if (Comparator.
equivalent(StringRef(Path), FileName))
110 return StringRef(Path);
113 StringRef Element(llvm::sys::path::filename(FileName.drop_back(
115 llvm::StringMap<FileMatchTrieNode>::const_iterator MatchingChild =
116 Children.find(Element);
117 if (MatchingChild != Children.end()) {
118 StringRef Result = MatchingChild->getValue().findEquivalent(
119 Comparator, FileName, IsAmbiguous,
120 ConsumedLength + Element.size() + 1);
121 if (!Result.empty() || IsAmbiguous)
124 std::vector<StringRef> AllChildren;
125 getAll(AllChildren, MatchingChild);
127 for (
const auto &Child : AllChildren) {
129 if (Result.empty()) {
142 void getAll(std::vector<StringRef> &Results,
143 llvm::StringMap<FileMatchTrieNode>::const_iterator Except)
const {
146 if (Children.empty()) {
147 Results.push_back(StringRef(Path));
150 for (llvm::StringMap<FileMatchTrieNode>::const_iterator
151 It = Children.begin(), E = Children.end();
155 It->getValue().getAll(Results, Children.end());
164 llvm::StringMap<FileMatchTrieNode> Children;
185 raw_ostream &Error)
const {
186 if (llvm::sys::path::is_relative(FileName)) {
187 Error <<
"Cannot resolve relative paths";
190 bool IsAmbiguous =
false;
191 StringRef Result = Root->
findEquivalent(*Comparator, FileName, IsAmbiguous);
193 Error <<
"Path is ambiguous";
Dataflow Directional Tag Classes.