14#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_DOC_REPRESENTATION_H
15#define LLVM_CLANG_TOOLS_EXTRA_CLANG_DOC_REPRESENTATION_H
18#include "clang/AST/Type.h"
19#include "clang/Basic/Diagnostic.h"
20#include "clang/Basic/Specifiers.h"
21#include "clang/Tooling/Execution.h"
22#include "llvm/ADT/SmallString.h"
23#include "llvm/ADT/SmallVector.h"
24#include "llvm/ADT/ilist_node.h"
25#include "llvm/ADT/simple_ilist.h"
26#include "llvm/Support/Allocator.h"
27#include "llvm/Support/Casting.h"
48 llvm::BumpPtrAllocator &Alloc) {
50 return llvm::ArrayRef<T>();
51 T *Allocated =
static_cast<T *
>(Alloc.Allocate<T>(V.size()));
52 std::uninitialized_move(V.begin(), V.end(), Allocated);
53 return llvm::ArrayRef<T>(Allocated, V.size());
58 llvm::BumpPtrAllocator &Alloc) {
60 return llvm::ArrayRef<T>();
61 T *Allocated =
static_cast<T *
>(Alloc.Allocate<T>(V.size()));
62 std::uninitialized_move(V.begin(), V.end(), Allocated);
63 return llvm::ArrayRef<T>(Allocated, V.size());
68 llvm::BumpPtrAllocator &Alloc) {
70 return llvm::ArrayRef<T>();
71 T *Allocated =
static_cast<T *
>(Alloc.Allocate<T>(V.size()));
72 for (
size_t Idx = 0; Idx < V.size(); ++Idx) {
73 new (Allocated + Idx) T(V[Idx], Alloc);
75 return llvm::ArrayRef<T>(Allocated, V.size());
87 T(std::forward<Args>(args)...);
91template <
typename T,
typename... Args>
92T *
allocatePtr(llvm::BumpPtrAllocator &Alloc, Args &&...args) {
93 return new (Alloc.Allocate<T>()) T(std::forward<Args>(args)...);
96template <
typename T>
struct InfoNode :
public llvm::ilist_node<InfoNode<T>> {
100 operator T &() {
return *
Ptr; }
101 operator const T &()
const {
return *
Ptr; }
111 return *
Ptr == *Other.
Ptr;
123template <
typename T,
typename... Args>
129template <
typename T,
typename... Args>
143template <
typename T,
typename... Args>
154template <
typename T>
using DocList = llvm::simple_ilist<InfoNode<T>>;
159constexpr SymbolID GlobalNamespaceID = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
160 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
162struct BaseRecordInfo;
215 StringRef
Text = StringRef(), StringRef
Name = StringRef(),
282 StringRef
Path = StringRef())
365 TypeInfo(StringRef Name, StringRef Path = StringRef())
395 llvm::BumpPtrAllocator &Arena);
401 llvm::ArrayRef<TemplateParamInfo>
Params = {};
420 llvm::ArrayRef<TemplateParamInfo>
Params = {};
469 AccessSpecifier
Access = AccessSpecifier::AS_public;
504 StringRef
Name = StringRef(), StringRef
Path = StringRef())
507 Info(
const Info &Other, llvm::BumpPtrAllocator &Arena);
557 StringRef
Path = StringRef());
569 StringRef
Name = StringRef(), StringRef
Path = StringRef())
599 if (!
Loc.empty() && !Other.
Loc.empty() &&
Loc.front() != Other.
Loc.front())
600 return Loc.front() < Other.
Loc.front();
618 const StringRef
Name = StringRef())
630 llvm::ArrayRef<FieldTypeInfo>
Params = {};
657 llvm::ArrayRef<FieldTypeInfo>
Params = {};
667 AccessSpecifier
Access = AccessSpecifier::AS_public;
677 StringRef
Path = StringRef());
704 llvm::ArrayRef<BaseRecordInfo>
Bases =
745 AccessSpecifier
Access = AccessSpecifier::AS_public;
754 StringRef
Value = StringRef(
"0"),
838llvm::Expected<Info *>
mergeInfos(SmallVectorImpl<Info *> &Values);
843 llvm::BumpPtrAllocator &Arena);
852 tooling::ExecutionContext *
ECtx;
884static_assert(std::is_trivially_destructible_v<CommentInfo>);
885static_assert(std::is_trivially_destructible_v<ConceptInfo>);
886static_assert(std::is_trivially_destructible_v<ConstraintInfo>);
887static_assert(std::is_trivially_destructible_v<EnumInfo>);
888static_assert(std::is_trivially_destructible_v<FieldTypeInfo>);
889static_assert(std::is_trivially_destructible_v<FriendInfo>);
890static_assert(std::is_trivially_destructible_v<FunctionInfo>);
891static_assert(std::is_trivially_destructible_v<Info>);
892static_assert(std::is_trivially_destructible_v<Location>);
893static_assert(std::is_trivially_destructible_v<MemberTypeInfo>);
894static_assert(std::is_trivially_destructible_v<NamespaceInfo>);
895static_assert(std::is_trivially_destructible_v<RecordInfo>);
896static_assert(std::is_trivially_destructible_v<Reference>);
897static_assert(std::is_trivially_destructible_v<ScopeChildren>);
898static_assert(std::is_trivially_destructible_v<SymbolInfo>);
899static_assert(std::is_trivially_destructible_v<TemplateInfo>);
900static_assert(std::is_trivially_destructible_v<TemplateParamInfo>);
901static_assert(std::is_trivially_destructible_v<TemplateSpecializationInfo>);
902static_assert(std::is_trivially_destructible_v<TypeInfo>);
903static_assert(std::is_trivially_destructible_v<TypedefInfo>);
904static_assert(std::is_trivially_destructible_v<VarInfo>);
static llvm::cl::opt< std::string > RepositoryCodeLinePrefix("repository-line-prefix", llvm::cl::desc("Prefix of line code for repository."), llvm::cl::cat(ClangDocCategory))
This file defines ConcurrentStringPool, a lock-free deduplicating string saver for clang-doc.
clang::find_all_symbols::SymbolInfo SymbolInfo
llvm::StringRef save(const char *S)
Save string S in the arena.
T * allocatePtr(llvm::BumpPtrAllocator &Alloc, Args &&...args)
@ CK_InlineCommandComment
@ CK_VerbatimBlockLineComment
@ CK_VerbatimBlockComment
@ CK_TParamCommandComment
llvm::simple_ilist< InfoNode< T > > DocList
llvm::BumpPtrAllocator & getPersistentArena()
T * allocatePersistent(Args &&...args)
T * allocateTransient(Args &&...args)
ConcurrentStringPoolImpl<> ConcurrentStringPool
ConcurrentStringPool & getGlobalStringPool()
CommentKind stringToCommentKind(llvm::StringRef KindStr)
llvm::ArrayRef< T > deepCopyArray(llvm::ArrayRef< T > V, llvm::BumpPtrAllocator &Alloc)
InfoNode< T > * allocateListNodePersistent(Args &&...args)
InfoNode< T > * allocateListNode(llvm::BumpPtrAllocator &Alloc, Args &&...args)
StringRef internString(const Twine &T)
llvm::ArrayRef< T > allocateArray(llvm::SmallVectorImpl< T > &V, llvm::BumpPtrAllocator &Alloc)
llvm::Expected< Info * > mergeInfos(SmallVectorImpl< Info * > &Values)
InfoNode< T > * allocateListNodeTransient(Args &&...args)
constexpr SymbolID GlobalNamespaceID
llvm::BumpPtrAllocator & getTransientArena()
std::array< uint8_t, 20 > SymbolID
llvm::StringRef commentKindToString(CommentKind Kind)
llvm::Error mergeSingleInfo(doc::Info *&Reduced, doc::Info *NewInfo, llvm::BumpPtrAllocator &Arena)
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
std::optional< std::string > RepositoryUrl
std::vector< std::string > UserStylesheets
llvm::StringMap< std::string > MustacheTemplates
std::vector< std::string > JsScripts
tooling::ExecutionContext * ECtx
clang::DiagnosticsEngine & Diags
ClangDocContext(tooling::ExecutionContext *ECtx, StringRef ProjectName, bool PublicOnly, StringRef OutDirectory, StringRef SourceRoot, StringRef RepositoryUrl, StringRef RepositoryCodeLinePrefix, StringRef Base, std::vector< std::string > UserStylesheets, clang::DiagnosticsEngine &Diags, OutputFormatTy Format, bool FTimeTrace=false, bool Pretty=false)
std::optional< std::string > RepositoryLinePrefix
static bool classof(const Info *I)
ConceptInfo(SymbolID USR)
void merge(ConceptInfo &&I)
StringRef ConstraintExpression
ConstraintInfo(SymbolID USR, StringRef Name)
Context(SymbolID USR, StringRef Name, InfoType IT, StringRef QualName, StringRef Path, StringRef DocumentationFileName)
llvm::ArrayRef< EnumValueInfo > Members
std::optional< TypeInfo > BaseType
static bool classof(const Info *I)
DocList< CommentInfo > Description
Comment description of this field.
bool operator==(const EnumValueInfo &Other) const
EnumValueInfo(StringRef Name=StringRef(), StringRef Value=StringRef("0"), StringRef ValueExpr=StringRef())
FieldTypeInfo(const TypeInfo &TI, StringRef Name=StringRef(), StringRef DefaultValue=StringRef())
bool operator==(const FieldTypeInfo &Other) const
FriendInfo(const InfoType IT, const SymbolID &USR, const StringRef Name=StringRef())
std::optional< TypeInfo > ReturnType
void merge(FriendInfo &&Other)
llvm::ArrayRef< FieldTypeInfo > Params
static bool classof(const Info *I)
std::optional< TemplateInfo > Template
bool mergeable(const FriendInfo &Other)
FunctionInfo(SymbolID USR=SymbolID())
static bool classof(const Info *I)
llvm::ArrayRef< FieldTypeInfo > Params
void merge(FunctionInfo &&I)
std::optional< TemplateInfo > Template
Index(StringRef Name, StringRef JumpToSection)
bool operator<(const Index &Other) const
std::optional< StringRef > JumpToSection
bool operator==(const SymbolID &Other) const
Index(SymbolID USR, StringRef Name, InfoType IT, StringRef Path)
llvm::StringMap< Index > Children
std::vector< const Index * > getSortedChildren() const
bool operator<(const InfoNode< T > &Other) const
bool operator!=(const InfoNode< T > &Other) const
const T * operator->() const
const T & operator*() const
bool operator==(const InfoNode< T > &Other) const
StringRef getRelativeFilePath(const StringRef &CurrentPath) const
Returns the file path for this Info relative to CurrentPath.
Info & operator=(Info &&Other)=default
Info(InfoType IT=InfoType::IT_default, SymbolID USR=SymbolID(), StringRef Name=StringRef(), StringRef Path=StringRef())
bool mergeable(const Info &Other)
DocList< CommentInfo > Description
llvm::ArrayRef< Reference > Namespace
StringRef extractName() const
StringRef DocumentationFileName
Info(Info &&Other)=default
Info(const Info &Other)=delete
StringRef getFileBaseName() const
Returns the basename that should be used for this Info.
bool operator==(const Location &Other) const
Location(int StartLineNumber=0, int EndLineNumber=0, StringRef Filename=StringRef(), bool IsFileInRootDir=false)
bool operator<(const Location &Other) const
bool operator!=(const Location &Other) const
MemberTypeInfo(const TypeInfo &TI, StringRef Name, AccessSpecifier Access, bool IsStatic=false)
DocList< CommentInfo > Description
bool operator==(const MemberTypeInfo &Other) const
NamespaceInfo(SymbolID USR=SymbolID(), StringRef Name=StringRef(), StringRef Path=StringRef())
static bool classof(const Info *I)
void merge(NamespaceInfo &&I)
llvm::ArrayRef< BaseRecordInfo > Bases
llvm::ArrayRef< FriendInfo > Friends
RecordInfo(SymbolID USR=SymbolID(), StringRef Name=StringRef(), StringRef Path=StringRef())
llvm::ArrayRef< Reference > VirtualParents
std::optional< TemplateInfo > Template
static bool classof(const Info *I)
llvm::ArrayRef< Reference > Parents
llvm::ArrayRef< MemberTypeInfo > Members
void merge(RecordInfo &&I)
Reference(SymbolID USR, StringRef Name, InfoType IT, StringRef QualName, StringRef Path, StringRef DocumentationFileName)
void merge(Reference &&I)
StringRef DocumentationFileName
Reference(SymbolID USR, StringRef Name, InfoType IT, StringRef QualName, StringRef Path=StringRef())
Reference(SymbolID USR=SymbolID(), StringRef Name=StringRef(), InfoType IT=InfoType::IT_default)
bool mergeable(const Reference &Other)
StringRef getFileBaseName() const
Returns the basename that should be used for this Reference.
StringRef getRelativeFilePath(const StringRef &CurrentPath) const
Returns the path for this Reference relative to CurrentPath.
bool operator<(const Reference &Other) const
bool operator==(const Reference &Other) const
DocList< Reference > Records
DocList< EnumInfo > Enums
DocList< ConceptInfo > Concepts
DocList< VarInfo > Variables
DocList< FunctionInfo > Functions
DocList< Reference > Namespaces
DocList< TypedefInfo > Typedefs
SymbolInfo(InfoType IT, SymbolID USR=SymbolID(), StringRef Name=StringRef(), StringRef Path=StringRef())
static bool classof(const Info *I)
bool operator<(const SymbolInfo &Other) const
std::optional< Location > DefLoc
void merge(SymbolInfo &&I)
llvm::ArrayRef< TemplateParamInfo > Params
llvm::ArrayRef< ConstraintInfo > Constraints
std::optional< TemplateSpecializationInfo > Specialization
TemplateParamInfo()=default
TemplateParamInfo(StringRef Contents)
SymbolID SpecializationOf
TemplateSpecializationInfo()=default
llvm::ArrayRef< TemplateParamInfo > Params
TypeInfo(StringRef Name, StringRef Path=StringRef())
TypeInfo(const Reference &R)
bool operator==(const TypeInfo &Other) const
static bool classof(const Info *I)
StringRef TypeDeclaration
void merge(TypedefInfo &&I)
std::optional< TemplateInfo > Template
TypedefInfo(SymbolID USR=SymbolID())
static bool classof(const Info *I)