clang 8.0.0

CommentSema.cpp
Go to the documentation of this file.
1 //===--- CommentSema.cpp - Doxygen comment semantic analysis --------------===//
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/CommentSema.h"
11 #include "clang/AST/Attr.h"
12 #include "clang/AST/CommentCommandTraits.h"
13 #include "clang/AST/CommentDiagnostic.h"
14 #include "clang/AST/Decl.h"
15 #include "clang/AST/DeclTemplate.h"
16 #include "clang/Basic/SourceManager.h"
17 #include "clang/Lex/Preprocessor.h"
18 #include "llvm/ADT/SmallString.h"
19 #include "llvm/ADT/StringSwitch.h"
20
21 namespace clang {
22 namespace comments {
23
24 namespace {
25 #include "clang/AST/CommentHTMLTagsProperties.inc"
26 } // end anonymous namespace
27
28 Sema::Sema(llvm::BumpPtrAllocator &Allocator, const SourceManager &SourceMgr,
29 DiagnosticsEngine &Diags, CommandTraits &Traits,
30 const Preprocessor *PP) :
31 Allocator(Allocator), SourceMgr(SourceMgr), Diags(Diags), Traits(Traits),
32 PP(PP), ThisDeclInfo(nullptr), BriefCommand(nullptr),
33 HeaderfileCommand(nullptr) {
34 }
35
36 void Sema::setDecl(const Decl *D) {
37 if (!D)
38 return;
39
40 ThisDeclInfo = new (Allocator) DeclInfo;
41 ThisDeclInfo->CommentDecl = D;
42 ThisDeclInfo->IsFilled = false;
43 }
44
45 ParagraphComment *Sema::actOnParagraphComment(
46 ArrayRef<InlineContentComment *> Content) {
47 return new (Allocator) ParagraphComment(Content);
48 }
49
50 BlockCommandComment *Sema::actOnBlockCommandStart(
51 SourceLocation LocBegin,
52 SourceLocation LocEnd,
53 unsigned CommandID,
54 CommandMarkerKind CommandMarker) {
55 BlockCommandComment *BC = new (Allocator) BlockCommandComment(LocBegin, LocEnd,
56 CommandID,
57 CommandMarker);
58 checkContainerDecl(BC);
59 return BC;
60 }
61
62 void Sema::actOnBlockCommandArgs(BlockCommandComment *Command,
63 ArrayRef<BlockCommandComment::Argument> Args) {
64 Command->setArgs(Args);
65 }
66
67 void Sema::actOnBlockCommandFinish(BlockCommandComment *Command,
68 ParagraphComment *Paragraph) {
69 Command->setParagraph(Paragraph);
70 checkBlockCommandEmptyParagraph(Command);
71 checkBlockCommandDuplicate(Command);
72 if (ThisDeclInfo) {
73 // These checks only make sense if the comment is attached to a
74 // declaration.
75 checkReturnsCommand(Command);
76 checkDeprecatedCommand(Command);
77 }
78 }
79
80 ParamCommandComment *Sema::actOnParamCommandStart(
81 SourceLocation LocBegin,
82 SourceLocation LocEnd,
83 unsigned CommandID,
84 CommandMarkerKind CommandMarker) {
85 ParamCommandComment *Command =
86 new (Allocator) ParamCommandComment(LocBegin, LocEnd, CommandID,
87 CommandMarker);
88
89 if (!isFunctionDecl() && !isFunctionOrBlockPointerVarLikeDecl())
90 Diag(Command->getLocation(),
91 diag::warn_doc_param_not_attached_to_a_function_decl)
92 << CommandMarker
93 << Command->getCommandNameRange(Traits);
94
95 return Command;
96 }
97
98 void Sema::checkFunctionDeclVerbatimLine(const BlockCommandComment *Comment) {
99 const CommandInfo *Info = Traits.getCommandInfo(Comment->getCommandID());
100 if (!Info->IsFunctionDeclarationCommand)
101 return;
102
103 unsigned DiagSelect;
104 switch (Comment->getCommandID()) {
105 case CommandTraits::KCI_function:
106 DiagSelect = (!isAnyFunctionDecl() && !isFunctionTemplateDecl())? 1 : 0;
107 break;
108 case CommandTraits::KCI_functiongroup:
109 DiagSelect = (!isAnyFunctionDecl() && !isFunctionTemplateDecl())? 2 : 0;
110 break;
111 case CommandTraits::KCI_method:
112 DiagSelect = !isObjCMethodDecl() ? 3 : 0;
113 break;
114 case CommandTraits::KCI_methodgroup:
115 DiagSelect = !isObjCMethodDecl() ? 4 : 0;
116 break;
117 case CommandTraits::KCI_callback:
118 DiagSelect = !isFunctionPointerVarDecl() ? 5 : 0;
119 break;
120 default:
121 DiagSelect = 0;
122 break;
123 }
124 if (DiagSelect)
125 Diag(Comment->getLocation(), diag::warn_doc_function_method_decl_mismatch)
126 << Comment->getCommandMarker()
127 << (DiagSelect-1) << (DiagSelect-1)
128 << Comment->getSourceRange();
129 }
130
131 void Sema::checkContainerDeclVerbatimLine(const BlockCommandComment *Comment) {
132 const CommandInfo *Info = Traits.getCommandInfo(Comment->getCommandID());
133 if (!Info->IsRecordLikeDeclarationCommand)
134 return;
135 unsigned DiagSelect;
136 switch (Comment->getCommandID()) {
137 case CommandTraits::KCI_class:
138 DiagSelect = (!isClassOrStructDecl() && !isClassTemplateDecl()) ? 1 : 0;
139 // Allow @class command on @interface declarations.
140 // FIXME. Currently, \class and @class are indistinguishable. So,
141 // \class is also allowed on an @interface declaration
142 if (DiagSelect && Comment->getCommandMarker() && isObjCInterfaceDecl())
143 DiagSelect = 0;
144 break;
145 case CommandTraits::KCI_interface:
146 DiagSelect = !isObjCInterfaceDecl() ? 2 : 0;
147 break;
148 case CommandTraits::KCI_protocol:
149 DiagSelect = !isObjCProtocolDecl() ? 3 : 0;
150 break;
151 case CommandTraits::KCI_struct:
152 DiagSelect = !isClassOrStructDecl() ? 4 : 0;
153 break;
154 case CommandTraits::KCI_union:
155 DiagSelect = !isUnionDecl() ? 5 : 0;
156 break;
157 default:
158 DiagSelect = 0;
159 break;
160 }
161 if (DiagSelect)
162 Diag(Comment->getLocation(), diag::warn_doc_api_container_decl_mismatch)
163 << Comment->getCommandMarker()
164 << (DiagSelect-1) << (DiagSelect-1)
165 << Comment->getSourceRange();
166 }
167
168 void Sema::checkContainerDecl(const BlockCommandComment *Comment) {
169 const CommandInfo *Info = Traits.getCommandInfo(Comment->getCommandID());
170 if (!Info->IsRecordLikeDetailCommand || isRecordLikeDecl())
171 return;
172 unsigned DiagSelect;
173 switch (Comment->getCommandID()) {
174 case CommandTraits::KCI_classdesign:
175 DiagSelect = 1;
176 break;
177 case CommandTraits::KCI_coclass:
178 DiagSelect = 2;
179 break;
180 case CommandTraits::KCI_dependency:
181 DiagSelect = 3;
182 break;
183 case CommandTraits::KCI_helper:
184 DiagSelect = 4;
185 break;
186 case CommandTraits::KCI_helperclass:
187 DiagSelect = 5;
188 break;
189 case CommandTraits::KCI_helps:
190 DiagSelect = 6;
191 break;
192 case CommandTraits::KCI_instancesize:
193 DiagSelect = 7;
194 break;
195 case CommandTraits::KCI_ownership:
196 DiagSelect = 8;
197 break;
198 case CommandTraits::KCI_performance:
199 DiagSelect = 9;
200 break;
201 case CommandTraits::KCI_security:
202 DiagSelect = 10;
203 break;
204 case CommandTraits::KCI_superclass:
205 DiagSelect = 11;
206 break;
207 default:
208 DiagSelect = 0;
209 break;
210 }
211 if (DiagSelect)
212 Diag(Comment->getLocation(), diag::warn_doc_container_decl_mismatch)
213 << Comment->getCommandMarker()
214 << (DiagSelect-1)
215 << Comment->getSourceRange();
216 }
217
218 /// Turn a string into the corresponding PassDirection or -1 if it's not
219 /// valid.
220 static int getParamPassDirection(StringRef Arg) {
221 return llvm::StringSwitch<int>(Arg)
222 .Case("[in]", ParamCommandComment::In)
223 .Case("[out]", ParamCommandComment::Out)
224 .Cases("[in,out]", "[out,in]", ParamCommandComment::InOut)
225 .Default(-1);
226 }
227
228 void Sema::actOnParamCommandDirectionArg(ParamCommandComment *Command,
229 SourceLocation ArgLocBegin,
230 SourceLocation ArgLocEnd,
231 StringRef Arg) {
232 std::string ArgLower = Arg.lower();
233 int Direction = getParamPassDirection(ArgLower);
234
235 if (Direction == -1) {
236 // Try again with whitespace removed.
237 ArgLower.erase(
238 std::remove_if(ArgLower.begin(), ArgLower.end(), clang::isWhitespace),
239 ArgLower.end());
240 Direction = getParamPassDirection(ArgLower);
241
242 SourceRange ArgRange(ArgLocBegin, ArgLocEnd);
243 if (Direction != -1) {
244 const char *FixedName = ParamCommandComment::getDirectionAsString(
245 (ParamCommandComment::PassDirection)Direction);
246 Diag(ArgLocBegin, diag::warn_doc_param_spaces_in_direction)
247 << ArgRange << FixItHint::CreateReplacement(ArgRange, FixedName);
248 } else {
249 Diag(ArgLocBegin, diag::warn_doc_param_invalid_direction) << ArgRange;
250 Direction = ParamCommandComment::In; // Sane fall back.
251 }
252 }
253 Command->setDirection((ParamCommandComment::PassDirection)Direction,
254 /*Explicit=*/true);
255 }
256
257 void Sema::actOnParamCommandParamNameArg(ParamCommandComment *Command,
258 SourceLocation ArgLocBegin,
259 SourceLocation ArgLocEnd,
260 StringRef Arg) {
261 // Parser will not feed us more arguments than needed.
262 assert(Command->getNumArgs() == 0);
263
264 if (!Command->isDirectionExplicit()) {
265 // User didn't provide a direction argument.
266 Command->setDirection(ParamCommandComment::In, /* Explicit = */ false);
267 }
268 typedef BlockCommandComment::Argument Argument;
269 Argument *A = new (Allocator) Argument(SourceRange(ArgLocBegin,
270 ArgLocEnd),
271 Arg);
272 Command->setArgs(llvm::makeArrayRef(A, 1));
273 }
274
275 void Sema::actOnParamCommandFinish(ParamCommandComment *Command,
276 ParagraphComment *Paragraph) {
277 Command->setParagraph(Paragraph);
278 checkBlockCommandEmptyParagraph(Command);
279 }
280
281 TParamCommandComment *Sema::actOnTParamCommandStart(
282 SourceLocation LocBegin,
283 SourceLocation LocEnd,
284 unsigned CommandID,
285 CommandMarkerKind CommandMarker) {
286 TParamCommandComment *Command =
287 new (Allocator) TParamCommandComment(LocBegin, LocEnd, CommandID,
288 CommandMarker);
289
290 if (!isTemplateOrSpecialization())
291 Diag(Command->getLocation(),
292 diag::warn_doc_tparam_not_attached_to_a_template_decl)
293 << CommandMarker
294 << Command->getCommandNameRange(Traits);
295
296 return Command;
297 }
298
299 void Sema::actOnTParamCommandParamNameArg(TParamCommandComment *Command,
300 SourceLocation ArgLocBegin,
301 SourceLocation ArgLocEnd,
302 StringRef Arg) {
303 // Parser will not feed us more arguments than needed.
304 assert(Command->getNumArgs() == 0);
305
306 typedef BlockCommandComment::Argument Argument;
307 Argument *A = new (Allocator) Argument(SourceRange(ArgLocBegin,
308 ArgLocEnd),
309 Arg);
310 Command->setArgs(llvm::makeArrayRef(A, 1));
311
312 if (!isTemplateOrSpecialization()) {
313 // We already warned that this \\tparam is not attached to a template decl.
314 return;
315 }
316
317 const TemplateParameterList *TemplateParameters =
318 ThisDeclInfo->TemplateParameters;
319 SmallVector<unsigned, 2> Position;
320 if (resolveTParamReference(Arg, TemplateParameters, &Position)) {
321 Command->setPosition(copyArray(llvm::makeArrayRef(Position)));
322 TParamCommandComment *&PrevCommand = TemplateParameterDocs[Arg];
323 if (PrevCommand) {
324 SourceRange ArgRange(ArgLocBegin, ArgLocEnd);
325 Diag(ArgLocBegin, diag::warn_doc_tparam_duplicate)
326 << Arg << ArgRange;
327 Diag(PrevCommand->getLocation(), diag::note_doc_tparam_previous)
328 << PrevCommand->getParamNameRange();
329 }
330 PrevCommand = Command;
331 return;
332 }
333
334 SourceRange ArgRange(ArgLocBegin, ArgLocEnd);
335 Diag(ArgLocBegin, diag::warn_doc_tparam_not_found)
336 << Arg << ArgRange;
337
338 if (!TemplateParameters || TemplateParameters->size() == 0)
339 return;
340
341 StringRef CorrectedName;
342 if (TemplateParameters->size() == 1) {
343 const NamedDecl *Param = TemplateParameters->getParam(0);
344 const IdentifierInfo *II = Param->getIdentifier();
345 if (II)
346 CorrectedName = II->getName();
347 } else {
348 CorrectedName = correctTypoInTParamReference(Arg, TemplateParameters);
349 }
350
351 if (!CorrectedName.empty()) {
352 Diag(ArgLocBegin, diag::note_doc_tparam_name_suggestion)
353 << CorrectedName
354 << FixItHint::CreateReplacement(ArgRange, CorrectedName);
355 }
356 }
357
358 void Sema::actOnTParamCommandFinish(TParamCommandComment *Command,
359 ParagraphComment *Paragraph) {
360 Command->setParagraph(Paragraph);
361 checkBlockCommandEmptyParagraph(Command);
362 }
363
364 InlineCommandComment *Sema::actOnInlineCommand(SourceLocation CommandLocBegin,
365 SourceLocation CommandLocEnd,
366 unsigned CommandID) {
367 ArrayRef<InlineCommandComment::Argument> Args;
368 StringRef CommandName = Traits.getCommandInfo(CommandID)->Name;
369 return new (Allocator) InlineCommandComment(
370 CommandLocBegin,
371 CommandLocEnd,
372 CommandID,
373 getInlineCommandRenderKind(CommandName),
374 Args);
375 }
376
377 InlineCommandComment *Sema::actOnInlineCommand(SourceLocation CommandLocBegin,
378 SourceLocation CommandLocEnd,
379 unsigned CommandID,
380 SourceLocation ArgLocBegin,
381 SourceLocation ArgLocEnd,
382 StringRef Arg) {
383 typedef InlineCommandComment::Argument Argument;
384 Argument *A = new (Allocator) Argument(SourceRange(ArgLocBegin,
385 ArgLocEnd),
386 Arg);
387 StringRef CommandName = Traits.getCommandInfo(CommandID)->Name;
388
389 return new (Allocator) InlineCommandComment(
390 CommandLocBegin,
391 CommandLocEnd,
392 CommandID,
393 getInlineCommandRenderKind(CommandName),
394 llvm::makeArrayRef(A, 1));
395 }
396
397 InlineContentComment *Sema::actOnUnknownCommand(SourceLocation LocBegin,
398 SourceLocation LocEnd,
399 StringRef CommandName) {
400 unsigned CommandID = Traits.registerUnknownCommand(CommandName)->getID();
401 return actOnUnknownCommand(LocBegin, LocEnd, CommandID);
402 }
403
404 InlineContentComment *Sema::actOnUnknownCommand(SourceLocation LocBegin,
405 SourceLocation LocEnd,
406 unsigned CommandID) {
407 ArrayRef<InlineCommandComment::Argument> Args;
408 return new (Allocator) InlineCommandComment(
409 LocBegin, LocEnd, CommandID,
410 InlineCommandComment::RenderNormal,
411 Args);
412 }
413
414 TextComment *Sema::actOnText(SourceLocation LocBegin,
415 SourceLocation LocEnd,
416 StringRef Text) {
417 return new (Allocator) TextComment(LocBegin, LocEnd, Text);
418 }
419
420 VerbatimBlockComment *Sema::actOnVerbatimBlockStart(SourceLocation Loc,
421 unsigned CommandID) {
422 StringRef CommandName = Traits.getCommandInfo(CommandID)->Name;
423 return new (Allocator) VerbatimBlockComment(
424 Loc,
425 Loc.getLocWithOffset(1 + CommandName.size()),
426 CommandID);
427 }
428
429 VerbatimBlockLineComment *Sema::actOnVerbatimBlockLine(SourceLocation Loc,
430 StringRef Text) {
431 return new (Allocator) VerbatimBlockLineComment(Loc, Text);
432 }
433
434 void Sema::actOnVerbatimBlockFinish(
435 VerbatimBlockComment *Block,
436 SourceLocation CloseNameLocBegin,
437 StringRef CloseName,
438 ArrayRef<VerbatimBlockLineComment *> Lines) {
439 Block->setCloseName(CloseName, CloseNameLocBegin);
440 Block->setLines(Lines);
441 }
442
443 VerbatimLineComment *Sema::actOnVerbatimLine(SourceLocation LocBegin,
444 unsigned CommandID,
445 SourceLocation TextBegin,
446 StringRef Text) {
447 VerbatimLineComment *VL = new (Allocator) VerbatimLineComment(
448 LocBegin,
449 TextBegin.getLocWithOffset(Text.size()),
450 CommandID,
451 TextBegin,
452 Text);
453 checkFunctionDeclVerbatimLine(VL);
454 checkContainerDeclVerbatimLine(VL);
455 return VL;
456 }
457
458 HTMLStartTagComment *Sema::actOnHTMLStartTagStart(SourceLocation LocBegin,
459 StringRef TagName) {
460 return new (Allocator) HTMLStartTagComment(LocBegin, TagName);
461 }
462
463 void Sema::actOnHTMLStartTagFinish(
464 HTMLStartTagComment *Tag,
465 ArrayRef<HTMLStartTagComment::Attribute> Attrs,
466 SourceLocation GreaterLoc,
467 bool IsSelfClosing) {
468 Tag->setAttrs(Attrs);
469 Tag->setGreaterLoc(GreaterLoc);
470 if (IsSelfClosing)
471 Tag->setSelfClosing();
472 else if (!isHTMLEndTagForbidden(Tag->getTagName()))
473 HTMLOpenTags.push_back(Tag);
474 }
475
476 HTMLEndTagComment *Sema::actOnHTMLEndTag(SourceLocation LocBegin,
477 SourceLocation LocEnd,
478 StringRef TagName) {
479 HTMLEndTagComment *HET =
480 new (Allocator) HTMLEndTagComment(LocBegin, LocEnd, TagName);
481 if (isHTMLEndTagForbidden(TagName)) {
482 Diag(HET->getLocation(), diag::warn_doc_html_end_forbidden)
483 << TagName << HET->getSourceRange();
484 HET->setIsMalformed();
485 return HET;
486 }
487
488 bool FoundOpen = false;
489 for (SmallVectorImpl<HTMLStartTagComment *>::const_reverse_iterator
490 I = HTMLOpenTags.rbegin(), E = HTMLOpenTags.rend();
491 I != E; ++I) {
492 if ((*I)->getTagName() == TagName) {
493 FoundOpen = true;
494 break;
495 }
496 }
497 if (!FoundOpen) {
498 Diag(HET->getLocation(), diag::warn_doc_html_end_unbalanced)
499 << HET->getSourceRange();
500 HET->setIsMalformed();
501 return HET;
502 }
503
504 while (!HTMLOpenTags.empty()) {
505 HTMLStartTagComment *HST = HTMLOpenTags.pop_back_val();
506 StringRef LastNotClosedTagName = HST->getTagName();
507 if (LastNotClosedTagName == TagName) {
508 // If the start tag is malformed, end tag is malformed as well.
509 if (HST->isMalformed())
510 HET->setIsMalformed();
511 break;
512 }
513
514 if (isHTMLEndTagOptional(LastNotClosedTagName))
515 continue;
516
517 bool OpenLineInvalid;
518 const unsigned OpenLine = SourceMgr.getPresumedLineNumber(
519 HST->getLocation(),
520 &OpenLineInvalid);
521 bool CloseLineInvalid;
522 const unsigned CloseLine = SourceMgr.getPresumedLineNumber(
523 HET->getLocation(),
524 &CloseLineInvalid);
525
526 if (OpenLineInvalid || CloseLineInvalid || OpenLine == CloseLine) {
527 Diag(HST->getLocation(), diag::warn_doc_html_start_end_mismatch)
528 << HST->getTagName() << HET->getTagName()
529 << HST->getSourceRange() << HET->getSourceRange();
530 HST->setIsMalformed();
531 } else {
532 Diag(HST->getLocation(), diag::warn_doc_html_start_end_mismatch)
533 << HST->getTagName() << HET->getTagName()
534 << HST->getSourceRange();
535 Diag(HET->getLocation(), diag::note_doc_html_end_tag)
536 << HET->getSourceRange();
537 HST->setIsMalformed();
538 }
539 }
540
541 return HET;
542 }
543
544 FullComment *Sema::actOnFullComment(
545 ArrayRef<BlockContentComment *> Blocks) {
546 FullComment *FC = new (Allocator) FullComment(Blocks, ThisDeclInfo);
547 resolveParamCommandIndexes(FC);
548
549 // Complain about HTML tags that are not closed.
550 while (!HTMLOpenTags.empty()) {
551 HTMLStartTagComment *HST = HTMLOpenTags.pop_back_val();
552 if (isHTMLEndTagOptional(HST->getTagName()))
553 continue;
554
555 Diag(HST->getLocation(), diag::warn_doc_html_missing_end_tag)
556 << HST->getTagName() << HST->getSourceRange();
557 HST->setIsMalformed();
558 }
559
560 return FC;
561 }
562
563 void Sema::checkBlockCommandEmptyParagraph(BlockCommandComment *Command) {
564 if (Traits.getCommandInfo(Command->getCommandID())->IsEmptyParagraphAllowed)
565 return;
566
567 ParagraphComment *Paragraph = Command->getParagraph();
568 if (Paragraph->isWhitespace()) {
569 SourceLocation DiagLoc;
570 if (Command->getNumArgs() > 0)
571 DiagLoc = Command->getArgRange(Command->getNumArgs() - 1).getEnd();
572 if (!DiagLoc.isValid())
573 DiagLoc = Command->getCommandNameRange(Traits).getEnd();
574 Diag(DiagLoc, diag::warn_doc_block_command_empty_paragraph)
575 << Command->getCommandMarker()
576 << Command->getCommandName(Traits)
577 << Command->getSourceRange();
578 }
579 }
580
581 void Sema::checkReturnsCommand(const BlockCommandComment *Command) {
582 if (!Traits.getCommandInfo(Command->getCommandID())->IsReturnsCommand)
583 return;
584
585 assert(ThisDeclInfo && "should not call this check on a bare comment");
586
587 // We allow the return command for all @properties because it can be used
588 // to document the value that the property getter returns.
589 if (isObjCPropertyDecl())
590 return;
591 if (isFunctionDecl() || isFunctionOrBlockPointerVarLikeDecl()) {
592 if (ThisDeclInfo->ReturnType->isVoidType()) {
593 unsigned DiagKind;
594 switch (ThisDeclInfo->CommentDecl->getKind()) {
595 default:
596 if (ThisDeclInfo->IsObjCMethod)
597 DiagKind = 3;
598 else
599 DiagKind = 0;
600 break;
601 case Decl::CXXConstructor:
602 DiagKind = 1;
603 break;
604 case Decl::CXXDestructor:
605 DiagKind = 2;
606 break;
607 }
608 Diag(Command->getLocation(),
609 diag::warn_doc_returns_attached_to_a_void_function)
610 << Command->getCommandMarker()
611 << Command->getCommandName(Traits)
612 << DiagKind
613 << Command->getSourceRange();
614 }
615 return;
616 }
617
618 Diag(Command->getLocation(),
619 diag::warn_doc_returns_not_attached_to_a_function_decl)
620 << Command->getCommandMarker()
621 << Command->getCommandName(Traits)
622 << Command->getSourceRange();
623 }
624
625 void Sema::checkBlockCommandDuplicate(const BlockCommandComment *Command) {
626 const CommandInfo *Info = Traits.getCommandInfo(Command->getCommandID());
627 const BlockCommandComment *PrevCommand = nullptr;
628 if (Info->IsBriefCommand) {
629 if (!BriefCommand) {
630 BriefCommand = Command;
631 return;
632 }
633 PrevCommand = BriefCommand;
634 } else if (Info->IsHeaderfileCommand) {
635 if (!HeaderfileCommand) {
636 HeaderfileCommand = Command;
637 return;
638 }
639 PrevCommand = HeaderfileCommand;
640 } else {
641 // We don't want to check this command for duplicates.
642 return;
643 }
644 StringRef CommandName = Command->getCommandName(Traits);
645 StringRef PrevCommandName = PrevCommand->getCommandName(Traits);
646 Diag(Command->getLocation(), diag::warn_doc_block_command_duplicate)
647 << Command->getCommandMarker()
648 << CommandName
649 << Command->getSourceRange();
650 if (CommandName == PrevCommandName)
651 Diag(PrevCommand->getLocation(), diag::note_doc_block_command_previous)
652 << PrevCommand->getCommandMarker()
653 << PrevCommandName
654 << PrevCommand->getSourceRange();
655 else
656 Diag(PrevCommand->getLocation(),
657 diag::note_doc_block_command_previous_alias)
658 << PrevCommand->getCommandMarker()
659 << PrevCommandName
660 << CommandName;
661 }
662
663 void Sema::checkDeprecatedCommand(const BlockCommandComment *Command) {
664 if (!Traits.getCommandInfo(Command->getCommandID())->IsDeprecatedCommand)
665 return;
666
667 assert(ThisDeclInfo && "should not call this check on a bare comment");
668
669 const Decl *D = ThisDeclInfo->CommentDecl;
670 if (!D)
671 return;
672
673 if (D->hasAttr<DeprecatedAttr>() ||
674 D->hasAttr<AvailabilityAttr>() ||
675 D->hasAttr<UnavailableAttr>())
676 return;
677
678 Diag(Command->getLocation(),
679 diag::warn_doc_deprecated_not_sync)
680 << Command->getSourceRange();
681
682 // Try to emit a fixit with a deprecation attribute.
683 if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
684 // Don't emit a Fix-It for non-member function definitions. GCC does not
685 // accept attributes on them.
686 const DeclContext *Ctx = FD->getDeclContext();
687 if ((!Ctx || !Ctx->isRecord()) &&
688 FD->doesThisDeclarationHaveABody())
689 return;
690
691 StringRef AttributeSpelling = "__attribute__((deprecated))";
692 if (PP) {
693 TokenValue Tokens[] = {
694 tok::kw___attribute, tok::l_paren, tok::l_paren,
695 PP->getIdentifierInfo("deprecated"),
696 tok::r_paren, tok::r_paren
697 };
698 StringRef MacroName = PP->getLastMacroWithSpelling(FD->getLocation(),
699 Tokens);
700 if (!MacroName.empty())
701 AttributeSpelling = MacroName;
702 }
703
704 SmallString<64> TextToInsert(" ");
705 TextToInsert += AttributeSpelling;
706 Diag(FD->getEndLoc(), diag::note_add_deprecation_attr)
707 << FixItHint::CreateInsertion(FD->getEndLoc().getLocWithOffset(1),
708 TextToInsert);
709 }
710 }
711
712 void Sema::resolveParamCommandIndexes(const FullComment *FC) {
713 if (!isFunctionDecl()) {
714 // We already warned that \\param commands are not attached to a function
715 // decl.
716 return;
717 }
718
719 SmallVector<ParamCommandComment *, 8> UnresolvedParamCommands;
720
721 // Comment AST nodes that correspond to \c ParamVars for which we have
722 // found a \\param command or NULL if no documentation was found so far.
723 SmallVector<ParamCommandComment *, 8> ParamVarDocs;
724
725 ArrayRef<const ParmVarDecl *> ParamVars = getParamVars();
726 ParamVarDocs.resize(ParamVars.size(), nullptr);
727
728 // First pass over all \\param commands: resolve all parameter names.
729 for (Comment::child_iterator I = FC->child_begin(), E = FC->child_end();
730 I != E; ++I) {
731 ParamCommandComment *PCC = dyn_cast<ParamCommandComment>(*I);
732 if (!PCC || !PCC->hasParamName())
733 continue;
734 StringRef ParamName = PCC->getParamNameAsWritten();
735
736 // Check that referenced parameter name is in the function decl.
737 const unsigned ResolvedParamIndex = resolveParmVarReference(ParamName,
738 ParamVars);
739 if (ResolvedParamIndex == ParamCommandComment::VarArgParamIndex) {
740 PCC->setIsVarArgParam();
741 continue;
742 }
743 if (ResolvedParamIndex == ParamCommandComment::InvalidParamIndex) {
744 UnresolvedParamCommands.push_back(PCC);
745 continue;
746 }
747 PCC->setParamIndex(ResolvedParamIndex);
748 if (ParamVarDocs[ResolvedParamIndex]) {
749 SourceRange ArgRange = PCC->getParamNameRange();
750 Diag(ArgRange.getBegin(), diag::warn_doc_param_duplicate)
751 << ParamName << ArgRange;
752 ParamCommandComment *PrevCommand = ParamVarDocs[ResolvedParamIndex];
753 Diag(PrevCommand->getLocation(), diag::note_doc_param_previous)
754 << PrevCommand->getParamNameRange();
755 }
756 ParamVarDocs[ResolvedParamIndex] = PCC;
757 }
758
759 // Find parameter declarations that have no corresponding \\param.
760 SmallVector<const ParmVarDecl *, 8> OrphanedParamDecls;
761 for (unsigned i = 0, e = ParamVarDocs.size(); i != e; ++i) {
762 if (!ParamVarDocs[i])
763 OrphanedParamDecls.push_back(ParamVars[i]);
764 }
765
766 // Second pass over unresolved \\param commands: do typo correction.
767 // Suggest corrections from a set of parameter declarations that have no
768 // corresponding \\param.
769 for (unsigned i = 0, e = UnresolvedParamCommands.size(); i != e; ++i) {
770 const ParamCommandComment *PCC = UnresolvedParamCommands[i];
771
772 SourceRange ArgRange = PCC->getParamNameRange();
773 StringRef ParamName = PCC->getParamNameAsWritten();
774 Diag(ArgRange.getBegin(), diag::warn_doc_param_not_found)
775 << ParamName << ArgRange;
776
777 // All parameters documented -- can't suggest a correction.
778 if (OrphanedParamDecls.size() == 0)
779 continue;
780
781 unsigned CorrectedParamIndex = ParamCommandComment::InvalidParamIndex;
782 if (OrphanedParamDecls.size() == 1) {
783 // If one parameter is not documented then that parameter is the only
784 // possible suggestion.
785 CorrectedParamIndex = 0;
786 } else {
787 // Do typo correction.
788 CorrectedParamIndex = correctTypoInParmVarReference(ParamName,
789 OrphanedParamDecls);
790 }
791 if (CorrectedParamIndex != ParamCommandComment::InvalidParamIndex) {
792 const ParmVarDecl *CorrectedPVD = OrphanedParamDecls[CorrectedParamIndex];
793 if (const IdentifierInfo *CorrectedII = CorrectedPVD->getIdentifier())
794 Diag(ArgRange.getBegin(), diag::note_doc_param_name_suggestion)
795 << CorrectedII->getName()
796 << FixItHint::CreateReplacement(ArgRange, CorrectedII->getName());
797 }
798 }
799 }
800
801 bool Sema::isFunctionDecl() {
802 if (!ThisDeclInfo)
803 return false;
804 if (!ThisDeclInfo->IsFilled)
805 inspectThisDecl();
806 return ThisDeclInfo->getKind() == DeclInfo::FunctionKind;
807 }
808
809 bool Sema::isAnyFunctionDecl() {
810 return isFunctionDecl() && ThisDeclInfo->CurrentDecl &&
811 isa<FunctionDecl>(ThisDeclInfo->CurrentDecl);
812 }
813
814 bool Sema::isFunctionOrMethodVariadic() {
815 if (!isFunctionDecl() || !ThisDeclInfo->CurrentDecl)
816 return false;
817 if (const FunctionDecl *FD =
818 dyn_cast<FunctionDecl>(ThisDeclInfo->CurrentDecl))
819 return FD->isVariadic();
820 if (const FunctionTemplateDecl *FTD =
821 dyn_cast<FunctionTemplateDecl>(ThisDeclInfo->CurrentDecl))
822 return FTD->getTemplatedDecl()->isVariadic();
823 if (const ObjCMethodDecl *MD =
824 dyn_cast<ObjCMethodDecl>(ThisDeclInfo->CurrentDecl))
825 return MD->isVariadic();
826 if (const TypedefNameDecl *TD =
827 dyn_cast<TypedefNameDecl>(ThisDeclInfo->CurrentDecl)) {
828 QualType Type = TD->getUnderlyingType();
829 if (Type->isFunctionPointerType() || Type->isBlockPointerType())
830 Type = Type->getPointeeType();
831 if (const auto *FT = Type->getAs<FunctionProtoType>())
832 return FT->isVariadic();
833 }
834 return false;
835 }
836
837 bool Sema::isObjCMethodDecl() {
838 return isFunctionDecl() && ThisDeclInfo->CurrentDecl &&
839 isa<ObjCMethodDecl>(ThisDeclInfo->CurrentDecl);
840 }
841
842 bool Sema::isFunctionPointerVarDecl() {
843 if (!ThisDeclInfo)
844 return false;
845 if (!ThisDeclInfo->IsFilled)
846 inspectThisDecl();
847 if (ThisDeclInfo->getKind() == DeclInfo::VariableKind) {
848 if (const VarDecl *VD = dyn_cast_or_null<VarDecl>(ThisDeclInfo->CurrentDecl)) {
849 QualType QT = VD->getType();
850 return QT->isFunctionPointerType();
851 }
852 }
853 return false;
854 }
855
856 bool Sema::isFunctionOrBlockPointerVarLikeDecl() {
857 if (!ThisDeclInfo)
858 return false;
859 if (!ThisDeclInfo->IsFilled)
860 inspectThisDecl();
861 if (ThisDeclInfo->getKind() != DeclInfo::VariableKind ||
862 !ThisDeclInfo->CurrentDecl)
863 return false;
864 QualType QT;
865 if (const auto *VD = dyn_cast<DeclaratorDecl>(ThisDeclInfo->CurrentDecl))
866 QT = VD->getType();
867 else if (const auto *PD =
868 dyn_cast<ObjCPropertyDecl>(ThisDeclInfo->CurrentDecl))
869 QT = PD->getType();
870 else
871 return false;
872 // We would like to warn about the 'returns'/'param' commands for
873 // variables that don't directly specify the function type, so type aliases
874 // can be ignored.
875 if (QT->getAs<TypedefType>())
876 return false;
877 return QT->isFunctionPointerType() || QT->isBlockPointerType();
878 }
879
880 bool Sema::isObjCPropertyDecl() {
881 if (!ThisDeclInfo)
882 return false;
883 if (!ThisDeclInfo->IsFilled)
884 inspectThisDecl();
885 return ThisDeclInfo->CurrentDecl->getKind() == Decl::ObjCProperty;
886 }
887
888 bool Sema::isTemplateOrSpecialization() {
889 if (!ThisDeclInfo)
890 return false;
891 if (!ThisDeclInfo->IsFilled)
892 inspectThisDecl();
893 return ThisDeclInfo->getTemplateKind() != DeclInfo::NotTemplate;
894 }
895
896 bool Sema::isRecordLikeDecl() {
897 if (!ThisDeclInfo)
898 return false;
899 if (!ThisDeclInfo->IsFilled)
900 inspectThisDecl();
901 return isUnionDecl() || isClassOrStructDecl() || isObjCInterfaceDecl() ||
902 isObjCProtocolDecl();
903 }
904
905 bool Sema::isUnionDecl() {
906 if (!ThisDeclInfo)
907 return false;
908 if (!ThisDeclInfo->IsFilled)
909 inspectThisDecl();
910 if (const RecordDecl *RD =
911 dyn_cast_or_null<RecordDecl>(ThisDeclInfo->CurrentDecl))
912 return RD->isUnion();
913 return false;
914 }
915
916 bool Sema::isClassOrStructDecl() {
917 if (!ThisDeclInfo)
918 return false;
919 if (!ThisDeclInfo->IsFilled)
920 inspectThisDecl();
921 return ThisDeclInfo->CurrentDecl &&
922 isa<RecordDecl>(ThisDeclInfo->CurrentDecl) &&
923 !isUnionDecl();
924 }
925
926 bool Sema::isClassTemplateDecl() {
927 if (!ThisDeclInfo)
928 return false;
929 if (!ThisDeclInfo->IsFilled)
930 inspectThisDecl();
931 return ThisDeclInfo->CurrentDecl &&
932 (isa<ClassTemplateDecl>(ThisDeclInfo->CurrentDecl));
933 }
934
935 bool Sema::isFunctionTemplateDecl() {
936 if (!ThisDeclInfo)
937 return false;
938 if (!ThisDeclInfo->IsFilled)
939 inspectThisDecl();
940 return ThisDeclInfo->CurrentDecl &&
941 (isa<FunctionTemplateDecl>(ThisDeclInfo->CurrentDecl));
942 }
943
944 bool Sema::isObjCInterfaceDecl() {
945 if (!ThisDeclInfo)
946 return false;
947 if (!ThisDeclInfo->IsFilled)
948 inspectThisDecl();
949 return ThisDeclInfo->CurrentDecl &&
950 isa<ObjCInterfaceDecl>(ThisDeclInfo->CurrentDecl);
951 }
952
953 bool Sema::isObjCProtocolDecl() {
954 if (!ThisDeclInfo)
955 return false;
956 if (!ThisDeclInfo->IsFilled)
957 inspectThisDecl();
958 return ThisDeclInfo->CurrentDecl &&
959 isa<ObjCProtocolDecl>(ThisDeclInfo->CurrentDecl);
960 }
961
962 ArrayRef<const ParmVarDecl *> Sema::getParamVars() {
963 if (!ThisDeclInfo->IsFilled)
964 inspectThisDecl();
965 return ThisDeclInfo->ParamVars;
966 }
967
968 void Sema::inspectThisDecl() {
969 ThisDeclInfo->fill();
970 }
971
972 unsigned Sema::resolveParmVarReference(StringRef Name,
973 ArrayRef<const ParmVarDecl *> ParamVars) {
974 for (unsigned i = 0, e = ParamVars.size(); i != e; ++i) {
975 const IdentifierInfo *II = ParamVars[i]->getIdentifier();
976 if (II && II->getName() == Name)
977 return i;
978 }
979 if (Name == "..." && isFunctionOrMethodVariadic())
980 return ParamCommandComment::VarArgParamIndex;
981 return ParamCommandComment::InvalidParamIndex;
982 }
983
984 namespace {
985 class SimpleTypoCorrector {
986 const NamedDecl *BestDecl;
987
988 StringRef Typo;
989 const unsigned MaxEditDistance;
990
991 unsigned BestEditDistance;
992 unsigned BestIndex;
993 unsigned NextIndex;
994
995 public:
996 explicit SimpleTypoCorrector(StringRef Typo)
997 : BestDecl(nullptr), Typo(Typo), MaxEditDistance((Typo.size() + 2) / 3),
998 BestEditDistance(MaxEditDistance + 1), BestIndex(0), NextIndex(0) {}
999
1000 void addDecl(const NamedDecl *ND);
1001
1002 const NamedDecl *getBestDecl() const {
1003 if (BestEditDistance > MaxEditDistance)
1004 return nullptr;
1005
1006 return BestDecl;
1007 }
1008
1009 unsigned getBestDeclIndex() const {
1010 assert(getBestDecl());
1011 return BestIndex;
1012 }
1013 };
1014
1015 void SimpleTypoCorrector::addDecl(const NamedDecl *ND) {
1016 unsigned CurrIndex = NextIndex++;
1017
1018 const IdentifierInfo *II = ND->getIdentifier();
1019 if (!II)
1020 return;
1021
1022 StringRef Name = II->getName();
1023 unsigned MinPossibleEditDistance = abs((int)Name.size() - (int)Typo.size());
1024 if (MinPossibleEditDistance > 0 &&
1025 Typo.size() / MinPossibleEditDistance < 3)
1026 return;
1027
1028 unsigned EditDistance = Typo.edit_distance(Name, true, MaxEditDistance);
1029 if (EditDistance < BestEditDistance) {
1030 BestEditDistance = EditDistance;
1031 BestDecl = ND;
1032 BestIndex = CurrIndex;
1033 }
1034 }
1035 } // end anonymous namespace
1036
1037 unsigned Sema::correctTypoInParmVarReference(
1038 StringRef Typo,
1039 ArrayRef<const ParmVarDecl *> ParamVars) {
1040 SimpleTypoCorrector Corrector(Typo);
1041 for (unsigned i = 0, e = ParamVars.size(); i != e; ++i)
1042 Corrector.addDecl(ParamVars[i]);
1043 if (Corrector.getBestDecl())
1044 return Corrector.getBestDeclIndex();
1045 else
1046 return ParamCommandComment::InvalidParamIndex;
1047 }
1048
1049 namespace {
1050 bool ResolveTParamReferenceHelper(
1051 StringRef Name,
1052 const TemplateParameterList *TemplateParameters,
1053 SmallVectorImpl<unsigned> *Position) {
1054 for (unsigned i = 0, e = TemplateParameters->size(); i != e; ++i) {
1055 const NamedDecl *Param = TemplateParameters->getParam(i);
1056 const IdentifierInfo *II = Param->getIdentifier();
1057 if (II && II->getName() == Name) {
1058 Position->push_back(i);
1059 return true;
1060 }
1061
1062 if (const TemplateTemplateParmDecl *TTP =
1063 dyn_cast<TemplateTemplateParmDecl>(Param)) {
1064 Position->push_back(i);
1065 if (ResolveTParamReferenceHelper(Name, TTP->getTemplateParameters(),
1066 Position))
1067 return true;
1068 Position->pop_back();
1069 }
1070 }
1071 return false;
1072 }
1073 } // end anonymous namespace
1074
1075 bool Sema::resolveTParamReference(
1076 StringRef Name,
1077 const TemplateParameterList *TemplateParameters,
1078 SmallVectorImpl<unsigned> *Position) {
1079 Position->clear();
1080 if (!TemplateParameters)
1081 return false;
1082
1083 return ResolveTParamReferenceHelper(Name, TemplateParameters, Position);
1084 }
1085
1086 namespace {
1087 void CorrectTypoInTParamReferenceHelper(
1088 const TemplateParameterList *TemplateParameters,
1089 SimpleTypoCorrector &Corrector) {
1090 for (unsigned i = 0, e = TemplateParameters->size(); i != e; ++i) {
1091 const NamedDecl *Param = TemplateParameters->getParam(i);
1092 Corrector.addDecl(Param);
1093
1094 if (const TemplateTemplateParmDecl *TTP =
1095 dyn_cast<TemplateTemplateParmDecl>(Param))
1096 CorrectTypoInTParamReferenceHelper(TTP->getTemplateParameters(),
1097 Corrector);
1098 }
1099 }
1100 } // end anonymous namespace
1101
1102 StringRef Sema::correctTypoInTParamReference(
1103 StringRef Typo,
1104 const TemplateParameterList *TemplateParameters) {
1105 SimpleTypoCorrector Corrector(Typo);
1106 CorrectTypoInTParamReferenceHelper(TemplateParameters, Corrector);
1107 if (const NamedDecl *ND = Corrector.getBestDecl()) {
1108 const IdentifierInfo *II = ND->getIdentifier();
1109 assert(II && "SimpleTypoCorrector should not return this decl");
1110 return II->getName();
1111 }
1112 return StringRef();
1113 }
1114
1115 InlineCommandComment::RenderKind
1116 Sema::getInlineCommandRenderKind(StringRef Name) const {
1117 assert(Traits.getCommandInfo(Name)->IsInlineCommand);
1118
1119 return llvm::StringSwitch<InlineCommandComment::RenderKind>(Name)
1120 .Case("b", InlineCommandComment::RenderBold)
1121 .Cases("c", "p", InlineCommandComment::RenderMonospaced)
1122 .Cases("a", "e", "em", InlineCommandComment::RenderEmphasized)
1123 .Default(InlineCommandComment::RenderNormal);
1124 }
1125
1126 } // end namespace comments
1127 } // end namespace clang
clang::comments::Sema::actOnParamCommandFinish
void actOnParamCommandFinish(ParamCommandComment *Command, ParagraphComment *Paragraph)
Definition: CommentSema.cpp:275
clang::comments::ParamCommandComment::setDirection
void setDirection(PassDirection Direction, bool Explicit)
Definition: Comment.h:754
clang::comments::ParamCommandComment::hasParamName
bool hasParamName() const
Definition: Comment.h:759
clang::comments::Sema::correctTypoInTParamReference
StringRef correctTypoInTParamReference(StringRef Typo, const TemplateParameterList *TemplateParameters)
Definition: CommentSema.cpp:1102
clang::FunctionDecl
Represents a function declaration or definition.
Definition: Decl.h:1738
clang::comments::CommandInfo::IsRecordLikeDeclarationCommand
unsigned IsRecordLikeDeclarationCommand
True if block command is a container API; such as @interface.
Definition: CommentCommandTraits.h:119
clang::comments::DeclInfo::CommentDecl
const Decl * CommentDecl
Declaration the comment is actually attached to (in the source).
Definition: Comment.h:984
clang::SourceLocation::getLocWithOffset
SourceLocation getLocWithOffset(int Offset) const
Return a source location with the specified offset from this SourceLocation.
Definition: SourceLocation.h:134
clang::QualType
A (possibly-)qualified type.
Definition: Type.h:638
clang::comments::ParamCommandComment::VarArgParamIndex
Definition: Comment.h:720
clang::Type::isBlockPointerType
bool isBlockPointerType() const
Definition: Type.h:6304
clang::comments::Sema::getParamVars
ArrayRef< const ParmVarDecl * > getParamVars()
Definition: CommentSema.cpp:962
clang::comments::BlockCommandComment::getCommandID
unsigned getCommandID() const
Definition: Comment.h:651
clang::comments::InlineCommandComment::RenderEmphasized
Definition: Comment.h:314
clang::Preprocessor::getIdentifierInfo
IdentifierInfo * getIdentifierInfo(StringRef Name) const
Return information about the specified preprocessor identifier token.
Definition: Preprocessor.h:1066
clang::comments::VerbatimBlockComment::setLines
void setLines(ArrayRef< VerbatimBlockLineComment *> L)
Definition: Comment.h:924
clang::comments::DeclInfo::NotTemplate
Definition: Comment.h:1052
clang::comments::Sema::isClassTemplateDecl
bool isClassTemplateDecl()
Definition: CommentSema.cpp:926
clang::comments::Sema::isFunctionTemplateDecl
bool isFunctionTemplateDecl()
Definition: CommentSema.cpp:935
clang::comments::Sema::checkBlockCommandEmptyParagraph
void checkBlockCommandEmptyParagraph(BlockCommandComment *Command)
Definition: CommentSema.cpp:563
clang::comments::Sema::actOnHTMLStartTagFinish
void actOnHTMLStartTagFinish(HTMLStartTagComment *Tag, ArrayRef< HTMLStartTagComment::Attribute > Attrs, SourceLocation GreaterLoc, bool IsSelfClosing)
Definition: CommentSema.cpp:463
clang::comments::DeclInfo::IsObjCMethod
unsigned IsObjCMethod
Is CommentDecl an ObjCMethodDecl.
Definition: Comment.h:1068
clang::Type::getPointeeType
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee...
Definition: Type.cpp:505
SourceManager.h
Defines the SourceManager interface.
clang::comments::Sema::isFunctionOrMethodVariadic
bool isFunctionOrMethodVariadic()
Definition: CommentSema.cpp:814
clang::Decl
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:87
abs
__DEVICE__ long long abs(long long __n)
Definition: __clang_cuda_cmath.h:49
DeclTemplate.h
Defines the C++ template declaration subclasses.
clang::comments::Comment::getLocation
SourceLocation getLocation() const LLVM_READONLY
Definition: Comment.h:222
clang::comments::Sema::actOnParagraphComment
ParagraphComment * actOnParagraphComment(ArrayRef< InlineContentComment *> Content)
Definition: CommentSema.cpp:45
clang::Type
The base class of the type hierarchy.
Definition: Type.h:1407
clang::comments::Sema::isClassOrStructDecl
bool isClassOrStructDecl()
Definition: CommentSema.cpp:916
clang::comments::Sema::actOnVerbatimBlockStart
VerbatimBlockComment * actOnVerbatimBlockStart(SourceLocation Loc, unsigned CommandID)
Definition: CommentSema.cpp:420
clang::Preprocessor::getLastMacroWithSpelling
StringRef getLastMacroWithSpelling(SourceLocation Loc, ArrayRef< TokenValue > Tokens) const
Return the name of the macro defined before Loc that has spelling Tokens.
Definition: Preprocessor.cpp:345
clang::TemplateParameterList::getParam
NamedDecl * getParam(unsigned Idx)
Definition: DeclTemplate.h:133
clang::comments::Sema::correctTypoInParmVarReference
unsigned correctTypoInParmVarReference(StringRef Typo, ArrayRef< const ParmVarDecl *> ParamVars)
Returns index of a function parameter with the name closest to a given typo.
Definition: CommentSema.cpp:1037
clang::comments::Sema::actOnHTMLStartTagStart
HTMLStartTagComment * actOnHTMLStartTagStart(SourceLocation LocBegin, StringRef TagName)
Definition: CommentSema.cpp:458
clang::VarDecl
Represents a variable declaration or definition.
Definition: Decl.h:813
clang::comments::Sema::actOnBlockCommandArgs
void actOnBlockCommandArgs(BlockCommandComment *Command, ArrayRef< BlockCommandComment::Argument > Args)
Definition: CommentSema.cpp:62
clang::Type::getAs
const T * getAs() const
Member-template getAs<specific type>&#39;.
Definition: Type.h:6748
clang::ObjCMethodDecl
ObjCMethodDecl - Represents an instance or class method declaration.
Definition: DeclObjC.h:139
clang::comments::Sema::checkContainerDeclVerbatimLine
void checkContainerDeclVerbatimLine(const BlockCommandComment *Comment)
Definition: CommentSema.cpp:131
clang::TemplateParameterList
Stores a list of template parameters for a TemplateDecl and its derived classes.
Definition: DeclTemplate.h:68
clang::comments::DeclInfo::VariableKind
Something that we consider a "variable":
Definition: Comment.h:1037
clang::comments::DeclInfo::FunctionKind
Something that we consider a "function":
Definition: Comment.h:1025
clang::ParmVarDecl
Represents a parameter to a function.
Definition: Decl.h:1550
clang::comments::Sema::checkBlockCommandDuplicate
void checkBlockCommandDuplicate(const BlockCommandComment *Command)
Emit diagnostics about duplicate block commands that should be used only once per comment...
Definition: CommentSema.cpp:625
clang::comments::CommandInfo
Information about a single command.
Definition: CommentCommandTraits.h:33
clang::NamedDecl::getIdentifier
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
Definition: Decl.h:270
clang::comments::BlockCommandComment::getParagraph
ParagraphComment * getParagraph() const LLVM_READONLY
Definition: Comment.h:690
clang::RecordDecl
Represents a struct/union/class.
Definition: Decl.h:3593
clang::comments::BlockCommandComment::getCommandName
StringRef getCommandName(const CommandTraits &Traits) const
Definition: Comment.h:655
clang::IdentifierInfo
One of these records is kept for each identifier that is lexed.
Definition: IdentifierTable.h:58
clang::comments::FullComment::child_end
child_iterator child_end() const
Definition: Comment.h:1116
clang::comments::Sema::actOnVerbatimBlockFinish
void actOnVerbatimBlockFinish(VerbatimBlockComment *Block, SourceLocation CloseNameLocBegin, StringRef CloseName, ArrayRef< VerbatimBlockLineComment *> Lines)
Definition: CommentSema.cpp:434
clang::comments::InlineCommandComment::RenderBold
Definition: Comment.h:312
clang::comments::DeclInfo::CurrentDecl
const Decl * CurrentDecl
CurrentDecl is the declaration with which the FullComment is associated.
Definition: Comment.h:994
clang::comments::DeclInfo::IsFilled
unsigned IsFilled
If false, only CommentDecl is valid.
Definition: Comment.h:1059
clang::comments::ParamCommandComment::PassDirection
PassDirection
Definition: Comment.h:738
llvm::SmallVectorImpl
Definition: LLVM.h:37
clang::comments::TParamCommandComment::getParamNameRange
SourceRange getParamNameRange() const
Definition: Comment.h:839
clang::comments::Sema::actOnText
TextComment * actOnText(SourceLocation LocBegin, SourceLocation LocEnd, StringRef Text)
Definition: CommentSema.cpp:414
clang::comments::InlineCommandComment
A command with word-like arguments that is considered inline content.
Definition: Comment.h:299
clang::comments::VerbatimBlockLineComment
A line of text contained in a verbatim block.
Definition: Comment.h:864
clang::isWhitespace
LLVM_READONLY bool isWhitespace(unsigned char c)
Return true if this character is horizontal or vertical ASCII whitespace: &#39; &#39;, &#39;\t&#39;, &#39;\f&#39;, &#39;\v&#39;, &#39;\n&#39;, &#39;\r&#39;.
Definition: CharInfo.h:88
clang::comments::TextComment
Plain text.
Definition: Comment.h:263
clang::comments::VerbatimLineComment
A verbatim line command.
Definition: Comment.h:944
clang::comments::HTMLStartTagComment::setSelfClosing
void setSelfClosing()
Definition: Comment.h:502
clang::comments::Sema::checkReturnsCommand
void checkReturnsCommand(const BlockCommandComment *Command)
Definition: CommentSema.cpp:581
clang::comments::Sema::isFunctionPointerVarDecl
bool isFunctionPointerVarDecl()
Definition: CommentSema.cpp:842
clang::DiagnosticsEngine
Concrete class used by the front-end to report problems and issues.
Definition: Diagnostic.h:149
CommentCommandTraits.h
clang::comments::Sema::actOnUnknownCommand
InlineContentComment * actOnUnknownCommand(SourceLocation LocBegin, SourceLocation LocEnd, StringRef CommandName)
Definition: CommentSema.cpp:397
clang::comments::Sema::actOnFullComment
FullComment * actOnFullComment(ArrayRef< BlockContentComment *> Blocks)
Definition: CommentSema.cpp:544
clang::comments::Comment
Any part of the comment.
Definition: Comment.h:53
clang::comments::InlineContentComment
Inline content (contained within a block).
Definition: Comment.h:238
clang::comments::CommandInfo::getID
unsigned getID() const
Definition: CommentCommandTraits.h:34
clang::comments::ParamCommandComment::In
Definition: Comment.h:739
llvm::ArrayRef
Definition: LLVM.h:32
clang::comments::InlineCommandComment::RenderKind
RenderKind
The most appropriate rendering mode for this command, chosen on command semantics in Doxygen...
Definition: Comment.h:310
llvm::SmallString
Definition: LLVM.h:35
clang::comments::Sema::isObjCPropertyDecl
bool isObjCPropertyDecl()
Definition: CommentSema.cpp:880
clang::comments::Sema::copyArray
ArrayRef< T > copyArray(ArrayRef< T > Source)
Returns a copy of array, owned by Sema&#39;s allocator.
Definition: CommentSema.h:81
clang::comments::HTMLTagComment::setIsMalformed
void setIsMalformed()
Definition: Comment.h:408
CommentSema.h
clang::comments::CommandInfo::Name
const char * Name
Definition: CommentCommandTraits.h:38
clang::comments::VerbatimBlockComment
A verbatim block command (e.
Definition: Comment.h:892
clang::Decl::hasAttr
bool hasAttr() const
Definition: DeclBase.h:531
clang::comments::Sema::isTemplateOrSpecialization
bool isTemplateOrSpecialization()
Definition: CommentSema.cpp:888
clang::comments::Sema::resolveTParamReference
bool resolveTParamReference(StringRef Name, const TemplateParameterList *TemplateParameters, SmallVectorImpl< unsigned > *Position)
Definition: CommentSema.cpp:1075
clang::FunctionProtoType
Represents a prototype with parameter type info, e.g.
Definition: Type.h:3687
clang::comments::HTMLStartTagComment::setAttrs
void setAttrs(ArrayRef< Attribute > Attrs)
Definition: Comment.h:481
clang::comments::Sema::isObjCMethodDecl
bool isObjCMethodDecl()
Definition: CommentSema.cpp:837
clang::comments::Sema::inspectThisDecl
void inspectThisDecl()
Extract all important semantic information from ThisDeclInfo->ThisDecl into ThisDeclInfo members...
Definition: CommentSema.cpp:968
clang::comments::Sema::actOnTParamCommandFinish
void actOnTParamCommandFinish(TParamCommandComment *Command, ParagraphComment *Paragraph)
Definition: CommentSema.cpp:358
clang::comments::TParamCommandComment::setPosition
void setPosition(ArrayRef< unsigned > NewPosition)
Definition: Comment.h:857
clang::comments::CommandInfo::IsBriefCommand
unsigned IsBriefCommand
True if this command is introducing a brief documentation paragraph ( an alias).
Definition: CommentCommandTraits.h:61
clang::comments::DeclInfo::ReturnType
QualType ReturnType
Function return type if CommentDecl is something that we consider a "function".
Definition: Comment.h:1002
clang::comments::FullComment::child_begin
child_iterator child_begin() const
Definition: Comment.h:1112
clang::comments::DeclInfo::fill
void fill()
Definition: Comment.cpp:190
Preprocessor.h
Defines the clang::Preprocessor interface.
clang::comments::CommandMarkerKind
CommandMarkerKind
Describes the syntax that was used in a documentation command.
Definition: Comment.h:37
clang::comments::BlockCommandComment
A command that has zero or more word-like arguments (number of word-like arguments depends on command...
Definition: Comment.h:597
clang::comments::InlineCommandComment::Argument
Definition: Comment.h:301
clang::TokenValue
Stores token information for comparing actual tokens with predefined values.
Definition: Preprocessor.h:86
clang::comments::BlockCommandComment::getCommandMarker
CommandMarkerKind getCommandMarker() const LLVM_READONLY
Definition: Comment.h:705
clang::comments::Sema::actOnVerbatimBlockLine
VerbatimBlockLineComment * actOnVerbatimBlockLine(SourceLocation Loc, StringRef Text)
Definition: CommentSema.cpp:429
clang::comments::DeclInfo::TemplateParameters
const TemplateParameterList * TemplateParameters
Template parameters that can be referenced by \tparam if CommentDecl is a template (IsTemplateDecl or...
Definition: Comment.h:1007
clang::comments::ParamCommandComment::isDirectionExplicit
bool isDirectionExplicit() const LLVM_READONLY
Definition: Comment.h:750
clang::comments::ParamCommandComment::getParamNameRange
SourceRange getParamNameRange() const
Definition: Comment.h:769
clang::comments::Sema::resolveParmVarReference
unsigned resolveParmVarReference(StringRef Name, ArrayRef< const ParmVarDecl *> ParamVars)
Returns index of a function parameter with a given name.
Definition: CommentSema.cpp:972
clang::SourceRange::getEnd
SourceLocation getEnd() const
Definition: SourceLocation.h:208
clang::comments::HTMLStartTagComment
An opening HTML tag with attributes.
Definition: Comment.h:414
clang::TemplateTemplateParmDecl
TemplateTemplateParmDecl - Declares a template template parameter, e.g., "T" in.
Definition: DeclTemplate.h:1446
clang::comments::BlockCommandComment::getNumArgs
unsigned getNumArgs() const
Definition: Comment.h:669
clang::comments::Sema::checkFunctionDeclVerbatimLine
void checkFunctionDeclVerbatimLine(const BlockCommandComment *Comment)
Definition: CommentSema.cpp:98
clang::SourceManager::getPresumedLineNumber
unsigned getPresumedLineNumber(SourceLocation Loc, bool *Invalid=nullptr) const
Definition: SourceManager.cpp:1354
clang::comments::ParamCommandComment::getDirectionAsString
static const char * getDirectionAsString(PassDirection D)
Definition: Comment.cpp:178
clang::comments::Sema::actOnTParamCommandStart
TParamCommandComment * actOnTParamCommandStart(SourceLocation LocBegin, SourceLocation LocEnd, unsigned CommandID, CommandMarkerKind CommandMarker)
Definition: CommentSema.cpp:281
clang::comments::Sema::actOnBlockCommandFinish
void actOnBlockCommandFinish(BlockCommandComment *Command, ParagraphComment *Paragraph)
Definition: CommentSema.cpp:67
clang::comments::Sema::isFunctionDecl
bool isFunctionDecl()
Definition: CommentSema.cpp:801
clang::comments::CommandTraits
This class provides information about commands that can be used in comments.
Definition: CommentCommandTraits.h:128
clang::comments::ParamCommandComment::InvalidParamIndex
Definition: Comment.h:719
clang::comments::Sema::getInlineCommandRenderKind
InlineCommandComment::RenderKind getInlineCommandRenderKind(StringRef Name) const
Definition: CommentSema.cpp:1116
clang::comments::CommandInfo::IsRecordLikeDetailCommand
unsigned IsRecordLikeDetailCommand
True if block command is further describing a container API; such as @coclass, @classdesign, etc.
Definition: CommentCommandTraits.h:116
clang::comments::VerbatimBlockComment::setCloseName
void setCloseName(StringRef Name, SourceLocation LocBegin)
Definition: Comment.h:919
Attr.h
clang::comments::Sema::checkDeprecatedCommand
void checkDeprecatedCommand(const BlockCommandComment *Comment)
Definition: CommentSema.cpp:663
clang::comments::Sema::checkContainerDecl
void checkContainerDecl(const BlockCommandComment *Comment)
Definition: CommentSema.cpp:168
clang::SourceLocation
Encodes a location in the source.
Definition: SourceLocation.h:88
clang::comments::Sema::actOnVerbatimLine
VerbatimLineComment * actOnVerbatimLine(SourceLocation LocBegin, unsigned CommandID, SourceLocation TextBegin, StringRef Text)
Definition: CommentSema.cpp:443
clang::comments::Sema::isObjCProtocolDecl
bool isObjCProtocolDecl()
Definition: CommentSema.cpp:953
clang::comments::Sema::isFunctionOrBlockPointerVarLikeDecl
bool isFunctionOrBlockPointerVarLikeDecl()
Definition: CommentSema.cpp:856
clang::comments::Comment::getSourceRange
SourceRange getSourceRange() const LLVM_READONLY
Definition: Comment.h:216
clang::comments::Sema::actOnParamCommandStart
ParamCommandComment * actOnParamCommandStart(SourceLocation LocBegin, SourceLocation LocEnd, unsigned CommandID, CommandMarkerKind CommandMarker)
Definition: CommentSema.cpp:80
clang::comments::CommandTraits::getCommandInfo
const CommandInfo * getCommandInfo(StringRef Name) const
Definition: CommentCommandTraits.h:146
clang::comments::DeclInfo::getTemplateKind
TemplateDeclKind getTemplateKind() const LLVM_READONLY
Definition: Comment.h:1086
clang::comments::ParamCommandComment::InOut
Definition: Comment.h:741
clang::comments::getParamPassDirection
static int getParamPassDirection(StringRef Arg)
Turn a string into the corresponding PassDirection or -1 if it&#39;s not valid.
Definition: CommentSema.cpp:220
clang::comments::BlockCommandComment::Argument
Definition: Comment.h:599
clang::comments::Comment::child_iterator
Comment *const * child_iterator
Definition: Comment.h:224
clang::comments::HTMLTagComment::isMalformed
bool isMalformed() const
Definition: Comment.h:404
llvm::SmallVector
Definition: LLVM.h:36
clang::TemplateParameterList::size
unsigned size() const
Definition: DeclTemplate.h:124
clang::comments::BlockCommandComment::getCommandNameRange
SourceRange getCommandNameRange(const CommandTraits &Traits) const
Definition: Comment.h:663
clang::comments::ParagraphComment::isWhitespace
bool isWhitespace() const
Definition: Comment.h:581
clang::comments::HTMLEndTagComment
A closing HTML tag.
Definition: Comment.h:508
clang::comments::TParamCommandComment
Doxygen \tparam command, describes a template parameter.
Definition: Comment.h:800
clang::IdentifierInfo::getName
StringRef getName() const
Return the actual identifier string.
Definition: IdentifierTable.h:156
clang::TypedefNameDecl
Base class for declarations which introduce a typedef-name.
Definition: Decl.h:2916
clang::comments::CommandInfo::IsFunctionDeclarationCommand
unsigned IsFunctionDeclarationCommand
True if verbatim-like line command is a function declaration.
Definition: CommentCommandTraits.h:112
Decl.h
clang
Dataflow Directional Tag Classes.
Definition: CFGReachabilityAnalysis.h:22
clang::SourceLocation::isValid
bool isValid() const
Return true if this is a valid SourceLocation object.
Definition: SourceLocation.h:108
clang::DeclContext
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1262
clang::comments::Sema::actOnBlockCommandStart
BlockCommandComment * actOnBlockCommandStart(SourceLocation LocBegin, SourceLocation LocEnd, unsigned CommandID, CommandMarkerKind CommandMarker)
Definition: CommentSema.cpp:50
clang::comments::CommandInfo::IsHeaderfileCommand
unsigned IsHeaderfileCommand
True if this is a \headerfile-like command.
Definition: CommentCommandTraits.h:81
clang::DeclContext::isRecord
bool isRecord() const
Definition: DeclBase.h:1827
clang::Decl::getKind
Kind getKind() const
Definition: DeclBase.h:421
clang::comments::DeclInfo
Information about the declaration, useful to clients of FullComment.
Definition: Comment.h:981
clang::comments::ParagraphComment
A single paragraph that contains inline content.
Definition: Comment.h:547
clang::comments::DeclInfo::getKind
DeclKind getKind() const LLVM_READONLY
Definition: Comment.h:1082
clang::comments::InlineCommandComment::RenderNormal
Definition: Comment.h:311
clang::comments::Sema::actOnHTMLEndTag
HTMLEndTagComment * actOnHTMLEndTag(SourceLocation LocBegin, SourceLocation LocEnd, StringRef TagName)
Definition: CommentSema.cpp:476
CommentDiagnostic.h
clang::comments::HTMLTagComment::getTagName
StringRef getTagName() const LLVM_READONLY
Definition: Comment.h:396
clang::comments::Sema::isAnyFunctionDecl
bool isAnyFunctionDecl()
Definition: CommentSema.cpp:809
clang::comments::ParamCommandComment::setParamIndex
void setParamIndex(unsigned Index)
Definition: Comment.h:792
clang::comments::ParamCommandComment::setIsVarArgParam
void setIsVarArgParam()
Definition: Comment.h:781
clang::FixItHint::CreateInsertion
static FixItHint CreateInsertion(SourceLocation InsertionLoc, StringRef Code, bool BeforePreviousInsertions=false)
Create a code modification hint that inserts the given code string at a specific location.
Definition: Diagnostic.h:92
clang::comments::BlockCommandComment::setParagraph
void setParagraph(ParagraphComment *PC)
Definition: Comment.h:698
clang::comments::Sema::isUnionDecl
bool isUnionDecl()
Definition: CommentSema.cpp:905
clang::comments::Sema::actOnTParamCommandParamNameArg
void actOnTParamCommandParamNameArg(TParamCommandComment *Command, SourceLocation ArgLocBegin, SourceLocation ArgLocEnd, StringRef Arg)
Definition: CommentSema.cpp:299
clang::comments::Sema::isObjCInterfaceDecl
bool isObjCInterfaceDecl()
Definition: CommentSema.cpp:944
clang::comments::CommandTraits::registerUnknownCommand
const CommandInfo * registerUnknownCommand(StringRef CommandName)
Definition: CommentCommandTraits.cpp:103
clang::comments::Sema::setDecl
void setDecl(const Decl *D)
Definition: CommentSema.cpp:36
clang::Type::isVoidType
bool isVoidType() const
Definition: Type.h:6544
clang::FixItHint::CreateReplacement
static FixItHint CreateReplacement(CharSourceRange RemoveRange, StringRef Code)
Create a code modification hint that replaces the given source range with the given code string...
Definition: Diagnostic.h:129
clang::comments::ParamCommandComment::Out
Definition: Comment.h:740
clang::comments::ParamCommandComment::getParamNameAsWritten
StringRef getParamNameAsWritten() const
Definition: Comment.h:765
clang::comments::Sema::isRecordLikeDecl
bool isRecordLikeDecl()
Definition: CommentSema.cpp:896
clang::comments::Sema::actOnInlineCommand
InlineCommandComment * actOnInlineCommand(SourceLocation CommandLocBegin, SourceLocation CommandLocEnd, unsigned CommandID)
Definition: CommentSema.cpp:364
clang::comments::BlockCommandComment::setArgs
void setArgs(ArrayRef< Argument > A)
Definition: Comment.h:681
clang::comments::ParamCommandComment
Doxygen \param command.
Definition: Comment.h:712
clang::TypedefType
Definition: Type.h:4151
Text
StringRef Text
Definition: Format.cpp:1630
clang::comments::DeclInfo::ParamVars
ArrayRef< const ParmVarDecl * > ParamVars
Parameters that can be referenced by \param if CommentDecl is something that we consider a "function"...
Definition: Comment.h:998
clang::SourceRange
A trivial tuple used to represent a source range.
Definition: SourceLocation.h:198
clang::NamedDecl
This represents a decl that may have a name.
Definition: Decl.h:249
clang::comments::HTMLStartTagComment::setGreaterLoc
void setGreaterLoc(SourceLocation GreaterLoc)
Definition: Comment.h:494
clang::comments::Sema::actOnParamCommandParamNameArg
void actOnParamCommandParamNameArg(ParamCommandComment *Command, SourceLocation ArgLocBegin, SourceLocation ArgLocEnd, StringRef Arg)
Definition: CommentSema.cpp:257
clang::comments::InlineCommandComment::RenderMonospaced
Definition: Comment.h:313
clang::comments::BlockCommandComment::getArgRange
SourceRange getArgRange(unsigned Idx) const
Definition: Comment.h:677
clang::Type::isFunctionPointerType
bool isFunctionPointerType() const
Definition: Type.h:6320
clang::SourceRange::getBegin
SourceLocation getBegin() const
Definition: SourceLocation.h:207
clang::comments::Sema::resolveParamCommandIndexes
void resolveParamCommandIndexes(const FullComment *FC)
Resolve parameter names to parameter indexes in function declaration.
Definition: CommentSema.cpp:712
clang::SourceManager
This class handles loading and caching of source files into memory.
Definition: SourceManager.h:582
clang::FunctionTemplateDecl
Declaration of a template function.
Definition: DeclTemplate.h:969
clang::comments::Sema::actOnParamCommandDirectionArg
void actOnParamCommandDirectionArg(ParamCommandComment *Command, SourceLocation ArgLocBegin, SourceLocation ArgLocEnd, StringRef Arg)
Definition: CommentSema.cpp:228
clang::comments::FullComment
A full comment attached to a declaration, contains block content.
Definition: Comment.h:1092
clang::Preprocessor
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
Definition: Preprocessor.h:125