clang-tools 8.0.0

YamlSymbolIndex.cpp
Go to the documentation of this file.
1 //===-- YamlSymbolIndex.cpp -----------------------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #include "YamlSymbolIndex.h"
11 #include "llvm/ADT/SmallVector.h"
12 #include "llvm/Support/Errc.h"
13 #include "llvm/Support/FileSystem.h"
14 #include "llvm/Support/MemoryBuffer.h"
15 #include "llvm/Support/Path.h"
16 #include <string>
17 #include <vector>
18
19 using clang::find_all_symbols::SymbolInfo;
20 using clang::find_all_symbols::SymbolAndSignals;
21
22 namespace clang {
23 namespace include_fixer {
24
25 llvm::ErrorOr<std::unique_ptr<YamlSymbolIndex>>
26 YamlSymbolIndex::createFromFile(llvm::StringRef FilePath) {
27 auto Buffer = llvm::MemoryBuffer::getFile(FilePath);
28 if (!Buffer)
29 return Buffer.getError();
30
31 return std::unique_ptr<YamlSymbolIndex>(new YamlSymbolIndex(
32 find_all_symbols::ReadSymbolInfosFromYAML(Buffer.get()->getBuffer())));
33 }
34
35 llvm::ErrorOr<std::unique_ptr<YamlSymbolIndex>>
36 YamlSymbolIndex::createFromDirectory(llvm::StringRef Directory,
37 llvm::StringRef Name) {
38 // Walk upwards from Directory, looking for files.
39 for (llvm::SmallString<128> PathStorage = Directory; !Directory.empty();
40 Directory = llvm::sys::path::parent_path(Directory)) {
41 assert(Directory.size() <= PathStorage.size());
42 PathStorage.resize(Directory.size()); // Shrink to parent.
43 llvm::sys::path::append(PathStorage, Name);
44 if (auto DB = createFromFile(PathStorage))
45 return DB;
46 }
47 return llvm::make_error_code(llvm::errc::no_such_file_or_directory);
48 }
49
50 std::vector<SymbolAndSignals>
51 YamlSymbolIndex::search(llvm::StringRef Identifier) {
52 std::vector<SymbolAndSignals> Results;
53 for (const auto &Symbol : Symbols) {
54 if (Symbol.Symbol.getName() == Identifier)
55 Results.push_back(Symbol);
56 }
57 return Results;
58 }
59
60 } // namespace include_fixer
61 } // namespace clang
YamlSymbolIndex.h
Results
std::vector< CodeCompletionResult > Results
Definition: CodeComplete.cpp:702
clang::find_all_symbols::ReadSymbolInfosFromYAML
std::vector< SymbolAndSignals > ReadSymbolInfosFromYAML(llvm::StringRef Yaml)
Read SymbolInfos from a YAML document.
Definition: SymbolInfo.cpp:129
Directory
static cl::opt< std::string > Directory(cl::Positional, cl::Required, cl::desc("<Search Root Directory>"))
SymbolInfo
clang::find_all_symbols::SymbolInfo SymbolInfo
Definition: FindAllSymbolsMain.cpp:39
clang::include_fixer::YamlSymbolIndex::search
std::vector< find_all_symbols::SymbolAndSignals > search(llvm::StringRef Identifier) override
Search for all SymbolInfos corresponding to an identifier.
Definition: YamlSymbolIndex.cpp:51
clang::find_all_symbols::SymbolAndSignals
Definition: SymbolInfo.h:127
clang::include_fixer::YamlSymbolIndex::createFromDirectory
static llvm::ErrorOr< std::unique_ptr< YamlSymbolIndex > > createFromDirectory(llvm::StringRef Directory, llvm::StringRef Name)
Look for a file called Name in Directory and all parent directories.
Definition: YamlSymbolIndex.cpp:36
clang::include_fixer::YamlSymbolIndex
Yaml format database.
Definition: YamlSymbolIndex.h:23
Name
static constexpr llvm::StringLiteral Name
Definition: UppercaseLiteralSuffixCheck.cpp:28
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ChangeNamespace.cpp:18
clang::include_fixer::YamlSymbolIndex::createFromFile
static llvm::ErrorOr< std::unique_ptr< YamlSymbolIndex > > createFromFile(llvm::StringRef FilePath)
Create a new Yaml db from a file.
Definition: YamlSymbolIndex.cpp:26