22 #include "llvm/ADT/Optional.h" 23 #include "llvm/ADT/SmallVector.h" 24 #include "llvm/ADT/StringRef.h" 25 #include "llvm/Support/Allocator.h" 26 #include "llvm/Support/Errc.h" 27 #include "llvm/Support/MemoryBuffer.h" 28 #include "llvm/Support/StringSaver.h" 29 #include "llvm/Support/YAMLTraits.h" 30 #include "llvm/Support/raw_ostream.h" 38 std::pair<clang::clangd::SymbolID, std::vector<clang::clangd::Ref>>;
41 llvm::Optional<clang::clangd::Symbol> Symbol;
42 llvm::Optional<RefBundle>
Refs;
43 llvm::Optional<clang::clangd::Relation> Relation;
66 using clang::index::SymbolLanguage;
67 using clang::index::SymbolRole;
73 llvm::raw_string_ostream OS(HexString);
78 auto ID = SymbolID::fromStr(HexString);
92 Flag =
static_cast<uint8_t
>(F);
105 Origin =
static_cast<uint8_t
>(O);
113 template <>
struct MappingTraits<YPosition> {
114 static void mapping(IO &IO, YPosition &Value) {
115 IO.mapRequired(
"Line", Value.Line);
116 IO.mapRequired(
"Column", Value.Column);
142 assert(IO.getContext() &&
143 "Expecting an UniqueStringSaver to allocate data");
144 return static_cast<llvm::UniqueStringSaver *
>(IO.getContext())
154 MappingNormalization<NormalizedFileURI, const char *> NFile(IO,
156 IO.mapRequired(
"FileURI", NFile->URI);
157 MappingNormalization<NormalizedPosition, SymbolLocation::Position> NStart(
159 IO.mapRequired(
"Start", NStart->P);
160 MappingNormalization<NormalizedPosition, SymbolLocation::Position> NEnd(
162 IO.mapRequired(
"End", NEnd->P);
169 io.mapRequired(
"Kind", SymInfo.Kind);
170 io.mapRequired(
"Lang", SymInfo.Lang);
175 struct MappingTraits<
clang::clangd::Symbol::IncludeHeaderWithReferences> {
183 template <>
struct MappingTraits<
Symbol> {
185 MappingNormalization<NormalizedSymbolID, SymbolID> NSymbolID(IO, Sym.
ID);
186 MappingNormalization<NormalizedSymbolFlag, Symbol::SymbolFlag> NSymbolFlag(
188 MappingNormalization<NormalizedSymbolOrigin, SymbolOrigin> NSymbolOrigin(
190 IO.mapRequired(
"ID", NSymbolID->HexString);
191 IO.mapRequired(
"Name", Sym.
Name);
192 IO.mapRequired(
"Scope", Sym.
Scope);
193 IO.mapRequired(
"SymInfo", Sym.
SymInfo);
197 IO.mapOptional(
"References", Sym.
References, 0u);
198 IO.mapOptional(
"Origin", NSymbolOrigin->Origin);
199 IO.mapOptional(
"Flags", NSymbolFlag->Flag);
200 IO.mapOptional(
"Signature", Sym.
Signature);
201 IO.mapOptional(
"TemplateSpecializationArgs",
206 IO.mapOptional(
"Type", Sym.
Type);
211 template <>
struct ScalarEnumerationTraits<SymbolLanguage> {
213 IO.enumCase(Value,
"C", SymbolLanguage::C);
214 IO.enumCase(Value,
"Cpp", SymbolLanguage::CXX);
215 IO.enumCase(Value,
"ObjC", SymbolLanguage::ObjC);
216 IO.enumCase(Value,
"Swift", SymbolLanguage::Swift);
222 #define DEFINE_ENUM(name) IO.enumCase(Value, #name, SymbolKind::name) 257 template <>
struct MappingTraits<RefBundle> {
259 MappingNormalization<NormalizedSymbolID, SymbolID> NSymbolID(IO,
261 IO.mapRequired(
"ID", NSymbolID->HexString);
262 IO.mapRequired(
"References", Refs.second);
275 template <>
struct MappingTraits<
Ref> {
277 MappingNormalization<NormalizedRefKind, RefKind> NKind(IO, R.
Kind);
278 IO.mapRequired(
"Kind", NKind->Kind);
279 IO.mapRequired(
"Location", R.
Location);
286 Kind =
static_cast<uint8_t
>(R);
296 MappingNormalization<NormalizedSymbolID, SymbolID> NSymbolID(IO, ID);
297 IO.mapRequired(
"ID", NSymbolID->HexString);
303 MappingNormalization<NormalizedSymbolRole, RelationKind> NRole(
305 IO.mapRequired(
"Subject", Relation.
Subject);
306 IO.mapRequired(
"Predicate", NRole->Kind);
307 IO.mapRequired(
"Object", Relation.
Object);
311 template <>
struct MappingTraits<VariantEntry> {
312 static void mapping(IO &IO, VariantEntry &Variant) {
313 if (IO.mapTag(
"!Symbol", Variant.Symbol.hasValue())) {
314 if (!IO.outputting())
315 Variant.Symbol.emplace();
316 MappingTraits<Symbol>::mapping(IO, *Variant.Symbol);
317 }
else if (IO.mapTag(
"!Refs", Variant.Refs.hasValue())) {
318 if (!IO.outputting())
319 Variant.Refs.emplace();
320 MappingTraits<RefBundle>::mapping(IO, *Variant.Refs);
321 }
else if (IO.mapTag(
"!Relations", Variant.Relation.hasValue())) {
322 if (!IO.outputting())
323 Variant.Relation.emplace();
324 MappingTraits<Relation>::mapping(IO, *Variant.Relation);
336 llvm::yaml::Output Yout(OS);
337 for (
const auto &Sym : *O.
Symbols) {
343 for (
auto &Sym : *O.
Refs) {
356 llvm::Expected<IndexFileIn>
readYAML(llvm::StringRef Data) {
360 llvm::BumpPtrAllocator
362 llvm::UniqueStringSaver
Strings(Arena);
363 llvm::yaml::Input Yin(Data, &Strings);
364 while (Yin.setCurrentDocument()) {
365 llvm::yaml::EmptyContext
Ctx;
366 VariantEntry Variant;
367 yamlize(Yin, Variant,
true, Ctx);
369 return llvm::errorCodeToError(Yin.error());
372 Symbols.
insert(*Variant.Symbol);
374 for (
const auto &
Ref : Variant.Refs->second)
376 if (Variant.Relation)
377 Relations.
insert(*Variant.Relation);
382 Result.
Symbols.emplace(std::move(Symbols).build());
383 Result.
Refs.emplace(std::move(Refs).build());
384 Result.
Relations.emplace(std::move(Relations).build());
385 return std::move(Result);
391 llvm::raw_string_ostream OS(Buf);
392 llvm::yaml::Output Yout(OS);
400 RefBundle
Refs = {Data.first, Data.second};
403 llvm::raw_string_ostream OS(Buf);
404 llvm::yaml::Output Yout(OS);
413 llvm::raw_string_ostream OS(Buf);
414 llvm::yaml::Output Yout(OS);
llvm::Expected< IndexFileIn > readYAML(llvm::StringRef)
llvm::Optional< SymbolSlab > Symbols
Symbol::SymbolFlag denormalize(IO &)
Some operations such as code completion produce a set of candidates.
Represents a relation between two symbols.
void setColumn(uint32_t Column)
static void mapping(IO &io, SymbolInfo &SymInfo)
This defines Dex - a symbol index implementation based on query iterators over symbol tokens...
void writeYAML(const IndexFileOut &, llvm::raw_ostream &)
clang::find_all_symbols::SymbolInfo::SymbolKind SymbolKind
void setLine(uint32_t Line)
NormalizedSymbolOrigin(IO &)
const char * denormalize(IO &IO)
Represents a symbol occurrence in the source file.
void insert(const Symbol &S)
Adds a symbol, overwriting any existing one with the same ID.
static llvm::StringRef toString(SpecialMemberFunctionsCheck::SpecialMemberFunctionKind K)
static void enumeration(IO &IO, SymbolKind &Value)
llvm::StringRef Scope
The containing namespace. e.g. "" (global), "ns::" (top-level namespace).
llvm::Optional< RelationSlab > Relations
static void mapping(IO &IO, Ref &R)
const SymbolSlab * Symbols
unsigned References
The number of translation units that reference this symbol from their main file.
SymbolSlab::Builder is a mutable container that can 'freeze' to SymbolSlab.
SymbolID ID
The ID of the symbol.
static void mapping(IO &IO, Symbol &Sym)
index::SymbolInfo SymInfo
The symbol information, like symbol kind.
static void mapping(IO &IO, SymbolID &ID)
llvm::BumpPtrAllocator Arena
SymbolLocation Definition
The location of the symbol's definition, if one was found.
NormalizedSymbolRole(IO &)
clang::find_all_symbols::SymbolInfo SymbolInfo
NormalizedSymbolFlag(IO &, Symbol::SymbolFlag F)
llvm::SmallVector< IncludeHeaderWithReferences, 1 > IncludeHeaders
One Symbol can potentially be included via different headers.
llvm::StringRef Signature
A brief description of the symbol that can be appended in the completion candidate list...
SymbolLocation Location
The source location where the symbol is named.
static void enumeration(IO &IO, SymbolLanguage &Value)
llvm::StringRef Documentation
Documentation including comment for the symbol declaration.
SymbolLocation CanonicalDeclaration
The location of the preferred declaration of the symbol.
void insert(const Relation &R)
Adds a relation to the slab.
RefKind
Describes the kind of a cross-reference.
std::string toYAML(const std::pair< SymbolID, llvm::ArrayRef< Ref >> &Data)
NormalizedSymbolFlag(IO &)
RelationSlab::Builder is a mutable container that can 'freeze' to RelationSlab.
RefSlab::Builder is a mutable container that can 'freeze' to RefSlab.
static void mapping(IO &IO, SymbolLocation &Value)
std::vector< llvm::StringRef > Strings
NormalizedPosition(IO &, const Position &Pos)
const RelationSlab * Relations
llvm::Optional< RefSlab > Refs
Position denormalize(IO &)
The class presents a C++ symbol, e.g.
Position Start
The symbol range, using half-open range [Start, End).
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
llvm::StringRef Name
The unqualified name of the symbol, e.g. "bar" (for ns::bar).
static void mapping(IO &IO, RefBundle &Refs)
RefKind denormalize(IO &)
NormalizedSymbolID(IO &, const SymbolID &ID)
NormalizedSymbolOrigin(IO &, SymbolOrigin O)
static void mapping(IO &IO, VariantEntry &Variant)
void insert(const SymbolID &ID, const Ref &S)
Adds a ref to the slab. Deep copy: Strings will be owned by the slab.
RelationKind denormalize(IO &IO)
llvm::StringRef CompletionSnippetSuffix
What to insert when completing this symbol, after the symbol name.
#define DEFINE_ENUM(name)
static void mapping(IO &IO, YPosition &Value)
llvm::StringRef Type
Raw representation of the OpaqueType of the symbol, used for scoring purposes.
SymbolOrigin Origin
Where this symbol came from. Usually an index provides a constant value.
NormalizedFileURI(IO &, const char *FileURI)
NormalizedSymbolRole(IO &IO, RelationKind R)
llvm::StringRef TemplateSpecializationArgs
Argument list in human-readable format, will be displayed to help disambiguate between different spec...
llvm::StringRef ReturnType
Type when this symbol is used in an expression.
std::array< uint8_t, 20 > SymbolID
SymbolID denormalize(IO &I)
static void mapping(IO &IO, Relation &Relation)
SymbolOrigin denormalize(IO &)
NormalizedRefKind(IO &, RefKind O)