clang-tools 8.0.0

Serialization.h
Go to the documentation of this file.
1 //===--- Serialization.h - Binary serialization of index data ----*- C++-*-===//
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 // This file provides serialization of indexed symbols and other data.
11 //
12 // It writes sections:
13 // - metadata such as version info
14 // - a string table (which is compressed)
15 // - lists of encoded symbols
16 //
17 // The format has a simple versioning scheme: the format version number is
18 // written in the file and non-current versions are rejected when reading.
19 //
20 // Human-readable YAML serialization is also supported, and recommended for
21 // debugging and experiments only.
22 //
23 //===----------------------------------------------------------------------===//
24
25 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_RIFF_H
26 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_RIFF_H
27 #include "Headers.h"
28 #include "Index.h"
29 #include "llvm/Support/Error.h"
30
31 namespace clang {
32 namespace clangd {
33
34 enum class IndexFileFormat {
35 RIFF, // Versioned binary format, suitable for production use.
36 YAML, // Human-readable format, suitable for experiments and debugging.
37 };
38
39 // Holds the contents of an index file that was read.
40 struct IndexFileIn {
41 llvm::Optional<SymbolSlab> Symbols;
42 llvm::Optional<RefSlab> Refs;
43 // Keys are URIs of the source files.
44 llvm::Optional<IncludeGraph> Sources;
45 };
46 // Parse an index file. The input must be a RIFF or YAML file.
47 llvm::Expected<IndexFileIn> readIndexFile(llvm::StringRef);
48
49 // Specifies the contents of an index file to be written.
50 struct IndexFileOut {
51 const SymbolSlab *Symbols = nullptr;
52 const RefSlab *Refs = nullptr;
53 // Keys are URIs of the source files.
54 const IncludeGraph *Sources = nullptr;
55 // TODO: Support serializing Dex posting lists.
56 IndexFileFormat Format = IndexFileFormat::RIFF;
57
58 IndexFileOut() = default;
59 IndexFileOut(const IndexFileIn &I)
60 : Symbols(I.Symbols ? I.Symbols.getPointer() : nullptr),
61 Refs(I.Refs ? I.Refs.getPointer() : nullptr) {}
62 };
63 // Serializes an index file.
64 llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const IndexFileOut &O);
65
66 // Convert a single symbol to YAML, a nice debug representation.
67 std::string toYAML(const Symbol &);
68 std::string toYAML(const std::pair<SymbolID, ArrayRef<Ref>> &);
69
70 // Build an in-memory static index from an index file.
71 // The size should be relatively small, so data can be managed in memory.
72 std::unique_ptr<SymbolIndex> loadIndex(llvm::StringRef Filename,
73 bool UseDex = true);
74
75 } // namespace clangd
76 } // namespace clang
77
78 #endif
clang::clangd::IndexFileIn::Symbols
llvm::Optional< SymbolSlab > Symbols
Definition: Serialization.h:41
clang::clangd::SymbolSlab
Definition: Index.h:292
clang::clangd::loadIndex
std::unique_ptr< SymbolIndex > loadIndex(llvm::StringRef SymbolFilename, bool UseDex)
Definition: Serialization.cpp:551
clang::clangd::RefSlab
Definition: Index.h:388
Index.h
clang::clangd::IndexFileFormat::YAML
clang::clangd::IndexFileFormat
IndexFileFormat
Definition: Serialization.h:34
clang::clangd::IndexFileFormat::RIFF
clang::clangd::readIndexFile
llvm::Expected< IndexFileIn > readIndexFile(llvm::StringRef Data)
Definition: Serialization.cpp:540
clang::clangd::toYAML
std::string toYAML(const Symbol &)
Definition: YAMLSerialization.cpp:338
Headers.h
clang::clangd::IndexFileIn::Sources
llvm::Optional< IncludeGraph > Sources
Definition: Serialization.h:44
clang::clangd::UseDex
static llvm::cl::opt< bool > UseDex("use-dex-index", llvm::cl::desc("Use experimental Dex dynamic index."), llvm::cl::init(false), llvm::cl::Hidden)
clang::clangd::IndexFileIn
Definition: Serialization.h:40
clang::clangd::IncludeGraph
llvm::StringMap< IncludeGraphNode > IncludeGraph
Definition: Headers.h:65
Filename
std::string Filename
Filename as a string.
Definition: IncludeOrderCheck.cpp:39
clang::clangd::IndexFileOut::IndexFileOut
IndexFileOut(const IndexFileIn &I)
Definition: Serialization.h:59
clang::clangd::IndexFileIn::Refs
llvm::Optional< RefSlab > Refs
Definition: Serialization.h:42
clang::clangd::Symbol
Definition: Index.h:160
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ChangeNamespace.cpp:18
clang::clangd::IndexFileOut
Definition: Serialization.h:50
clang::clangd::operator<<
llvm::raw_ostream & operator<<(llvm::raw_ostream &OS, const CodeCompletion &C)
Definition: CodeComplete.cpp:1719
clang::clangd::SymbolID
Definition: SymbolID.h:31