clang-tools 23.0.0git
Representation.h
Go to the documentation of this file.
1///===-- Representation.h - ClangDoc Representation -------------*- 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 defines the internal representations of different declaration
10// types for the clang-doc tool.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_DOC_REPRESENTATION_H
15#define LLVM_CLANG_TOOLS_EXTRA_CLANG_DOC_REPRESENTATION_H
16
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"
28#include <array>
29#include <memory>
30#include <optional>
31#include <string>
32
33namespace clang {
34namespace doc {
35
37public:
38 StringRef intern(StringRef Name) {
39 if (Name.empty())
40 return StringRef();
41
42 llvm::sys::SmartScopedLock<true> Lock(PoolMutex);
43 return Saver.save(Name);
44 }
45
46private:
47 llvm::sys::SmartMutex<true> PoolMutex;
48 llvm::BumpPtrAllocator Alloc;
49 llvm::UniqueStringSaver Saver{Alloc};
50};
51
52ConcurrentStringPool &getGlobalStringPool();
53
54extern thread_local llvm::BumpPtrAllocator TransientArena;
55
56inline StringRef internString(const Twine &T) {
57 if (T.isTriviallyEmpty())
58 return StringRef();
59
60 if (T.isSingleStringRef()) {
61 StringRef S = T.getSingleStringRef();
62 if (S.empty())
63 return StringRef();
64 return getGlobalStringPool().intern(S);
65 }
66
67 SmallString<128> Buffer;
68 StringRef S = T.toStringRef(Buffer);
69 if (S.empty())
70 return StringRef();
71 return getGlobalStringPool().intern(S);
72}
73
74template <typename T>
75inline llvm::ArrayRef<T> allocateArray(llvm::ArrayRef<T> V,
76 llvm::BumpPtrAllocator &Alloc) {
77 if (V.empty())
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());
82}
83
84// An abstraction for owned pointers. Initially mapped to OwnedPtr,
85// to be eventually transitioned to bare pointers in an arena.
86template <typename T> using OwnedPtr = std::unique_ptr<T>;
87
88// An abstraction for vectors that are populated and read sequentially.
89// To be eventually transitioned to llvm::ArrayRef for arena storage.
90template <typename T> using OwningArray = std::vector<T>;
91
92// An abstraction for lists that are dynamically managed (inserted/removed).
93// To be eventually transitioned to llvm::simple_ilist.
94template <typename T> using OwningVec = std::vector<T>;
95
96// An abstraction for dynamic lists of owned pointers.
97// To be eventually transitioned to llvm::simple_ilist<T*> or similar.
98template <typename T> using OwningPtrVec = std::vector<OwnedPtr<T>>;
99
100// An abstraction for arrays of owned pointers.
101// To be eventually transitioned to arena-allocated arrays of bare pointers.
102template <typename T> using OwningPtrArray = std::vector<OwnedPtr<T>>;
103
104// A helper function to create an owned pointer, abstracting away the memory
105// allocation mechanism.
106template <typename T, typename... Args>
107OwnedPtr<T> allocatePtr(Args &&...args) {
108 return std::make_unique<T>(std::forward<Args>(args)...);
109}
110
111template <typename T, typename... Args>
112T *allocatePtr(llvm::BumpPtrAllocator &Alloc, Args &&...args) {
113 return new (Alloc.Allocate<T>()) T(std::forward<Args>(args)...);
114}
115
116// A helper function to access the underlying pointer from an owned pointer,
117// abstracting away the pointer dereferencing mechanism.
118template <typename T> T *getPtr(const OwnedPtr<T> &O) { return O.get(); }
119
120// SHA1'd hash of a USR.
121using SymbolID = std::array<uint8_t, 20>;
122
123constexpr SymbolID GlobalNamespaceID = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
124 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
125
126struct BaseRecordInfo;
127struct EnumInfo;
128struct FunctionInfo;
129struct Info;
130struct TypedefInfo;
131struct ConceptInfo;
132struct VarInfo;
133
145
161
163
164CommentKind stringToCommentKind(llvm::StringRef KindStr);
165llvm::StringRef commentKindToString(CommentKind Kind);
166
167// A representation of a parsed comment.
168struct CommentInfo : public llvm::ilist_node<CommentInfo> {
169 CommentInfo() = default;
170 CommentInfo(const CommentInfo &Other) = default;
171 CommentInfo &operator=(const CommentInfo &Other) = default;
172 CommentInfo(CommentInfo &&Other) = default;
173 CommentInfo &operator=(CommentInfo &&Other) = default;
174
175 CommentInfo(CommentKind Kind, llvm::ArrayRef<CommentInfo> Children = {},
176 StringRef Text = StringRef(), StringRef Name = StringRef(),
177 StringRef CloseName = StringRef(),
178 StringRef Direction = StringRef(),
179 StringRef ParamName = StringRef(), bool Explicit = false,
180 bool SelfClosing = false, llvm::ArrayRef<StringRef> AttrKeys = {},
181 llvm::ArrayRef<StringRef> AttrValues = {})
184 AttrKeys(AttrKeys), AttrValues(AttrValues), Kind(Kind),
186
187 bool operator==(const CommentInfo &Other) const;
188
189 // This operator is used to sort a vector of CommentInfos.
190 // No specific order (attributes more important than others) is required. Any
191 // sort is enough, the order is only needed to call std::unique after sorting
192 // the vector.
193 bool operator<(const CommentInfo &Other) const;
194
195 llvm::ArrayRef<CommentInfo>
196 Children; // List of child comments for this CommentInfo.
197 StringRef Direction; // Parameter direction (for (T)ParamCommand).
198 StringRef Name; // Name of the comment (for Verbatim and HTML).
199 StringRef ParamName; // Parameter name (for (T)ParamCommand).
200 StringRef CloseName; // Closing tag name (for VerbatimBlock).
201 StringRef Text; // Text of the comment.
202 llvm::ArrayRef<StringRef> AttrKeys; // List of attribute keys (for HTML).
203 llvm::ArrayRef<StringRef>
204 AttrValues; // List of attribute values for each key (for HTML).
205 llvm::ArrayRef<StringRef>
206 Args; // List of arguments to commands (for InlineCommand).
207 CommentKind Kind = CommentKind::
208 CK_Unknown; // Kind of comment (FullComment, ParagraphComment,
209 // TextComment, InlineCommandComment, HTMLStartTagComment,
210 // HTMLEndTagComment, BlockCommandComment,
211 // ParamCommandComment, TParamCommandComment,
212 // VerbatimBlockComment, VerbatimBlockLineComment,
213 // VerbatimLineComment).
214 bool SelfClosing = false; // Indicates if tag is self-closing (for HTML).
215 bool Explicit = false; // Indicates if the direction of a param is explicit
216 // (for (T)ParamCommand).
217};
218
219struct Reference : public llvm::ilist_node<Reference> {
220 // This variant (that takes no qualified name parameter) uses the Name as the
221 // QualName (very useful in unit tests to reduce verbosity). This can't use an
222 // empty string to indicate the default because we need to accept the empty
223 // string as a valid input for the global namespace (it will have
224 // "GlobalNamespace" as the name, but an empty QualName).
225 Reference(SymbolID USR = SymbolID(), StringRef Name = StringRef(),
227 : USR(USR), RefType(IT), Name(internString(Name)),
229 Reference(SymbolID USR, StringRef Name, InfoType IT, StringRef QualName,
230 StringRef Path = StringRef())
231 : USR(USR), RefType(IT), Name(internString(Name)),
238
239 bool operator==(const Reference &Other) const {
240 return std::tie(USR, Name, QualName, RefType) ==
241 std::tie(Other.USR, Other.Name, QualName, Other.RefType);
242 }
243
244 bool mergeable(const Reference &Other);
245 void merge(Reference &&I);
246 bool operator<(const Reference &Other) const { return Name < Other.Name; }
247
248 /// Returns the path for this Reference relative to CurrentPath.
249 StringRef getRelativeFilePath(const StringRef &CurrentPath) const;
250
251 /// Returns the basename that should be used for this Reference.
252 StringRef getFileBaseName() const;
253
254 SymbolID USR = SymbolID(); // Unique identifier for referenced decl
255
256 InfoType RefType = InfoType::IT_default; // Indicates the type of this
257 // Reference (namespace, record,
258 // function, enum, default).
259
260 // Name of type (possibly unresolved). Not including namespaces or template
261 // parameters (so for a std::vector<int> this would be "vector"). See also
262 // QualName.
263 StringRef Name;
264
265 // Full qualified name of this type, including namespaces and template
266 // parameter (for example this could be "std::vector<int>"). Contrast to
267 // Name.
268 StringRef QualName;
269
270 // Path of directory where the clang-doc generated file will be saved
271 // (possibly unresolved)
272 StringRef Path;
274};
275
276// A Context is a reference that holds a relative path from a certain Info's
277// location.
278struct Context : public Reference {
279 Context(SymbolID USR, StringRef Name, InfoType IT, StringRef QualName,
280 StringRef Path, StringRef DocumentationFileName)
282 explicit Context(const Info &I);
283 StringRef RelativePath;
284};
285
286// Holds the children of a record or namespace.
288 // Namespaces and Records are references because they will be properly
289 // documented in their own info, while the entirety of Functions and Enums are
290 // included here because they should not have separate documentation from
291 // their scope.
292 //
293 // Namespaces are not syntactically valid as children of records, but making
294 // this general for all possible container types reduces code complexity.
295 llvm::simple_ilist<Reference> Namespaces;
302
303 void sort();
304};
305
306// A base struct for TypeInfos
307struct TypeInfo {
308 TypeInfo() = default;
309 TypeInfo(const Reference &R) : Type(R) {}
310
311 // Convenience constructor for when there is no symbol ID or info type
312 // (normally used for built-in types in tests).
313 TypeInfo(StringRef Name, StringRef Path = StringRef())
314 : Type(SymbolID(), Name, InfoType::IT_default, Name, Path) {}
315
316 bool operator==(const TypeInfo &Other) const { return Type == Other.Type; }
317
318 Reference Type; // Referenced type in this info.
319
320 bool IsTemplate = false;
321 bool IsBuiltIn = false;
322};
323
324// Represents one template parameter.
325//
326// This is a very simple serialization of the text of the source code of the
327// template parameter. It is saved in a struct so there is a place to add the
328// name and default values in the future if needed.
330 TemplateParamInfo() = default;
333
334 // The literal contents of the code for that specifies this template parameter
335 // for this declaration. Typical values will be "class T" and
336 // "typename T = int".
337 StringRef Contents;
338};
339
341 // Indicates the declaration that this specializes.
343
344 // Template parameters applying to the specialized record/function.
346};
347
349 ConstraintInfo() = default;
350 ConstraintInfo(SymbolID USR, StringRef Name)
351 : ConceptRef(USR, Name, InfoType::IT_concept) {}
353
354 StringRef ConstraintExpr;
355};
356
357// Records the template information for a struct or function that is a template
358// or an explicit template specialization.
360 // May be empty for non-partial specializations.
362
363 // Set when this is a specialization of another record/function.
364 std::optional<TemplateSpecializationInfo> Specialization;
366};
367
368// Info for field types.
369struct FieldTypeInfo : public TypeInfo {
370 FieldTypeInfo() = default;
371 FieldTypeInfo(const TypeInfo &TI, StringRef Name = StringRef(),
372 StringRef DefaultValue = StringRef())
375
376 bool operator==(const FieldTypeInfo &Other) const {
377 return std::tie(Type, Name, DefaultValue) ==
378 std::tie(Other.Type, Other.Name, Other.DefaultValue);
379 }
380
381 StringRef Name; // Name associated with this info.
382
383 // When used for function parameters, contains the string representing the
384 // expression of the default value, if any.
385 StringRef DefaultValue;
386};
387
388// Info for member types.
390 MemberTypeInfo() = default;
391 MemberTypeInfo(const TypeInfo &TI, StringRef Name, AccessSpecifier Access,
392 bool IsStatic = false)
394
395 bool operator==(const MemberTypeInfo &Other) const {
396 return std::tie(Type, Name, Access, IsStatic, Description) ==
397 std::tie(Other.Type, Other.Name, Other.Access, Other.IsStatic,
398 Other.Description);
399 }
400
402
403 // Access level associated with this info (public, protected, private, none).
404 // AS_public is set as default because the bitcode writer requires the enum
405 // with value 0 to be used as the default.
406 // (AS_public = 0, AS_protected = 1, AS_private = 2, AS_none = 3)
407 AccessSpecifier Access = AccessSpecifier::AS_public;
408 bool IsStatic = false;
409};
410
411struct Location : public llvm::ilist_node<Location> {
416
417 bool operator==(const Location &Other) const {
418 return std::tie(StartLineNumber, EndLineNumber, Filename) ==
419 std::tie(Other.StartLineNumber, Other.EndLineNumber, Other.Filename);
420 }
421
422 bool operator!=(const Location &Other) const { return !(*this == Other); }
423
424 // This operator is used to sort a vector of Locations.
425 // No specific order (attributes more important than others) is required. Any
426 // sort is enough, the order is only needed to call std::unique after sorting
427 // the vector.
428 bool operator<(const Location &Other) const {
429 return std::tie(StartLineNumber, EndLineNumber, Filename) <
430 std::tie(Other.StartLineNumber, Other.EndLineNumber, Other.Filename);
431 }
432
433 StringRef Filename;
436 bool IsFileInRootDir = false;
437};
438
439/// A base struct for Infos.
440struct Info {
442 StringRef Name = StringRef(), StringRef Path = StringRef())
444
445 Info(const Info &Other) = delete;
446 Info(Info &&Other) = default;
447 virtual ~Info() = default;
448
449 Info &operator=(Info &&Other) = default;
450
451 void mergeBase(Info &&I);
452 bool mergeable(const Info &Other);
453
454 StringRef extractName() const;
455
456 /// Returns the file path for this Info relative to CurrentPath.
457 StringRef getRelativeFilePath(const StringRef &CurrentPath) const;
458
459 /// Returns the basename that should be used for this Info.
460 StringRef getFileBaseName() const;
461
462 // Path of directory where the clang-doc generated file will be saved.
463 StringRef Path;
464
465 // Unqualified name of the decl.
466 StringRef Name;
467
468 // The name used for the file that this info is documented in.
469 // In the JSON generator, infos are documented in files with mangled names.
470 // Thus, we keep track of the physical filename for linking purposes.
472
473 // List of parent namespaces for this decl.
474 llvm::SmallVector<Reference, 4> Namespace;
475
476 // Unique identifier for the decl described by this Info.
478
479 // Currently only used for namespaces and records.
481
482 // InfoType of this particular Info.
484
485 // Comment description of this decl.
487
489};
490
491inline Context::Context(const Info &I)
492 : Reference(I.USR, I.Name, I.IT, I.Name, I.Path, I.DocumentationFileName) {}
493
494// Info for namespaces.
495struct NamespaceInfo : public Info {
496 NamespaceInfo(SymbolID USR = SymbolID(), StringRef Name = StringRef(),
497 StringRef Path = StringRef());
498
499 void merge(NamespaceInfo &&I);
500
502};
503
504// Info for symbols.
505struct SymbolInfo : public Info {
507 StringRef Name = StringRef(), StringRef Path = StringRef())
508 : Info(IT, USR, Name, Path) {}
509
510 void merge(SymbolInfo &&I);
511
512 bool operator<(const SymbolInfo &Other) const {
513 // Sort by declaration location since we want the doc to be
514 // generated in the order of the source code.
515 // If the declaration location is the same, or not present
516 // we sort by defined location otherwise fallback to the extracted name
517 if (Loc.size() > 0 && Other.Loc.size() > 0 && Loc[0] != Other.Loc[0])
518 return Loc[0] < Other.Loc[0];
519
520 if (DefLoc && Other.DefLoc && *DefLoc != *Other.DefLoc)
521 return *DefLoc < *Other.DefLoc;
522
523 return extractName() < Other.extractName();
524 }
525
526 std::optional<Location> DefLoc; // Location where this decl is defined.
527 llvm::SmallVector<Location, 2> Loc; // Locations where this decl is declared.
528 StringRef MangledName;
529 bool IsStatic = false;
530};
531
532struct FriendInfo : public SymbolInfo, public llvm::ilist_node<FriendInfo> {
536 const StringRef Name = StringRef())
537 : SymbolInfo(IT, USR, Name) {}
538 bool mergeable(const FriendInfo &Other);
539 void merge(FriendInfo &&Other);
540
542 std::optional<TemplateInfo> Template;
543 std::optional<TypeInfo> ReturnType;
544 llvm::ArrayRef<FieldTypeInfo> Params;
545 bool IsClass = false;
546};
547
548struct VarInfo : public SymbolInfo, public llvm::ilist_node<VarInfo> {
551
552 void merge(VarInfo &&I);
553
555};
556
557// TODO: Expand to allow for documenting templating and default args.
558// Info for functions.
559struct FunctionInfo : public SymbolInfo, public llvm::ilist_node<FunctionInfo> {
562
563 void merge(FunctionInfo &&I);
564
567 llvm::SmallVector<FieldTypeInfo, 4> Params;
568 StringRef Prototype;
569
570 // When present, this function is a template or specialization.
571 std::optional<TemplateInfo> Template;
572
573 // Access level for this method (public, private, protected, none).
574 // AS_public is set as default because the bitcode writer requires the enum
575 // with value 0 to be used as the default.
576 // (AS_public = 0, AS_protected = 1, AS_private = 2, AS_none = 3)
577 AccessSpecifier Access = AccessSpecifier::AS_public;
578
579 bool IsMethod = false;
580};
581
582// TODO: Expand to allow for documenting templating, inheritance access,
583// friend classes
584// Info for types.
585struct RecordInfo : public SymbolInfo {
586 RecordInfo(SymbolID USR = SymbolID(), StringRef Name = StringRef(),
587 StringRef Path = StringRef());
588
589 void merge(RecordInfo &&I);
590
591 // Type of this record (struct, class, union, interface).
592 TagTypeKind TagType = TagTypeKind::Struct;
593
594 // Indicates if the record was declared using a typedef. Things like anonymous
595 // structs in a typedef:
596 // typedef struct { ... } foo_t;
597 // are converted into records with the typedef as the Name + this flag set.
598 bool IsTypeDef = false;
599
600 // When present, this record is a template or specialization.
601 std::optional<TemplateInfo> Template;
602
603 llvm::SmallVector<MemberTypeInfo, 4>
604 Members; // List of info about record members.
605 llvm::SmallVector<Reference, 4> Parents; // List of base/parent records
606 // (does not include virtual
607 // parents).
608 llvm::SmallVector<Reference, 4>
609 VirtualParents; // List of virtual base/parent records.
610
611 OwningVec<BaseRecordInfo> Bases; // List of base/parent records; this includes
612 // inherited methods and attributes
613
615
617};
618
619// Info for typedef and using statements.
620struct TypedefInfo : public SymbolInfo, public llvm::ilist_node<TypedefInfo> {
623
624 void merge(TypedefInfo &&I);
625
627
628 // Only type aliases can be templates.
629 std::optional<TemplateInfo> Template;
630
631 // Underlying type declaration
633
634 // Indicates if this is a new C++ "using"-style typedef:
635 // using MyVector = std::vector<int>
636 // False means it's a C-style typedef:
637 // typedef std::vector<int> MyVector;
638 bool IsUsing = false;
639};
640
641struct BaseRecordInfo : public RecordInfo {
643 BaseRecordInfo(SymbolID USR, StringRef Name, StringRef Path, bool IsVirtual,
644 AccessSpecifier Access, bool IsParent);
645
646 // Access level associated with this inherited info (public, protected,
647 // private).
648 AccessSpecifier Access = AccessSpecifier::AS_public;
649 // Indicates if base corresponds to a virtual inheritance
650 bool IsVirtual = false;
651 bool IsParent = false; // Indicates if this base is a direct parent
652};
653
654// Information for a single possible value of an enumeration.
656 explicit EnumValueInfo(StringRef Name = StringRef(),
657 StringRef Value = StringRef("0"),
658 StringRef ValueExpr = StringRef())
661
662 bool operator==(const EnumValueInfo &Other) const {
663 return std::tie(Name, Value, ValueExpr) ==
664 std::tie(Other.Name, Other.Value, Other.ValueExpr);
665 }
666
667 StringRef Name;
668
669 // The computed value of the enumeration constant. This could be the result of
670 // evaluating the ValueExpr, or it could be automatically generated according
671 // to C rules.
672 StringRef Value;
673
674 // Stores the user-supplied initialization expression for this enumeration
675 // constant. This will be empty for implicit enumeration values.
676 StringRef ValueExpr;
677
678 /// Comment description of this field.
680};
681
682// TODO: Expand to allow for documenting templating.
683// Info for types.
684struct EnumInfo : public SymbolInfo, public llvm::ilist_node<EnumInfo> {
687
688 void merge(EnumInfo &&I);
689
690 // Indicates whether this enum is scoped (e.g. enum class).
691 bool Scoped = false;
692
693 // Set to nonempty to the type when this is an explicitly typed enum. For
694 // enum Foo : short { ... };
695 // this will be "short".
696 std::optional<TypeInfo> BaseType;
697
698 llvm::SmallVector<EnumValueInfo, 4> Members; // List of enum members.
699};
700
701struct ConceptInfo : public SymbolInfo, public llvm::ilist_node<ConceptInfo> {
704
705 void merge(ConceptInfo &&I);
706
707 bool IsType;
710};
711
712struct Index : public Reference {
713 Index() = default;
714 Index(StringRef Name) : Reference(SymbolID(), Name) {}
717 Index(SymbolID USR, StringRef Name, InfoType IT, StringRef Path)
718 : Reference(USR, Name, IT, Name, Path) {}
719 // This is used to look for a USR in a vector of Indexes using std::find
720 bool operator==(const SymbolID &Other) const { return USR == Other; }
721 bool operator<(const Index &Other) const;
722
723 std::optional<StringRef> JumpToSection;
724 llvm::StringMap<Index> Children;
725
727 void sort();
728};
729
730// TODO: Add functionality to include separate markdown pages.
731
732// A standalone function to call to merge a vector of infos into one.
733// This assumes that all infos in the vector are of the same type, and will fail
734// if they are different.
735llvm::Expected<OwnedPtr<Info>> mergeInfos(OwningPtrArray<Info> &Values);
736
738 ClangDocContext(tooling::ExecutionContext *ECtx, StringRef ProjectName,
739 bool PublicOnly, StringRef OutDirectory, StringRef SourceRoot,
740 StringRef RepositoryUrl, StringRef RepositoryCodeLinePrefix,
741 StringRef Base, std::vector<std::string> UserStylesheets,
742 clang::DiagnosticsEngine &Diags, OutputFormatTy Format,
743 bool FTimeTrace = false);
744 tooling::ExecutionContext *ECtx;
745 std::string ProjectName; // Name of project clang-doc is documenting.
746 std::string OutDirectory; // Directory for outputting generated files.
747 std::string SourceRoot; // Directory where processed files are stored. Links
748 // to definition locations will only be generated if
749 // the file is in this dir.
750 // URL of repository that hosts code used for links to definition locations.
751 std::optional<std::string> RepositoryUrl;
752 // Prefix of line code for repository.
753 std::optional<std::string> RepositoryLinePrefix;
754 // Path of CSS stylesheets that will be copied to OutDirectory and used to
755 // style all HTML files.
756 std::vector<std::string> UserStylesheets;
757 // JavaScript files that will be imported in all HTML files.
758 std::vector<std::string> JsScripts;
759 // Base directory for remote repositories.
760 StringRef Base;
761 // Maps mustache template types to specific mustache template files.
762 // Ex. comment-template -> /path/to/comment-template.mustache
763 llvm::StringMap<std::string> MustacheTemplates;
764 // A pointer to a DiagnosticsEngine for error reporting.
765 clang::DiagnosticsEngine &Diags;
768 int Granularity; // Granularity of ftime trace
769 bool PublicOnly; // Indicates if only public declarations are documented.
770 bool FTimeTrace; // Indicates if ftime trace is turned on
771};
772
773// Ensure arena allocated types remain safe to allocate in the arena.
774// Only trivially destructible types are safe, so enforce that at compile-time.
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>);
782
783// FIXME: These types need to be trivially destructible for arena allocation.
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>);
798
799} // namespace doc
800} // namespace clang
801
802#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_DOC_REPRESENTATION_H
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
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
llvm::ArrayRef< StringRef > Args
llvm::ArrayRef< StringRef > AttrValues
CommentInfo & operator=(CommentInfo &&Other)=default
CommentInfo(CommentKind Kind, llvm::ArrayRef< CommentInfo > Children={}, StringRef Text=StringRef(), StringRef Name=StringRef(), StringRef CloseName=StringRef(), StringRef Direction=StringRef(), StringRef ParamName=StringRef(), bool Explicit=false, bool SelfClosing=false, llvm::ArrayRef< StringRef > AttrKeys={}, llvm::ArrayRef< StringRef > AttrValues={})
llvm::ArrayRef< CommentInfo > Children
bool operator<(const CommentInfo &Other) const
CommentInfo(CommentInfo &&Other)=default
bool operator==(const CommentInfo &Other) const
CommentInfo(const CommentInfo &Other)=default
llvm::ArrayRef< StringRef > AttrKeys
CommentInfo & operator=(const CommentInfo &Other)=default
void merge(ConceptInfo &&I)
ConstraintInfo(SymbolID USR, StringRef Name)
Context(SymbolID USR, StringRef Name, InfoType IT, StringRef QualName, StringRef Path, StringRef DocumentationFileName)
llvm::SmallVector< EnumValueInfo, 4 > Members
void merge(EnumInfo &&I)
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)
Index(StringRef Name)
llvm::StringMap< Index > Children
A base struct for Infos.
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
virtual ~Info()=default
StringRef DocumentationFileName
void mergeBase(Info &&I)
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)
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(StringRef Contents)
OwningVec< TemplateParamInfo > Params
TypeInfo(StringRef Name, StringRef Path=StringRef())
TypeInfo(const Reference &R)
bool operator==(const TypeInfo &Other) const
void merge(TypedefInfo &&I)
std::optional< TemplateInfo > Template
TypedefInfo(SymbolID USR=SymbolID())
VarInfo(SymbolID USR)
void merge(VarInfo &&I)