14#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_DOC_REPRESENTATION_H
15#define LLVM_CLANG_TOOLS_EXTRA_CLANG_DOC_REPRESENTATION_H
17#include "clang/AST/Type.h"
18#include "clang/Basic/Diagnostic.h"
19#include "clang/Basic/Specifiers.h"
20#include "clang/Tooling/Execution.h"
21#include "llvm/ADT/SmallString.h"
22#include "llvm/ADT/SmallVector.h"
23#include "llvm/ADT/ilist_node.h"
24#include "llvm/ADT/simple_ilist.h"
25#include "llvm/Support/Allocator.h"
26#include "llvm/Support/Mutex.h"
27#include "llvm/Support/StringSaver.h"
42 llvm::sys::SmartScopedLock<true> Lock(PoolMutex);
43 return Saver.save(Name);
47 llvm::sys::SmartMutex<true> PoolMutex;
48 llvm::BumpPtrAllocator Alloc;
49 llvm::UniqueStringSaver Saver{Alloc};
57 if (T.isTriviallyEmpty())
60 if (T.isSingleStringRef()) {
61 StringRef S = T.getSingleStringRef();
67 SmallString<128> Buffer;
68 StringRef S = T.toStringRef(Buffer);
76 llvm::BumpPtrAllocator &Alloc) {
78 return llvm::ArrayRef<T>();
79 T *Allocated = (T *)Alloc.Allocate<T>(V.size());
80 std::uninitialized_move(V.begin(), V.end(), Allocated);
81 return llvm::ArrayRef<T>(Allocated, V.size());
86template <
typename T>
using OwnedPtr = std::unique_ptr<T>;
94template <
typename T>
using OwningVec = std::vector<T>;
98template <
typename T>
using OwningPtrVec = std::vector<OwnedPtr<T>>;
106template <
typename T,
typename... Args>
108 return std::make_unique<T>(std::forward<Args>(args)...);
111template <
typename T,
typename... Args>
113 return new (Alloc.Allocate<T>()) T(std::forward<Args>(args)...);
123constexpr SymbolID GlobalNamespaceID = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
124 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
126struct BaseRecordInfo;
176 StringRef
Text = StringRef(), StringRef
Name = StringRef(),
195 llvm::ArrayRef<CommentInfo>
203 llvm::ArrayRef<StringRef>
205 llvm::ArrayRef<StringRef>
230 StringRef
Path = StringRef())
313 TypeInfo(StringRef Name, StringRef Path = StringRef())
407 AccessSpecifier
Access = AccessSpecifier::AS_public;
411struct Location :
public llvm::ilist_node<Location> {
442 StringRef
Name = StringRef(), StringRef
Path = StringRef())
497 StringRef
Path = StringRef());
507 StringRef
Name = StringRef(), StringRef
Path = StringRef())
517 if (
Loc.size() > 0 && Other.
Loc.size() > 0 &&
Loc[0] != Other.
Loc[0])
518 return Loc[0] < Other.
Loc[0];
527 llvm::SmallVector<Location, 2>
Loc;
536 const StringRef
Name = StringRef())
567 llvm::SmallVector<FieldTypeInfo, 4>
Params;
577 AccessSpecifier
Access = AccessSpecifier::AS_public;
587 StringRef
Path = StringRef());
603 llvm::SmallVector<MemberTypeInfo, 4>
608 llvm::SmallVector<Reference, 4>
648 AccessSpecifier
Access = AccessSpecifier::AS_public;
657 StringRef
Value = StringRef(
"0"),
744 tooling::ExecutionContext *
ECtx;
775static_assert(std::is_trivially_destructible_v<CommentInfo>);
776static_assert(std::is_trivially_destructible_v<ConstraintInfo>);
777static_assert(std::is_trivially_destructible_v<FieldTypeInfo>);
778static_assert(std::is_trivially_destructible_v<Location>);
779static_assert(std::is_trivially_destructible_v<Reference>);
780static_assert(std::is_trivially_destructible_v<TemplateParamInfo>);
781static_assert(std::is_trivially_destructible_v<TypeInfo>);
784static_assert(!std::is_trivially_destructible_v<ConceptInfo>);
785static_assert(!std::is_trivially_destructible_v<EnumInfo>);
786static_assert(!std::is_trivially_destructible_v<FriendInfo>);
787static_assert(!std::is_trivially_destructible_v<FunctionInfo>);
788static_assert(!std::is_trivially_destructible_v<Info>);
789static_assert(!std::is_trivially_destructible_v<MemberTypeInfo>);
790static_assert(!std::is_trivially_destructible_v<NamespaceInfo>);
791static_assert(!std::is_trivially_destructible_v<RecordInfo>);
792static_assert(!std::is_trivially_destructible_v<ScopeChildren>);
793static_assert(!std::is_trivially_destructible_v<SymbolInfo>);
794static_assert(!std::is_trivially_destructible_v<TemplateInfo>);
795static_assert(!std::is_trivially_destructible_v<TemplateSpecializationInfo>);
796static_assert(!std::is_trivially_destructible_v<TypedefInfo>);
797static_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))
StringRef intern(StringRef Name)
std::vector< T > OwningArray
std::vector< OwnedPtr< T > > OwningPtrVec
@ CK_InlineCommandComment
@ CK_VerbatimBlockLineComment
@ CK_VerbatimBlockComment
@ CK_TParamCommandComment
llvm::Expected< OwnedPtr< Info > > mergeInfos(OwningPtrArray< Info > &Values)
std::unique_ptr< T > OwnedPtr
llvm::ArrayRef< T > allocateArray(llvm::ArrayRef< T > V, llvm::BumpPtrAllocator &Alloc)
T * getPtr(const OwnedPtr< T > &O)
ConcurrentStringPool & getGlobalStringPool()
CommentKind stringToCommentKind(llvm::StringRef KindStr)
std::vector< OwnedPtr< T > > OwningPtrArray
thread_local llvm::BumpPtrAllocator TransientArena
StringRef internString(const Twine &T)
std::vector< T > OwningVec
constexpr SymbolID GlobalNamespaceID
OwnedPtr< T > allocatePtr(Args &&...args)
std::array< uint8_t, 20 > SymbolID
llvm::StringRef commentKindToString(CommentKind Kind)
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
std::optional< std::string > RepositoryUrl
std::vector< std::string > UserStylesheets
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)
llvm::StringMap< std::string > MustacheTemplates
std::vector< std::string > JsScripts
tooling::ExecutionContext * ECtx
clang::DiagnosticsEngine & Diags
std::optional< std::string > RepositoryLinePrefix
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::SmallVector< EnumValueInfo, 4 > Members
std::optional< TypeInfo > BaseType
OwningVec< 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
std::optional< TemplateInfo > Template
bool mergeable(const FriendInfo &Other)
FunctionInfo(SymbolID USR=SymbolID())
llvm::SmallVector< FieldTypeInfo, 4 > Params
void merge(FunctionInfo &&I)
std::optional< TemplateInfo > Template
OwningVec< const Index * > getSortedChildren() const
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
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)
OwningVec< CommentInfo > Description
SmallVector< Context, 4 > Contexts
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.
llvm::SmallVector< Reference, 4 > Namespace
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)
bool operator==(const MemberTypeInfo &Other) const
OwningVec< CommentInfo > Description
NamespaceInfo(SymbolID USR=SymbolID(), StringRef Name=StringRef(), StringRef Path=StringRef())
void merge(NamespaceInfo &&I)
OwningVec< BaseRecordInfo > Bases
llvm::SmallVector< MemberTypeInfo, 4 > Members
RecordInfo(SymbolID USR=SymbolID(), StringRef Name=StringRef(), StringRef Path=StringRef())
std::optional< TemplateInfo > Template
llvm::SmallVector< Reference, 4 > VirtualParents
llvm::SmallVector< Reference, 4 > Parents
void merge(RecordInfo &&I)
OwningVec< FriendInfo > Friends
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
OwningVec< FunctionInfo > Functions
OwningVec< TypedefInfo > Typedefs
OwningVec< EnumInfo > Enums
OwningVec< Reference > Records
OwningVec< ConceptInfo > Concepts
OwningVec< VarInfo > Variables
llvm::simple_ilist< Reference > Namespaces
SymbolInfo(InfoType IT, SymbolID USR=SymbolID(), StringRef Name=StringRef(), StringRef Path=StringRef())
bool operator<(const SymbolInfo &Other) const
llvm::SmallVector< Location, 2 > Loc
std::optional< Location > DefLoc
void merge(SymbolInfo &&I)
OwningVec< TemplateParamInfo > Params
OwningVec< ConstraintInfo > Constraints
std::optional< TemplateSpecializationInfo > Specialization
TemplateParamInfo()=default
TemplateParamInfo(StringRef Contents)
SymbolID SpecializationOf
OwningVec< TemplateParamInfo > Params
TypeInfo(StringRef Name, StringRef Path=StringRef())
TypeInfo(const Reference &R)
bool operator==(const TypeInfo &Other) const
StringRef TypeDeclaration
void merge(TypedefInfo &&I)
std::optional< TemplateInfo > Template
TypedefInfo(SymbolID USR=SymbolID())