Bug Summary

File:tools/clang/lib/AST/Comment.cpp
Warning:line 370, column 30
Called C++ object pointer is null

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name Comment.cpp -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -mrelocation-model pic -pic-level 2 -mthread-model posix -relaxed-aliasing -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -dwarf-column-info -debugger-tuning=gdb -momit-leaf-frame-pointer -ffunction-sections -fdata-sections -resource-dir /usr/lib/llvm-8/lib/clang/8.0.0 -D _DEBUG -D _GNU_SOURCE -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -I /build/llvm-toolchain-snapshot-8~svn345461/build-llvm/tools/clang/lib/AST -I /build/llvm-toolchain-snapshot-8~svn345461/tools/clang/lib/AST -I /build/llvm-toolchain-snapshot-8~svn345461/tools/clang/include -I /build/llvm-toolchain-snapshot-8~svn345461/build-llvm/tools/clang/include -I /build/llvm-toolchain-snapshot-8~svn345461/build-llvm/include -I /build/llvm-toolchain-snapshot-8~svn345461/include -U NDEBUG -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/c++/6.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/x86_64-linux-gnu/c++/6.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/x86_64-linux-gnu/c++/6.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/c++/6.3.0/backward -internal-isystem /usr/include/clang/8.0.0/include/ -internal-isystem /usr/local/include -internal-isystem /usr/lib/llvm-8/lib/clang/8.0.0/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -Wno-unused-parameter -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long -Wno-maybe-uninitialized -Wno-comment -std=c++11 -fdeprecated-macro -fdebug-compilation-dir /build/llvm-toolchain-snapshot-8~svn345461/build-llvm/tools/clang/lib/AST -ferror-limit 19 -fmessage-length 0 -fvisibility-inlines-hidden -fobjc-runtime=gcc -fno-common -fdiagnostics-show-option -vectorize-loops -vectorize-slp -analyzer-output=html -analyzer-config stable-report-filename=true -o /tmp/scan-build-2018-10-27-211344-32123-1 -x c++ /build/llvm-toolchain-snapshot-8~svn345461/tools/clang/lib/AST/Comment.cpp -faddrsig

/build/llvm-toolchain-snapshot-8~svn345461/tools/clang/lib/AST/Comment.cpp

