90 lines · c
1//===-- Serializer.h - ClangDoc Serializer ----------------------*- 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-exception6//7//===----------------------------------------------------------------------===//8//9// This file implements the serializing functions fro the clang-doc tool. Given10// a particular declaration, it collects the appropriate information and returns11// a serialized bitcode string for the declaration.12//13//===----------------------------------------------------------------------===//14 15#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_DOC_SERIALIZE_H16#define LLVM_CLANG_TOOLS_EXTRA_CLANG_DOC_SERIALIZE_H17 18#include "Representation.h"19#include <string>20 21using namespace clang::comments;22 23namespace clang {24namespace doc {25namespace serialize {26 27// The first element will contain the relevant information about the declaration28// passed as parameter.29// The second element will contain the relevant information about the30// declaration's parent, it can be a NamespaceInfo or RecordInfo.31// Both elements can be nullptrs if the declaration shouldn't be handled.32// When the declaration is handled, the first element will be a nullptr for33// EnumDecl, FunctionDecl and CXXMethodDecl; they are only returned wrapped in34// its parent scope. For NamespaceDecl and RecordDecl both elements are not35// nullptr.36std::pair<std::unique_ptr<Info>, std::unique_ptr<Info>>37emitInfo(const NamespaceDecl *D, const FullComment *FC, Location Loc,38 bool PublicOnly);39 40std::pair<std::unique_ptr<Info>, std::unique_ptr<Info>>41emitInfo(const RecordDecl *D, const FullComment *FC, Location Loc,42 bool PublicOnly);43 44std::pair<std::unique_ptr<Info>, std::unique_ptr<Info>>45emitInfo(const EnumDecl *D, const FullComment *FC, Location Loc,46 bool PublicOnly);47 48std::pair<std::unique_ptr<Info>, std::unique_ptr<Info>>49emitInfo(const FunctionDecl *D, const FullComment *FC, Location Loc,50 bool PublicOnly);51 52std::pair<std::unique_ptr<Info>, std::unique_ptr<Info>>53emitInfo(const VarDecl *D, const FullComment *FC, int LineNumber,54 StringRef File, bool IsFileInRootDir, bool PublicOnly);55 56std::pair<std::unique_ptr<Info>, std::unique_ptr<Info>>57emitInfo(const CXXMethodDecl *D, const FullComment *FC, Location Loc,58 bool PublicOnly);59 60std::pair<std::unique_ptr<Info>, std::unique_ptr<Info>>61emitInfo(const TypedefDecl *D, const FullComment *FC, Location Loc,62 bool PublicOnly);63 64std::pair<std::unique_ptr<Info>, std::unique_ptr<Info>>65emitInfo(const TypeAliasDecl *D, const FullComment *FC, Location Loc,66 bool PublicOnly);67 68std::pair<std::unique_ptr<Info>, std::unique_ptr<Info>>69emitInfo(const ConceptDecl *D, const FullComment *FC, const Location &Loc,70 bool PublicOnly);71 72std::pair<std::unique_ptr<Info>, std::unique_ptr<Info>>73emitInfo(const VarDecl *D, const FullComment *FC, const Location &Loc,74 bool PublicOnly);75 76// Function to hash a given USR value for storage.77// As USRs (Unified Symbol Resolution) could be large, especially for functions78// with long type arguments, we use 160-bits SHA1(USR) values to79// guarantee the uniqueness of symbols while using a relatively small amount of80// memory (vs storing USRs directly).81SymbolID hashUSR(llvm::StringRef USR);82 83std::string serialize(std::unique_ptr<Info> &I);84 85} // namespace serialize86} // namespace doc87} // namespace clang88 89#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_DOC_SERIALIZE_H90