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.
57 
58  IndexFileOut() = default;
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
llvm::Optional< SymbolSlab > Symbols
Definition: Serialization.h:41
std::unique_ptr< SymbolIndex > loadIndex(llvm::StringRef SymbolFilename, bool UseDex)
llvm::Expected< IndexFileIn > readIndexFile(llvm::StringRef Data)
std::string toYAML(const Symbol &)
llvm::Optional< IncludeGraph > Sources
Definition: Serialization.h:44
static llvm::cl::opt< bool > UseDex("use-dex-index", llvm::cl::desc("Use experimental Dex dynamic index."), llvm::cl::init(false), llvm::cl::Hidden)
llvm::StringMap< IncludeGraphNode > IncludeGraph
Definition: Headers.h:65
std::string Filename
Filename as a string.
IndexFileOut(const IndexFileIn &I)
Definition: Serialization.h:59
llvm::Optional< RefSlab > Refs
Definition: Serialization.h:42
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
llvm::raw_ostream & operator<<(llvm::raw_ostream &OS, const CodeCompletion &C)