1//===--- Comment.cpp - Comment AST node implementation --------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "clang/AST/Comment.h"
11#include "clang/AST/ASTContext.h"
12#include "clang/AST/Decl.h"
13#include "clang/AST/DeclObjC.h"
14#include "clang/AST/DeclTemplate.h"
15#include "clang/Basic/CharInfo.h"
16#include "llvm/Support/ErrorHandling.h"
17
18namespace clang {
19namespace comments {
20
21const char *Comment::getCommentKindName() const {
22 switch (getCommentKind()) {
23 case NoCommentKind: return "NoCommentKind";
24#define ABSTRACT_COMMENT(COMMENT)
25#define COMMENT(CLASS, PARENT) \
26 case CLASS##Kind: \
27 return #CLASS;
28#include "clang/AST/CommentNodes.inc"
29#undef COMMENT
30#undef ABSTRACT_COMMENT
31 }
32 llvm_unreachable("Unknown comment kind!")::llvm::llvm_unreachable_internal("Unknown comment kind!", "/build/llvm-toolchain-snapshot-8~svn345461/tools/clang/lib/AST/Comment.cpp"
, 32)
;
33}
34
35namespace {
36struct good {};
37struct bad {};
38
39template <typename T>
40good implements_child_begin_end(Comment::child_iterator (T::*)() const) {
41 return good();
42}
43
44LLVM_ATTRIBUTE_UNUSED__attribute__((__unused__))
45static inline bad implements_child_begin_end(
46 Comment::child_iterator (Comment::*)() const) {
47 return bad();
48}
49
50#define ASSERT_IMPLEMENTS_child_begin(function) \
51 (void) good(implements_child_begin_end(function))
52
53LLVM_ATTRIBUTE_UNUSED__attribute__((__unused__))
54static inline void CheckCommentASTNodes() {
55#define ABSTRACT_COMMENT(COMMENT)
56#define COMMENT(CLASS, PARENT) \
57 ASSERT_IMPLEMENTS_child_begin(&CLASS::child_begin); \
58 ASSERT_IMPLEMENTS_child_begin(&CLASS::child_end);
59#include "clang/AST/CommentNodes.inc"
60#undef COMMENT
61#undef ABSTRACT_COMMENT
62}
63
64#undef ASSERT_IMPLEMENTS_child_begin
65
66} // end unnamed namespace
67
68Comment::child_iterator Comment::child_begin() const {
69 switch (getCommentKind()) {
70 case NoCommentKind: llvm_unreachable("comment without a kind")::llvm::llvm_unreachable_internal("comment without a kind", "/build/llvm-toolchain-snapshot-8~svn345461/tools/clang/lib/AST/Comment.cpp"
, 70)
;
71#define ABSTRACT_COMMENT(COMMENT)
72#define COMMENT(CLASS, PARENT) \
73 case CLASS##Kind: \
74 return static_cast<const CLASS *>(this)->child_begin();
75#include "clang/AST/CommentNodes.inc"
76#undef COMMENT
77#undef ABSTRACT_COMMENT
78 }
79 llvm_unreachable("Unknown comment kind!")::llvm::llvm_unreachable_internal("Unknown comment kind!", "/build/llvm-toolchain-snapshot-8~svn345461/tools/clang/lib/AST/Comment.cpp"
, 79)
;
80}
81
82Comment::child_iterator Comment::child_end() const {
83 switch (getCommentKind()) {
84 case NoCommentKind: llvm_unreachable("comment without a kind")::llvm::llvm_unreachable_internal("comment without a kind", "/build/llvm-toolchain-snapshot-8~svn345461/tools/clang/lib/AST/Comment.cpp"
, 84)
;
85#define ABSTRACT_COMMENT(COMMENT)
86#define COMMENT(CLASS, PARENT) \
87 case CLASS##Kind: \
88 return static_cast<const CLASS *>(this)->child_end();
89#include "clang/AST/CommentNodes.inc"
90#undef COMMENT
91#undef ABSTRACT_COMMENT
92 }
93 llvm_unreachable("Unknown comment kind!")::llvm::llvm_unreachable_internal("Unknown comment kind!", "/build/llvm-toolchain-snapshot-8~svn345461/tools/clang/lib/AST/Comment.cpp"
, 93)
;
94}
95
96bool TextComment::isWhitespaceNoCache() const {
97 for (StringRef::const_iterator I = Text.begin(), E = Text.end();
98 I != E; ++I) {
99 if (!clang::isWhitespace(*I))
100 return false;
101 }
102 return true;
103}
104
105bool ParagraphComment::isWhitespaceNoCache() const {
106 for (child_iterator I = child_begin(), E = child_end(); I != E; ++I) {
107 if (const TextComment *TC = dyn_cast<TextComment>(*I)) {
108 if (!TC->isWhitespace())
109 return false;
110 } else
111 return false;
112 }
113 return true;
114}
115
116static TypeLoc lookThroughTypedefOrTypeAliasLocs(TypeLoc &SrcTL) {
117 TypeLoc TL = SrcTL.IgnoreParens();
118
119 // Look through attribute types.
120 if (AttributedTypeLoc AttributeTL = TL.getAs<AttributedTypeLoc>())
121 return AttributeTL.getModifiedLoc();
122 // Look through qualified types.
123 if (QualifiedTypeLoc QualifiedTL = TL.getAs<QualifiedTypeLoc>())
124 return QualifiedTL.getUnqualifiedLoc();
125 // Look through pointer types.
126 if (PointerTypeLoc PointerTL = TL.getAs<PointerTypeLoc>())
127 return PointerTL.getPointeeLoc().getUnqualifiedLoc();
128 // Look through reference types.
129 if (ReferenceTypeLoc ReferenceTL = TL.getAs<ReferenceTypeLoc>())
130 return ReferenceTL.getPointeeLoc().getUnqualifiedLoc();
131 // Look through adjusted types.
132 if (AdjustedTypeLoc ATL = TL.getAs<AdjustedTypeLoc>())
133 return ATL.getOriginalLoc();
134 if (BlockPointerTypeLoc BlockPointerTL = TL.getAs<BlockPointerTypeLoc>())
135 return BlockPointerTL.getPointeeLoc().getUnqualifiedLoc();
136 if (MemberPointerTypeLoc MemberPointerTL = TL.getAs<MemberPointerTypeLoc>())
137 return MemberPointerTL.getPointeeLoc().getUnqualifiedLoc();
138 if (ElaboratedTypeLoc ETL = TL.getAs<ElaboratedTypeLoc>())
139 return ETL.getNamedTypeLoc();
140
141 return TL;
142}
143
144static bool getFunctionTypeLoc(TypeLoc TL, FunctionTypeLoc &ResFTL) {
145 TypeLoc PrevTL;
146 while (PrevTL != TL) {
147 PrevTL = TL;
148 TL = lookThroughTypedefOrTypeAliasLocs(TL);
149 }
150
151 if (FunctionTypeLoc FTL = TL.getAs<FunctionTypeLoc>()) {
152 ResFTL = FTL;
153 return true;
154 }
155
156 if (TemplateSpecializationTypeLoc STL =
157 TL.getAs<TemplateSpecializationTypeLoc>()) {
158 // If we have a typedef to a template specialization with exactly one
159 // template argument of a function type, this looks like std::function,
160 // boost::function, or other function wrapper. Treat these typedefs as
161 // functions.
162 if (STL.getNumArgs() != 1)
163 return false;
164 TemplateArgumentLoc MaybeFunction = STL.getArgLoc(0);
165 if (MaybeFunction.getArgument().getKind() != TemplateArgument::Type)
166 return false;
167 TypeSourceInfo *MaybeFunctionTSI = MaybeFunction.getTypeSourceInfo();
168 TypeLoc TL = MaybeFunctionTSI->getTypeLoc().getUnqualifiedLoc();
169 if (FunctionTypeLoc FTL = TL.getAs<FunctionTypeLoc>()) {
170 ResFTL = FTL;
171 return true;
172 }
173 }
174
175 return false;
176}
177
178const char *ParamCommandComment::getDirectionAsString(PassDirection D) {
179 switch (D) {
180 case ParamCommandComment::In:
181 return "[in]";
182 case ParamCommandComment::Out:
183 return "[out]";
184 case ParamCommandComment::InOut:
185 return "[in,out]";
186 }
187 llvm_unreachable("unknown PassDirection")::llvm::llvm_unreachable_internal("unknown PassDirection", "/build/llvm-toolchain-snapshot-8~svn345461/tools/clang/lib/AST/Comment.cpp"
, 187)
;
188}
189
190void DeclInfo::fill() {
191 assert(!IsFilled)((!IsFilled) ? static_cast<void> (0) : __assert_fail ("!IsFilled"
, "/build/llvm-toolchain-snapshot-8~svn345461/tools/clang/lib/AST/Comment.cpp"
, 191, __PRETTY_FUNCTION__))
;
192
193 // Set defaults.
194 Kind = OtherKind;
195 TemplateKind = NotTemplate;
196 IsObjCMethod = false;
197 IsInstanceMethod = false;
198 IsClassMethod = false;
199 ParamVars = None;
200 TemplateParameters = nullptr;
5
Null pointer value stored to field 'TemplateParameters'
201
202 if (!CommentDecl) {
6
Assuming the condition is true
7
Taking true branch
203 // If there is no declaration, the defaults is our only guess.
204 IsFilled = true;
205 return;
206 }
207 CurrentDecl = CommentDecl;
208
209 Decl::Kind K = CommentDecl->getKind();
210 switch (K) {
211 default:
212 // Defaults are should be good for declarations we don't handle explicitly.
213 break;
214 case Decl::Function:
215 case Decl::CXXMethod:
216 case Decl::CXXConstructor:
217 case Decl::CXXDestructor:
218 case Decl::CXXConversion: {
219 const FunctionDecl *FD = cast<FunctionDecl>(CommentDecl);
220 Kind = FunctionKind;
221 ParamVars = FD->parameters();
222 ReturnType = FD->getReturnType();
223 unsigned NumLists = FD->getNumTemplateParameterLists();
224 if (NumLists != 0) {
225 TemplateKind = TemplateSpecialization;
226 TemplateParameters =
227 FD->getTemplateParameterList(NumLists - 1);
228 }
229
230 if (K == Decl::CXXMethod || K == Decl::CXXConstructor ||
231 K == Decl::CXXDestructor || K == Decl::CXXConversion) {
232 const CXXMethodDecl *MD = cast<CXXMethodDecl>(CommentDecl);
233 IsInstanceMethod = MD->isInstance();
234 IsClassMethod = !IsInstanceMethod;
235 }
236 break;
237 }
238 case Decl::ObjCMethod: {
239 const ObjCMethodDecl *MD = cast<ObjCMethodDecl>(CommentDecl);
240 Kind = FunctionKind;
241 ParamVars = MD->parameters();
242 ReturnType = MD->getReturnType();
243 IsObjCMethod = true;
244 IsInstanceMethod = MD->isInstanceMethod();
245 IsClassMethod = !IsInstanceMethod;
246 break;
247 }
248 case Decl::FunctionTemplate: {
249 const FunctionTemplateDecl *FTD = cast<FunctionTemplateDecl>(CommentDecl);
250 Kind = FunctionKind;
251 TemplateKind = Template;
252 const FunctionDecl *FD = FTD->getTemplatedDecl();
253 ParamVars = FD->parameters();
254 ReturnType = FD->getReturnType();
255 TemplateParameters = FTD->getTemplateParameters();
256 break;
257 }
258 case Decl::ClassTemplate: {
259 const ClassTemplateDecl *CTD = cast<ClassTemplateDecl>(CommentDecl);
260 Kind = ClassKind;
261 TemplateKind = Template;
262 TemplateParameters = CTD->getTemplateParameters();
263 break;
264 }
265 case Decl::ClassTemplatePartialSpecialization: {
266 const ClassTemplatePartialSpecializationDecl *CTPSD =
267 cast<ClassTemplatePartialSpecializationDecl>(CommentDecl);
268 Kind = ClassKind;
269 TemplateKind = TemplatePartialSpecialization;
270 TemplateParameters = CTPSD->getTemplateParameters();
271 break;
272 }
273 case Decl::ClassTemplateSpecialization:
274 Kind = ClassKind;
275 TemplateKind = TemplateSpecialization;
276 break;
277 case Decl::Record:
278 case Decl::CXXRecord:
279 Kind = ClassKind;
280 break;
281 case Decl::Var:
282 case Decl::Field:
283 case Decl::EnumConstant:
284 case Decl::ObjCIvar:
285 case Decl::ObjCAtDefsField:
286 case Decl::ObjCProperty: {
287 const TypeSourceInfo *TSI;
288 if (const auto *VD = dyn_cast<DeclaratorDecl>(CommentDecl))
289 TSI = VD->getTypeSourceInfo();
290 else if (const auto *PD = dyn_cast<ObjCPropertyDecl>(CommentDecl))
291 TSI = PD->getTypeSourceInfo();
292 else
293 TSI = nullptr;
294 if (TSI) {
295 TypeLoc TL = TSI->getTypeLoc().getUnqualifiedLoc();
296 FunctionTypeLoc FTL;
297 if (getFunctionTypeLoc(TL, FTL)) {
298 ParamVars = FTL.getParams();
299 ReturnType = FTL.getReturnLoc().getType();
300 }
301 }
302 Kind = VariableKind;
303 break;
304 }
305 case Decl::Namespace:
306 Kind = NamespaceKind;
307 break;
308 case Decl::TypeAlias:
309 case Decl::Typedef: {
310 Kind = TypedefKind;
311 // If this is a typedef / using to something we consider a function, extract
312 // arguments and return type.
313 const TypeSourceInfo *TSI =
314 K == Decl::Typedef
315 ? cast<TypedefDecl>(CommentDecl)->getTypeSourceInfo()
316 : cast<TypeAliasDecl>(CommentDecl)->getTypeSourceInfo();
317 if (!TSI)
318 break;
319 TypeLoc TL = TSI->getTypeLoc().getUnqualifiedLoc();
320 FunctionTypeLoc FTL;
321 if (getFunctionTypeLoc(TL, FTL)) {
322 Kind = FunctionKind;
323 ParamVars = FTL.getParams();
324 ReturnType = FTL.getReturnLoc().getType();
325 }
326 break;
327 }
328 case Decl::TypeAliasTemplate: {
329 const TypeAliasTemplateDecl *TAT = cast<TypeAliasTemplateDecl>(CommentDecl);
330 Kind = TypedefKind;
331 TemplateKind = Template;
332 TemplateParameters = TAT->getTemplateParameters();
333 TypeAliasDecl *TAD = TAT->getTemplatedDecl();
334 if (!TAD)
335 break;
336
337 const TypeSourceInfo *TSI = TAD->getTypeSourceInfo();
338 if (!TSI)
339 break;
340 TypeLoc TL = TSI->getTypeLoc().getUnqualifiedLoc();
341 FunctionTypeLoc FTL;
342 if (getFunctionTypeLoc(TL, FTL)) {
343 Kind = FunctionKind;
344 ParamVars = FTL.getParams();
345 ReturnType = FTL.getReturnLoc().getType();
346 }
347 break;
348 }
349 case Decl::Enum:
350 Kind = EnumKind;
351 break;
352 }
353
354 IsFilled = true;
355}
356
357StringRef ParamCommandComment::getParamName(const FullComment *FC) const {
358 assert(isParamIndexValid())((isParamIndexValid()) ? static_cast<void> (0) : __assert_fail
("isParamIndexValid()", "/build/llvm-toolchain-snapshot-8~svn345461/tools/clang/lib/AST/Comment.cpp"
, 358, __PRETTY_FUNCTION__))
;
359 if (isVarArgParam())
360 return "...";
361 return FC->getDeclInfo()->ParamVars[getParamIndex()]->getName();
362}
363
364StringRef TParamCommandComment::getParamName(const FullComment *FC) const {
365 assert(isPositionValid())((isPositionValid()) ? static_cast<void> (0) : __assert_fail
("isPositionValid()", "/build/llvm-toolchain-snapshot-8~svn345461/tools/clang/lib/AST/Comment.cpp"
, 365, __PRETTY_FUNCTION__))
;
366 const TemplateParameterList *TPL = FC->getDeclInfo()->TemplateParameters;
1
Calling 'FullComment::getDeclInfo'
9
Returning from 'FullComment::getDeclInfo'
10
'TPL' initialized to a null pointer value
367 for (unsigned i = 0, e = getDepth(); i != e; ++i) {
11
Assuming 'i' is not equal to 'e'
12
Loop condition is true. Entering loop body
368 if (i == e-1)
13
Assuming the condition is false
14
Taking false branch
369 return TPL->getParam(getIndex(i))->getName();
370 const NamedDecl *Param = TPL->getParam(getIndex(i));
15
Called C++ object pointer is null
371 if (const TemplateTemplateParmDecl *TTP =
372 dyn_cast<TemplateTemplateParmDecl>(Param))
373 TPL = TTP->getTemplateParameters();
374 }
375 return "";
376}
377
378} // end namespace comments
379} // end namespace clang
380

