1e975a473SJulie Hockett //===-- Serializer.h - ClangDoc Serializer ----------------------*- C++ -*-===// 2e975a473SJulie Hockett // 32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information. 52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6e975a473SJulie Hockett // 7e975a473SJulie Hockett //===----------------------------------------------------------------------===// 8e975a473SJulie Hockett // 9e975a473SJulie Hockett // This file implements the serializing functions fro the clang-doc tool. Given 10e975a473SJulie Hockett // a particular declaration, it collects the appropriate information and returns 11e975a473SJulie Hockett // a serialized bitcode string for the declaration. 12e975a473SJulie Hockett // 13e975a473SJulie Hockett //===----------------------------------------------------------------------===// 14e975a473SJulie Hockett 15e975a473SJulie Hockett #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_DOC_SERIALIZE_H 16e975a473SJulie Hockett #define LLVM_CLANG_TOOLS_EXTRA_CLANG_DOC_SERIALIZE_H 17e975a473SJulie Hockett 18e975a473SJulie Hockett #include "Representation.h" 19e975a473SJulie Hockett #include "clang/AST/AST.h" 20e975a473SJulie Hockett #include "clang/AST/CommentVisitor.h" 21e975a473SJulie Hockett #include <string> 22e975a473SJulie Hockett #include <vector> 23e975a473SJulie Hockett 24e975a473SJulie Hockett using namespace clang::comments; 25e975a473SJulie Hockett 26e975a473SJulie Hockett namespace clang { 27e975a473SJulie Hockett namespace doc { 28e975a473SJulie Hockett namespace serialize { 29e975a473SJulie Hockett 30097aedc9SJulie Hockett // The first element will contain the relevant information about the declaration 31097aedc9SJulie Hockett // passed as parameter. 32097aedc9SJulie Hockett // The second element will contain the relevant information about the 33097aedc9SJulie Hockett // declaration's parent, it can be a NamespaceInfo or RecordInfo. 34097aedc9SJulie Hockett // Both elements can be nullptrs if the declaration shouldn't be handled. 35097aedc9SJulie Hockett // When the declaration is handled, the first element will be a nullptr for 36097aedc9SJulie Hockett // EnumDecl, FunctionDecl and CXXMethodDecl; they are only returned wrapped in 37097aedc9SJulie Hockett // its parent scope. For NamespaceDecl and RecordDecl both elements are not 38097aedc9SJulie Hockett // nullptr. 39097aedc9SJulie Hockett std::pair<std::unique_ptr<Info>, std::unique_ptr<Info>> 40097aedc9SJulie Hockett emitInfo(const NamespaceDecl *D, const FullComment *FC, int LineNumber, 41665e9676SDiego Astiazaran StringRef File, bool IsFileInRootDir, bool PublicOnly); 42*21fb70c6SBrett Wilson 43097aedc9SJulie Hockett std::pair<std::unique_ptr<Info>, std::unique_ptr<Info>> 44097aedc9SJulie Hockett emitInfo(const RecordDecl *D, const FullComment *FC, int LineNumber, 45665e9676SDiego Astiazaran StringRef File, bool IsFileInRootDir, bool PublicOnly); 46*21fb70c6SBrett Wilson 47097aedc9SJulie Hockett std::pair<std::unique_ptr<Info>, std::unique_ptr<Info>> 48097aedc9SJulie Hockett emitInfo(const EnumDecl *D, const FullComment *FC, int LineNumber, 49665e9676SDiego Astiazaran StringRef File, bool IsFileInRootDir, bool PublicOnly); 50*21fb70c6SBrett Wilson 51097aedc9SJulie Hockett std::pair<std::unique_ptr<Info>, std::unique_ptr<Info>> 52097aedc9SJulie Hockett emitInfo(const FunctionDecl *D, const FullComment *FC, int LineNumber, 53665e9676SDiego Astiazaran StringRef File, bool IsFileInRootDir, bool PublicOnly); 54*21fb70c6SBrett Wilson 55097aedc9SJulie Hockett std::pair<std::unique_ptr<Info>, std::unique_ptr<Info>> 56097aedc9SJulie Hockett emitInfo(const CXXMethodDecl *D, const FullComment *FC, int LineNumber, 57665e9676SDiego Astiazaran StringRef File, bool IsFileInRootDir, bool PublicOnly); 58e975a473SJulie Hockett 59*21fb70c6SBrett Wilson std::pair<std::unique_ptr<Info>, std::unique_ptr<Info>> 60*21fb70c6SBrett Wilson emitInfo(const TypedefDecl *D, const FullComment *FC, int LineNumber, 61*21fb70c6SBrett Wilson StringRef File, bool IsFileInRootDir, bool PublicOnly); 62*21fb70c6SBrett Wilson 63*21fb70c6SBrett Wilson std::pair<std::unique_ptr<Info>, std::unique_ptr<Info>> 64*21fb70c6SBrett Wilson emitInfo(const TypeAliasDecl *D, const FullComment *FC, int LineNumber, 65*21fb70c6SBrett Wilson StringRef File, bool IsFileInRootDir, bool PublicOnly); 66*21fb70c6SBrett Wilson 67e975a473SJulie Hockett // Function to hash a given USR value for storage. 68e975a473SJulie Hockett // As USRs (Unified Symbol Resolution) could be large, especially for functions 69e975a473SJulie Hockett // with long type arguments, we use 160-bits SHA1(USR) values to 70e975a473SJulie Hockett // guarantee the uniqueness of symbols while using a relatively small amount of 71e975a473SJulie Hockett // memory (vs storing USRs directly). 72e975a473SJulie Hockett SymbolID hashUSR(llvm::StringRef USR); 73e975a473SJulie Hockett 748899c29bSJulie Hockett std::string serialize(std::unique_ptr<Info> &I); 758899c29bSJulie Hockett 76e975a473SJulie Hockett } // namespace serialize 77e975a473SJulie Hockett } // namespace doc 78e975a473SJulie Hockett } // namespace clang 79e975a473SJulie Hockett 80e975a473SJulie Hockett #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_DOC_SERIALIZE_H 81