llvm/clang-tools-extra/clangd/index/YAMLSerialization.cpp

//===-- YAMLSerialization.cpp ------------------------------------*- C++-*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// A YAML index file is a sequence of tagged entries.
// Each entry either encodes a Symbol or the list of references to a symbol
// (a "ref bundle").
//
//===----------------------------------------------------------------------===//

#include "Headers.h"
#include "index/Ref.h"
#include "index/Relation.h"
#include "index/Serialization.h"
#include "index/Symbol.h"
#include "index/SymbolLocation.h"
#include "index/SymbolOrigin.h"
#include "clang/Tooling/CompilationDatabase.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Allocator.h"
#include "llvm/Support/StringSaver.h"
#include "llvm/Support/YAMLTraits.h"
#include "llvm/Support/raw_ostream.h"
#include <cstdint>
#include <optional>

namespace {
struct YIncludeHeaderWithReferences;
}

LLVM_YAML_IS_SEQUENCE_VECTOR(clang::clangd::Symbol::IncludeHeaderWithReferences)
LLVM_YAML_IS_SEQUENCE_VECTOR(clang::clangd::Ref)
LLVM_YAML_IS_SEQUENCE_VECTOR(YIncludeHeaderWithReferences)

namespace {
RefBundle;
// This is a pale imitation of std::variant<Symbol, RefBundle, Relation>
struct VariantEntry {};
// A class helps YAML to serialize the 32-bit encoded position (Line&Column),
// as YAMLIO can't directly map bitfields.
struct YPosition {};
// A class helps YAML to serialize the IncludeHeaderWithReferences as YAMLIO
// can't directly map bitfields.
struct YIncludeHeaderWithReferences {};

// avoid ODR violation of specialization for non-owned CompileCommand
struct CompileCommandYAML : clang::tooling::CompileCommand {};

} // namespace
namespace llvm {
namespace yaml {

FileDigest;
IncludeGraph;
IncludeGraphNode;
Ref;
RefKind;
Relation;
RelationKind;
Symbol;
SymbolID;
SymbolLocation;
SymbolInfo;
SymbolKind;
SymbolLanguage;
CompileCommand;

// Helper to (de)serialize the SymbolID. We serialize it as a hex string.
struct NormalizedSymbolID {};

struct NormalizedSymbolFlag {};

template <> struct MappingTraits<YPosition> {};

struct NormalizedPosition {};

struct NormalizedFileURI {};

template <> struct MappingTraits<SymbolLocation> {};

template <> struct MappingTraits<SymbolInfo> {};

template <> struct ScalarBitSetTraits<clang::clangd::Symbol::IncludeDirective> {};

template <> struct MappingTraits<YIncludeHeaderWithReferences> {};

struct NormalizedIncludeHeaders {};

template <> struct MappingTraits<Symbol> {};

template <> struct ScalarEnumerationTraits<SymbolLanguage> {};

template <> struct ScalarEnumerationTraits<SymbolKind> {};

template <> struct MappingTraits<RefBundle> {};

struct NormalizedRefKind {};

template <> struct MappingTraits<Ref> {};

struct NormalizedSymbolRole {};

template <> struct MappingTraits<SymbolID> {};

template <> struct MappingTraits<Relation> {};

struct NormalizedSourceFlag {};

struct NormalizedFileDigest {};

template <> struct MappingTraits<IncludeGraphNode> {};

template <> struct MappingTraits<CompileCommandYAML> {};

template <> struct MappingTraits<VariantEntry> {};

} // namespace yaml
} // namespace llvm

namespace clang {
namespace clangd {

void writeYAML(const IndexFileOut &O, llvm::raw_ostream &OS) {}

llvm::Expected<IndexFileIn> readYAML(llvm::StringRef Data,
                                     SymbolOrigin Origin) {}

std::string toYAML(const Symbol &S) {}

std::string toYAML(const std::pair<SymbolID, llvm::ArrayRef<Ref>> &Data) {}

std::string toYAML(const Relation &R) {}

std::string toYAML(const Ref &R) {}

} // namespace clangd
} // namespace clang