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"
23using 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))
66 Path = std::string(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 {
109 if (Children.empty()) {
112 if (llvm::sys::path::filename(Path) ==
113 llvm::sys::path::filename(
FileName) &&
115 return StringRef(Path);
118 StringRef Element(llvm::sys::path::filename(
FileName.drop_back(
120 llvm::StringMap<FileMatchTrieNode>::const_iterator MatchingChild =
121 Children.find(Element);
122 if (MatchingChild != Children.end()) {
123 StringRef
Result = MatchingChild->getValue().findEquivalent(
125 ConsumedLength + Element.size() + 1);
126 if (!
Result.empty() || IsAmbiguous)
133 if (ConsumedLength == 0)
136 std::vector<StringRef> AllChildren;
137 getAll(AllChildren, MatchingChild);
139 for (
const auto &Child : AllChildren) {
154 void getAll(std::vector<StringRef> &Results,
155 llvm::StringMap<FileMatchTrieNode>::const_iterator Except)
const {
158 if (Children.empty()) {
159 Results.push_back(StringRef(Path));
162 for (llvm::StringMap<FileMatchTrieNode>::const_iterator
163 It = Children.begin(),
E = Children.end();
167 It->getValue().getAll(Results, Children.end());
176 llvm::StringMap<FileMatchTrieNode> Children;
197 raw_ostream &Error)
const {
198 if (llvm::sys::path::is_relative(
FileName)) {
199 Error <<
"Cannot resolve relative paths";
202 bool IsAmbiguous =
false;
205 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.