clang-tools 10.0.0

YamlSymbolIndex.cpp
Go to the documentation of this file.
1 //===-- YamlSymbolIndex.cpp -----------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8
9 #include "YamlSymbolIndex.h"
10 #include "llvm/ADT/SmallVector.h"
11 #include "llvm/Support/Errc.h"
12 #include "llvm/Support/FileSystem.h"
13 #include "llvm/Support/MemoryBuffer.h"
14 #include "llvm/Support/Path.h"
15 #include <string>
16 #include <vector>
17
18 using clang::find_all_symbols::SymbolInfo;
19 using clang::find_all_symbols::SymbolAndSignals;
20
21 namespace clang {
22 namespace include_fixer {
23
24 llvm::ErrorOr<std::unique_ptr<YamlSymbolIndex>>
25 YamlSymbolIndex::createFromFile(llvm::StringRef FilePath) {
26 auto Buffer = llvm::MemoryBuffer::getFile(FilePath);
27 if (!Buffer)
28 return Buffer.getError();
29
30 return std::unique_ptr<YamlSymbolIndex>(new YamlSymbolIndex(
31 find_all_symbols::ReadSymbolInfosFromYAML(Buffer.get()->getBuffer())));
32 }
33
34 llvm::ErrorOr<std::unique_ptr<YamlSymbolIndex>>
35 YamlSymbolIndex::createFromDirectory(llvm::StringRef Directory,
36 llvm::StringRef Name) {
37 // Walk upwards from Directory, looking for files.
38 for (llvm::SmallString<128> PathStorage = Directory; !Directory.empty();
39 Directory = llvm::sys::path::parent_path(Directory)) {
40 assert(Directory.size() <= PathStorage.size());
41 PathStorage.resize(Directory.size()); // Shrink to parent.
42 llvm::sys::path::append(PathStorage, Name);
43 if (auto DB = createFromFile(PathStorage))
44 return DB;
45 }
46 return llvm::make_error_code(llvm::errc::no_such_file_or_directory);
47 }
48
49 std::vector<SymbolAndSignals>
50 YamlSymbolIndex::search(llvm::StringRef Identifier) {
51 std::vector<SymbolAndSignals> Results;
52 for (const auto &Symbol : Symbols) {
53 if (Symbol.Symbol.getName() == Identifier)
54 Results.push_back(Symbol);
55 }
56 return Results;
57 }
58
59 } // namespace include_fixer
60 } // namespace clang
YamlSymbolIndex.h
Results
std::vector< CodeCompletionResult > Results
Definition: CodeComplete.cpp:689
clang::find_all_symbols::ReadSymbolInfosFromYAML
std::vector< SymbolAndSignals > ReadSymbolInfosFromYAML(llvm::StringRef Yaml)
Read SymbolInfos from a YAML document.
Definition: SymbolInfo.cpp:128
SymbolInfo
clang::find_all_symbols::SymbolInfo SymbolInfo
Definition: FindAllSymbolsMain.cpp:38
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:50
clang::find_all_symbols::SymbolAndSignals
Definition: SymbolInfo.h:126
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:35
clang::include_fixer::YamlSymbolIndex
Yaml format database.
Definition: YamlSymbolIndex.h:22
Name
static constexpr llvm::StringLiteral Name
Definition: UppercaseLiteralSuffixCheck.cpp:27
Directory
llvm::StringRef Directory
Definition: Serialization.cpp:387
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ApplyReplacements.h:27
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:25