1 //===--- Comment.h - Comment AST nodes --------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines comment AST nodes.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_CLANG_AST_COMMENT_H
15 #define LLVM_CLANG_AST_COMMENT_H
17 #include "clang/AST/CommentCommandTraits.h"
18 #include "clang/AST/DeclObjC.h"
19 #include "clang/AST/Type.h"
20 #include "clang/Basic/SourceLocation.h"
21 #include "llvm/ADT/ArrayRef.h"
22 #include "llvm/ADT/StringRef.h"
27 class TemplateParameterList;
32 /// Describes the syntax that was used in a documentation command.
34 /// Exact values of this enumeration are important because they used to select
35 /// parts of diagnostic messages. Audit diagnostics before changing or adding
37 enum CommandMarkerKind {
38 /// Command started with a backslash character:
44 /// Command started with an 'at' character:
51 /// Any part of the comment.
55 /// Preferred location to show caret.
58 /// Source range of this AST node.
61 class CommentBitfields {
64 /// Type of this AST node.
67 enum { NumCommentBits = 8 };
69 class InlineContentCommentBitfields {
70 friend class InlineContentComment;
72 unsigned : NumCommentBits;
74 /// True if there is a newline after this inline content node.
75 /// (There is no separate AST node for a newline.)
76 unsigned HasTrailingNewline : 1;
78 enum { NumInlineContentCommentBits = NumCommentBits + 1 };
80 class TextCommentBitfields {
81 friend class TextComment;
83 unsigned : NumInlineContentCommentBits;
85 /// True if \c IsWhitespace field contains a valid value.
86 mutable unsigned IsWhitespaceValid : 1;
88 /// True if this comment AST node contains only whitespace.
89 mutable unsigned IsWhitespace : 1;
91 enum { NumTextCommentBits = NumInlineContentCommentBits + 2 };
93 class InlineCommandCommentBitfields {
94 friend class InlineCommandComment;
96 unsigned : NumInlineContentCommentBits;
98 unsigned RenderKind : 2;
99 unsigned CommandID : CommandInfo::NumCommandIDBits;
101 enum { NumInlineCommandCommentBits = NumInlineContentCommentBits + 2 +
102 CommandInfo::NumCommandIDBits };
104 class HTMLTagCommentBitfields {
105 friend class HTMLTagComment;
107 unsigned : NumInlineContentCommentBits;
109 /// True if we found that this tag is malformed in some way.
110 unsigned IsMalformed : 1;
112 enum { NumHTMLTagCommentBits = NumInlineContentCommentBits + 1 };
114 class HTMLStartTagCommentBitfields {
115 friend class HTMLStartTagComment;
117 unsigned : NumHTMLTagCommentBits;
119 /// True if this tag is self-closing (e. g., <br />). This is based on tag
120 /// spelling in comment (plain <br> would not set this flag).
121 unsigned IsSelfClosing : 1;
123 enum { NumHTMLStartTagCommentBits = NumHTMLTagCommentBits + 1 };
125 class ParagraphCommentBitfields {
126 friend class ParagraphComment;
128 unsigned : NumCommentBits;
130 /// True if \c IsWhitespace field contains a valid value.
131 mutable unsigned IsWhitespaceValid : 1;
133 /// True if this comment AST node contains only whitespace.
134 mutable unsigned IsWhitespace : 1;
136 enum { NumParagraphCommentBits = NumCommentBits + 2 };
138 class BlockCommandCommentBitfields {
139 friend class BlockCommandComment;
141 unsigned : NumCommentBits;
143 unsigned CommandID : CommandInfo::NumCommandIDBits;
145 /// Describes the syntax that was used in a documentation command.
146 /// Contains values from CommandMarkerKind enum.
147 unsigned CommandMarker : 1;
149 enum { NumBlockCommandCommentBits = NumCommentBits +
150 CommandInfo::NumCommandIDBits + 1 };
152 class ParamCommandCommentBitfields {
153 friend class ParamCommandComment;
155 unsigned : NumBlockCommandCommentBits;
157 /// Parameter passing direction, see ParamCommandComment::PassDirection.
158 unsigned Direction : 2;
160 /// True if direction was specified explicitly in the comment.
161 unsigned IsDirectionExplicit : 1;
163 enum { NumParamCommandCommentBits = NumBlockCommandCommentBits + 3 };
166 CommentBitfields CommentBits;
167 InlineContentCommentBitfields InlineContentCommentBits;
168 TextCommentBitfields TextCommentBits;
169 InlineCommandCommentBitfields InlineCommandCommentBits;
170 HTMLTagCommentBitfields HTMLTagCommentBits;
171 HTMLStartTagCommentBitfields HTMLStartTagCommentBits;
172 ParagraphCommentBitfields ParagraphCommentBits;
173 BlockCommandCommentBitfields BlockCommandCommentBits;
174 ParamCommandCommentBitfields ParamCommandCommentBits;
177 void setSourceRange(SourceRange SR) {
181 void setLocation(SourceLocation L) {
188 #define COMMENT(CLASS, PARENT) CLASS##Kind,
189 #define COMMENT_RANGE(BASE, FIRST, LAST) \
190 First##BASE##Constant=FIRST##Kind, Last##BASE##Constant=LAST##Kind,
191 #define LAST_COMMENT_RANGE(BASE, FIRST, LAST) \
192 First##BASE##Constant=FIRST##Kind, Last##BASE##Constant=LAST##Kind
193 #define ABSTRACT_COMMENT(COMMENT)
194 #include "clang/AST/CommentNodes.inc"
197 Comment(CommentKind K,
198 SourceLocation LocBegin,
199 SourceLocation LocEnd) :
200 Loc(LocBegin), Range(SourceRange(LocBegin, LocEnd)) {
201 CommentBits.Kind = K;
204 CommentKind getCommentKind() const {
205 return static_cast<CommentKind>(CommentBits.Kind);
208 const char *getCommentKindName() const;
211 void dumpColor() const;
212 void dump(const ASTContext &Context) const;
213 void dump(raw_ostream &OS, const CommandTraits *Traits,
214 const SourceManager *SM) const;
216 SourceRange getSourceRange() const LLVM_READONLY { return Range; }
218 SourceLocation getBeginLoc() const LLVM_READONLY { return Range.getBegin(); }
220 SourceLocation getEndLoc() const LLVM_READONLY { return Range.getEnd(); }
222 SourceLocation getLocation() const LLVM_READONLY { return Loc; }
224 typedef Comment * const *child_iterator;
226 child_iterator child_begin() const;
227 child_iterator child_end() const;
229 // TODO: const child iterator
231 unsigned child_count() const {
232 return child_end() - child_begin();
236 /// Inline content (contained within a block).
238 class InlineContentComment : public Comment {
240 InlineContentComment(CommentKind K,
241 SourceLocation LocBegin,
242 SourceLocation LocEnd) :
243 Comment(K, LocBegin, LocEnd) {
244 InlineContentCommentBits.HasTrailingNewline = 0;
248 static bool classof(const Comment *C) {
249 return C->getCommentKind() >= FirstInlineContentCommentConstant &&
250 C->getCommentKind() <= LastInlineContentCommentConstant;
253 void addTrailingNewline() {
254 InlineContentCommentBits.HasTrailingNewline = 1;
257 bool hasTrailingNewline() const {
258 return InlineContentCommentBits.HasTrailingNewline;
263 class TextComment : public InlineContentComment {
267 TextComment(SourceLocation LocBegin,
268 SourceLocation LocEnd,
270 InlineContentComment(TextCommentKind, LocBegin, LocEnd),
272 TextCommentBits.IsWhitespaceValid = false;
275 static bool classof(const Comment *C) {
276 return C->getCommentKind() == TextCommentKind;
279 child_iterator child_begin() const { return nullptr; }
281 child_iterator child_end() const { return nullptr; }
283 StringRef getText() const LLVM_READONLY { return Text; }
285 bool isWhitespace() const {
286 if (TextCommentBits.IsWhitespaceValid)
287 return TextCommentBits.IsWhitespace;
289 TextCommentBits.IsWhitespace = isWhitespaceNoCache();
290 TextCommentBits.IsWhitespaceValid = true;
291 return TextCommentBits.IsWhitespace;
295 bool isWhitespaceNoCache() const;
298 /// A command with word-like arguments that is considered inline content.
299 class InlineCommandComment : public InlineContentComment {
305 Argument(SourceRange Range, StringRef Text) : Range(Range), Text(Text) { }
308 /// The most appropriate rendering mode for this command, chosen on command
309 /// semantics in Doxygen.
318 /// Command arguments.
319 ArrayRef<Argument> Args;
322 InlineCommandComment(SourceLocation LocBegin,
323 SourceLocation LocEnd,
326 ArrayRef<Argument> Args) :
327 InlineContentComment(InlineCommandCommentKind, LocBegin, LocEnd),
329 InlineCommandCommentBits.RenderKind = RK;
330 InlineCommandCommentBits.CommandID = CommandID;
333 static bool classof(const Comment *C) {
334 return C->getCommentKind() == InlineCommandCommentKind;
337 child_iterator child_begin() const { return nullptr; }
339 child_iterator child_end() const { return nullptr; }
341 unsigned getCommandID() const {
342 return InlineCommandCommentBits.CommandID;
345 StringRef getCommandName(const CommandTraits &Traits) const {
346 return Traits.getCommandInfo(getCommandID())->Name;
349 SourceRange getCommandNameRange() const {
350 return SourceRange(getBeginLoc().getLocWithOffset(-1), getEndLoc());
353 RenderKind getRenderKind() const {
354 return static_cast<RenderKind>(InlineCommandCommentBits.RenderKind);
357 unsigned getNumArgs() const {
361 StringRef getArgText(unsigned Idx) const {
362 return Args[Idx].Text;
365 SourceRange getArgRange(unsigned Idx) const {
366 return Args[Idx].Range;
370 /// Abstract class for opening and closing HTML tags. HTML tags are always
371 /// treated as inline content (regardless HTML semantics).
372 class HTMLTagComment : public InlineContentComment {
375 SourceRange TagNameRange;
377 HTMLTagComment(CommentKind K,
378 SourceLocation LocBegin,
379 SourceLocation LocEnd,
381 SourceLocation TagNameBegin,
382 SourceLocation TagNameEnd) :
383 InlineContentComment(K, LocBegin, LocEnd),
385 TagNameRange(TagNameBegin, TagNameEnd) {
386 setLocation(TagNameBegin);
387 HTMLTagCommentBits.IsMalformed = 0;
391 static bool classof(const Comment *C) {
392 return C->getCommentKind() >= FirstHTMLTagCommentConstant &&
393 C->getCommentKind() <= LastHTMLTagCommentConstant;
396 StringRef getTagName() const LLVM_READONLY { return TagName; }
398 SourceRange getTagNameSourceRange() const LLVM_READONLY {
399 SourceLocation L = getLocation();
400 return SourceRange(L.getLocWithOffset(1),
401 L.getLocWithOffset(1 + TagName.size()));
404 bool isMalformed() const {
405 return HTMLTagCommentBits.IsMalformed;
408 void setIsMalformed() {
409 HTMLTagCommentBits.IsMalformed = 1;
413 /// An opening HTML tag with attributes.
414 class HTMLStartTagComment : public HTMLTagComment {
418 SourceLocation NameLocBegin;
421 SourceLocation EqualsLoc;
423 SourceRange ValueRange;
428 Attribute(SourceLocation NameLocBegin, StringRef Name) :
429 NameLocBegin(NameLocBegin), Name(Name),
430 EqualsLoc(SourceLocation()),
431 ValueRange(SourceRange()), Value(StringRef())
434 Attribute(SourceLocation NameLocBegin, StringRef Name,
435 SourceLocation EqualsLoc,
436 SourceRange ValueRange, StringRef Value) :
437 NameLocBegin(NameLocBegin), Name(Name),
438 EqualsLoc(EqualsLoc),
439 ValueRange(ValueRange), Value(Value)
442 SourceLocation getNameLocEnd() const {
443 return NameLocBegin.getLocWithOffset(Name.size());
446 SourceRange getNameRange() const {
447 return SourceRange(NameLocBegin, getNameLocEnd());
452 ArrayRef<Attribute> Attributes;
455 HTMLStartTagComment(SourceLocation LocBegin,
457 HTMLTagComment(HTMLStartTagCommentKind,
458 LocBegin, LocBegin.getLocWithOffset(1 + TagName.size()),
460 LocBegin.getLocWithOffset(1),
461 LocBegin.getLocWithOffset(1 + TagName.size())) {
462 HTMLStartTagCommentBits.IsSelfClosing = false;
465 static bool classof(const Comment *C) {
466 return C->getCommentKind() == HTMLStartTagCommentKind;
469 child_iterator child_begin() const { return nullptr; }
471 child_iterator child_end() const { return nullptr; }
473 unsigned getNumAttrs() const {
474 return Attributes.size();
477 const Attribute &getAttr(unsigned Idx) const {
478 return Attributes[Idx];
481 void setAttrs(ArrayRef<Attribute> Attrs) {
483 if (!Attrs.empty()) {
484 const Attribute &Attr = Attrs.back();
485 SourceLocation L = Attr.ValueRange.getEnd();
489 Range.setEnd(Attr.getNameLocEnd());
494 void setGreaterLoc(SourceLocation GreaterLoc) {
495 Range.setEnd(GreaterLoc);
498 bool isSelfClosing() const {
499 return HTMLStartTagCommentBits.IsSelfClosing;
502 void setSelfClosing() {
503 HTMLStartTagCommentBits.IsSelfClosing = true;
507 /// A closing HTML tag.
508 class HTMLEndTagComment : public HTMLTagComment {
510 HTMLEndTagComment(SourceLocation LocBegin,
511 SourceLocation LocEnd,
513 HTMLTagComment(HTMLEndTagCommentKind,
516 LocBegin.getLocWithOffset(2),
517 LocBegin.getLocWithOffset(2 + TagName.size()))
520 static bool classof(const Comment *C) {
521 return C->getCommentKind() == HTMLEndTagCommentKind;
524 child_iterator child_begin() const { return nullptr; }
526 child_iterator child_end() const { return nullptr; }
529 /// Block content (contains inline content).
531 class BlockContentComment : public Comment {
533 BlockContentComment(CommentKind K,
534 SourceLocation LocBegin,
535 SourceLocation LocEnd) :
536 Comment(K, LocBegin, LocEnd)
540 static bool classof(const Comment *C) {
541 return C->getCommentKind() >= FirstBlockContentCommentConstant &&
542 C->getCommentKind() <= LastBlockContentCommentConstant;
546 /// A single paragraph that contains inline content.
547 class ParagraphComment : public BlockContentComment {
548 ArrayRef<InlineContentComment *> Content;
551 ParagraphComment(ArrayRef<InlineContentComment *> Content) :
552 BlockContentComment(ParagraphCommentKind,
556 if (Content.empty()) {
557 ParagraphCommentBits.IsWhitespace = true;
558 ParagraphCommentBits.IsWhitespaceValid = true;
562 ParagraphCommentBits.IsWhitespaceValid = false;
564 setSourceRange(SourceRange(Content.front()->getBeginLoc(),
565 Content.back()->getEndLoc()));
566 setLocation(Content.front()->getBeginLoc());
569 static bool classof(const Comment *C) {
570 return C->getCommentKind() == ParagraphCommentKind;
573 child_iterator child_begin() const {
574 return reinterpret_cast<child_iterator>(Content.begin());
577 child_iterator child_end() const {
578 return reinterpret_cast<child_iterator>(Content.end());
581 bool isWhitespace() const {
582 if (ParagraphCommentBits.IsWhitespaceValid)
583 return ParagraphCommentBits.IsWhitespace;
585 ParagraphCommentBits.IsWhitespace = isWhitespaceNoCache();
586 ParagraphCommentBits.IsWhitespaceValid = true;
587 return ParagraphCommentBits.IsWhitespace;
591 bool isWhitespaceNoCache() const;
594 /// A command that has zero or more word-like arguments (number of word-like
595 /// arguments depends on command name) and a paragraph as an argument
596 /// (e. g., \\brief).
597 class BlockCommandComment : public BlockContentComment {
604 Argument(SourceRange Range, StringRef Text) : Range(Range), Text(Text) { }
608 /// Word-like arguments.
609 ArrayRef<Argument> Args;
611 /// Paragraph argument.
612 ParagraphComment *Paragraph;
614 BlockCommandComment(CommentKind K,
615 SourceLocation LocBegin,
616 SourceLocation LocEnd,
618 CommandMarkerKind CommandMarker) :
619 BlockContentComment(K, LocBegin, LocEnd),
621 setLocation(getCommandNameBeginLoc());
622 BlockCommandCommentBits.CommandID = CommandID;
623 BlockCommandCommentBits.CommandMarker = CommandMarker;
627 BlockCommandComment(SourceLocation LocBegin,
628 SourceLocation LocEnd,
630 CommandMarkerKind CommandMarker) :
631 BlockContentComment(BlockCommandCommentKind, LocBegin, LocEnd),
633 setLocation(getCommandNameBeginLoc());
634 BlockCommandCommentBits.CommandID = CommandID;
635 BlockCommandCommentBits.CommandMarker = CommandMarker;
638 static bool classof(const Comment *C) {
639 return C->getCommentKind() >= FirstBlockCommandCommentConstant &&
640 C->getCommentKind() <= LastBlockCommandCommentConstant;
643 child_iterator child_begin() const {
644 return reinterpret_cast<child_iterator>(&Paragraph);
647 child_iterator child_end() const {
648 return reinterpret_cast<child_iterator>(&Paragraph + 1);
651 unsigned getCommandID() const {
652 return BlockCommandCommentBits.CommandID;
655 StringRef getCommandName(const CommandTraits &Traits) const {
656 return Traits.getCommandInfo(getCommandID())->Name;
659 SourceLocation getCommandNameBeginLoc() const {
660 return getBeginLoc().getLocWithOffset(1);
663 SourceRange getCommandNameRange(const CommandTraits &Traits) const {
664 StringRef Name = getCommandName(Traits);
665 return SourceRange(getCommandNameBeginLoc(),
666 getBeginLoc().getLocWithOffset(1 + Name.size()));
669 unsigned getNumArgs() const {
673 StringRef getArgText(unsigned Idx) const {
674 return Args[Idx].Text;
677 SourceRange getArgRange(unsigned Idx) const {
678 return Args[Idx].Range;
681 void setArgs(ArrayRef<Argument> A) {
683 if (Args.size() > 0) {
684 SourceLocation NewLocEnd = Args.back().Range.getEnd();
685 if (NewLocEnd.isValid())
686 setSourceRange(SourceRange(getBeginLoc(), NewLocEnd));
690 ParagraphComment *getParagraph() const LLVM_READONLY {
694 bool hasNonWhitespaceParagraph() const {
695 return Paragraph && !Paragraph->isWhitespace();
698 void setParagraph(ParagraphComment *PC) {
700 SourceLocation NewLocEnd = PC->getEndLoc();
701 if (NewLocEnd.isValid())
702 setSourceRange(SourceRange(getBeginLoc(), NewLocEnd));
705 CommandMarkerKind getCommandMarker() const LLVM_READONLY {
706 return static_cast<CommandMarkerKind>(
707 BlockCommandCommentBits.CommandMarker);
711 /// Doxygen \\param command.
712 class ParamCommandComment : public BlockCommandComment {
714 /// Parameter index in the function declaration.
719 InvalidParamIndex = ~0U,
720 VarArgParamIndex = ~0U/*InvalidParamIndex*/ - 1U
723 ParamCommandComment(SourceLocation LocBegin,
724 SourceLocation LocEnd,
726 CommandMarkerKind CommandMarker) :
727 BlockCommandComment(ParamCommandCommentKind, LocBegin, LocEnd,
728 CommandID, CommandMarker),
729 ParamIndex(InvalidParamIndex) {
730 ParamCommandCommentBits.Direction = In;
731 ParamCommandCommentBits.IsDirectionExplicit = false;
734 static bool classof(const Comment *C) {
735 return C->getCommentKind() == ParamCommandCommentKind;
744 static const char *getDirectionAsString(PassDirection D);
746 PassDirection getDirection() const LLVM_READONLY {
747 return static_cast<PassDirection>(ParamCommandCommentBits.Direction);
750 bool isDirectionExplicit() const LLVM_READONLY {
751 return ParamCommandCommentBits.IsDirectionExplicit;
754 void setDirection(PassDirection Direction, bool Explicit) {
755 ParamCommandCommentBits.Direction = Direction;
756 ParamCommandCommentBits.IsDirectionExplicit = Explicit;
759 bool hasParamName() const {
760 return getNumArgs() > 0;
763 StringRef getParamName(const FullComment *FC) const;
765 StringRef getParamNameAsWritten() const {
769 SourceRange getParamNameRange() const {
770 return Args[0].Range;
773 bool isParamIndexValid() const LLVM_READONLY {
774 return ParamIndex != InvalidParamIndex;
777 bool isVarArgParam() const LLVM_READONLY {
778 return ParamIndex == VarArgParamIndex;
781 void setIsVarArgParam() {
782 ParamIndex = VarArgParamIndex;
783 assert(isParamIndexValid());
786 unsigned getParamIndex() const LLVM_READONLY {
787 assert(isParamIndexValid());
788 assert(!isVarArgParam());
792 void setParamIndex(unsigned Index) {
794 assert(isParamIndexValid());
795 assert(!isVarArgParam());
799 /// Doxygen \\tparam command, describes a template parameter.
800 class TParamCommandComment : public BlockCommandComment {
802 /// If this template parameter name was resolved (found in template parameter
803 /// list), then this stores a list of position indexes in all template
808 /// template<typename C, template<typename T> class TT>
809 /// void test(TT<int> aaa);
811 /// For C: Position = { 0 }
812 /// For TT: Position = { 1 }
813 /// For T: Position = { 1, 0 }
814 ArrayRef<unsigned> Position;
817 TParamCommandComment(SourceLocation LocBegin,
818 SourceLocation LocEnd,
820 CommandMarkerKind CommandMarker) :
821 BlockCommandComment(TParamCommandCommentKind, LocBegin, LocEnd, CommandID,
825 static bool classof(const Comment *C) {
826 return C->getCommentKind() == TParamCommandCommentKind;
829 bool hasParamName() const {
830 return getNumArgs() > 0;
833 StringRef getParamName(const FullComment *FC) const;
835 StringRef getParamNameAsWritten() const {
839 SourceRange getParamNameRange() const {
840 return Args[0].Range;
843 bool isPositionValid() const LLVM_READONLY {
844 return !Position.empty();
847 unsigned getDepth() const {
848 assert(isPositionValid());
849 return Position.size();
852 unsigned getIndex(unsigned Depth) const {
853 assert(isPositionValid());
854 return Position[Depth];
857 void setPosition(ArrayRef<unsigned> NewPosition) {
858 Position = NewPosition;
859 assert(isPositionValid());
863 /// A line of text contained in a verbatim block.
864 class VerbatimBlockLineComment : public Comment {
868 VerbatimBlockLineComment(SourceLocation LocBegin,
870 Comment(VerbatimBlockLineCommentKind,
872 LocBegin.getLocWithOffset(Text.size())),
876 static bool classof(const Comment *C) {
877 return C->getCommentKind() == VerbatimBlockLineCommentKind;
880 child_iterator child_begin() const { return nullptr; }
882 child_iterator child_end() const { return nullptr; }
884 StringRef getText() const LLVM_READONLY {
889 /// A verbatim block command (e. g., preformatted code). Verbatim block has an
890 /// opening and a closing command and contains multiple lines of text
891 /// (VerbatimBlockLineComment nodes).
892 class VerbatimBlockComment : public BlockCommandComment {
895 SourceLocation CloseNameLocBegin;
896 ArrayRef<VerbatimBlockLineComment *> Lines;
899 VerbatimBlockComment(SourceLocation LocBegin,
900 SourceLocation LocEnd,
901 unsigned CommandID) :
902 BlockCommandComment(VerbatimBlockCommentKind,
903 LocBegin, LocEnd, CommandID,
904 CMK_At) // FIXME: improve source fidelity.
907 static bool classof(const Comment *C) {
908 return C->getCommentKind() == VerbatimBlockCommentKind;
911 child_iterator child_begin() const {
912 return reinterpret_cast<child_iterator>(Lines.begin());
915 child_iterator child_end() const {
916 return reinterpret_cast<child_iterator>(Lines.end());
919 void setCloseName(StringRef Name, SourceLocation LocBegin) {
921 CloseNameLocBegin = LocBegin;
924 void setLines(ArrayRef<VerbatimBlockLineComment *> L) {
928 StringRef getCloseName() const {
932 unsigned getNumLines() const {
936 StringRef getText(unsigned LineIdx) const {
937 return Lines[LineIdx]->getText();
941 /// A verbatim line command. Verbatim line has an opening command, a single
942 /// line of text (up to the newline after the opening command) and has no
944 class VerbatimLineComment : public BlockCommandComment {
947 SourceLocation TextBegin;
950 VerbatimLineComment(SourceLocation LocBegin,
951 SourceLocation LocEnd,
953 SourceLocation TextBegin,
955 BlockCommandComment(VerbatimLineCommentKind,
958 CMK_At), // FIXME: improve source fidelity.
963 static bool classof(const Comment *C) {
964 return C->getCommentKind() == VerbatimLineCommentKind;
967 child_iterator child_begin() const { return nullptr; }
969 child_iterator child_end() const { return nullptr; }
971 StringRef getText() const {
975 SourceRange getTextRange() const {
976 return SourceRange(TextBegin, getEndLoc());
980 /// Information about the declaration, useful to clients of FullComment.
982 /// Declaration the comment is actually attached to (in the source).
983 /// Should not be NULL.
984 const Decl *CommentDecl;
986 /// CurrentDecl is the declaration with which the FullComment is associated.
988 /// It can be different from \c CommentDecl. It happens when we decide
989 /// that the comment originally attached to \c CommentDecl is fine for
990 /// \c CurrentDecl too (for example, for a redeclaration or an overrider of
993 /// The information in the DeclInfo corresponds to CurrentDecl.
994 const Decl *CurrentDecl;
996 /// Parameters that can be referenced by \\param if \c CommentDecl is something
997 /// that we consider a "function".
998 ArrayRef<const ParmVarDecl *> ParamVars;
1000 /// Function return type if \c CommentDecl is something that we consider
1002 QualType ReturnType;
1004 /// Template parameters that can be referenced by \\tparam if \c CommentDecl is
1005 /// a template (\c IsTemplateDecl or \c IsTemplatePartialSpecialization is
1007 const TemplateParameterList *TemplateParameters;
1009 /// A simplified description of \c CommentDecl kind that should be good enough
1010 /// for documentation rendering purposes.
1012 /// Everything else not explicitly mentioned below.
1015 /// Something that we consider a "function":
1017 /// \li function template,
1018 /// \li function template specialization,
1019 /// \li member function,
1020 /// \li member function template,
1021 /// \li member function template specialization,
1022 /// \li ObjC method,
1023 /// \li a typedef for a function pointer, member function pointer,
1027 /// Something that we consider a "class":
1028 /// \li class/struct,
1029 /// \li class template,
1030 /// \li class template (partial) specialization.
1033 /// Something that we consider a "variable":
1034 /// \li namespace scope variables;
1035 /// \li static and non-static class data members;
1036 /// \li enumerators.
1039 /// A C++ namespace.
1042 /// A C++ typedef-name (a 'typedef' decl specifier or alias-declaration),
1043 /// see \c TypedefNameDecl.
1046 /// An enumeration or scoped enumeration.
1050 /// What kind of template specialization \c CommentDecl is.
1051 enum TemplateDeclKind {
1054 TemplateSpecialization,
1055 TemplatePartialSpecialization
1058 /// If false, only \c CommentDecl is valid.
1059 unsigned IsFilled : 1;
1061 /// Simplified kind of \c CommentDecl, see \c DeclKind enum.
1064 /// Is \c CommentDecl a template declaration.
1065 unsigned TemplateKind : 2;
1067 /// Is \c CommentDecl an ObjCMethodDecl.
1068 unsigned IsObjCMethod : 1;
1070 /// Is \c CommentDecl a non-static member function of C++ class or
1071 /// instance method of ObjC class.
1072 /// Can be true only if \c IsFunctionDecl is true.
1073 unsigned IsInstanceMethod : 1;
1075 /// Is \c CommentDecl a static member function of C++ class or
1076 /// class method of ObjC class.
1077 /// Can be true only if \c IsFunctionDecl is true.
1078 unsigned IsClassMethod : 1;
1082 DeclKind getKind() const LLVM_READONLY {
1083 return static_cast<DeclKind>(Kind);
1086 TemplateDeclKind getTemplateKind() const LLVM_READONLY {
1087 return static_cast<TemplateDeclKind>(TemplateKind);
1091 /// A full comment attached to a declaration, contains block content.
1092 class FullComment : public Comment {
1093 ArrayRef<BlockContentComment *> Blocks;
1094 DeclInfo *ThisDeclInfo;
1097 FullComment(ArrayRef<BlockContentComment *> Blocks, DeclInfo *D) :
1098 Comment(FullCommentKind, SourceLocation(), SourceLocation()),
1099 Blocks(Blocks), ThisDeclInfo(D) {
1104 SourceRange(Blocks.front()->getBeginLoc(), Blocks.back()->getEndLoc()));
1105 setLocation(Blocks.front()->getBeginLoc());
1108 static bool classof(const Comment *C) {
1109 return C->getCommentKind() == FullCommentKind;
1112 child_iterator child_begin() const {
1113 return reinterpret_cast<child_iterator>(Blocks.begin());
1116 child_iterator child_end() const {
1117 return reinterpret_cast<child_iterator>(Blocks.end());
1120 const Decl *getDecl() const LLVM_READONLY {
1121 return ThisDeclInfo->CommentDecl;
1124 const DeclInfo *getDeclInfo() const LLVM_READONLY {
1125 if (!ThisDeclInfo->IsFilled)
1126 ThisDeclInfo->fill();
1127 return ThisDeclInfo;
1130 ArrayRef<BlockContentComment *> getBlocks() const { return Blocks; }
1133 } // end namespace comments
1134 } // end namespace clang