14#include "llvm/ADT/StringMap.h"
15#include "llvm/ADT/StringRef.h"
16#include "llvm/Support/FileSystem.h"
17#include "llvm/Support/Path.h"
22using namespace tooling;
28 bool equivalent(StringRef FileA, StringRef FileB)
const override {
29 return FileA == FileB || llvm::sys::fs::equivalent(FileA, FileB);
58 void insert(StringRef NewPath,
unsigned ConsumedLength = 0) {
61 if (llvm::sys::path::is_relative(NewPath))
65 Path = std::string(NewPath);
68 if (Children.empty()) {
73 StringRef Element(llvm::sys::path::filename(
74 StringRef(Path).drop_back(ConsumedLength)));
75 Children[Element].Path = Path;
77 StringRef Element(llvm::sys::path::filename(
78 StringRef(NewPath).drop_back(ConsumedLength)));
79 Children[Element].insert(NewPath, ConsumedLength + Element.size() + 1);
106 unsigned ConsumedLength = 0)
const {
108 if (Children.empty()) {
111 if (llvm::sys::path::filename(Path) ==
112 llvm::sys::path::filename(
FileName) &&
114 return StringRef(Path);
117 StringRef Element(llvm::sys::path::filename(
FileName.drop_back(
119 llvm::StringMap<FileMatchTrieNode>::const_iterator MatchingChild =
120 Children.find(Element);
121 if (MatchingChild != Children.end()) {
122 StringRef
Result = MatchingChild->getValue().findEquivalent(
124 ConsumedLength + Element.size() + 1);
125 if (!
Result.empty() || IsAmbiguous)
132 if (ConsumedLength == 0)
135 std::vector<StringRef> AllChildren;
136 getAll(AllChildren, MatchingChild);
138 for (
const auto &Child : AllChildren) {
153 void getAll(std::vector<StringRef> &Results,
154 llvm::StringMap<FileMatchTrieNode>::const_iterator Except)
const {
157 if (Children.empty()) {
158 Results.push_back(StringRef(Path));
161 for (llvm::StringMap<FileMatchTrieNode>::const_iterator
162 It = Children.begin(),
E = Children.end();
166 It->getValue().getAll(Results, Children.end());
175 llvm::StringMap<FileMatchTrieNode> Children;
196 raw_ostream &Error)
const {
197 if (llvm::sys::path::is_relative(
FileName)) {
198 Error <<
"Cannot resolve relative paths";
201 bool IsAmbiguous =
false;
204 Error <<
"Path is ambiguous";
The JSON file list parser is used to communicate input to InstallAPI.
@ Result
The result type of a method or function.