/build/llvm-toolchain-snapshot-8~svn345461/tools/clang/include/clang/AST/Comment.h

1//===--- Comment.h - Comment AST nodes --------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file defines comment AST nodes.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_CLANG_AST_COMMENT_H
15#define LLVM_CLANG_AST_COMMENT_H
16
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"
23
24namespace clang {
25class Decl;
26class ParmVarDecl;
27class TemplateParameterList;
28
29namespace comments {
30class FullComment;
31
32/// Describes the syntax that was used in a documentation command.
33///
34/// Exact values of this enumeration are important because they used to select
35/// parts of diagnostic messages. Audit diagnostics before changing or adding
36/// a new value.
37enum CommandMarkerKind {
38 /// Command started with a backslash character:
39 /// \code
40 /// \foo
41 /// \endcode
42 CMK_Backslash = 0,
43
44 /// Command started with an 'at' character:
45 /// \code
46 /// @foo
47 /// \endcode
48 CMK_At = 1
49};
50
51/// Any part of the comment.
52/// Abstract class.
53class Comment {
54protected:
55 /// Preferred location to show caret.
56 SourceLocation Loc;
57
58 /// Source range of this AST node.
59 SourceRange Range;
60
61 class CommentBitfields {
62 friend class Comment;
63
64 /// Type of this AST node.
65 unsigned Kind : 8;
66 };
67 enum { NumCommentBits = 8 };
68
69 class InlineContentCommentBitfields {
70 friend class InlineContentComment;
71
72 unsigned : NumCommentBits;
73
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;
77 };
78 enum { NumInlineContentCommentBits = NumCommentBits + 1 };
79
80 class TextCommentBitfields {
81 friend class TextComment;
82
83 unsigned : NumInlineContentCommentBits;
84
85 /// True if \c IsWhitespace field contains a valid value.
86 mutable unsigned IsWhitespaceValid : 1;
87
88 /// True if this comment AST node contains only whitespace.
89 mutable unsigned IsWhitespace : 1;
90 };
91 enum { NumTextCommentBits = NumInlineContentCommentBits + 2 };
92
93 class InlineCommandCommentBitfields {
94 friend class InlineCommandComment;
95
96 unsigned : NumInlineContentCommentBits;
97
98 unsigned RenderKind : 2;
99 unsigned CommandID : CommandInfo::NumCommandIDBits;
100 };
101 enum { NumInlineCommandCommentBits = NumInlineContentCommentBits + 2 +
102 CommandInfo::NumCommandIDBits };
103
104 class HTMLTagCommentBitfields {
105 friend class HTMLTagComment;
106
107 unsigned : NumInlineContentCommentBits;
108
109 /// True if we found that this tag is malformed in some way.
110 unsigned IsMalformed : 1;
111 };
112 enum { NumHTMLTagCommentBits = NumInlineContentCommentBits + 1 };
113
114 class HTMLStartTagCommentBitfields {
115 friend class HTMLStartTagComment;
116
117 unsigned : NumHTMLTagCommentBits;
118
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;
122 };
123 enum { NumHTMLStartTagCommentBits = NumHTMLTagCommentBits + 1 };
124
125 class ParagraphCommentBitfields {
126 friend class ParagraphComment;
127
128 unsigned : NumCommentBits;
129
130 /// True if \c IsWhitespace field contains a valid value.
131 mutable unsigned IsWhitespaceValid : 1;
132
133 /// True if this comment AST node contains only whitespace.
134 mutable unsigned IsWhitespace : 1;
135 };
136 enum { NumParagraphCommentBits = NumCommentBits + 2 };
137
138 class BlockCommandCommentBitfields {
139 friend class BlockCommandComment;
140
141 unsigned : NumCommentBits;
142
143 unsigned CommandID : CommandInfo::NumCommandIDBits;
144
145 /// Describes the syntax that was used in a documentation command.
146 /// Contains values from CommandMarkerKind enum.
147 unsigned CommandMarker : 1;
148 };
149 enum { NumBlockCommandCommentBits = NumCommentBits +
150 CommandInfo::NumCommandIDBits + 1 };
151
152 class ParamCommandCommentBitfields {
153 friend class ParamCommandComment;
154
155 unsigned : NumBlockCommandCommentBits;
156
157 /// Parameter passing direction, see ParamCommandComment::PassDirection.
158 unsigned Direction : 2;
159
160 /// True if direction was specified explicitly in the comment.
161 unsigned IsDirectionExplicit : 1;
162 };
163 enum { NumParamCommandCommentBits = NumBlockCommandCommentBits + 3 };
164
165 union {
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;
175 };
176
177 void setSourceRange(SourceRange SR) {
178 Range = SR;
179 }
180
181 void setLocation(SourceLocation L) {
182 Loc = L;
183 }
184
185public:
186 enum CommentKind {
187 NoCommentKind = 0,
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"
195 };
196
197 Comment(CommentKind K,
198 SourceLocation LocBegin,
199 SourceLocation LocEnd) :
200 Loc(LocBegin), Range(SourceRange(LocBegin, LocEnd)) {
201 CommentBits.Kind = K;
202 }
203
204 CommentKind getCommentKind() const {
205 return static_cast<CommentKind>(CommentBits.Kind);
206 }
207
208 const char *getCommentKindName() const;
209
210 void dump() 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;
215
216 SourceRange getSourceRange() const LLVM_READONLY__attribute__((__pure__)) { return Range; }
217
218 SourceLocation getBeginLoc() const LLVM_READONLY__attribute__((__pure__)) { return Range.getBegin(); }
219
220 SourceLocation getEndLoc() const LLVM_READONLY__attribute__((__pure__)) { return Range.getEnd(); }
221
222 SourceLocation getLocation() const LLVM_READONLY__attribute__((__pure__)) { return Loc; }
223
224 typedef Comment * const *child_iterator;
225
226 child_iterator child_begin() const;
227 child_iterator child_end() const;
228
229 // TODO: const child iterator
230
231 unsigned child_count() const {
232 return child_end() - child_begin();
233 }
234};
235
236/// Inline content (contained within a block).
237/// Abstract class.
238class InlineContentComment : public Comment {
239protected:
240 InlineContentComment(CommentKind K,
241 SourceLocation LocBegin,
242 SourceLocation LocEnd) :
243 Comment(K, LocBegin, LocEnd) {
244 InlineContentCommentBits.HasTrailingNewline = 0;
245 }
246
247public:
248 static bool classof(const Comment *C) {
249 return C->getCommentKind() >= FirstInlineContentCommentConstant &&
250 C->getCommentKind() <= LastInlineContentCommentConstant;
251 }
252
253 void addTrailingNewline() {
254 InlineContentCommentBits.HasTrailingNewline = 1;
255 }
256
257 bool hasTrailingNewline() const {
258 return InlineContentCommentBits.HasTrailingNewline;
259 }
260};
261
262/// Plain text.
263class TextComment : public InlineContentComment {
264 StringRef Text;
265
266public:
267 TextComment(SourceLocation LocBegin,
268 SourceLocation LocEnd,
269 StringRef Text) :
270 InlineContentComment(TextCommentKind, LocBegin, LocEnd),
271 Text(Text) {
272 TextCommentBits.IsWhitespaceValid = false;
273 }
274
275 static bool classof(const Comment *C) {
276 return C->getCommentKind() == TextCommentKind;
277 }
278
279 child_iterator child_begin() const { return nullptr; }
280
281 child_iterator child_end() const { return nullptr; }
282
283 StringRef getText() const LLVM_READONLY__attribute__((__pure__)) { return Text; }
284
285 bool isWhitespace() const {
286 if (TextCommentBits.IsWhitespaceValid)
287 return TextCommentBits.IsWhitespace;
288
289 TextCommentBits.IsWhitespace = isWhitespaceNoCache();
290 TextCommentBits.IsWhitespaceValid = true;
291 return TextCommentBits.IsWhitespace;
292 }
293
294private:
295 bool isWhitespaceNoCache() const;
296};
297
298/// A command with word-like arguments that is considered inline content.
299class InlineCommandComment : public InlineContentComment {
300public:
301 struct Argument {
302 SourceRange Range;
303 StringRef Text;
304
305 Argument(SourceRange Range, StringRef Text) : Range(Range), Text(Text) { }
306 };
307
308 /// The most appropriate rendering mode for this command, chosen on command
309 /// semantics in Doxygen.
310 enum RenderKind {
311 RenderNormal,
312 RenderBold,
313 RenderMonospaced,
314 RenderEmphasized
315 };
316
317protected:
318 /// Command arguments.
319 ArrayRef<Argument> Args;
320
321public:
322 InlineCommandComment(SourceLocation LocBegin,
323 SourceLocation LocEnd,
324 unsigned CommandID,
325 RenderKind RK,
326 ArrayRef<Argument> Args) :
327 InlineContentComment(InlineCommandCommentKind, LocBegin, LocEnd),
328 Args(Args) {
329 InlineCommandCommentBits.RenderKind = RK;
330 InlineCommandCommentBits.CommandID = CommandID;
331 }
332
333 static bool classof(const Comment *C) {
334 return C->getCommentKind() == InlineCommandCommentKind;
335 }
336
337 child_iterator child_begin() const { return nullptr; }
338
339 child_iterator child_end() const { return nullptr; }
340
341 unsigned getCommandID() const {
342 return InlineCommandCommentBits.CommandID;
343 }
344
345 StringRef getCommandName(const CommandTraits &Traits) const {
346 return Traits.getCommandInfo(getCommandID())->Name;
347 }
348
349 SourceRange getCommandNameRange() const {
350 return SourceRange(getBeginLoc().getLocWithOffset(-1), getEndLoc());
351 }
352
353 RenderKind getRenderKind() const {
354 return static_cast<RenderKind>(InlineCommandCommentBits.RenderKind);
355 }
356
357 unsigned getNumArgs() const {
358 return Args.size();
359 }
360
361 StringRef getArgText(unsigned Idx) const {
362 return Args[Idx].Text;
363 }
364
365 SourceRange getArgRange(unsigned Idx) const {
366 return Args[Idx].Range;
367 }
368};
369
370/// Abstract class for opening and closing HTML tags. HTML tags are always
371/// treated as inline content (regardless HTML semantics).
372class HTMLTagComment : public InlineContentComment {
373protected:
374 StringRef TagName;
375 SourceRange TagNameRange;
376
377 HTMLTagComment(CommentKind K,
378 SourceLocation LocBegin,
379 SourceLocation LocEnd,
380 StringRef TagName,
381 SourceLocation TagNameBegin,
382 SourceLocation TagNameEnd) :
383 InlineContentComment(K, LocBegin, LocEnd),
384 TagName(TagName),
385 TagNameRange(TagNameBegin, TagNameEnd) {
386 setLocation(TagNameBegin);
387 HTMLTagCommentBits.IsMalformed = 0;
388 }
389
390public:
391 static bool classof(const Comment *C) {
392 return C->getCommentKind() >= FirstHTMLTagCommentConstant &&
393 C->getCommentKind() <= LastHTMLTagCommentConstant;
394 }
395
396 StringRef getTagName() const LLVM_READONLY__attribute__((__pure__)) { return TagName; }
397
398 SourceRange getTagNameSourceRange() const LLVM_READONLY__attribute__((__pure__)) {
399 SourceLocation L = getLocation();
400 return SourceRange(L.getLocWithOffset(1),
401 L.getLocWithOffset(1 + TagName.size()));
402 }
403
404 bool isMalformed() const {
405 return HTMLTagCommentBits.IsMalformed;
406 }
407
408 void setIsMalformed() {
409 HTMLTagCommentBits.IsMalformed = 1;
410 }
411};
412
413/// An opening HTML tag with attributes.
414class HTMLStartTagComment : public HTMLTagComment {
415public:
416 class Attribute {
417 public:
418 SourceLocation NameLocBegin;
419 StringRef Name;
420
421 SourceLocation EqualsLoc;
422
423 SourceRange ValueRange;
424 StringRef Value;
425
426 Attribute() { }
427
428 Attribute(SourceLocation NameLocBegin, StringRef Name) :
429 NameLocBegin(NameLocBegin), Name(Name),
430 EqualsLoc(SourceLocation()),
431 ValueRange(SourceRange()), Value(StringRef())
432 { }
433
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)
440 { }
441
442 SourceLocation getNameLocEnd() const {
443 return NameLocBegin.getLocWithOffset(Name.size());
444 }
445
446 SourceRange getNameRange() const {
447 return SourceRange(NameLocBegin, getNameLocEnd());
448 }
449 };
450
451private:
452 ArrayRef<Attribute> Attributes;
453
454public:
455 HTMLStartTagComment(SourceLocation LocBegin,
456 StringRef TagName) :
457 HTMLTagComment(HTMLStartTagCommentKind,
458 LocBegin, LocBegin.getLocWithOffset(1 + TagName.size()),
459 TagName,
460 LocBegin.getLocWithOffset(1),
461 LocBegin.getLocWithOffset(1 + TagName.size())) {
462 HTMLStartTagCommentBits.IsSelfClosing = false;
463 }
464
465 static bool classof(const Comment *C) {
466 return C->getCommentKind() == HTMLStartTagCommentKind;
467 }
468
469 child_iterator child_begin() const { return nullptr; }
470
471 child_iterator child_end() const { return nullptr; }
472
473 unsigned getNumAttrs() const {
474 return Attributes.size();
475 }
476
477 const Attribute &getAttr(unsigned Idx) const {
478 return Attributes[Idx];
479 }
480
481 void setAttrs(ArrayRef<Attribute> Attrs) {
482 Attributes = Attrs;
483 if (!Attrs.empty()) {
484 const Attribute &Attr = Attrs.back();
485 SourceLocation L = Attr.ValueRange.getEnd();
486 if (L.isValid())
487 Range.setEnd(L);
488 else {
489 Range.setEnd(Attr.getNameLocEnd());
490 }
491 }
492 }
493
494 void setGreaterLoc(SourceLocation GreaterLoc) {
495 Range.setEnd(GreaterLoc);
496 }
497
498 bool isSelfClosing() const {
499 return HTMLStartTagCommentBits.IsSelfClosing;
500 }
501
502 void setSelfClosing() {
503 HTMLStartTagCommentBits.IsSelfClosing = true;
504 }
505};
506
507/// A closing HTML tag.
508class HTMLEndTagComment : public HTMLTagComment {
509public:
510 HTMLEndTagComment(SourceLocation LocBegin,
511 SourceLocation LocEnd,
512 StringRef TagName) :
513 HTMLTagComment(HTMLEndTagCommentKind,
514 LocBegin, LocEnd,
515 TagName,
516 LocBegin.getLocWithOffset(2),
517 LocBegin.getLocWithOffset(2 + TagName.size()))
518 { }
519
520 static bool classof(const Comment *C) {
521 return C->getCommentKind() == HTMLEndTagCommentKind;
522 }
523
524 child_iterator child_begin() const { return nullptr; }
525
526 child_iterator child_end() const { return nullptr; }
527};
528
529/// Block content (contains inline content).
530/// Abstract class.
531class BlockContentComment : public Comment {
532protected:
533 BlockContentComment(CommentKind K,
534 SourceLocation LocBegin,
535 SourceLocation LocEnd) :
536 Comment(K, LocBegin, LocEnd)
537 { }
538
539public:
540 static bool classof(const Comment *C) {
541 return C->getCommentKind() >= FirstBlockContentCommentConstant &&
542 C->getCommentKind() <= LastBlockContentCommentConstant;
543 }
544};
545
546/// A single paragraph that contains inline content.
547class ParagraphComment : public BlockContentComment {
548 ArrayRef<InlineContentComment *> Content;
549
550public:
551 ParagraphComment(ArrayRef<InlineContentComment *> Content) :
552 BlockContentComment(ParagraphCommentKind,
553 SourceLocation(),
554 SourceLocation()),
555 Content(Content) {
556 if (Content.empty()) {
557 ParagraphCommentBits.IsWhitespace = true;
558 ParagraphCommentBits.IsWhitespaceValid = true;
559 return;
560 }
561
562 ParagraphCommentBits.IsWhitespaceValid = false;
563
564 setSourceRange(SourceRange(Content.front()->getBeginLoc(),
565 Content.back()->getEndLoc()));
566 setLocation(Content.front()->getBeginLoc());
567 }
568
569 static bool classof(const Comment *C) {
570 return C->getCommentKind() == ParagraphCommentKind;
571 }
572
573 child_iterator child_begin() const {
574 return reinterpret_cast<child_iterator>(Content.begin());
575 }
576
577 child_iterator child_end() const {
578 return reinterpret_cast<child_iterator>(Content.end());
579 }
580
581 bool isWhitespace() const {
582 if (ParagraphCommentBits.IsWhitespaceValid)
583 return ParagraphCommentBits.IsWhitespace;
584
585 ParagraphCommentBits.IsWhitespace = isWhitespaceNoCache();
586 ParagraphCommentBits.IsWhitespaceValid = true;
587 return ParagraphCommentBits.IsWhitespace;
588 }
589
590private:
591 bool isWhitespaceNoCache() const;
592};
593
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).
597class BlockCommandComment : public BlockContentComment {
598public:
599 struct Argument {
600 SourceRange Range;
601 StringRef Text;
602
603 Argument() { }
604 Argument(SourceRange Range, StringRef Text) : Range(Range), Text(Text) { }
605 };
606
607protected:
608 /// Word-like arguments.
609 ArrayRef<Argument> Args;
610
611 /// Paragraph argument.
612 ParagraphComment *Paragraph;
613
614 BlockCommandComment(CommentKind K,
615 SourceLocation LocBegin,
616 SourceLocation LocEnd,
617 unsigned CommandID,
618 CommandMarkerKind CommandMarker) :
619 BlockContentComment(K, LocBegin, LocEnd),
620 Paragraph(nullptr) {
621 setLocation(getCommandNameBeginLoc());
622 BlockCommandCommentBits.CommandID = CommandID;
623 BlockCommandCommentBits.CommandMarker = CommandMarker;
624 }
625
626public:
627 BlockCommandComment(SourceLocation LocBegin,
628 SourceLocation LocEnd,
629 unsigned CommandID,
630 CommandMarkerKind CommandMarker) :
631 BlockContentComment(BlockCommandCommentKind, LocBegin, LocEnd),
632 Paragraph(nullptr) {
633 setLocation(getCommandNameBeginLoc());
634 BlockCommandCommentBits.CommandID = CommandID;
635 BlockCommandCommentBits.CommandMarker = CommandMarker;
636 }
637
638 static bool classof(const Comment *C) {
639 return C->getCommentKind() >= FirstBlockCommandCommentConstant &&
640 C->getCommentKind() <= LastBlockCommandCommentConstant;
641 }
642
643 child_iterator child_begin() const {
644 return reinterpret_cast<child_iterator>(&Paragraph);
645 }
646
647 child_iterator child_end() const {
648 return reinterpret_cast<child_iterator>(&Paragraph + 1);
649 }
650
651 unsigned getCommandID() const {
652 return BlockCommandCommentBits.CommandID;
653 }
654
655 StringRef getCommandName(const CommandTraits &Traits) const {
656 return Traits.getCommandInfo(getCommandID())->Name;
657 }
658
659 SourceLocation getCommandNameBeginLoc() const {
660 return getBeginLoc().getLocWithOffset(1);
661 }
662
663 SourceRange getCommandNameRange(const CommandTraits &Traits) const {
664 StringRef Name = getCommandName(Traits);
665 return SourceRange(getCommandNameBeginLoc(),
666 getBeginLoc().getLocWithOffset(1 + Name.size()));
667 }
668
669 unsigned getNumArgs() const {
670 return Args.size();
671 }
672
673 StringRef getArgText(unsigned Idx) const {
674 return Args[Idx].Text;
675 }
676
677 SourceRange getArgRange(unsigned Idx) const {
678 return Args[Idx].Range;
679 }
680
681 void setArgs(ArrayRef<Argument> A) {
682 Args = A;
683 if (Args.size() > 0) {
684 SourceLocation NewLocEnd = Args.back().Range.getEnd();
685 if (NewLocEnd.isValid())
686 setSourceRange(SourceRange(getBeginLoc(), NewLocEnd));
687 }
688 }
689
690 ParagraphComment *getParagraph() const LLVM_READONLY__attribute__((__pure__)) {
691 return Paragraph;
692 }
693
694 bool hasNonWhitespaceParagraph() const {
695 return Paragraph && !Paragraph->isWhitespace();
696 }
697
698 void setParagraph(ParagraphComment *PC) {
699 Paragraph = PC;
700 SourceLocation NewLocEnd = PC->getEndLoc();
701 if (NewLocEnd.isValid())
702 setSourceRange(SourceRange(getBeginLoc(), NewLocEnd));
703 }
704
705 CommandMarkerKind getCommandMarker() const LLVM_READONLY__attribute__((__pure__)) {
706 return static_cast<CommandMarkerKind>(
707 BlockCommandCommentBits.CommandMarker);
708 }
709};
710
711/// Doxygen \\param command.
712class ParamCommandComment : public BlockCommandComment {
713private:
714 /// Parameter index in the function declaration.
715 unsigned ParamIndex;
716
717public:
718 enum : unsigned {
719 InvalidParamIndex = ~0U,
720 VarArgParamIndex = ~0U/*InvalidParamIndex*/ - 1U
721 };
722
723 ParamCommandComment(SourceLocation LocBegin,
724 SourceLocation LocEnd,
725 unsigned CommandID,
726 CommandMarkerKind CommandMarker) :
727 BlockCommandComment(ParamCommandCommentKind, LocBegin, LocEnd,
728 CommandID, CommandMarker),
729 ParamIndex(InvalidParamIndex) {
730 ParamCommandCommentBits.Direction = In;
731 ParamCommandCommentBits.IsDirectionExplicit = false;
732 }
733
734 static bool classof(const Comment *C) {
735 return C->getCommentKind() == ParamCommandCommentKind;
736 }
737
738 enum PassDirection {
739 In,
740 Out,
741 InOut
742 };
743
744 static const char *getDirectionAsString(PassDirection D);
745
746 PassDirection getDirection() const LLVM_READONLY__attribute__((__pure__)) {
747 return static_cast<PassDirection>(ParamCommandCommentBits.Direction);
748 }
749
750 bool isDirectionExplicit() const LLVM_READONLY__attribute__((__pure__)) {
751 return ParamCommandCommentBits.IsDirectionExplicit;
752 }
753
754 void setDirection(PassDirection Direction, bool Explicit) {
755 ParamCommandCommentBits.Direction = Direction;
756 ParamCommandCommentBits.IsDirectionExplicit = Explicit;
757 }
758
759 bool hasParamName() const {
760 return getNumArgs() > 0;
761 }
762
763 StringRef getParamName(const FullComment *FC) const;
764
765 StringRef getParamNameAsWritten() const {
766 return Args[0].Text;
767 }
768
769 SourceRange getParamNameRange() const {
770 return Args[0].Range;
771 }
772
773 bool isParamIndexValid() const LLVM_READONLY__attribute__((__pure__)) {
774 return ParamIndex != InvalidParamIndex;
775 }
776
777 bool isVarArgParam() const LLVM_READONLY__attribute__((__pure__)) {
778 return ParamIndex == VarArgParamIndex;
779 }
780
781 void setIsVarArgParam() {
782 ParamIndex = VarArgParamIndex;
783 assert(isParamIndexValid())((isParamIndexValid()) ? static_cast<void> (0) : __assert_fail
("isParamIndexValid()", "/build/llvm-toolchain-snapshot-8~svn345461/tools/clang/include/clang/AST/Comment.h"
, 783, __PRETTY_FUNCTION__))
;
784 }
785
786 unsigned getParamIndex() const LLVM_READONLY__attribute__((__pure__)) {
787 assert(isParamIndexValid())((isParamIndexValid()) ? static_cast<void> (0) : __assert_fail
("isParamIndexValid()", "/build/llvm-toolchain-snapshot-8~svn345461/tools/clang/include/clang/AST/Comment.h"
, 787, __PRETTY_FUNCTION__))
;
788 assert(!isVarArgParam())((!isVarArgParam()) ? static_cast<void> (0) : __assert_fail
("!isVarArgParam()", "/build/llvm-toolchain-snapshot-8~svn345461/tools/clang/include/clang/AST/Comment.h"
, 788, __PRETTY_FUNCTION__))
;
789 return ParamIndex;
790 }
791
792 void setParamIndex(unsigned Index) {
793 ParamIndex = Index;
794 assert(isParamIndexValid())((isParamIndexValid()) ? static_cast<void> (0) : __assert_fail
("isParamIndexValid()", "/build/llvm-toolchain-snapshot-8~svn345461/tools/clang/include/clang/AST/Comment.h"
, 794, __PRETTY_FUNCTION__))
;
795 assert(!isVarArgParam())((!isVarArgParam()) ? static_cast<void> (0) : __assert_fail
("!isVarArgParam()", "/build/llvm-toolchain-snapshot-8~svn345461/tools/clang/include/clang/AST/Comment.h"
, 795, __PRETTY_FUNCTION__))
;
796 }
797};
798
799/// Doxygen \\tparam command, describes a template parameter.
800class TParamCommandComment : public BlockCommandComment {
801private:
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
804 /// parameter lists.
805 ///
806 /// For example:
807 /// \verbatim
808 /// template<typename C, template<typename T> class TT>
809 /// void test(TT<int> aaa);
810 /// \endverbatim
811 /// For C: Position = { 0 }
812 /// For TT: Position = { 1 }
813 /// For T: Position = { 1, 0 }
814 ArrayRef<unsigned> Position;
815
816public:
817 TParamCommandComment(SourceLocation LocBegin,
818 SourceLocation LocEnd,
819 unsigned CommandID,
820 CommandMarkerKind CommandMarker) :
821 BlockCommandComment(TParamCommandCommentKind, LocBegin, LocEnd, CommandID,
822 CommandMarker)
823 { }
824
825 static bool classof(const Comment *C) {
826 return C->getCommentKind() == TParamCommandCommentKind;
827 }
828
829 bool hasParamName() const {
830 return getNumArgs() > 0;
831 }
832
833 StringRef getParamName(const FullComment *FC) const;
834
835 StringRef getParamNameAsWritten() const {
836 return Args[0].Text;
837 }
838
839 SourceRange getParamNameRange() const {
840 return Args[0].Range;
841 }
842
843 bool isPositionValid() const LLVM_READONLY__attribute__((__pure__)) {
844 return !Position.empty();
845 }
846
847 unsigned getDepth() const {
848 assert(isPositionValid())((isPositionValid()) ? static_cast<void> (0) : __assert_fail
("isPositionValid()", "/build/llvm-toolchain-snapshot-8~svn345461/tools/clang/include/clang/AST/Comment.h"
, 848, __PRETTY_FUNCTION__))
;
849 return Position.size();
850 }
851
852 unsigned getIndex(unsigned Depth) const {
853 assert(isPositionValid())((isPositionValid()) ? static_cast<void> (0) : __assert_fail
("isPositionValid()", "/build/llvm-toolchain-snapshot-8~svn345461/tools/clang/include/clang/AST/Comment.h"
, 853, __PRETTY_FUNCTION__))
;
854 return Position[Depth];
855 }
856
857 void setPosition(ArrayRef<unsigned> NewPosition) {
858 Position = NewPosition;
859 assert(isPositionValid())((isPositionValid()) ? static_cast<void> (0) : __assert_fail
("isPositionValid()", "/build/llvm-toolchain-snapshot-8~svn345461/tools/clang/include/clang/AST/Comment.h"
, 859, __PRETTY_FUNCTION__))
;
860 }
861};
862
863/// A line of text contained in a verbatim block.
864class VerbatimBlockLineComment : public Comment {
865 StringRef Text;
866
867public:
868 VerbatimBlockLineComment(SourceLocation LocBegin,
869 StringRef Text) :
870 Comment(VerbatimBlockLineCommentKind,
871 LocBegin,
872 LocBegin.getLocWithOffset(Text.size())),
873 Text(Text)
874 { }
875
876 static bool classof(const Comment *C) {
877 return C->getCommentKind() == VerbatimBlockLineCommentKind;
878 }
879
880 child_iterator child_begin() const { return nullptr; }
881
882 child_iterator child_end() const { return nullptr; }
883
884 StringRef getText() const LLVM_READONLY__attribute__((__pure__)) {
885 return Text;
886 }
887};
888
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).
892class VerbatimBlockComment : public BlockCommandComment {
893protected:
894 StringRef CloseName;
895 SourceLocation CloseNameLocBegin;
896 ArrayRef<VerbatimBlockLineComment *> Lines;
897
898public:
899 VerbatimBlockComment(SourceLocation LocBegin,
900 SourceLocation LocEnd,
901 unsigned CommandID) :
902 BlockCommandComment(VerbatimBlockCommentKind,
903 LocBegin, LocEnd, CommandID,
904 CMK_At) // FIXME: improve source fidelity.
905 { }
906
907 static bool classof(const Comment *C) {
908 return C->getCommentKind() == VerbatimBlockCommentKind;
909 }
910
911 child_iterator child_begin() const {
912 return reinterpret_cast<child_iterator>(Lines.begin());
913 }
914
915 child_iterator child_end() const {
916 return reinterpret_cast<child_iterator>(Lines.end());
917 }
918
919 void setCloseName(StringRef Name, SourceLocation LocBegin) {
920 CloseName = Name;
921 CloseNameLocBegin = LocBegin;
922 }
923
924 void setLines(ArrayRef<VerbatimBlockLineComment *> L) {
925 Lines = L;
926 }
927
928 StringRef getCloseName() const {
929 return CloseName;
930 }
931
932 unsigned getNumLines() const {
933 return Lines.size();
934 }
935
936 StringRef getText(unsigned LineIdx) const {
937 return Lines[LineIdx]->getText();
938 }
939};
940
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
943/// closing command.
944class VerbatimLineComment : public BlockCommandComment {
945protected:
946 StringRef Text;
947 SourceLocation TextBegin;
948
949public:
950 VerbatimLineComment(SourceLocation LocBegin,
951 SourceLocation LocEnd,
952 unsigned CommandID,
953 SourceLocation TextBegin,
954 StringRef Text) :
955 BlockCommandComment(VerbatimLineCommentKind,
956 LocBegin, LocEnd,
957 CommandID,
958 CMK_At), // FIXME: improve source fidelity.
959 Text(Text),
960 TextBegin(TextBegin)
961 { }
962
963 static bool classof(const Comment *C) {
964 return C->getCommentKind() == VerbatimLineCommentKind;
965 }
966
967 child_iterator child_begin() const { return nullptr; }
968
969 child_iterator child_end() const { return nullptr; }
970
971 StringRef getText() const {
972 return Text;
973 }
974
975 SourceRange getTextRange() const {
976 return SourceRange(TextBegin, getEndLoc());
977 }
978};
979
980/// Information about the declaration, useful to clients of FullComment.
981struct DeclInfo {
982 /// Declaration the comment is actually attached to (in the source).
983 /// Should not be NULL.
984 const Decl *CommentDecl;
985
986 /// CurrentDecl is the declaration with which the FullComment is associated.
987 ///
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
991 /// \c CommentDecl).
992 ///
993 /// The information in the DeclInfo corresponds to CurrentDecl.
994 const Decl *CurrentDecl;
995
996 /// Parameters that can be referenced by \\param if \c CommentDecl is something
997 /// that we consider a "function".
998 ArrayRef<const ParmVarDecl *> ParamVars;
999
1000 /// Function return type if \c CommentDecl is something that we consider
1001 /// a "function".
1002 QualType ReturnType;
1003
1004 /// Template parameters that can be referenced by \\tparam if \c CommentDecl is
1005 /// a template (\c IsTemplateDecl or \c IsTemplatePartialSpecialization is
1006 /// true).
1007 const TemplateParameterList *TemplateParameters;
1008
1009 /// A simplified description of \c CommentDecl kind that should be good enough
1010 /// for documentation rendering purposes.
1011 enum DeclKind {
1012 /// Everything else not explicitly mentioned below.
1013 OtherKind,
1014
1015 /// Something that we consider a "function":
1016 /// \li 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,
1024 /// ObjC block.
1025 FunctionKind,
1026
1027 /// Something that we consider a "class":
1028 /// \li class/struct,
1029 /// \li class template,
1030 /// \li class template (partial) specialization.
1031 ClassKind,
1032
1033 /// Something that we consider a "variable":
1034 /// \li namespace scope variables;
1035 /// \li static and non-static class data members;
1036 /// \li enumerators.
1037 VariableKind,
1038
1039 /// A C++ namespace.
1040 NamespaceKind,
1041
1042 /// A C++ typedef-name (a 'typedef' decl specifier or alias-declaration),
1043 /// see \c TypedefNameDecl.
1044 TypedefKind,
1045
1046 /// An enumeration or scoped enumeration.
1047 EnumKind
1048 };
1049
1050 /// What kind of template specialization \c CommentDecl is.
1051 enum TemplateDeclKind {
1052 NotTemplate,
1053 Template,
1054 TemplateSpecialization,
1055 TemplatePartialSpecialization
1056 };
1057
1058 /// If false, only \c CommentDecl is valid.
1059 unsigned IsFilled : 1;
1060
1061 /// Simplified kind of \c CommentDecl, see \c DeclKind enum.
1062 unsigned Kind : 3;
1063
1064 /// Is \c CommentDecl a template declaration.
1065 unsigned TemplateKind : 2;
1066
1067 /// Is \c CommentDecl an ObjCMethodDecl.
1068 unsigned IsObjCMethod : 1;
1069
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;
1074
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;
1079
1080 void fill();
1081
1082 DeclKind getKind() const LLVM_READONLY__attribute__((__pure__)) {
1083 return static_cast<DeclKind>(Kind);
1084 }
1085
1086 TemplateDeclKind getTemplateKind() const LLVM_READONLY__attribute__((__pure__)) {
1087 return static_cast<TemplateDeclKind>(TemplateKind);
1088 }
1089};
1090
1091/// A full comment attached to a declaration, contains block content.
1092class FullComment : public Comment {
1093 ArrayRef<BlockContentComment *> Blocks;
1094 DeclInfo *ThisDeclInfo;
1095
1096public:
1097 FullComment(ArrayRef<BlockContentComment *> Blocks, DeclInfo *D) :
1098 Comment(FullCommentKind, SourceLocation(), SourceLocation()),
1099 Blocks(Blocks), ThisDeclInfo(D) {
1100 if (Blocks.empty())
1101 return;
1102
1103 setSourceRange(
1104 SourceRange(Blocks.front()->getBeginLoc(), Blocks.back()->getEndLoc()));
1105 setLocation(Blocks.front()->getBeginLoc());
1106 }
1107
1108 static bool classof(const Comment *C) {
1109 return C->getCommentKind() == FullCommentKind;
1110 }
1111
1112 child_iterator child_begin() const {
1113 return reinterpret_cast<child_iterator>(Blocks.begin());
1114 }
1115
1116 child_iterator child_end() const {
1117 return reinterpret_cast<child_iterator>(Blocks.end());
1118 }
1119
1120 const Decl *getDecl() const LLVM_READONLY__attribute__((__pure__)) {
1121 return ThisDeclInfo->CommentDecl;
1122 }
1123
1124 const DeclInfo *getDeclInfo() const LLVM_READONLY__attribute__((__pure__)) {
1125 if (!ThisDeclInfo->IsFilled)
2
Assuming the condition is true
3
Taking true branch
1126 ThisDeclInfo->fill();
4
Calling 'DeclInfo::fill'
8
Returning from 'DeclInfo::fill'
1127 return ThisDeclInfo;
1128 }
1129
1130 ArrayRef<BlockContentComment *> getBlocks() const { return Blocks; }
1131
1132};
1133} // end namespace comments
1134} // end namespace clang
1135
1136#endif
1137