2016-05-13 17:27:54 +08:00
|
|
|
//===-- YamlSymbolIndex.cpp -----------------------------------------------===//
|
2016-04-29 17:23:38 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2016-05-13 17:27:54 +08:00
|
|
|
#include "YamlSymbolIndex.h"
|
2016-04-29 17:23:38 +08:00
|
|
|
#include "llvm/ADT/SmallVector.h"
|
2016-05-09 22:14:55 +08:00
|
|
|
#include "llvm/Support/Errc.h"
|
2016-04-29 17:23:38 +08:00
|
|
|
#include "llvm/Support/FileSystem.h"
|
|
|
|
#include "llvm/Support/MemoryBuffer.h"
|
2016-05-09 22:14:55 +08:00
|
|
|
#include "llvm/Support/Path.h"
|
2016-04-29 17:23:38 +08:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2016-05-04 16:22:35 +08:00
|
|
|
using clang::find_all_symbols::SymbolInfo;
|
2017-02-28 16:13:15 +08:00
|
|
|
using clang::find_all_symbols::SymbolAndSignals;
|
2016-05-04 16:22:35 +08:00
|
|
|
|
2016-04-29 17:23:38 +08:00
|
|
|
namespace clang {
|
|
|
|
namespace include_fixer {
|
|
|
|
|
2016-05-13 17:27:54 +08:00
|
|
|
llvm::ErrorOr<std::unique_ptr<YamlSymbolIndex>>
|
|
|
|
YamlSymbolIndex::createFromFile(llvm::StringRef FilePath) {
|
2016-05-09 22:14:55 +08:00
|
|
|
auto Buffer = llvm::MemoryBuffer::getFile(FilePath);
|
2016-04-29 17:23:38 +08:00
|
|
|
if (!Buffer)
|
2016-05-09 22:14:55 +08:00
|
|
|
return Buffer.getError();
|
|
|
|
|
2017-02-28 16:13:15 +08:00
|
|
|
return std::unique_ptr<YamlSymbolIndex>(new YamlSymbolIndex(
|
|
|
|
find_all_symbols::ReadSymbolInfosFromYAML(Buffer.get()->getBuffer())));
|
2016-05-09 22:14:55 +08:00
|
|
|
}
|
|
|
|
|
2016-05-13 17:27:54 +08:00
|
|
|
llvm::ErrorOr<std::unique_ptr<YamlSymbolIndex>>
|
|
|
|
YamlSymbolIndex::createFromDirectory(llvm::StringRef Directory,
|
|
|
|
llvm::StringRef Name) {
|
2016-05-09 22:14:55 +08:00
|
|
|
// Walk upwards from Directory, looking for files.
|
|
|
|
for (llvm::SmallString<128> PathStorage = Directory; !Directory.empty();
|
|
|
|
Directory = llvm::sys::path::parent_path(Directory)) {
|
|
|
|
assert(Directory.size() <= PathStorage.size());
|
|
|
|
PathStorage.resize(Directory.size()); // Shrink to parent.
|
|
|
|
llvm::sys::path::append(PathStorage, Name);
|
|
|
|
if (auto DB = createFromFile(PathStorage))
|
|
|
|
return DB;
|
|
|
|
}
|
|
|
|
return llvm::make_error_code(llvm::errc::no_such_file_or_directory);
|
2016-04-29 17:23:38 +08:00
|
|
|
}
|
|
|
|
|
2017-02-28 16:13:15 +08:00
|
|
|
std::vector<SymbolAndSignals>
|
|
|
|
YamlSymbolIndex::search(llvm::StringRef Identifier) {
|
|
|
|
std::vector<SymbolAndSignals> Results;
|
2016-04-29 17:23:38 +08:00
|
|
|
for (const auto &Symbol : Symbols) {
|
2017-02-28 16:13:15 +08:00
|
|
|
if (Symbol.Symbol.getName() == Identifier)
|
2016-05-04 16:22:35 +08:00
|
|
|
Results.push_back(Symbol);
|
2016-04-29 17:23:38 +08:00
|
|
|
}
|
|
|
|
return Results;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace include_fixer
|
|
|
|
} // namespace clang
|