clang-tools 22.0.0git
Serialize.h
Go to the documentation of this file.
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-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file implements the serializing functions fro the clang-doc tool. Given
10// a particular declaration, it collects the appropriate information and returns
11// a serialized bitcode string for the declaration.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_DOC_SERIALIZE_H
16#define LLVM_CLANG_TOOLS_EXTRA_CLANG_DOC_SERIALIZE_H
17
18#include "Representation.h"
19#include "clang/AST/AST.h"
20#include "clang/AST/CommentVisitor.h"
21#include <string>
22#include <vector>
23
24using namespace clang::comments;
25
26namespace clang {
27namespace doc {
28namespace serialize {
29
30// The first element will contain the relevant information about the declaration
31// passed as parameter.
32// The second element will contain the relevant information about the
33// declaration's parent, it can be a NamespaceInfo or RecordInfo.
34// Both elements can be nullptrs if the declaration shouldn't be handled.
35// When the declaration is handled, the first element will be a nullptr for
36// EnumDecl, FunctionDecl and CXXMethodDecl; they are only returned wrapped in
37// its parent scope. For NamespaceDecl and RecordDecl both elements are not
38// nullptr.
39std::pair<std::unique_ptr<Info>, std::unique_ptr<Info>>
40emitInfo(const NamespaceDecl *D, const FullComment *FC, Location Loc,
41 bool PublicOnly);
42
43std::pair<std::unique_ptr<Info>, std::unique_ptr<Info>>
44emitInfo(const RecordDecl *D, const FullComment *FC, Location Loc,
45 bool PublicOnly);
46
47std::pair<std::unique_ptr<Info>, std::unique_ptr<Info>>
48emitInfo(const EnumDecl *D, const FullComment *FC, Location Loc,
49 bool PublicOnly);
50
51std::pair<std::unique_ptr<Info>, std::unique_ptr<Info>>
52emitInfo(const FunctionDecl *D, const FullComment *FC, Location Loc,
53 bool PublicOnly);
54
55std::pair<std::unique_ptr<Info>, std::unique_ptr<Info>>
56emitInfo(const VarDecl *D, const FullComment *FC, int LineNumber,
57 StringRef File, bool IsFileInRootDir, bool PublicOnly);
58
59std::pair<std::unique_ptr<Info>, std::unique_ptr<Info>>
60emitInfo(const CXXMethodDecl *D, const FullComment *FC, Location Loc,
61 bool PublicOnly);
62
63std::pair<std::unique_ptr<Info>, std::unique_ptr<Info>>
64emitInfo(const TypedefDecl *D, const FullComment *FC, Location Loc,
65 bool PublicOnly);
66
67std::pair<std::unique_ptr<Info>, std::unique_ptr<Info>>
68emitInfo(const TypeAliasDecl *D, const FullComment *FC, Location Loc,
69 bool PublicOnly);
70
71std::pair<std::unique_ptr<Info>, std::unique_ptr<Info>>
72emitInfo(const ConceptDecl *D, const FullComment *FC, const Location &Loc,
73 bool PublicOnly);
74
75std::pair<std::unique_ptr<Info>, std::unique_ptr<Info>>
76emitInfo(const VarDecl *D, const FullComment *FC, const Location &Loc,
77 bool PublicOnly);
78
79// Function to hash a given USR value for storage.
80// As USRs (Unified Symbol Resolution) could be large, especially for functions
81// with long type arguments, we use 160-bits SHA1(USR) values to
82// guarantee the uniqueness of symbols while using a relatively small amount of
83// memory (vs storing USRs directly).
84SymbolID hashUSR(llvm::StringRef USR);
85
86std::string serialize(std::unique_ptr<Info> &I);
87
88} // namespace serialize
89} // namespace doc
90} // namespace clang
91
92#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_DOC_SERIALIZE_H
static llvm::cl::opt< bool > PublicOnly("public", llvm::cl::desc("Document only public declarations."), llvm::cl::init(false), llvm::cl::cat(ClangDocCategory))
std::pair< std::unique_ptr< Info >, std::unique_ptr< Info > > emitInfo(const NamespaceDecl *D, const FullComment *FC, Location Loc, bool PublicOnly)
static std::string serialize(T &I)
SymbolID hashUSR(llvm::StringRef USR)
Definition Serialize.cpp:38
std::array< uint8_t, 20 > SymbolID
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//