clang 22.0.0git
Comment.h
Go to the documentation of this file.
1//===--- Comment.h - Comment AST nodes --------------------------*- 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 comment AST nodes.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_CLANG_AST_COMMENT_H
14#define LLVM_CLANG_AST_COMMENT_H
15
17#include "clang/AST/DeclObjC.h"
18#include "clang/AST/Type.h"
20#include "llvm/ADT/ArrayRef.h"
21#include "llvm/ADT/StringRef.h"
22#include "llvm/Support/Compiler.h"
23
24namespace clang {
25class Decl;
26class ParmVarDecl;
27class TemplateParameterList;
28
29namespace comments {
30class FullComment;
33
34/// Describes the syntax that was used in a documentation command.
35///
36/// Exact values of this enumeration are important because they used to select
37/// parts of diagnostic messages. Audit diagnostics before changing or adding
38/// a new value.
40 /// Command started with a backslash character:
41 /// \code
42 /// \foo
43 /// \endcode
45
46 /// Command started with an 'at' character:
47 /// \code
48 /// @foo
49 /// \endcode
50 CMK_At = 1
51};
52
53enum class CommentKind {
54 None = 0,
55#define COMMENT(CLASS, PARENT) CLASS,
56#define COMMENT_RANGE(BASE, FIRST, LAST) \
57 First##BASE##Constant = FIRST, Last##BASE##Constant = LAST,
58#define LAST_COMMENT_RANGE(BASE, FIRST, LAST) \
59 First##BASE##Constant = FIRST, Last##BASE##Constant = LAST
60#define ABSTRACT_COMMENT(COMMENT)
61#include "clang/AST/CommentNodes.inc"
62};
63
64/// Any part of the comment.
65/// Abstract class.
66class Comment {
67protected:
68 /// Preferred location to show caret.
70
71 /// Source range of this AST node.
73
75 friend class Comment;
76
77 /// Type of this AST node.
78 LLVM_PREFERRED_TYPE(CommentKind)
79 unsigned Kind : 8;
80 };
81 enum { NumCommentBits = 8 };
82
85
86 LLVM_PREFERRED_TYPE(CommentBitfields)
88
89 /// True if there is a newline after this inline content node.
90 /// (There is no separate AST node for a newline.)
91 LLVM_PREFERRED_TYPE(bool)
92 unsigned HasTrailingNewline : 1;
93 };
95
97 friend class TextComment;
98
99 LLVM_PREFERRED_TYPE(InlineContentCommentBitfields)
101
102 /// True if \c IsWhitespace field contains a valid value.
103 LLVM_PREFERRED_TYPE(bool)
104 mutable unsigned IsWhitespaceValid : 1;
105
106 /// True if this comment AST node contains only whitespace.
107 LLVM_PREFERRED_TYPE(bool)
108 mutable unsigned IsWhitespace : 1;
109 };
111
114
115 LLVM_PREFERRED_TYPE(InlineContentCommentBitfields)
117
118 LLVM_PREFERRED_TYPE(InlineCommandRenderKind)
119 unsigned RenderKind : 3;
120
121 LLVM_PREFERRED_TYPE(CommandTraits::KnownCommandIDs)
122 unsigned CommandID : CommandInfo::NumCommandIDBits;
123
124 /// Describes the syntax that was used in a documentation command.
125 /// Contains values from CommandMarkerKind enum.
126 LLVM_PREFERRED_TYPE(CommandMarkerKind)
127 unsigned CommandMarker : 1;
128 };
131
133 friend class HTMLTagComment;
134
135 LLVM_PREFERRED_TYPE(InlineContentCommentBitfields)
137
138 /// True if we found that this tag is malformed in some way.
139 LLVM_PREFERRED_TYPE(bool)
140 unsigned IsMalformed : 1;
141 };
143
146
147 LLVM_PREFERRED_TYPE(HTMLTagCommentBitfields)
149
150 /// True if this tag is self-closing (e. g., <br />). This is based on tag
151 /// spelling in comment (plain <br> would not set this flag).
152 LLVM_PREFERRED_TYPE(bool)
153 unsigned IsSelfClosing : 1;
154 };
156
158 friend class ParagraphComment;
159
160 LLVM_PREFERRED_TYPE(CommentBitfields)
162
163 /// True if \c IsWhitespace field contains a valid value.
164 LLVM_PREFERRED_TYPE(bool)
165 mutable unsigned IsWhitespaceValid : 1;
166
167 /// True if this comment AST node contains only whitespace.
168 LLVM_PREFERRED_TYPE(bool)
169 mutable unsigned IsWhitespace : 1;
170 };
172
175
176 LLVM_PREFERRED_TYPE(CommentBitfields)
178
179 LLVM_PREFERRED_TYPE(CommandTraits::KnownCommandIDs)
180 unsigned CommandID : CommandInfo::NumCommandIDBits;
181
182 /// Describes the syntax that was used in a documentation command.
183 /// Contains values from CommandMarkerKind enum.
184 LLVM_PREFERRED_TYPE(CommandMarkerKind)
185 unsigned CommandMarker : 1;
186 };
189
192
193 LLVM_PREFERRED_TYPE(BlockCommandCommentBitfields)
195
196 /// Parameter passing direction.
197 LLVM_PREFERRED_TYPE(ParamCommandPassDirection)
198 unsigned Direction : 2;
199
200 /// True if direction was specified explicitly in the comment.
201 LLVM_PREFERRED_TYPE(bool)
202 unsigned IsDirectionExplicit : 1;
203 };
205
206 union {
216 };
217
219 Range = SR;
220 }
221
223 Loc = L;
224 }
225
226public:
227 struct Argument {
229 StringRef Text;
230 };
231
233 SourceLocation LocBegin,
234 SourceLocation LocEnd) :
235 Loc(LocBegin), Range(SourceRange(LocBegin, LocEnd)) {
236 CommentBits.Kind = llvm::to_underlying(K);
237 }
238
240 return static_cast<CommentKind>(CommentBits.Kind);
241 }
242
243 const char *getCommentKindName() const;
244
245 void dump() const;
246 void dumpColor() const;
247 void dump(raw_ostream &OS, const ASTContext &Context) const;
248
249 SourceRange getSourceRange() const LLVM_READONLY { return Range; }
250
251 SourceLocation getBeginLoc() const LLVM_READONLY { return Range.getBegin(); }
252
253 SourceLocation getEndLoc() const LLVM_READONLY { return Range.getEnd(); }
254
255 SourceLocation getLocation() const LLVM_READONLY { return Loc; }
256
257 typedef Comment * const *child_iterator;
258
261
262 // TODO: const child iterator
263
264 unsigned child_count() const {
265 return child_end() - child_begin();
266 }
267};
268
269/// Inline content (contained within a block).
270/// Abstract class.
272protected:
274 SourceLocation LocBegin,
275 SourceLocation LocEnd) :
276 Comment(K, LocBegin, LocEnd) {
277 InlineContentCommentBits.HasTrailingNewline = 0;
278 }
279
280public:
281 static bool classof(const Comment *C) {
282 return C->getCommentKind() >=
283 CommentKind::FirstInlineContentCommentConstant &&
284 C->getCommentKind() <= CommentKind::LastInlineContentCommentConstant;
285 }
286
288 InlineContentCommentBits.HasTrailingNewline = 1;
289 }
290
291 bool hasTrailingNewline() const {
292 return InlineContentCommentBits.HasTrailingNewline;
293 }
294};
295
296/// Plain text.
298 StringRef Text;
299
300public:
301 TextComment(SourceLocation LocBegin, SourceLocation LocEnd, StringRef Text)
302 : InlineContentComment(CommentKind::TextComment, LocBegin, LocEnd),
303 Text(Text) {
304 TextCommentBits.IsWhitespaceValid = false;
305 }
306
307 static bool classof(const Comment *C) {
308 return C->getCommentKind() == CommentKind::TextComment;
309 }
310
311 child_iterator child_begin() const { return nullptr; }
312
313 child_iterator child_end() const { return nullptr; }
314
315 StringRef getText() const LLVM_READONLY { return Text; }
316
317 bool isWhitespace() const {
318 if (TextCommentBits.IsWhitespaceValid)
319 return TextCommentBits.IsWhitespace;
320
321 TextCommentBits.IsWhitespace = isWhitespaceNoCache();
322 TextCommentBits.IsWhitespaceValid = true;
323 return TextCommentBits.IsWhitespace;
324 }
325
326private:
327 bool isWhitespaceNoCache() const;
328};
329
330/// The most appropriate rendering mode for this command, chosen on command
331/// semantics in Doxygen.
333 Normal,
334 Bold,
337 Anchor
338};
339
340/// A command with word-like arguments that is considered inline content.
342protected:
343 /// Command arguments.
345
346public:
348 unsigned CommandID, InlineCommandRenderKind RK,
351 LocEnd),
352 Args(Args) {
353 InlineCommandCommentBits.RenderKind = llvm::to_underlying(RK);
354 InlineCommandCommentBits.CommandID = CommandID;
355 }
357 unsigned CommandID, InlineCommandRenderKind RK,
360 LocEnd),
361 Args(Args) {
362 InlineCommandCommentBits.RenderKind = llvm::to_underlying(RK);
363 InlineCommandCommentBits.CommandID = CommandID;
364 InlineCommandCommentBits.CommandMarker = llvm::to_underlying(CommandMarker);
365 }
366
367 static bool classof(const Comment *C) {
368 return C->getCommentKind() == CommentKind::InlineCommandComment;
369 }
370
371 child_iterator child_begin() const { return nullptr; }
372
373 child_iterator child_end() const { return nullptr; }
374
375 unsigned getCommandID() const {
376 return InlineCommandCommentBits.CommandID;
377 }
378
379 StringRef getCommandName(const CommandTraits &Traits) const {
380 return Traits.getCommandInfo(getCommandID())->Name;
381 }
382
384 return SourceRange(getBeginLoc().getLocWithOffset(-1), getEndLoc());
385 }
386
388 return static_cast<InlineCommandRenderKind>(
389 InlineCommandCommentBits.RenderKind);
390 }
391
392 unsigned getNumArgs() const {
393 return Args.size();
394 }
395
396 StringRef getArgText(unsigned Idx) const {
397 return Args[Idx].Text;
398 }
399
400 SourceRange getArgRange(unsigned Idx) const {
401 return Args[Idx].Range;
402 }
403
405 return static_cast<CommandMarkerKind>(
406 InlineCommandCommentBits.CommandMarker);
407 }
408};
409
410/// Abstract class for opening and closing HTML tags. HTML tags are always
411/// treated as inline content (regardless HTML semantics).
413protected:
414 StringRef TagName;
416
418 SourceLocation LocBegin,
419 SourceLocation LocEnd,
420 StringRef TagName,
421 SourceLocation TagNameBegin,
422 SourceLocation TagNameEnd) :
423 InlineContentComment(K, LocBegin, LocEnd),
425 TagNameRange(TagNameBegin, TagNameEnd) {
426 setLocation(TagNameBegin);
427 HTMLTagCommentBits.IsMalformed = 0;
428 }
429
430public:
431 static bool classof(const Comment *C) {
432 return C->getCommentKind() >= CommentKind::FirstHTMLTagCommentConstant &&
433 C->getCommentKind() <= CommentKind::LastHTMLTagCommentConstant;
434 }
435
436 StringRef getTagName() const LLVM_READONLY { return TagName; }
437
438 SourceRange getTagNameSourceRange() const LLVM_READONLY {
440 return SourceRange(L.getLocWithOffset(1),
441 L.getLocWithOffset(1 + TagName.size()));
442 }
443
444 bool isMalformed() const {
445 return HTMLTagCommentBits.IsMalformed;
446 }
447
449 HTMLTagCommentBits.IsMalformed = 1;
450 }
451};
452
453/// An opening HTML tag with attributes.
455public:
456 class Attribute {
457 public:
459 StringRef Name;
460
462
464 StringRef Value;
465
467
470
475
477 return NameLocBegin.getLocWithOffset(Name.size());
478 }
479
482 }
483 };
484
485private:
486 ArrayRef<Attribute> Attributes;
487
488public:
491 LocBegin.getLocWithOffset(1 + TagName.size()), TagName,
492 LocBegin.getLocWithOffset(1),
493 LocBegin.getLocWithOffset(1 + TagName.size())) {
494 HTMLStartTagCommentBits.IsSelfClosing = false;
495 }
496
497 static bool classof(const Comment *C) {
498 return C->getCommentKind() == CommentKind::HTMLStartTagComment;
499 }
500
501 child_iterator child_begin() const { return nullptr; }
502
503 child_iterator child_end() const { return nullptr; }
504
505 unsigned getNumAttrs() const {
506 return Attributes.size();
507 }
508
509 const Attribute &getAttr(unsigned Idx) const {
510 return Attributes[Idx];
511 }
512
514 Attributes = Attrs;
515 if (!Attrs.empty()) {
516 const Attribute &Attr = Attrs.back();
517 SourceLocation L = Attr.ValueRange.getEnd();
518 if (L.isValid())
519 Range.setEnd(L);
520 else {
521 Range.setEnd(Attr.getNameLocEnd());
522 }
523 }
524 }
525
526 void setGreaterLoc(SourceLocation GreaterLoc) {
527 Range.setEnd(GreaterLoc);
528 }
529
530 bool isSelfClosing() const {
531 return HTMLStartTagCommentBits.IsSelfClosing;
532 }
533
535 HTMLStartTagCommentBits.IsSelfClosing = true;
536 }
537};
538
539/// A closing HTML tag.
541public:
543 StringRef TagName)
544 : HTMLTagComment(CommentKind::HTMLEndTagComment, LocBegin, LocEnd,
545 TagName, LocBegin.getLocWithOffset(2),
546 LocBegin.getLocWithOffset(2 + TagName.size())) {}
547
548 static bool classof(const Comment *C) {
549 return C->getCommentKind() == CommentKind::HTMLEndTagComment;
550 }
551
552 child_iterator child_begin() const { return nullptr; }
553
554 child_iterator child_end() const { return nullptr; }
555};
556
557/// Block content (contains inline content).
558/// Abstract class.
560protected:
562 SourceLocation LocBegin,
563 SourceLocation LocEnd) :
564 Comment(K, LocBegin, LocEnd)
565 { }
566
567public:
568 static bool classof(const Comment *C) {
569 return C->getCommentKind() >=
570 CommentKind::FirstBlockContentCommentConstant &&
571 C->getCommentKind() <= CommentKind::LastBlockContentCommentConstant;
572 }
573};
574
575/// A single paragraph that contains inline content.
578
579public:
583 Content(Content) {
584 if (Content.empty()) {
585 ParagraphCommentBits.IsWhitespace = true;
586 ParagraphCommentBits.IsWhitespaceValid = true;
587 return;
588 }
589
590 ParagraphCommentBits.IsWhitespaceValid = false;
591
592 setSourceRange(SourceRange(Content.front()->getBeginLoc(),
593 Content.back()->getEndLoc()));
594 setLocation(Content.front()->getBeginLoc());
595 }
596
597 static bool classof(const Comment *C) {
598 return C->getCommentKind() == CommentKind::ParagraphComment;
599 }
600
602 return reinterpret_cast<child_iterator>(Content.begin());
603 }
604
606 return reinterpret_cast<child_iterator>(Content.end());
607 }
608
609 bool isWhitespace() const {
610 if (ParagraphCommentBits.IsWhitespaceValid)
611 return ParagraphCommentBits.IsWhitespace;
612
613 ParagraphCommentBits.IsWhitespace = isWhitespaceNoCache();
614 ParagraphCommentBits.IsWhitespaceValid = true;
615 return ParagraphCommentBits.IsWhitespace;
616 }
617
618private:
619 bool isWhitespaceNoCache() const;
620};
621
622/// A command that has zero or more word-like arguments (number of word-like
623/// arguments depends on command name) and a paragraph as an argument
624/// (e. g., \\brief).
626protected:
627 /// Word-like arguments.
629
630 /// Paragraph argument.
632
634 SourceLocation LocBegin,
635 SourceLocation LocEnd,
636 unsigned CommandID,
637 CommandMarkerKind CommandMarker) :
638 BlockContentComment(K, LocBegin, LocEnd),
639 Paragraph(nullptr) {
641 BlockCommandCommentBits.CommandID = CommandID;
642 BlockCommandCommentBits.CommandMarker = CommandMarker;
643 }
644
645public:
647 unsigned CommandID, CommandMarkerKind CommandMarker)
649 Paragraph(nullptr) {
651 BlockCommandCommentBits.CommandID = CommandID;
652 BlockCommandCommentBits.CommandMarker = CommandMarker;
653 }
654
655 static bool classof(const Comment *C) {
656 return C->getCommentKind() >=
657 CommentKind::FirstBlockCommandCommentConstant &&
658 C->getCommentKind() <= CommentKind::LastBlockCommandCommentConstant;
659 }
660
662 return reinterpret_cast<child_iterator>(&Paragraph);
663 }
664
666 return reinterpret_cast<child_iterator>(&Paragraph + 1);
667 }
668
669 unsigned getCommandID() const {
670 return BlockCommandCommentBits.CommandID;
671 }
672
673 StringRef getCommandName(const CommandTraits &Traits) const {
674 return Traits.getCommandInfo(getCommandID())->Name;
675 }
676
678 return getBeginLoc().getLocWithOffset(1);
679 }
680
682 StringRef Name = getCommandName(Traits);
684 getBeginLoc().getLocWithOffset(1 + Name.size()));
685 }
686
687 unsigned getNumArgs() const {
688 return Args.size();
689 }
690
691 StringRef getArgText(unsigned Idx) const {
692 return Args[Idx].Text;
693 }
694
695 SourceRange getArgRange(unsigned Idx) const {
696 return Args[Idx].Range;
697 }
698
700 Args = A;
701 if (Args.size() > 0) {
702 SourceLocation NewLocEnd = Args.back().Range.getEnd();
703 if (NewLocEnd.isValid())
705 }
706 }
707
708 ParagraphComment *getParagraph() const LLVM_READONLY {
709 return Paragraph;
710 }
711
713 return Paragraph && !Paragraph->isWhitespace();
714 }
715
717 Paragraph = PC;
718 SourceLocation NewLocEnd = PC->getEndLoc();
719 if (NewLocEnd.isValid())
721 }
722
723 CommandMarkerKind getCommandMarker() const LLVM_READONLY {
724 return static_cast<CommandMarkerKind>(
725 BlockCommandCommentBits.CommandMarker);
726 }
727};
728
730
731/// Doxygen \\param command.
733private:
734 /// Parameter index in the function declaration.
735 unsigned ParamIndex;
736
737public:
738 enum : unsigned {
740 VarArgParamIndex = ~0U/*InvalidParamIndex*/ - 1U
741 };
742
744 unsigned CommandID, CommandMarkerKind CommandMarker)
746 CommandID, CommandMarker),
747 ParamIndex(InvalidParamIndex) {
748 ParamCommandCommentBits.Direction =
749 llvm::to_underlying(ParamCommandPassDirection::In);
750 ParamCommandCommentBits.IsDirectionExplicit = false;
751 }
752
753 static bool classof(const Comment *C) {
754 return C->getCommentKind() == CommentKind::ParamCommandComment;
755 }
756
758
760 return static_cast<ParamCommandPassDirection>(
761 ParamCommandCommentBits.Direction);
762 }
763
764 bool isDirectionExplicit() const LLVM_READONLY {
765 return ParamCommandCommentBits.IsDirectionExplicit;
766 }
767
769 ParamCommandCommentBits.Direction = llvm::to_underlying(Direction);
770 ParamCommandCommentBits.IsDirectionExplicit = Explicit;
771 }
772
773 bool hasParamName() const {
774 return getNumArgs() > 0;
775 }
776
777 StringRef getParamName(const FullComment *FC) const;
778
779 StringRef getParamNameAsWritten() const {
780 return Args[0].Text;
781 }
782
784 return Args[0].Range;
785 }
786
787 bool isParamIndexValid() const LLVM_READONLY {
788 return ParamIndex != InvalidParamIndex;
789 }
790
791 bool isVarArgParam() const LLVM_READONLY {
792 return ParamIndex == VarArgParamIndex;
793 }
794
796 ParamIndex = VarArgParamIndex;
797 assert(isParamIndexValid());
798 }
799
800 unsigned getParamIndex() const LLVM_READONLY {
801 assert(isParamIndexValid());
802 assert(!isVarArgParam());
803 return ParamIndex;
804 }
805
806 void setParamIndex(unsigned Index) {
807 ParamIndex = Index;
808 assert(isParamIndexValid());
809 assert(!isVarArgParam());
810 }
811};
812
813/// Doxygen \\tparam command, describes a template parameter.
815private:
816 /// If this template parameter name was resolved (found in template parameter
817 /// list), then this stores a list of position indexes in all template
818 /// parameter lists.
819 ///
820 /// For example:
821 /// \verbatim
822 /// template<typename C, template<typename T> class TT>
823 /// void test(TT<int> aaa);
824 /// \endverbatim
825 /// For C: Position = { 0 }
826 /// For TT: Position = { 1 }
827 /// For T: Position = { 1, 0 }
828 ArrayRef<unsigned> Position;
829
830public:
832 unsigned CommandID, CommandMarkerKind CommandMarker)
834 CommandID, CommandMarker) {}
835
836 static bool classof(const Comment *C) {
837 return C->getCommentKind() == CommentKind::TParamCommandComment;
838 }
839
840 bool hasParamName() const {
841 return getNumArgs() > 0;
842 }
843
844 StringRef getParamName(const FullComment *FC) const;
845
846 StringRef getParamNameAsWritten() const {
847 return Args[0].Text;
848 }
849
851 return Args[0].Range;
852 }
853
854 bool isPositionValid() const LLVM_READONLY {
855 return !Position.empty();
856 }
857
858 unsigned getDepth() const {
859 assert(isPositionValid());
860 return Position.size();
861 }
862
863 unsigned getIndex(unsigned Depth) const {
864 assert(isPositionValid());
865 return Position[Depth];
866 }
867
868 void setPosition(ArrayRef<unsigned> NewPosition) {
869 Position = NewPosition;
870 assert(isPositionValid());
871 }
872};
873
874/// A line of text contained in a verbatim block.
876 StringRef Text;
877
878public:
879 VerbatimBlockLineComment(SourceLocation LocBegin, StringRef Text)
881 LocBegin.getLocWithOffset(Text.size())),
882 Text(Text) {}
883
884 static bool classof(const Comment *C) {
885 return C->getCommentKind() == CommentKind::VerbatimBlockLineComment;
886 }
887
888 child_iterator child_begin() const { return nullptr; }
889
890 child_iterator child_end() const { return nullptr; }
891
892 StringRef getText() const LLVM_READONLY {
893 return Text;
894 }
895};
896
897/// A verbatim block command (e. g., preformatted code). Verbatim block has an
898/// opening and a closing command and contains multiple lines of text
899/// (VerbatimBlockLineComment nodes).
901protected:
902 StringRef CloseName;
905
906public:
908 unsigned CommandID)
910 CommandID,
911 CMK_At) // FIXME: improve source fidelity.
912 {}
913
914 static bool classof(const Comment *C) {
915 return C->getCommentKind() == CommentKind::VerbatimBlockComment;
916 }
917
919 return reinterpret_cast<child_iterator>(Lines.begin());
920 }
921
923 return reinterpret_cast<child_iterator>(Lines.end());
924 }
925
926 void setCloseName(StringRef Name, SourceLocation LocBegin) {
927 CloseName = Name;
928 CloseNameLocBegin = LocBegin;
929 }
930
932 Lines = L;
933 }
934
935 StringRef getCloseName() const {
936 return CloseName;
937 }
938
939 unsigned getNumLines() const {
940 return Lines.size();
941 }
942
943 StringRef getText(unsigned LineIdx) const {
944 return Lines[LineIdx]->getText();
945 }
946};
947
948/// A verbatim line command. Verbatim line has an opening command, a single
949/// line of text (up to the newline after the opening command) and has no
950/// closing command.
952protected:
953 StringRef Text;
955
956public:
958 unsigned CommandID, SourceLocation TextBegin,
959 StringRef Text)
961 CommandID,
962 CMK_At), // FIXME: improve source fidelity.
964
965 static bool classof(const Comment *C) {
966 return C->getCommentKind() == CommentKind::VerbatimLineComment;
967 }
968
969 child_iterator child_begin() const { return nullptr; }
970
971 child_iterator child_end() const { return nullptr; }
972
973 StringRef getText() const {
974 return Text;
975 }
976
979 }
980};
981
982/// Information about the declaration, useful to clients of FullComment.
983struct DeclInfo {
984 /// Declaration the comment is actually attached to (in the source).
985 /// Should not be NULL.
987
988 /// CurrentDecl is the declaration with which the FullComment is associated.
989 ///
990 /// It can be different from \c CommentDecl. It happens when we decide
991 /// that the comment originally attached to \c CommentDecl is fine for
992 /// \c CurrentDecl too (for example, for a redeclaration or an overrider of
993 /// \c CommentDecl).
994 ///
995 /// The information in the DeclInfo corresponds to CurrentDecl.
997
998 /// Parameters that can be referenced by \\param if \c CommentDecl is something
999 /// that we consider a "function".
1001
1002 /// Function return type if \c CommentDecl is something that we consider
1003 /// a "function".
1005
1006 /// Template parameters that can be referenced by \\tparam if \c CommentDecl is
1007 /// a template (\c IsTemplateDecl or \c IsTemplatePartialSpecialization is
1008 /// true).
1010
1011 /// A simplified description of \c CommentDecl kind that should be good enough
1012 /// for documentation rendering purposes.
1014 /// Everything else not explicitly mentioned below.
1016
1017 /// Something that we consider a "function":
1018 /// \li function,
1019 /// \li function template,
1020 /// \li function template specialization,
1021 /// \li member function,
1022 /// \li member function template,
1023 /// \li member function template specialization,
1024 /// \li ObjC method,
1026
1027 /// Something that we consider a "class":
1028 /// \li class/struct,
1029 /// \li class template,
1030 /// \li class template (partial) specialization.
1032
1033 /// Something that we consider a "variable":
1034 /// \li namespace scope variables and variable templates;
1035 /// \li static and non-static class data members and member templates;
1036 /// \li enumerators.
1038
1039 /// A C++ namespace.
1041
1042 /// A C++ typedef-name (a 'typedef' decl specifier or alias-declaration),
1043 /// see \c TypedefNameDecl.
1045
1046 /// An enumeration or scoped enumeration.
1047 EnumKind
1049
1050 /// What kind of template specialization \c CommentDecl is.
1057
1058 /// If false, only \c CommentDecl is valid.
1059 LLVM_PREFERRED_TYPE(bool)
1061
1062 /// Simplified kind of \c CommentDecl, see \c DeclKind enum.
1063 LLVM_PREFERRED_TYPE(DeclKind)
1064 unsigned Kind : 3;
1065
1066 /// Is \c CommentDecl a template declaration.
1067 LLVM_PREFERRED_TYPE(TemplateDeclKind)
1068 unsigned TemplateKind : 2;
1069
1070 /// Is \c CommentDecl an ObjCMethodDecl.
1071 LLVM_PREFERRED_TYPE(bool)
1072 unsigned IsObjCMethod : 1;
1073
1074 /// Is \c CommentDecl a non-static member function of C++ class or
1075 /// instance method of ObjC class.
1076 /// Can be true only if \c IsFunctionDecl is true.
1077 LLVM_PREFERRED_TYPE(bool)
1078 unsigned IsInstanceMethod : 1;
1079
1080 /// Is \c CommentDecl a static member function of C++ class or
1081 /// class method of ObjC class.
1082 /// Can be true only if \c IsFunctionDecl is true.
1083 LLVM_PREFERRED_TYPE(bool)
1084 unsigned IsClassMethod : 1;
1085
1086 /// Is \c CommentDecl something we consider a "function" that's variadic.
1087 LLVM_PREFERRED_TYPE(bool)
1088 unsigned IsVariadic : 1;
1089
1090 void fill();
1091
1092 DeclKind getKind() const LLVM_READONLY {
1093 return static_cast<DeclKind>(Kind);
1094 }
1095
1096 TemplateDeclKind getTemplateKind() const LLVM_READONLY {
1097 return static_cast<TemplateDeclKind>(TemplateKind);
1098 }
1099
1100 bool involvesFunctionType() const { return !ReturnType.isNull(); }
1101};
1102
1103/// A full comment attached to a declaration, contains block content.
1104class FullComment : public Comment {
1106 DeclInfo *ThisDeclInfo;
1107
1108public:
1111 Blocks(Blocks), ThisDeclInfo(D) {
1112 if (Blocks.empty())
1113 return;
1114
1116 SourceRange(Blocks.front()->getBeginLoc(), Blocks.back()->getEndLoc()));
1117 setLocation(Blocks.front()->getBeginLoc());
1118 }
1119
1120 static bool classof(const Comment *C) {
1121 return C->getCommentKind() == CommentKind::FullComment;
1122 }
1123
1125 return reinterpret_cast<child_iterator>(Blocks.begin());
1126 }
1127
1129 return reinterpret_cast<child_iterator>(Blocks.end());
1130 }
1131
1132 const Decl *getDecl() const LLVM_READONLY {
1133 return ThisDeclInfo->CommentDecl;
1134 }
1135
1136 const DeclInfo *getDeclInfo() const LLVM_READONLY {
1137 if (!ThisDeclInfo->IsFilled)
1138 ThisDeclInfo->fill();
1139 return ThisDeclInfo;
1140 }
1141
1143
1144};
1145} // end namespace comments
1146} // end namespace clang
1147
1148#endif
1149
const Decl * D
enum clang::sema::@1840::IndirectLocalPathEntry::EntryKind Kind
StringRef Text
Definition: Format.cpp:3178
Defines the clang::SourceLocation class and associated facilities.
C Language Family Type Representation.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:188
Attr - This represents one attribute.
Definition: Attr.h:44
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:86
A (possibly-)qualified type.
Definition: TypeBase.h:937
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition: TypeBase.h:1004
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
SourceLocation getLocWithOffset(IntTy Offset) const
Return a source location with the specified offset from this SourceLocation.
A trivial tuple used to represent a source range.
SourceLocation getEnd() const
SourceLocation getBegin() const
void setEnd(SourceLocation e)
Stores a list of template parameters for a TemplateDecl and its derived classes.
Definition: DeclTemplate.h:74
A command that has zero or more word-like arguments (number of word-like arguments depends on command...
Definition: Comment.h:625
child_iterator child_begin() const
Definition: Comment.h:661
ArrayRef< Argument > Args
Word-like arguments.
Definition: Comment.h:628
static bool classof(const Comment *C)
Definition: Comment.h:655
BlockCommandComment(CommentKind K, SourceLocation LocBegin, SourceLocation LocEnd, unsigned CommandID, CommandMarkerKind CommandMarker)
Definition: Comment.h:633
SourceLocation getCommandNameBeginLoc() const
Definition: Comment.h:677
child_iterator child_end() const
Definition: Comment.h:665
SourceRange getCommandNameRange(const CommandTraits &Traits) const
Definition: Comment.h:681
void setParagraph(ParagraphComment *PC)
Definition: Comment.h:716
ParagraphComment * Paragraph
Paragraph argument.
Definition: Comment.h:631
StringRef getCommandName(const CommandTraits &Traits) const
Definition: Comment.h:673
void setArgs(ArrayRef< Argument > A)
Definition: Comment.h:699
BlockCommandComment(SourceLocation LocBegin, SourceLocation LocEnd, unsigned CommandID, CommandMarkerKind CommandMarker)
Definition: Comment.h:646
StringRef getArgText(unsigned Idx) const
Definition: Comment.h:691
SourceRange getArgRange(unsigned Idx) const
Definition: Comment.h:695
ParagraphComment * getParagraph() const LLVM_READONLY
Definition: Comment.h:708
CommandMarkerKind getCommandMarker() const LLVM_READONLY
Definition: Comment.h:723
Block content (contains inline content).
Definition: Comment.h:559
BlockContentComment(CommentKind K, SourceLocation LocBegin, SourceLocation LocEnd)
Definition: Comment.h:561
static bool classof(const Comment *C)
Definition: Comment.h:568
This class provides information about commands that can be used in comments.
const CommandInfo * getCommandInfo(StringRef Name) const
Any part of the comment.
Definition: Comment.h:66
InlineContentCommentBitfields InlineContentCommentBits
Definition: Comment.h:208
SourceRange Range
Source range of this AST node.
Definition: Comment.h:72
HTMLTagCommentBitfields HTMLTagCommentBits
Definition: Comment.h:211
Comment *const * child_iterator
Definition: Comment.h:257
TextCommentBitfields TextCommentBits
Definition: Comment.h:209
child_iterator child_end() const
Definition: Comment.cpp:98
child_iterator child_begin() const
Definition: Comment.cpp:83
Comment(CommentKind K, SourceLocation LocBegin, SourceLocation LocEnd)
Definition: Comment.h:232
CommentBitfields CommentBits
Definition: Comment.h:207
const char * getCommentKindName() const
Definition: Comment.cpp:35
HTMLStartTagCommentBitfields HTMLStartTagCommentBits
Definition: Comment.h:212
InlineCommandCommentBitfields InlineCommandCommentBits
Definition: Comment.h:210
SourceLocation getLocation() const LLVM_READONLY
Definition: Comment.h:255
ParagraphCommentBitfields ParagraphCommentBits
Definition: Comment.h:213
ParamCommandCommentBitfields ParamCommandCommentBits
Definition: Comment.h:215
BlockCommandCommentBitfields BlockCommandCommentBits
Definition: Comment.h:214
SourceLocation Loc
Preferred location to show caret.
Definition: Comment.h:69
void setSourceRange(SourceRange SR)
Definition: Comment.h:218
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Comment.h:251
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Comment.h:253
unsigned child_count() const
Definition: Comment.h:264
SourceRange getSourceRange() const LLVM_READONLY
Definition: Comment.h:249
CommentKind getCommentKind() const
Definition: Comment.h:239
void setLocation(SourceLocation L)
Definition: Comment.h:222
A full comment attached to a declaration, contains block content.
Definition: Comment.h:1104
ArrayRef< BlockContentComment * > getBlocks() const
Definition: Comment.h:1142
child_iterator child_end() const
Definition: Comment.h:1128
FullComment(ArrayRef< BlockContentComment * > Blocks, DeclInfo *D)
Definition: Comment.h:1109
const DeclInfo * getDeclInfo() const LLVM_READONLY
Definition: Comment.h:1136
const Decl * getDecl() const LLVM_READONLY
Definition: Comment.h:1132
static bool classof(const Comment *C)
Definition: Comment.h:1120
child_iterator child_begin() const
Definition: Comment.h:1124
HTMLEndTagComment(SourceLocation LocBegin, SourceLocation LocEnd, StringRef TagName)
Definition: Comment.h:542
child_iterator child_end() const
Definition: Comment.h:554
static bool classof(const Comment *C)
Definition: Comment.h:548
child_iterator child_begin() const
Definition: Comment.h:552
Attribute(SourceLocation NameLocBegin, StringRef Name)
Definition: Comment.h:468
Attribute(SourceLocation NameLocBegin, StringRef Name, SourceLocation EqualsLoc, SourceRange ValueRange, StringRef Value)
Definition: Comment.h:471
An opening HTML tag with attributes.
Definition: Comment.h:454
child_iterator child_begin() const
Definition: Comment.h:501
child_iterator child_end() const
Definition: Comment.h:503
HTMLStartTagComment(SourceLocation LocBegin, StringRef TagName)
Definition: Comment.h:489
void setGreaterLoc(SourceLocation GreaterLoc)
Definition: Comment.h:526
void setAttrs(ArrayRef< Attribute > Attrs)
Definition: Comment.h:513
static bool classof(const Comment *C)
Definition: Comment.h:497
const Attribute & getAttr(unsigned Idx) const
Definition: Comment.h:509
Abstract class for opening and closing HTML tags.
Definition: Comment.h:412
static bool classof(const Comment *C)
Definition: Comment.h:431
StringRef getTagName() const LLVM_READONLY
Definition: Comment.h:436
HTMLTagComment(CommentKind K, SourceLocation LocBegin, SourceLocation LocEnd, StringRef TagName, SourceLocation TagNameBegin, SourceLocation TagNameEnd)
Definition: Comment.h:417
SourceRange getTagNameSourceRange() const LLVM_READONLY
Definition: Comment.h:438
A command with word-like arguments that is considered inline content.
Definition: Comment.h:341
InlineCommandComment(SourceLocation LocBegin, SourceLocation LocEnd, unsigned CommandID, InlineCommandRenderKind RK, CommandMarkerKind CommandMarker, ArrayRef< Argument > Args)
Definition: Comment.h:356
StringRef getCommandName(const CommandTraits &Traits) const
Definition: Comment.h:379
SourceRange getArgRange(unsigned Idx) const
Definition: Comment.h:400
child_iterator child_begin() const
Definition: Comment.h:371
StringRef getArgText(unsigned Idx) const
Definition: Comment.h:396
static bool classof(const Comment *C)
Definition: Comment.h:367
InlineCommandComment(SourceLocation LocBegin, SourceLocation LocEnd, unsigned CommandID, InlineCommandRenderKind RK, ArrayRef< Argument > Args)
Definition: Comment.h:347
child_iterator child_end() const
Definition: Comment.h:373
InlineCommandRenderKind getRenderKind() const
Definition: Comment.h:387
ArrayRef< Argument > Args
Command arguments.
Definition: Comment.h:344
SourceRange getCommandNameRange() const
Definition: Comment.h:383
CommandMarkerKind getCommandMarker() const
Definition: Comment.h:404
Inline content (contained within a block).
Definition: Comment.h:271
InlineContentComment(CommentKind K, SourceLocation LocBegin, SourceLocation LocEnd)
Definition: Comment.h:273
static bool classof(const Comment *C)
Definition: Comment.h:281
A single paragraph that contains inline content.
Definition: Comment.h:576
static bool classof(const Comment *C)
Definition: Comment.h:597
child_iterator child_begin() const
Definition: Comment.h:601
ParagraphComment(ArrayRef< InlineContentComment * > Content)
Definition: Comment.h:580
child_iterator child_end() const
Definition: Comment.h:605
Doxygen \param command.
Definition: Comment.h:732
ParamCommandPassDirection getDirection() const LLVM_READONLY
Definition: Comment.h:759
static bool classof(const Comment *C)
Definition: Comment.h:753
bool isDirectionExplicit() const LLVM_READONLY
Definition: Comment.h:764
unsigned getParamIndex() const LLVM_READONLY
Definition: Comment.h:800
static const char * getDirectionAsString(ParamCommandPassDirection D)
Definition: Comment.cpp:189
StringRef getParamName(const FullComment *FC) const
Definition: Comment.cpp:373
SourceRange getParamNameRange() const
Definition: Comment.h:783
bool isParamIndexValid() const LLVM_READONLY
Definition: Comment.h:787
void setDirection(ParamCommandPassDirection Direction, bool Explicit)
Definition: Comment.h:768
StringRef getParamNameAsWritten() const
Definition: Comment.h:779
void setParamIndex(unsigned Index)
Definition: Comment.h:806
bool isVarArgParam() const LLVM_READONLY
Definition: Comment.h:791
ParamCommandComment(SourceLocation LocBegin, SourceLocation LocEnd, unsigned CommandID, CommandMarkerKind CommandMarker)
Definition: Comment.h:743
Doxygen \tparam command, describes a template parameter.
Definition: Comment.h:814
void setPosition(ArrayRef< unsigned > NewPosition)
Definition: Comment.h:868
bool isPositionValid() const LLVM_READONLY
Definition: Comment.h:854
StringRef getParamNameAsWritten() const
Definition: Comment.h:846
StringRef getParamName(const FullComment *FC) const
Definition: Comment.cpp:380
static bool classof(const Comment *C)
Definition: Comment.h:836
unsigned getIndex(unsigned Depth) const
Definition: Comment.h:863
TParamCommandComment(SourceLocation LocBegin, SourceLocation LocEnd, unsigned CommandID, CommandMarkerKind CommandMarker)
Definition: Comment.h:831
SourceRange getParamNameRange() const
Definition: Comment.h:850
static bool classof(const Comment *C)
Definition: Comment.h:307
TextComment(SourceLocation LocBegin, SourceLocation LocEnd, StringRef Text)
Definition: Comment.h:301
bool isWhitespace() const
Definition: Comment.h:317
StringRef getText() const LLVM_READONLY
Definition: Comment.h:315
child_iterator child_begin() const
Definition: Comment.h:311
child_iterator child_end() const
Definition: Comment.h:313
A verbatim block command (e.
Definition: Comment.h:900
ArrayRef< VerbatimBlockLineComment * > Lines
Definition: Comment.h:904
void setLines(ArrayRef< VerbatimBlockLineComment * > L)
Definition: Comment.h:931
static bool classof(const Comment *C)
Definition: Comment.h:914
child_iterator child_end() const
Definition: Comment.h:922
child_iterator child_begin() const
Definition: Comment.h:918
StringRef getText(unsigned LineIdx) const
Definition: Comment.h:943
void setCloseName(StringRef Name, SourceLocation LocBegin)
Definition: Comment.h:926
VerbatimBlockComment(SourceLocation LocBegin, SourceLocation LocEnd, unsigned CommandID)
Definition: Comment.h:907
A line of text contained in a verbatim block.
Definition: Comment.h:875
StringRef getText() const LLVM_READONLY
Definition: Comment.h:892
static bool classof(const Comment *C)
Definition: Comment.h:884
child_iterator child_end() const
Definition: Comment.h:890
VerbatimBlockLineComment(SourceLocation LocBegin, StringRef Text)
Definition: Comment.h:879
child_iterator child_begin() const
Definition: Comment.h:888
A verbatim line command.
Definition: Comment.h:951
child_iterator child_begin() const
Definition: Comment.h:969
VerbatimLineComment(SourceLocation LocBegin, SourceLocation LocEnd, unsigned CommandID, SourceLocation TextBegin, StringRef Text)
Definition: Comment.h:957
child_iterator child_end() const
Definition: Comment.h:971
SourceRange getTextRange() const
Definition: Comment.h:977
static bool classof(const Comment *C)
Definition: Comment.h:965
ParamCommandPassDirection
Definition: Comment.h:729
InlineCommandRenderKind
The most appropriate rendering mode for this command, chosen on command semantics in Doxygen.
Definition: Comment.h:332
CommandMarkerKind
Describes the syntax that was used in a documentation command.
Definition: Comment.h:39
@ CMK_Backslash
Command started with a backslash character:
Definition: Comment.h:44
@ CMK_At
Command started with an 'at' character:
Definition: Comment.h:50
std::variant< struct RequiresDecl, struct HeaderDecl, struct UmbrellaDirDecl, struct ModuleDecl, struct ExcludeDecl, struct ExportDecl, struct ExportAsDecl, struct ExternModuleDecl, struct UseDecl, struct LinkDecl, struct ConfigMacrosDecl, struct ConflictDecl > Decl
All declarations that can appear in a module declaration.
Definition: ModuleMapFile.h:36
The JSON file list parser is used to communicate input to InstallAPI.
Information about the declaration, useful to clients of FullComment.
Definition: Comment.h:983
unsigned TemplateKind
Is CommentDecl a template declaration.
Definition: Comment.h:1068
unsigned IsClassMethod
Is CommentDecl a static member function of C++ class or class method of ObjC class.
Definition: Comment.h:1084
DeclKind
A simplified description of CommentDecl kind that should be good enough for documentation rendering p...
Definition: Comment.h:1013
@ FunctionKind
Something that we consider a "function":
Definition: Comment.h:1025
@ EnumKind
An enumeration or scoped enumeration.
Definition: Comment.h:1047
@ OtherKind
Everything else not explicitly mentioned below.
Definition: Comment.h:1015
@ NamespaceKind
A C++ namespace.
Definition: Comment.h:1040
@ VariableKind
Something that we consider a "variable":
Definition: Comment.h:1037
@ ClassKind
Something that we consider a "class":
Definition: Comment.h:1031
@ TypedefKind
A C++ typedef-name (a 'typedef' decl specifier or alias-declaration), see TypedefNameDecl.
Definition: Comment.h:1044
unsigned Kind
Simplified kind of CommentDecl, see DeclKind enum.
Definition: Comment.h:1064
unsigned IsObjCMethod
Is CommentDecl an ObjCMethodDecl.
Definition: Comment.h:1072
const TemplateParameterList * TemplateParameters
Template parameters that can be referenced by \tparam if CommentDecl is a template (IsTemplateDecl or...
Definition: Comment.h:1009
ArrayRef< const ParmVarDecl * > ParamVars
Parameters that can be referenced by \param if CommentDecl is something that we consider a "function"...
Definition: Comment.h:1000
DeclKind getKind() const LLVM_READONLY
Definition: Comment.h:1092
unsigned IsInstanceMethod
Is CommentDecl a non-static member function of C++ class or instance method of ObjC class.
Definition: Comment.h:1078
TemplateDeclKind getTemplateKind() const LLVM_READONLY
Definition: Comment.h:1096
bool involvesFunctionType() const
Definition: Comment.h:1100
unsigned IsFilled
If false, only CommentDecl is valid.
Definition: Comment.h:1060
const Decl * CommentDecl
Declaration the comment is actually attached to (in the source).
Definition: Comment.h:986
unsigned IsVariadic
Is CommentDecl something we consider a "function" that's variadic.
Definition: Comment.h:1088
TemplateDeclKind
What kind of template specialization CommentDecl is.
Definition: Comment.h:1051
const Decl * CurrentDecl
CurrentDecl is the declaration with which the FullComment is associated.
Definition: Comment.h:996
QualType ReturnType
Function return type if CommentDecl is something that we consider a "function".
Definition: Comment.h:1004