clang-tools  14.0.0git
YAMLSerialization.cpp
Go to the documentation of this file.
1 //===-- YAMLSerialization.cpp ------------------------------------*- C++-*-===//
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 // A YAML index file is a sequence of tagged entries.
10 // Each entry either encodes a Symbol or the list of references to a symbol
11 // (a "ref bundle").
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #include "Index.h"
16 #include "Relation.h"
17 #include "Serialization.h"
18 #include "SymbolLocation.h"
19 #include "SymbolOrigin.h"
20 #include "dex/Dex.h"
21 #include "support/Logger.h"
22 #include "support/Trace.h"
23 #include "llvm/ADT/Optional.h"
24 #include "llvm/ADT/SmallVector.h"
25 #include "llvm/ADT/StringRef.h"
26 #include "llvm/Support/Allocator.h"
27 #include "llvm/Support/Errc.h"
28 #include "llvm/Support/MemoryBuffer.h"
29 #include "llvm/Support/StringSaver.h"
30 #include "llvm/Support/YAMLTraits.h"
31 #include "llvm/Support/raw_ostream.h"
32 #include <cstdint>
33 
34 LLVM_YAML_IS_SEQUENCE_VECTOR(clang::clangd::Symbol::IncludeHeaderWithReferences)
35 LLVM_YAML_IS_SEQUENCE_VECTOR(clang::clangd::Ref)
36 
37 namespace {
38 using RefBundle =
39  std::pair<clang::clangd::SymbolID, std::vector<clang::clangd::Ref>>;
40 // This is a pale imitation of std::variant<Symbol, RefBundle, Relation>
41 struct VariantEntry {
42  llvm::Optional<clang::clangd::Symbol> Symbol;
43  llvm::Optional<RefBundle> Refs;
44  llvm::Optional<clang::clangd::Relation> Relation;
45  llvm::Optional<clang::clangd::IncludeGraphNode> Source;
46  llvm::Optional<clang::tooling::CompileCommand> Cmd;
47 };
48 // A class helps YAML to serialize the 32-bit encoded position (Line&Column),
49 // as YAMLIO can't directly map bitfields.
50 struct YPosition {
51  uint32_t Line;
52  uint32_t Column;
53 };
54 
55 // avoid ODR violation of specialization for non-owned CompileCommand
56 struct CompileCommandYAML : clang::tooling::CompileCommand {};
57 
58 } // namespace
59 namespace llvm {
60 namespace yaml {
61 
65 using clang::clangd::Ref;
75 using clang::index::SymbolLanguage;
76 using clang::index::SymbolRole;
77 using clang::tooling::CompileCommand;
78 
79 // Helper to (de)serialize the SymbolID. We serialize it as a hex string.
82  NormalizedSymbolID(IO &, const SymbolID &ID) {
83  llvm::raw_string_ostream OS(HexString);
84  OS << ID;
85  }
86 
89  if (!ID) {
90  I.setError(llvm::toString(ID.takeError()));
91  return SymbolID();
92  }
93  return *ID;
94  }
95 
96  std::string HexString;
97 };
98 
102  Flag = static_cast<uint8_t>(F);
103  }
104 
106  return static_cast<Symbol::SymbolFlag>(Flag);
107  }
108 
109  uint8_t Flag = 0;
110 };
111 
115  Origin = static_cast<uint8_t>(O);
116  }
117 
118  SymbolOrigin denormalize(IO &) { return static_cast<SymbolOrigin>(Origin); }
119 
120  uint8_t Origin = 0;
121 };
122 
123 template <> struct MappingTraits<YPosition> {
124  static void mapping(IO &IO, YPosition &Value) {
125  IO.mapRequired("Line", Value.Line);
126  IO.mapRequired("Column", Value.Column);
127  }
128 };
129 
134  P.Line = Pos.line();
135  P.Column = Pos.column();
136  }
137 
139  Position Pos;
140  Pos.setLine(P.Line);
141  Pos.setColumn(P.Column);
142  return Pos;
143  }
144  YPosition P;
145 };
146 
149  NormalizedFileURI(IO &, const char *FileURI) { URI = FileURI; }
150 
151  const char *denormalize(IO &IO) {
152  assert(IO.getContext() &&
153  "Expecting an UniqueStringSaver to allocate data");
154  return static_cast<llvm::UniqueStringSaver *>(IO.getContext())
155  ->save(URI)
156  .data();
157  }
158 
159  std::string URI;
160 };
161 
162 template <> struct MappingTraits<SymbolLocation> {
163  static void mapping(IO &IO, SymbolLocation &Value) {
164  MappingNormalization<NormalizedFileURI, const char *> NFile(IO,
165  Value.FileURI);
166  IO.mapRequired("FileURI", NFile->URI);
167  MappingNormalization<NormalizedPosition, SymbolLocation::Position> NStart(
168  IO, Value.Start);
169  IO.mapRequired("Start", NStart->P);
170  MappingNormalization<NormalizedPosition, SymbolLocation::Position> NEnd(
171  IO, Value.End);
172  IO.mapRequired("End", NEnd->P);
173  }
174 };
175 
176 template <> struct MappingTraits<SymbolInfo> {
177  static void mapping(IO &io, SymbolInfo &SymInfo) {
178  // FIXME: expose other fields?
179  io.mapRequired("Kind", SymInfo.Kind);
180  io.mapRequired("Lang", SymInfo.Lang);
181  }
182 };
183 
184 template <>
185 struct MappingTraits<clang::clangd::Symbol::IncludeHeaderWithReferences> {
186  static void mapping(IO &io,
188  io.mapRequired("Header", Inc.IncludeHeader);
189  io.mapRequired("References", Inc.References);
190  }
191 };
192 
193 template <> struct MappingTraits<Symbol> {
194  static void mapping(IO &IO, Symbol &Sym) {
195  MappingNormalization<NormalizedSymbolID, SymbolID> NSymbolID(IO, Sym.ID);
196  MappingNormalization<NormalizedSymbolFlag, Symbol::SymbolFlag> NSymbolFlag(
197  IO, Sym.Flags);
198  MappingNormalization<NormalizedSymbolOrigin, SymbolOrigin> NSymbolOrigin(
199  IO, Sym.Origin);
200  IO.mapRequired("ID", NSymbolID->HexString);
201  IO.mapRequired("Name", Sym.Name);
202  IO.mapRequired("Scope", Sym.Scope);
203  IO.mapRequired("SymInfo", Sym.SymInfo);
204  IO.mapOptional("CanonicalDeclaration", Sym.CanonicalDeclaration,
205  SymbolLocation());
206  IO.mapOptional("Definition", Sym.Definition, SymbolLocation());
207  IO.mapOptional("References", Sym.References, 0u);
208  IO.mapOptional("Origin", NSymbolOrigin->Origin);
209  IO.mapOptional("Flags", NSymbolFlag->Flag);
210  IO.mapOptional("Signature", Sym.Signature);
211  IO.mapOptional("TemplateSpecializationArgs",
213  IO.mapOptional("CompletionSnippetSuffix", Sym.CompletionSnippetSuffix);
214  IO.mapOptional("Documentation", Sym.Documentation);
215  IO.mapOptional("ReturnType", Sym.ReturnType);
216  IO.mapOptional("Type", Sym.Type);
217  IO.mapOptional("IncludeHeaders", Sym.IncludeHeaders);
218  }
219 };
220 
221 template <> struct ScalarEnumerationTraits<SymbolLanguage> {
222  static void enumeration(IO &IO, SymbolLanguage &Value) {
223  IO.enumCase(Value, "C", SymbolLanguage::C);
224  IO.enumCase(Value, "Cpp", SymbolLanguage::CXX);
225  IO.enumCase(Value, "ObjC", SymbolLanguage::ObjC);
226  IO.enumCase(Value, "Swift", SymbolLanguage::Swift);
227  }
228 };
229 
230 template <> struct ScalarEnumerationTraits<SymbolKind> {
231  static void enumeration(IO &IO, SymbolKind &Value) {
232 #define DEFINE_ENUM(name) IO.enumCase(Value, #name, SymbolKind::name)
233 
234  DEFINE_ENUM(Unknown);
235  DEFINE_ENUM(Function);
236  DEFINE_ENUM(Module);
237  DEFINE_ENUM(Namespace);
238  DEFINE_ENUM(NamespaceAlias);
239  DEFINE_ENUM(Macro);
240  DEFINE_ENUM(Enum);
241  DEFINE_ENUM(Struct);
242  DEFINE_ENUM(Class);
243  DEFINE_ENUM(Protocol);
244  DEFINE_ENUM(Extension);
245  DEFINE_ENUM(Union);
246  DEFINE_ENUM(TypeAlias);
247  DEFINE_ENUM(Function);
248  DEFINE_ENUM(Variable);
249  DEFINE_ENUM(Field);
250  DEFINE_ENUM(EnumConstant);
251  DEFINE_ENUM(InstanceMethod);
252  DEFINE_ENUM(ClassMethod);
253  DEFINE_ENUM(StaticMethod);
254  DEFINE_ENUM(InstanceProperty);
255  DEFINE_ENUM(ClassProperty);
256  DEFINE_ENUM(StaticProperty);
257  DEFINE_ENUM(Constructor);
258  DEFINE_ENUM(Destructor);
259  DEFINE_ENUM(ConversionFunction);
260  DEFINE_ENUM(Parameter);
261  DEFINE_ENUM(Using);
262 
263 #undef DEFINE_ENUM
264  }
265 };
266 
267 template <> struct MappingTraits<RefBundle> {
268  static void mapping(IO &IO, RefBundle &Refs) {
269  MappingNormalization<NormalizedSymbolID, SymbolID> NSymbolID(IO,
270  Refs.first);
271  IO.mapRequired("ID", NSymbolID->HexString);
272  IO.mapRequired("References", Refs.second);
273  }
274 };
275 
278  NormalizedRefKind(IO &, RefKind O) { Kind = static_cast<uint8_t>(O); }
279 
280  RefKind denormalize(IO &) { return static_cast<RefKind>(Kind); }
281 
282  uint8_t Kind = 0;
283 };
284 
285 template <> struct MappingTraits<Ref> {
286  static void mapping(IO &IO, Ref &R) {
287  MappingNormalization<NormalizedRefKind, RefKind> NKind(IO, R.Kind);
288  IO.mapRequired("Kind", NKind->Kind);
289  IO.mapRequired("Location", R.Location);
290  }
291 };
292 
296  Kind = static_cast<uint8_t>(R);
297  }
298 
299  RelationKind denormalize(IO &IO) { return static_cast<RelationKind>(Kind); }
300 
301  uint8_t Kind = 0;
302 };
303 
304 template <> struct MappingTraits<SymbolID> {
305  static void mapping(IO &IO, SymbolID &ID) {
306  MappingNormalization<NormalizedSymbolID, SymbolID> NSymbolID(IO, ID);
307  IO.mapRequired("ID", NSymbolID->HexString);
308  }
309 };
310 
311 template <> struct MappingTraits<Relation> {
312  static void mapping(IO &IO, Relation &Relation) {
313  MappingNormalization<NormalizedSymbolRole, RelationKind> NRole(
314  IO, Relation.Predicate);
315  IO.mapRequired("Subject", Relation.Subject);
316  IO.mapRequired("Predicate", NRole->Kind);
317  IO.mapRequired("Object", Relation.Object);
318  }
319 };
320 
324  Flag = static_cast<uint8_t>(O);
325  }
326 
328  return static_cast<IncludeGraphNode::SourceFlag>(Flag);
329  }
330 
331  uint8_t Flag = 0;
332 };
333 
336  NormalizedFileDigest(IO &, const FileDigest &Digest) {
337  HexString = llvm::toHex(Digest);
338  }
339 
341  FileDigest Digest;
342  if (HexString.size() == Digest.size() * 2 &&
343  llvm::all_of(HexString, llvm::isHexDigit)) {
344  memcpy(Digest.data(), llvm::fromHex(HexString).data(), Digest.size());
345  } else {
346  I.setError(std::string("Bad hex file digest: ") + HexString);
347  }
348  return Digest;
349  }
350 
351  std::string HexString;
352 };
353 
354 template <> struct MappingTraits<IncludeGraphNode> {
355  static void mapping(IO &IO, IncludeGraphNode &Node) {
356  IO.mapRequired("URI", Node.URI);
357  MappingNormalization<NormalizedSourceFlag, IncludeGraphNode::SourceFlag>
358  NSourceFlag(IO, Node.Flags);
359  IO.mapRequired("Flags", NSourceFlag->Flag);
360  MappingNormalization<NormalizedFileDigest, FileDigest> NDigest(IO,
361  Node.Digest);
362  IO.mapRequired("Digest", NDigest->HexString);
363  IO.mapRequired("DirectIncludes", Node.DirectIncludes);
364  }
365 };
366 
367 template <> struct MappingTraits<CompileCommandYAML> {
368  static void mapping(IO &IO, CompileCommandYAML &Cmd) {
369  IO.mapRequired("Directory", Cmd.Directory);
370  IO.mapRequired("CommandLine", Cmd.CommandLine);
371  }
372 };
373 
374 template <> struct MappingTraits<VariantEntry> {
375  static void mapping(IO &IO, VariantEntry &Variant) {
376  if (IO.mapTag("!Symbol", Variant.Symbol.hasValue())) {
377  if (!IO.outputting())
378  Variant.Symbol.emplace();
379  MappingTraits<Symbol>::mapping(IO, *Variant.Symbol);
380  } else if (IO.mapTag("!Refs", Variant.Refs.hasValue())) {
381  if (!IO.outputting())
382  Variant.Refs.emplace();
383  MappingTraits<RefBundle>::mapping(IO, *Variant.Refs);
384  } else if (IO.mapTag("!Relations", Variant.Relation.hasValue())) {
385  if (!IO.outputting())
386  Variant.Relation.emplace();
387  MappingTraits<Relation>::mapping(IO, *Variant.Relation);
388  } else if (IO.mapTag("!Source", Variant.Source.hasValue())) {
389  if (!IO.outputting())
390  Variant.Source.emplace();
391  MappingTraits<IncludeGraphNode>::mapping(IO, *Variant.Source);
392  } else if (IO.mapTag("!Cmd", Variant.Cmd.hasValue())) {
393  if (!IO.outputting())
394  Variant.Cmd.emplace();
396  IO, static_cast<CompileCommandYAML &>(*Variant.Cmd));
397  }
398  }
399 };
400 
401 } // namespace yaml
402 } // namespace llvm
403 
404 namespace clang {
405 namespace clangd {
406 
407 void writeYAML(const IndexFileOut &O, llvm::raw_ostream &OS) {
408  llvm::yaml::Output Yout(OS);
409  for (const auto &Sym : *O.Symbols) {
410  VariantEntry Entry;
411  Entry.Symbol = Sym;
412  Yout << Entry;
413  }
414  if (O.Refs)
415  for (auto &Sym : *O.Refs) {
416  VariantEntry Entry;
417  Entry.Refs = Sym;
418  Yout << Entry;
419  }
420  if (O.Relations)
421  for (auto &R : *O.Relations) {
422  VariantEntry Entry;
423  Entry.Relation = R;
424  Yout << Entry;
425  }
426  if (O.Sources) {
427  for (const auto &Source : *O.Sources) {
428  VariantEntry Entry;
429  Entry.Source = Source.getValue();
430  Yout << Entry;
431  }
432  }
433  if (O.Cmd) {
434  VariantEntry Entry;
435  Entry.Cmd = *O.Cmd;
436  Yout << Entry;
437  }
438 }
439 
440 llvm::Expected<IndexFileIn> readYAML(llvm::StringRef Data) {
441  SymbolSlab::Builder Symbols;
443  RelationSlab::Builder Relations;
444  llvm::BumpPtrAllocator
445  Arena; // store the underlying data of Position::FileURI.
446  llvm::UniqueStringSaver Strings(Arena);
447  llvm::yaml::Input Yin(Data, &Strings);
448  IncludeGraph Sources;
449  llvm::Optional<tooling::CompileCommand> Cmd;
450  while (Yin.setCurrentDocument()) {
451  llvm::yaml::EmptyContext Ctx;
452  VariantEntry Variant;
453  yamlize(Yin, Variant, true, Ctx);
454  if (Yin.error())
455  return llvm::errorCodeToError(Yin.error());
456 
457  if (Variant.Symbol)
458  Symbols.insert(*Variant.Symbol);
459  if (Variant.Refs)
460  for (const auto &Ref : Variant.Refs->second)
461  Refs.insert(Variant.Refs->first, Ref);
462  if (Variant.Relation)
463  Relations.insert(*Variant.Relation);
464  if (Variant.Source) {
465  auto &IGN = Variant.Source.getValue();
466  auto Entry = Sources.try_emplace(IGN.URI).first;
467  Entry->getValue() = std::move(IGN);
468  // Fixup refs to refer to map keys which will live on
469  Entry->getValue().URI = Entry->getKey();
470  for (auto &Include : Entry->getValue().DirectIncludes)
471  Include = Sources.try_emplace(Include).first->getKey();
472  }
473  if (Variant.Cmd)
474  Cmd = *Variant.Cmd;
475  Yin.nextDocument();
476  }
477 
478  IndexFileIn Result;
479  Result.Symbols.emplace(std::move(Symbols).build());
480  Result.Refs.emplace(std::move(Refs).build());
481  Result.Relations.emplace(std::move(Relations).build());
482  if (Sources.size())
483  Result.Sources = std::move(Sources);
484  Result.Cmd = std::move(Cmd);
485  return std::move(Result);
486 }
487 
488 std::string toYAML(const Symbol &S) {
489  std::string Buf;
490  {
491  llvm::raw_string_ostream OS(Buf);
492  llvm::yaml::Output Yout(OS);
493  Symbol Sym = S; // copy: Yout<< requires mutability.
494  Yout << Sym;
495  }
496  return Buf;
497 }
498 
499 std::string toYAML(const std::pair<SymbolID, llvm::ArrayRef<Ref>> &Data) {
500  RefBundle Refs = {Data.first, Data.second};
501  std::string Buf;
502  {
503  llvm::raw_string_ostream OS(Buf);
504  llvm::yaml::Output Yout(OS);
505  Yout << Refs;
506  }
507  return Buf;
508 }
509 
510 std::string toYAML(const Relation &R) {
511  std::string Buf;
512  {
513  llvm::raw_string_ostream OS(Buf);
514  llvm::yaml::Output Yout(OS);
515  Relation Rel = R; // copy: Yout<< requires mutability.
516  Yout << Rel;
517  }
518  return Buf;
519 }
520 
521 std::string toYAML(const Ref &R) {
522  std::string Buf;
523  {
524  llvm::raw_string_ostream OS(Buf);
525  llvm::yaml::Output Yout(OS);
526  Ref Reference = R; // copy: Yout<< requires mutability.
527  Yout << Reference;
528  }
529  return Buf;
530 }
531 
532 llvm::Expected<clangd::Symbol>
533 symbolFromYAML(StringRef YAML, llvm::UniqueStringSaver *Strings) {
534  clangd::Symbol Deserialized;
535  llvm::yaml::Input YAMLInput(YAML, Strings);
536  if (YAMLInput.error())
537  return error("Unable to deserialize Symbol from YAML: {0}", YAML);
538  YAMLInput >> Deserialized;
539  return Deserialized;
540 }
541 
542 llvm::Expected<clangd::Ref> refFromYAML(StringRef YAML,
543  llvm::UniqueStringSaver *Strings) {
544  clangd::Ref Deserialized;
545  llvm::yaml::Input YAMLInput(YAML, Strings);
546  if (YAMLInput.error())
547  return error("Unable to deserialize Symbol from YAML: {0}", YAML);
548  YAMLInput >> Deserialized;
549  return Deserialized;
550 }
551 
552 } // namespace clangd
553 } // namespace clang
llvm::yaml::NormalizedSymbolOrigin::NormalizedSymbolOrigin
NormalizedSymbolOrigin(IO &)
Definition: YAMLSerialization.cpp:113
clang::clangd::IndexFileFormat::YAML
@ YAML
clang::clangd::Ref::Kind
RefKind Kind
Definition: Ref.h:90
llvm::yaml::NormalizedFileURI
Definition: YAMLSerialization.cpp:147
Dex.h
clang::clangd::SymbolLocation
Definition: SymbolLocation.h:19
llvm
Some operations such as code completion produce a set of candidates.
Definition: YAMLGenerator.cpp:28
SymbolOrigin.h
clang::clangd::Symbol::ID
SymbolID ID
The ID of the symbol.
Definition: Symbol.h:38
Refs
RefSlab Refs
Definition: SymbolCollectorTests.cpp:311
clang::clangd::Symbol::SymbolFlag
SymbolFlag
Definition: Symbol.h:113
SymbolLocation.h
clang::clangd::IndexFileIn
Definition: Serialization.h:42
llvm::yaml::NormalizedRefKind
Definition: YAMLSerialization.cpp:276
llvm::yaml::NormalizedSourceFlag::NormalizedSourceFlag
NormalizedSourceFlag(IO &)
Definition: YAMLSerialization.cpp:322
clang::clangd::error
llvm::Error error(std::error_code EC, const char *Fmt, Ts &&... Vals)
Definition: Logger.h:80
llvm::yaml::NormalizedSymbolRole::denormalize
RelationKind denormalize(IO &IO)
Definition: YAMLSerialization.cpp:299
clang::clangd::RefKind
RefKind
Describes the kind of a cross-reference.
Definition: Ref.h:30
llvm::yaml::NormalizedRefKind::NormalizedRefKind
NormalizedRefKind(IO &)
Definition: YAMLSerialization.cpp:277
llvm::yaml::NormalizedSymbolRole::NormalizedSymbolRole
NormalizedSymbolRole(IO &)
Definition: YAMLSerialization.cpp:294
Index.h
clang::clangd::RelationSlab::Builder::insert
void insert(const Relation &R)
Adds a relation to the slab.
Definition: Relation.h:80
clang::clangd::RefSlab::Builder
RefSlab::Builder is a mutable container that can 'freeze' to RefSlab.
Definition: Ref.h:134
llvm::yaml::NormalizedSymbolFlag
Definition: YAMLSerialization.cpp:99
llvm::yaml::NormalizedFileURI::URI
std::string URI
Definition: YAMLSerialization.cpp:159
llvm::yaml::NormalizedSymbolFlag::Flag
uint8_t Flag
Definition: YAMLSerialization.cpp:109
llvm::yaml::NormalizedSymbolFlag::NormalizedSymbolFlag
NormalizedSymbolFlag(IO &)
Definition: YAMLSerialization.cpp:100
llvm::yaml::NormalizedRefKind::Kind
uint8_t Kind
Definition: YAMLSerialization.cpp:282
Ctx
Context Ctx
Definition: TUScheduler.cpp:458
llvm::yaml::NormalizedRefKind::denormalize
RefKind denormalize(IO &)
Definition: YAMLSerialization.cpp:280
Trace.h
DEFINE_ENUM
#define DEFINE_ENUM(name)
llvm::yaml::NormalizedFileDigest::NormalizedFileDigest
NormalizedFileDigest(IO &, const FileDigest &Digest)
Definition: YAMLSerialization.cpp:336
llvm::yaml::NormalizedSymbolOrigin::denormalize
SymbolOrigin denormalize(IO &)
Definition: YAMLSerialization.cpp:118
clang::clangd::Relation
Represents a relation between two symbols.
Definition: Relation.h:34
clang::clangd::RelationSlab::Builder
RelationSlab::Builder is a mutable container that can 'freeze' to RelationSlab.
Definition: Relation.h:77
llvm::yaml::NormalizedFileURI::denormalize
const char * denormalize(IO &IO)
Definition: YAMLSerialization.cpp:151
clang::clangd::refFromYAML
llvm::Expected< clangd::Ref > refFromYAML(StringRef YAML, llvm::UniqueStringSaver *Strings)
Definition: YAMLSerialization.cpp:542
llvm::yaml::MappingTraits< SymbolInfo >::mapping
static void mapping(IO &io, SymbolInfo &SymInfo)
Definition: YAMLSerialization.cpp:177
clang::clangd::IndexFileOut
Definition: Serialization.h:55
llvm::yaml::NormalizedSymbolID::HexString
std::string HexString
Definition: YAMLSerialization.cpp:96
llvm::yaml::MappingTraits< clang::clangd::Symbol::IncludeHeaderWithReferences >::mapping
static void mapping(IO &io, clang::clangd::Symbol::IncludeHeaderWithReferences &Inc)
Definition: YAMLSerialization.cpp:186
llvm::yaml::NormalizedRefKind::NormalizedRefKind
NormalizedRefKind(IO &, RefKind O)
Definition: YAMLSerialization.cpp:278
llvm::yaml::NormalizedFileURI::NormalizedFileURI
NormalizedFileURI(IO &)
Definition: YAMLSerialization.cpp:148
clang::clangd::SymbolLocation::Position::line
uint32_t line() const
Definition: SymbolLocation.h:35
clang::clangd::Symbol::References
unsigned References
The number of translation units that reference this symbol from their main file.
Definition: Symbol.h:59
llvm::yaml::NormalizedFileDigest
Definition: YAMLSerialization.cpp:334
Relation.h
llvm::yaml::NormalizedFileURI::NormalizedFileURI
NormalizedFileURI(IO &, const char *FileURI)
Definition: YAMLSerialization.cpp:149
clang::clangd::readYAML
llvm::Expected< IndexFileIn > readYAML(llvm::StringRef)
Definition: YAMLSerialization.cpp:440
llvm::yaml::NormalizedFileDigest::HexString
std::string HexString
Definition: YAMLSerialization.cpp:351
llvm::yaml::NormalizedSourceFlag::denormalize
IncludeGraphNode::SourceFlag denormalize(IO &)
Definition: YAMLSerialization.cpp:327
llvm::yaml::NormalizedSymbolRole::NormalizedSymbolRole
NormalizedSymbolRole(IO &IO, RelationKind R)
Definition: YAMLSerialization.cpp:295
clang::clangd::Symbol::ReturnType
llvm::StringRef ReturnType
Type when this symbol is used in an expression.
Definition: Symbol.h:80
llvm::yaml::NormalizedPosition
Definition: YAMLSerialization.cpp:130
Line
int Line
Definition: PreprocessorTracker.cpp:514
llvm::yaml::MappingTraits< SymbolID >::mapping
static void mapping(IO &IO, SymbolID &ID)
Definition: YAMLSerialization.cpp:305
clang::clangd::Ref::Location
SymbolLocation Location
The source location where the symbol is named.
Definition: Ref.h:89
clang::clangd::writeYAML
void writeYAML(const IndexFileOut &, llvm::raw_ostream &)
Definition: YAMLSerialization.cpp:407
clang::clangd::toYAML
std::string toYAML(const Symbol &)
Definition: YAMLSerialization.cpp:488
clang::clangd::Relation::Object
SymbolID Object
Definition: Relation.h:37
clang::clangd::Symbol::Origin
SymbolOrigin Origin
Where this symbol came from. Usually an index provides a constant value.
Definition: Symbol.h:61
Logger.h
clang::clangd::Symbol
The class presents a C++ symbol, e.g.
Definition: Symbol.h:36
clang::clangd::Symbol::Flags
SymbolFlag Flags
Definition: Symbol.h:128
clang::clangd::IncludeGraphNode::SourceFlag
SourceFlag
Definition: Headers.h:73
clang::clangd::Symbol::SymInfo
index::SymbolInfo SymInfo
The symbol information, like symbol kind.
Definition: Symbol.h:40
llvm::yaml::NormalizedPosition::P
YPosition P
Definition: YAMLSerialization.cpp:144
clang::clangd::SymbolLocation::Position::setColumn
void setColumn(uint32_t Column)
Definition: SymbolLocation.cpp:22
llvm::yaml::NormalizedSymbolID
Definition: YAMLSerialization.cpp:80
llvm::yaml::MappingTraits< VariantEntry >::mapping
static void mapping(IO &IO, VariantEntry &Variant)
Definition: YAMLSerialization.cpp:375
clang::clangd::RefKind::Reference
@ Reference
Serialization.h
clang::clangd::Symbol::Name
llvm::StringRef Name
The unqualified name of the symbol, e.g. "bar" (for ns::bar).
Definition: Symbol.h:42
clang::doc::SymbolID
std::array< uint8_t, 20 > SymbolID
Definition: Representation.h:30
llvm::yaml::NormalizedSourceFlag::NormalizedSourceFlag
NormalizedSourceFlag(IO &, IncludeGraphNode::SourceFlag O)
Definition: YAMLSerialization.cpp:323
llvm::yaml::MappingTraits< YPosition >::mapping
static void mapping(IO &IO, YPosition &Value)
Definition: YAMLSerialization.cpp:124
llvm::yaml::NormalizedSymbolOrigin
Definition: YAMLSerialization.cpp:112
llvm::yaml::NormalizedSymbolOrigin::Origin
uint8_t Origin
Definition: YAMLSerialization.cpp:120
clang::clangd::SymbolOrigin
SymbolOrigin
Definition: SymbolOrigin.h:21
llvm::yaml::NormalizedSymbolRole
Definition: YAMLSerialization.cpp:293
Output
std::string Output
Definition: TraceTests.cpp:162
clang::clangd::SymbolLocation::Position::column
uint32_t column() const
Definition: SymbolLocation.h:37
SymbolKind
clang::find_all_symbols::SymbolInfo::SymbolKind SymbolKind
Definition: SymbolInfo.cpp:21
clang::clangd::Symbol::CanonicalDeclaration
SymbolLocation CanonicalDeclaration
The location of the preferred declaration of the symbol.
Definition: Symbol.h:56
llvm::yaml::NormalizedPosition::NormalizedPosition
NormalizedPosition(IO &, const Position &Pos)
Definition: YAMLSerialization.cpp:133
clang::clangd::IndexFileOut::Refs
const RefSlab * Refs
Definition: Serialization.h:57
llvm::yaml::NormalizedPosition::denormalize
Position denormalize(IO &)
Definition: YAMLSerialization.cpp:138
Entry
Definition: Modularize.cpp:428
clang::clangd::Symbol::CompletionSnippetSuffix
llvm::StringRef CompletionSnippetSuffix
What to insert when completing this symbol, after the symbol name.
Definition: Symbol.h:74
clang::clangd::SymbolLocation::Position
Definition: SymbolLocation.h:32
llvm::yaml::MappingTraits< Ref >::mapping
static void mapping(IO &IO, Ref &R)
Definition: YAMLSerialization.cpp:286
clang::clangd::symbolFromYAML
llvm::Expected< clangd::Symbol > symbolFromYAML(StringRef YAML, llvm::UniqueStringSaver *Strings)
Definition: YAMLSerialization.cpp:533
llvm::yaml::NormalizedFileDigest::denormalize
FileDigest denormalize(IO &I)
Definition: YAMLSerialization.cpp:340
Strings
std::vector< llvm::StringRef > Strings
Definition: Serialization.cpp:212
ID
static char ID
Definition: Logger.cpp:74
clang::clangd::Symbol::IncludeHeaderWithReferences
Definition: Symbol.h:87
clang::clangd::Ref
Represents a symbol occurrence in the source file.
Definition: Ref.h:87
llvm::yaml::MappingTraits< Symbol >::mapping
static void mapping(IO &IO, Symbol &Sym)
Definition: YAMLSerialization.cpp:194
clang::clangd::Relation::Subject
SymbolID Subject
Definition: Relation.h:35
clang::clangd::IndexFileOut::Cmd
const tooling::CompileCommand * Cmd
Definition: Serialization.h:63
clang::clangd::Symbol::TemplateSpecializationArgs
llvm::StringRef TemplateSpecializationArgs
Argument list in human-readable format, will be displayed to help disambiguate between different spec...
Definition: Symbol.h:69
llvm::yaml::NormalizedSourceFlag
Definition: YAMLSerialization.cpp:321
clang::clangd::FileDigest
std::array< uint8_t, 8 > FileDigest
Definition: SourceCode.h:40
Column
int Column
Definition: PreprocessorTracker.cpp:515
clang::clangd::IndexFileOut::Sources
const IncludeGraph * Sources
Definition: Serialization.h:60
C
const Criteria C
Definition: FunctionCognitiveComplexityCheck.cpp:93
clang::clangd::Relation::Predicate
RelationKind Predicate
Definition: Relation.h:36
clang::clangd::Symbol::IncludeHeaderWithReferences::References
unsigned References
The number of translation units that reference this symbol and include this header.
Definition: Symbol.h:104
clang::clangd::SymbolLocation::Position::setLine
void setLine(uint32_t Line)
Definition: SymbolLocation.cpp:17
clang::clangd::SymbolID::fromStr
static llvm::Expected< SymbolID > fromStr(llvm::StringRef)
Definition: SymbolID.cpp:36
llvm::yaml::MappingTraits< SymbolLocation >::mapping
static void mapping(IO &IO, SymbolLocation &Value)
Definition: YAMLSerialization.cpp:163
clang::clangd::Symbol::Scope
llvm::StringRef Scope
The containing namespace. e.g. "" (global), "ns::" (top-level namespace).
Definition: Symbol.h:44
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ApplyReplacements.h:27
OS
llvm::raw_string_ostream OS
Definition: TraceTests.cpp:163
clang::clangd::IncludeGraphNode
Definition: Headers.h:72
Arena
llvm::BumpPtrAllocator Arena
Definition: Serialization.cpp:211
llvm::yaml::NormalizedSourceFlag::Flag
uint8_t Flag
Definition: YAMLSerialization.cpp:331
clang::tidy::cppcoreguidelines::toString
static llvm::StringRef toString(SpecialMemberFunctionsCheck::SpecialMemberFunctionKind K)
Definition: SpecialMemberFunctionsCheck.cpp:55
SymbolInfo
clang::find_all_symbols::SymbolInfo SymbolInfo
Definition: FindAllSymbolsMain.cpp:38
llvm::yaml::NormalizedSymbolFlag::NormalizedSymbolFlag
NormalizedSymbolFlag(IO &, Symbol::SymbolFlag F)
Definition: YAMLSerialization.cpp:101
clang::clangd::IncludeGraph
llvm::StringMap< IncludeGraphNode > IncludeGraph
Definition: Headers.h:90
clang::clangd::Symbol::Definition
SymbolLocation Definition
The location of the symbol's definition, if one was found.
Definition: Symbol.h:47
llvm::yaml::NormalizedSymbolOrigin::NormalizedSymbolOrigin
NormalizedSymbolOrigin(IO &, SymbolOrigin O)
Definition: YAMLSerialization.cpp:114
Pos
Position Pos
Definition: SourceCode.cpp:657
llvm::yaml::MappingTraits< CompileCommandYAML >::mapping
static void mapping(IO &IO, CompileCommandYAML &Cmd)
Definition: YAMLSerialization.cpp:368
clang::clangd::SymbolSlab::Builder
SymbolSlab::Builder is a mutable container that can 'freeze' to SymbolSlab.
Definition: Symbol.h:200
llvm::yaml::MappingTraits< IncludeGraphNode >::mapping
static void mapping(IO &IO, IncludeGraphNode &Node)
Definition: YAMLSerialization.cpp:355
llvm::yaml::NormalizedSymbolFlag::denormalize
Symbol::SymbolFlag denormalize(IO &)
Definition: YAMLSerialization.cpp:105
llvm::yaml::ScalarEnumerationTraits< SymbolKind >::enumeration
static void enumeration(IO &IO, SymbolKind &Value)
Definition: YAMLSerialization.cpp:231
llvm::yaml::ScalarEnumerationTraits< SymbolLanguage >::enumeration
static void enumeration(IO &IO, SymbolLanguage &Value)
Definition: YAMLSerialization.cpp:222
llvm::yaml::NormalizedSymbolID::NormalizedSymbolID
NormalizedSymbolID(IO &, const SymbolID &ID)
Definition: YAMLSerialization.cpp:82
clang::clangd::SymbolID
Definition: SymbolID.h:32
clang::clangd::Symbol::Signature
llvm::StringRef Signature
A brief description of the symbol that can be appended in the completion candidate list.
Definition: Symbol.h:65
clang::clangd::Symbol::Type
llvm::StringRef Type
Raw representation of the OpaqueType of the symbol, used for scoring purposes.
Definition: Symbol.h:85
clang::clangd::Symbol::IncludeHeaders
llvm::SmallVector< IncludeHeaderWithReferences, 1 > IncludeHeaders
One Symbol can potentially be included via different headers.
Definition: Symbol.h:111
clang::clangd::IndexFileOut::Symbols
const SymbolSlab * Symbols
Definition: Serialization.h:56
clang::clangd::Symbol::Documentation
llvm::StringRef Documentation
Documentation including comment for the symbol declaration.
Definition: Symbol.h:76
clang::clangd::Symbol::IncludeHeaderWithReferences::IncludeHeader
llvm::StringRef IncludeHeader
This can be either a URI of the header to be #include'd for this symbol, or a literal header quoted w...
Definition: Symbol.h:101
llvm::yaml::NormalizedSymbolID::NormalizedSymbolID
NormalizedSymbolID(IO &)
Definition: YAMLSerialization.cpp:81
llvm::yaml::NormalizedFileDigest::NormalizedFileDigest
NormalizedFileDigest(IO &)
Definition: YAMLSerialization.cpp:335
clang::clangd::SymbolSlab::Builder::insert
void insert(const Symbol &S)
Adds a symbol, overwriting any existing one with the same ID.
Definition: Symbol.cpp:50
llvm::yaml::NormalizedPosition::NormalizedPosition
NormalizedPosition(IO &)
Definition: YAMLSerialization.cpp:132
yaml
@ yaml
Definition: ClangDocMain.cpp:92
llvm::yaml::NormalizedSymbolRole::Kind
uint8_t Kind
Definition: YAMLSerialization.cpp:301
llvm::yaml::MappingTraits< Relation >::mapping
static void mapping(IO &IO, Relation &Relation)
Definition: YAMLSerialization.cpp:312
llvm::yaml::NormalizedSymbolID::denormalize
SymbolID denormalize(IO &I)
Definition: YAMLSerialization.cpp:87
clang::clangd::RelationKind
RelationKind
Definition: Relation.h:22
llvm::yaml::MappingTraits< RefBundle >::mapping
static void mapping(IO &IO, RefBundle &Refs)
Definition: YAMLSerialization.cpp:268
clang::clangd::IndexFileOut::Relations
const RelationSlab * Relations
Definition: Serialization.h:58