CommentSema.cpp 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150
  1. //===--- CommentSema.cpp - Doxygen comment semantic analysis --------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. #include "clang/AST/CommentSema.h"
  9. #include "clang/AST/Attr.h"
  10. #include "clang/AST/CommentCommandTraits.h"
  11. #include "clang/AST/CommentDiagnostic.h"
  12. #include "clang/AST/Decl.h"
  13. #include "clang/AST/DeclTemplate.h"
  14. #include "clang/Basic/LLVM.h"
  15. #include "clang/Basic/SourceManager.h"
  16. #include "clang/Lex/Preprocessor.h"
  17. #include "llvm/ADT/SmallString.h"
  18. #include "llvm/ADT/StringSwitch.h"
  19. namespace clang {
  20. namespace comments {
  21. namespace {
  22. #include "clang/AST/CommentHTMLTagsProperties.inc"
  23. } // end anonymous namespace
  24. Sema::Sema(llvm::BumpPtrAllocator &Allocator, const SourceManager &SourceMgr,
  25. DiagnosticsEngine &Diags, CommandTraits &Traits,
  26. const Preprocessor *PP) :
  27. Allocator(Allocator), SourceMgr(SourceMgr), Diags(Diags), Traits(Traits),
  28. PP(PP), ThisDeclInfo(nullptr), BriefCommand(nullptr),
  29. HeaderfileCommand(nullptr) {
  30. }
  31. void Sema::setDecl(const Decl *D) {
  32. if (!D)
  33. return;
  34. ThisDeclInfo = new (Allocator) DeclInfo;
  35. ThisDeclInfo->CommentDecl = D;
  36. ThisDeclInfo->IsFilled = false;
  37. }
  38. ParagraphComment *Sema::actOnParagraphComment(
  39. ArrayRef<InlineContentComment *> Content) {
  40. return new (Allocator) ParagraphComment(Content);
  41. }
  42. BlockCommandComment *Sema::actOnBlockCommandStart(
  43. SourceLocation LocBegin,
  44. SourceLocation LocEnd,
  45. unsigned CommandID,
  46. CommandMarkerKind CommandMarker) {
  47. BlockCommandComment *BC = new (Allocator) BlockCommandComment(LocBegin, LocEnd,
  48. CommandID,
  49. CommandMarker);
  50. checkContainerDecl(BC);
  51. return BC;
  52. }
  53. void Sema::actOnBlockCommandArgs(BlockCommandComment *Command,
  54. ArrayRef<BlockCommandComment::Argument> Args) {
  55. Command->setArgs(Args);
  56. }
  57. void Sema::actOnBlockCommandFinish(BlockCommandComment *Command,
  58. ParagraphComment *Paragraph) {
  59. Command->setParagraph(Paragraph);
  60. checkBlockCommandEmptyParagraph(Command);
  61. checkBlockCommandDuplicate(Command);
  62. if (ThisDeclInfo) {
  63. // These checks only make sense if the comment is attached to a
  64. // declaration.
  65. checkReturnsCommand(Command);
  66. checkDeprecatedCommand(Command);
  67. }
  68. }
  69. ParamCommandComment *Sema::actOnParamCommandStart(
  70. SourceLocation LocBegin,
  71. SourceLocation LocEnd,
  72. unsigned CommandID,
  73. CommandMarkerKind CommandMarker) {
  74. ParamCommandComment *Command =
  75. new (Allocator) ParamCommandComment(LocBegin, LocEnd, CommandID,
  76. CommandMarker);
  77. if (!involvesFunctionType())
  78. Diag(Command->getLocation(),
  79. diag::warn_doc_param_not_attached_to_a_function_decl)
  80. << CommandMarker
  81. << Command->getCommandNameRange(Traits);
  82. return Command;
  83. }
  84. void Sema::checkFunctionDeclVerbatimLine(const BlockCommandComment *Comment) {
  85. const CommandInfo *Info = Traits.getCommandInfo(Comment->getCommandID());
  86. if (!Info->IsFunctionDeclarationCommand)
  87. return;
  88. unsigned DiagSelect;
  89. switch (Comment->getCommandID()) {
  90. case CommandTraits::KCI_function:
  91. DiagSelect = (!isAnyFunctionDecl() && !isFunctionTemplateDecl())? 1 : 0;
  92. break;
  93. case CommandTraits::KCI_functiongroup:
  94. DiagSelect = (!isAnyFunctionDecl() && !isFunctionTemplateDecl())? 2 : 0;
  95. break;
  96. case CommandTraits::KCI_method:
  97. DiagSelect = !isObjCMethodDecl() ? 3 : 0;
  98. break;
  99. case CommandTraits::KCI_methodgroup:
  100. DiagSelect = !isObjCMethodDecl() ? 4 : 0;
  101. break;
  102. case CommandTraits::KCI_callback:
  103. DiagSelect = !isFunctionPointerVarDecl() ? 5 : 0;
  104. break;
  105. default:
  106. DiagSelect = 0;
  107. break;
  108. }
  109. if (DiagSelect)
  110. Diag(Comment->getLocation(), diag::warn_doc_function_method_decl_mismatch)
  111. << Comment->getCommandMarker()
  112. << (DiagSelect-1) << (DiagSelect-1)
  113. << Comment->getSourceRange();
  114. }
  115. void Sema::checkContainerDeclVerbatimLine(const BlockCommandComment *Comment) {
  116. const CommandInfo *Info = Traits.getCommandInfo(Comment->getCommandID());
  117. if (!Info->IsRecordLikeDeclarationCommand)
  118. return;
  119. unsigned DiagSelect;
  120. switch (Comment->getCommandID()) {
  121. case CommandTraits::KCI_class:
  122. DiagSelect =
  123. (!isClassOrStructOrTagTypedefDecl() && !isClassTemplateDecl()) ? 1
  124. : 0;
  125. // Allow @class command on @interface declarations.
  126. // FIXME. Currently, \class and @class are indistinguishable. So,
  127. // \class is also allowed on an @interface declaration
  128. if (DiagSelect && Comment->getCommandMarker() && isObjCInterfaceDecl())
  129. DiagSelect = 0;
  130. break;
  131. case CommandTraits::KCI_interface:
  132. DiagSelect = !isObjCInterfaceDecl() ? 2 : 0;
  133. break;
  134. case CommandTraits::KCI_protocol:
  135. DiagSelect = !isObjCProtocolDecl() ? 3 : 0;
  136. break;
  137. case CommandTraits::KCI_struct:
  138. DiagSelect = !isClassOrStructOrTagTypedefDecl() ? 4 : 0;
  139. break;
  140. case CommandTraits::KCI_union:
  141. DiagSelect = !isUnionDecl() ? 5 : 0;
  142. break;
  143. default:
  144. DiagSelect = 0;
  145. break;
  146. }
  147. if (DiagSelect)
  148. Diag(Comment->getLocation(), diag::warn_doc_api_container_decl_mismatch)
  149. << Comment->getCommandMarker()
  150. << (DiagSelect-1) << (DiagSelect-1)
  151. << Comment->getSourceRange();
  152. }
  153. void Sema::checkContainerDecl(const BlockCommandComment *Comment) {
  154. const CommandInfo *Info = Traits.getCommandInfo(Comment->getCommandID());
  155. if (!Info->IsRecordLikeDetailCommand || isRecordLikeDecl())
  156. return;
  157. unsigned DiagSelect;
  158. switch (Comment->getCommandID()) {
  159. case CommandTraits::KCI_classdesign:
  160. DiagSelect = 1;
  161. break;
  162. case CommandTraits::KCI_coclass:
  163. DiagSelect = 2;
  164. break;
  165. case CommandTraits::KCI_dependency:
  166. DiagSelect = 3;
  167. break;
  168. case CommandTraits::KCI_helper:
  169. DiagSelect = 4;
  170. break;
  171. case CommandTraits::KCI_helperclass:
  172. DiagSelect = 5;
  173. break;
  174. case CommandTraits::KCI_helps:
  175. DiagSelect = 6;
  176. break;
  177. case CommandTraits::KCI_instancesize:
  178. DiagSelect = 7;
  179. break;
  180. case CommandTraits::KCI_ownership:
  181. DiagSelect = 8;
  182. break;
  183. case CommandTraits::KCI_performance:
  184. DiagSelect = 9;
  185. break;
  186. case CommandTraits::KCI_security:
  187. DiagSelect = 10;
  188. break;
  189. case CommandTraits::KCI_superclass:
  190. DiagSelect = 11;
  191. break;
  192. default:
  193. DiagSelect = 0;
  194. break;
  195. }
  196. if (DiagSelect)
  197. Diag(Comment->getLocation(), diag::warn_doc_container_decl_mismatch)
  198. << Comment->getCommandMarker()
  199. << (DiagSelect-1)
  200. << Comment->getSourceRange();
  201. }
  202. /// Turn a string into the corresponding PassDirection or -1 if it's not
  203. /// valid.
  204. static int getParamPassDirection(StringRef Arg) {
  205. return llvm::StringSwitch<int>(Arg)
  206. .Case("[in]", ParamCommandComment::In)
  207. .Case("[out]", ParamCommandComment::Out)
  208. .Cases("[in,out]", "[out,in]", ParamCommandComment::InOut)
  209. .Default(-1);
  210. }
  211. void Sema::actOnParamCommandDirectionArg(ParamCommandComment *Command,
  212. SourceLocation ArgLocBegin,
  213. SourceLocation ArgLocEnd,
  214. StringRef Arg) {
  215. std::string ArgLower = Arg.lower();
  216. int Direction = getParamPassDirection(ArgLower);
  217. if (Direction == -1) {
  218. // Try again with whitespace removed.
  219. llvm::erase_if(ArgLower, clang::isWhitespace);
  220. Direction = getParamPassDirection(ArgLower);
  221. SourceRange ArgRange(ArgLocBegin, ArgLocEnd);
  222. if (Direction != -1) {
  223. const char *FixedName = ParamCommandComment::getDirectionAsString(
  224. (ParamCommandComment::PassDirection)Direction);
  225. Diag(ArgLocBegin, diag::warn_doc_param_spaces_in_direction)
  226. << ArgRange << FixItHint::CreateReplacement(ArgRange, FixedName);
  227. } else {
  228. Diag(ArgLocBegin, diag::warn_doc_param_invalid_direction) << ArgRange;
  229. Direction = ParamCommandComment::In; // Sane fall back.
  230. }
  231. }
  232. Command->setDirection((ParamCommandComment::PassDirection)Direction,
  233. /*Explicit=*/true);
  234. }
  235. void Sema::actOnParamCommandParamNameArg(ParamCommandComment *Command,
  236. SourceLocation ArgLocBegin,
  237. SourceLocation ArgLocEnd,
  238. StringRef Arg) {
  239. // Parser will not feed us more arguments than needed.
  240. assert(Command->getNumArgs() == 0);
  241. if (!Command->isDirectionExplicit()) {
  242. // User didn't provide a direction argument.
  243. Command->setDirection(ParamCommandComment::In, /* Explicit = */ false);
  244. }
  245. typedef BlockCommandComment::Argument Argument;
  246. Argument *A = new (Allocator) Argument(SourceRange(ArgLocBegin,
  247. ArgLocEnd),
  248. Arg);
  249. Command->setArgs(llvm::makeArrayRef(A, 1));
  250. }
  251. void Sema::actOnParamCommandFinish(ParamCommandComment *Command,
  252. ParagraphComment *Paragraph) {
  253. Command->setParagraph(Paragraph);
  254. checkBlockCommandEmptyParagraph(Command);
  255. }
  256. TParamCommandComment *Sema::actOnTParamCommandStart(
  257. SourceLocation LocBegin,
  258. SourceLocation LocEnd,
  259. unsigned CommandID,
  260. CommandMarkerKind CommandMarker) {
  261. TParamCommandComment *Command =
  262. new (Allocator) TParamCommandComment(LocBegin, LocEnd, CommandID,
  263. CommandMarker);
  264. if (!isTemplateOrSpecialization())
  265. Diag(Command->getLocation(),
  266. diag::warn_doc_tparam_not_attached_to_a_template_decl)
  267. << CommandMarker
  268. << Command->getCommandNameRange(Traits);
  269. return Command;
  270. }
  271. void Sema::actOnTParamCommandParamNameArg(TParamCommandComment *Command,
  272. SourceLocation ArgLocBegin,
  273. SourceLocation ArgLocEnd,
  274. StringRef Arg) {
  275. // Parser will not feed us more arguments than needed.
  276. assert(Command->getNumArgs() == 0);
  277. typedef BlockCommandComment::Argument Argument;
  278. Argument *A = new (Allocator) Argument(SourceRange(ArgLocBegin,
  279. ArgLocEnd),
  280. Arg);
  281. Command->setArgs(llvm::makeArrayRef(A, 1));
  282. if (!isTemplateOrSpecialization()) {
  283. // We already warned that this \\tparam is not attached to a template decl.
  284. return;
  285. }
  286. const TemplateParameterList *TemplateParameters =
  287. ThisDeclInfo->TemplateParameters;
  288. SmallVector<unsigned, 2> Position;
  289. if (resolveTParamReference(Arg, TemplateParameters, &Position)) {
  290. Command->setPosition(copyArray(llvm::makeArrayRef(Position)));
  291. TParamCommandComment *&PrevCommand = TemplateParameterDocs[Arg];
  292. if (PrevCommand) {
  293. SourceRange ArgRange(ArgLocBegin, ArgLocEnd);
  294. Diag(ArgLocBegin, diag::warn_doc_tparam_duplicate)
  295. << Arg << ArgRange;
  296. Diag(PrevCommand->getLocation(), diag::note_doc_tparam_previous)
  297. << PrevCommand->getParamNameRange();
  298. }
  299. PrevCommand = Command;
  300. return;
  301. }
  302. SourceRange ArgRange(ArgLocBegin, ArgLocEnd);
  303. Diag(ArgLocBegin, diag::warn_doc_tparam_not_found)
  304. << Arg << ArgRange;
  305. if (!TemplateParameters || TemplateParameters->size() == 0)
  306. return;
  307. StringRef CorrectedName;
  308. if (TemplateParameters->size() == 1) {
  309. const NamedDecl *Param = TemplateParameters->getParam(0);
  310. const IdentifierInfo *II = Param->getIdentifier();
  311. if (II)
  312. CorrectedName = II->getName();
  313. } else {
  314. CorrectedName = correctTypoInTParamReference(Arg, TemplateParameters);
  315. }
  316. if (!CorrectedName.empty()) {
  317. Diag(ArgLocBegin, diag::note_doc_tparam_name_suggestion)
  318. << CorrectedName
  319. << FixItHint::CreateReplacement(ArgRange, CorrectedName);
  320. }
  321. }
  322. void Sema::actOnTParamCommandFinish(TParamCommandComment *Command,
  323. ParagraphComment *Paragraph) {
  324. Command->setParagraph(Paragraph);
  325. checkBlockCommandEmptyParagraph(Command);
  326. }
  327. InlineCommandComment *Sema::actOnInlineCommand(SourceLocation CommandLocBegin,
  328. SourceLocation CommandLocEnd,
  329. unsigned CommandID) {
  330. ArrayRef<InlineCommandComment::Argument> Args;
  331. StringRef CommandName = Traits.getCommandInfo(CommandID)->Name;
  332. return new (Allocator) InlineCommandComment(
  333. CommandLocBegin,
  334. CommandLocEnd,
  335. CommandID,
  336. getInlineCommandRenderKind(CommandName),
  337. Args);
  338. }
  339. InlineCommandComment *Sema::actOnInlineCommand(SourceLocation CommandLocBegin,
  340. SourceLocation CommandLocEnd,
  341. unsigned CommandID,
  342. SourceLocation ArgLocBegin,
  343. SourceLocation ArgLocEnd,
  344. StringRef Arg) {
  345. typedef InlineCommandComment::Argument Argument;
  346. Argument *A = new (Allocator) Argument(SourceRange(ArgLocBegin,
  347. ArgLocEnd),
  348. Arg);
  349. StringRef CommandName = Traits.getCommandInfo(CommandID)->Name;
  350. return new (Allocator) InlineCommandComment(
  351. CommandLocBegin,
  352. CommandLocEnd,
  353. CommandID,
  354. getInlineCommandRenderKind(CommandName),
  355. llvm::makeArrayRef(A, 1));
  356. }
  357. InlineContentComment *Sema::actOnUnknownCommand(SourceLocation LocBegin,
  358. SourceLocation LocEnd,
  359. StringRef CommandName) {
  360. unsigned CommandID = Traits.registerUnknownCommand(CommandName)->getID();
  361. return actOnUnknownCommand(LocBegin, LocEnd, CommandID);
  362. }
  363. InlineContentComment *Sema::actOnUnknownCommand(SourceLocation LocBegin,
  364. SourceLocation LocEnd,
  365. unsigned CommandID) {
  366. ArrayRef<InlineCommandComment::Argument> Args;
  367. return new (Allocator) InlineCommandComment(
  368. LocBegin, LocEnd, CommandID,
  369. InlineCommandComment::RenderNormal,
  370. Args);
  371. }
  372. TextComment *Sema::actOnText(SourceLocation LocBegin,
  373. SourceLocation LocEnd,
  374. StringRef Text) {
  375. return new (Allocator) TextComment(LocBegin, LocEnd, Text);
  376. }
  377. VerbatimBlockComment *Sema::actOnVerbatimBlockStart(SourceLocation Loc,
  378. unsigned CommandID) {
  379. StringRef CommandName = Traits.getCommandInfo(CommandID)->Name;
  380. return new (Allocator) VerbatimBlockComment(
  381. Loc,
  382. Loc.getLocWithOffset(1 + CommandName.size()),
  383. CommandID);
  384. }
  385. VerbatimBlockLineComment *Sema::actOnVerbatimBlockLine(SourceLocation Loc,
  386. StringRef Text) {
  387. return new (Allocator) VerbatimBlockLineComment(Loc, Text);
  388. }
  389. void Sema::actOnVerbatimBlockFinish(
  390. VerbatimBlockComment *Block,
  391. SourceLocation CloseNameLocBegin,
  392. StringRef CloseName,
  393. ArrayRef<VerbatimBlockLineComment *> Lines) {
  394. Block->setCloseName(CloseName, CloseNameLocBegin);
  395. Block->setLines(Lines);
  396. }
  397. VerbatimLineComment *Sema::actOnVerbatimLine(SourceLocation LocBegin,
  398. unsigned CommandID,
  399. SourceLocation TextBegin,
  400. StringRef Text) {
  401. VerbatimLineComment *VL = new (Allocator) VerbatimLineComment(
  402. LocBegin,
  403. TextBegin.getLocWithOffset(Text.size()),
  404. CommandID,
  405. TextBegin,
  406. Text);
  407. checkFunctionDeclVerbatimLine(VL);
  408. checkContainerDeclVerbatimLine(VL);
  409. return VL;
  410. }
  411. HTMLStartTagComment *Sema::actOnHTMLStartTagStart(SourceLocation LocBegin,
  412. StringRef TagName) {
  413. return new (Allocator) HTMLStartTagComment(LocBegin, TagName);
  414. }
  415. void Sema::actOnHTMLStartTagFinish(
  416. HTMLStartTagComment *Tag,
  417. ArrayRef<HTMLStartTagComment::Attribute> Attrs,
  418. SourceLocation GreaterLoc,
  419. bool IsSelfClosing) {
  420. Tag->setAttrs(Attrs);
  421. Tag->setGreaterLoc(GreaterLoc);
  422. if (IsSelfClosing)
  423. Tag->setSelfClosing();
  424. else if (!isHTMLEndTagForbidden(Tag->getTagName()))
  425. HTMLOpenTags.push_back(Tag);
  426. }
  427. HTMLEndTagComment *Sema::actOnHTMLEndTag(SourceLocation LocBegin,
  428. SourceLocation LocEnd,
  429. StringRef TagName) {
  430. HTMLEndTagComment *HET =
  431. new (Allocator) HTMLEndTagComment(LocBegin, LocEnd, TagName);
  432. if (isHTMLEndTagForbidden(TagName)) {
  433. Diag(HET->getLocation(), diag::warn_doc_html_end_forbidden)
  434. << TagName << HET->getSourceRange();
  435. HET->setIsMalformed();
  436. return HET;
  437. }
  438. bool FoundOpen = false;
  439. for (SmallVectorImpl<HTMLStartTagComment *>::const_reverse_iterator
  440. I = HTMLOpenTags.rbegin(), E = HTMLOpenTags.rend();
  441. I != E; ++I) {
  442. if ((*I)->getTagName() == TagName) {
  443. FoundOpen = true;
  444. break;
  445. }
  446. }
  447. if (!FoundOpen) {
  448. Diag(HET->getLocation(), diag::warn_doc_html_end_unbalanced)
  449. << HET->getSourceRange();
  450. HET->setIsMalformed();
  451. return HET;
  452. }
  453. while (!HTMLOpenTags.empty()) {
  454. HTMLStartTagComment *HST = HTMLOpenTags.pop_back_val();
  455. StringRef LastNotClosedTagName = HST->getTagName();
  456. if (LastNotClosedTagName == TagName) {
  457. // If the start tag is malformed, end tag is malformed as well.
  458. if (HST->isMalformed())
  459. HET->setIsMalformed();
  460. break;
  461. }
  462. if (isHTMLEndTagOptional(LastNotClosedTagName))
  463. continue;
  464. bool OpenLineInvalid;
  465. const unsigned OpenLine = SourceMgr.getPresumedLineNumber(
  466. HST->getLocation(),
  467. &OpenLineInvalid);
  468. bool CloseLineInvalid;
  469. const unsigned CloseLine = SourceMgr.getPresumedLineNumber(
  470. HET->getLocation(),
  471. &CloseLineInvalid);
  472. if (OpenLineInvalid || CloseLineInvalid || OpenLine == CloseLine) {
  473. Diag(HST->getLocation(), diag::warn_doc_html_start_end_mismatch)
  474. << HST->getTagName() << HET->getTagName()
  475. << HST->getSourceRange() << HET->getSourceRange();
  476. HST->setIsMalformed();
  477. } else {
  478. Diag(HST->getLocation(), diag::warn_doc_html_start_end_mismatch)
  479. << HST->getTagName() << HET->getTagName()
  480. << HST->getSourceRange();
  481. Diag(HET->getLocation(), diag::note_doc_html_end_tag)
  482. << HET->getSourceRange();
  483. HST->setIsMalformed();
  484. }
  485. }
  486. return HET;
  487. }
  488. FullComment *Sema::actOnFullComment(
  489. ArrayRef<BlockContentComment *> Blocks) {
  490. FullComment *FC = new (Allocator) FullComment(Blocks, ThisDeclInfo);
  491. resolveParamCommandIndexes(FC);
  492. // Complain about HTML tags that are not closed.
  493. while (!HTMLOpenTags.empty()) {
  494. HTMLStartTagComment *HST = HTMLOpenTags.pop_back_val();
  495. if (isHTMLEndTagOptional(HST->getTagName()))
  496. continue;
  497. Diag(HST->getLocation(), diag::warn_doc_html_missing_end_tag)
  498. << HST->getTagName() << HST->getSourceRange();
  499. HST->setIsMalformed();
  500. }
  501. return FC;
  502. }
  503. void Sema::checkBlockCommandEmptyParagraph(BlockCommandComment *Command) {
  504. if (Traits.getCommandInfo(Command->getCommandID())->IsEmptyParagraphAllowed)
  505. return;
  506. ParagraphComment *Paragraph = Command->getParagraph();
  507. if (Paragraph->isWhitespace()) {
  508. SourceLocation DiagLoc;
  509. if (Command->getNumArgs() > 0)
  510. DiagLoc = Command->getArgRange(Command->getNumArgs() - 1).getEnd();
  511. if (!DiagLoc.isValid())
  512. DiagLoc = Command->getCommandNameRange(Traits).getEnd();
  513. Diag(DiagLoc, diag::warn_doc_block_command_empty_paragraph)
  514. << Command->getCommandMarker()
  515. << Command->getCommandName(Traits)
  516. << Command->getSourceRange();
  517. }
  518. }
  519. void Sema::checkReturnsCommand(const BlockCommandComment *Command) {
  520. if (!Traits.getCommandInfo(Command->getCommandID())->IsReturnsCommand)
  521. return;
  522. assert(ThisDeclInfo && "should not call this check on a bare comment");
  523. // We allow the return command for all @properties because it can be used
  524. // to document the value that the property getter returns.
  525. if (isObjCPropertyDecl())
  526. return;
  527. if (involvesFunctionType()) {
  528. assert(!ThisDeclInfo->ReturnType.isNull() &&
  529. "should have a valid return type");
  530. if (ThisDeclInfo->ReturnType->isVoidType()) {
  531. unsigned DiagKind;
  532. switch (ThisDeclInfo->CommentDecl->getKind()) {
  533. default:
  534. if (ThisDeclInfo->IsObjCMethod)
  535. DiagKind = 3;
  536. else
  537. DiagKind = 0;
  538. break;
  539. case Decl::CXXConstructor:
  540. DiagKind = 1;
  541. break;
  542. case Decl::CXXDestructor:
  543. DiagKind = 2;
  544. break;
  545. }
  546. Diag(Command->getLocation(),
  547. diag::warn_doc_returns_attached_to_a_void_function)
  548. << Command->getCommandMarker()
  549. << Command->getCommandName(Traits)
  550. << DiagKind
  551. << Command->getSourceRange();
  552. }
  553. return;
  554. }
  555. Diag(Command->getLocation(),
  556. diag::warn_doc_returns_not_attached_to_a_function_decl)
  557. << Command->getCommandMarker()
  558. << Command->getCommandName(Traits)
  559. << Command->getSourceRange();
  560. }
  561. void Sema::checkBlockCommandDuplicate(const BlockCommandComment *Command) {
  562. const CommandInfo *Info = Traits.getCommandInfo(Command->getCommandID());
  563. const BlockCommandComment *PrevCommand = nullptr;
  564. if (Info->IsBriefCommand) {
  565. if (!BriefCommand) {
  566. BriefCommand = Command;
  567. return;
  568. }
  569. PrevCommand = BriefCommand;
  570. } else if (Info->IsHeaderfileCommand) {
  571. if (!HeaderfileCommand) {
  572. HeaderfileCommand = Command;
  573. return;
  574. }
  575. PrevCommand = HeaderfileCommand;
  576. } else {
  577. // We don't want to check this command for duplicates.
  578. return;
  579. }
  580. StringRef CommandName = Command->getCommandName(Traits);
  581. StringRef PrevCommandName = PrevCommand->getCommandName(Traits);
  582. Diag(Command->getLocation(), diag::warn_doc_block_command_duplicate)
  583. << Command->getCommandMarker()
  584. << CommandName
  585. << Command->getSourceRange();
  586. if (CommandName == PrevCommandName)
  587. Diag(PrevCommand->getLocation(), diag::note_doc_block_command_previous)
  588. << PrevCommand->getCommandMarker()
  589. << PrevCommandName
  590. << PrevCommand->getSourceRange();
  591. else
  592. Diag(PrevCommand->getLocation(),
  593. diag::note_doc_block_command_previous_alias)
  594. << PrevCommand->getCommandMarker()
  595. << PrevCommandName
  596. << CommandName;
  597. }
  598. void Sema::checkDeprecatedCommand(const BlockCommandComment *Command) {
  599. if (!Traits.getCommandInfo(Command->getCommandID())->IsDeprecatedCommand)
  600. return;
  601. assert(ThisDeclInfo && "should not call this check on a bare comment");
  602. const Decl *D = ThisDeclInfo->CommentDecl;
  603. if (!D)
  604. return;
  605. if (D->hasAttr<DeprecatedAttr>() ||
  606. D->hasAttr<AvailabilityAttr>() ||
  607. D->hasAttr<UnavailableAttr>())
  608. return;
  609. Diag(Command->getLocation(), diag::warn_doc_deprecated_not_sync)
  610. << Command->getSourceRange() << Command->getCommandMarker();
  611. // Try to emit a fixit with a deprecation attribute.
  612. if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
  613. // Don't emit a Fix-It for non-member function definitions. GCC does not
  614. // accept attributes on them.
  615. const DeclContext *Ctx = FD->getDeclContext();
  616. if ((!Ctx || !Ctx->isRecord()) &&
  617. FD->doesThisDeclarationHaveABody())
  618. return;
  619. const LangOptions &LO = FD->getLangOpts();
  620. const bool DoubleSquareBracket = LO.CPlusPlus14 || LO.C2x;
  621. StringRef AttributeSpelling =
  622. DoubleSquareBracket ? "[[deprecated]]" : "__attribute__((deprecated))";
  623. if (PP) {
  624. // Try to find a replacement macro:
  625. // - In C2x/C++14 we prefer [[deprecated]].
  626. // - If not found or an older C/C++ look for __attribute__((deprecated)).
  627. StringRef MacroName;
  628. if (DoubleSquareBracket) {
  629. TokenValue Tokens[] = {tok::l_square, tok::l_square,
  630. PP->getIdentifierInfo("deprecated"),
  631. tok::r_square, tok::r_square};
  632. MacroName = PP->getLastMacroWithSpelling(FD->getLocation(), Tokens);
  633. if (!MacroName.empty())
  634. AttributeSpelling = MacroName;
  635. }
  636. if (MacroName.empty()) {
  637. TokenValue Tokens[] = {
  638. tok::kw___attribute, tok::l_paren,
  639. tok::l_paren, PP->getIdentifierInfo("deprecated"),
  640. tok::r_paren, tok::r_paren};
  641. StringRef MacroName =
  642. PP->getLastMacroWithSpelling(FD->getLocation(), Tokens);
  643. if (!MacroName.empty())
  644. AttributeSpelling = MacroName;
  645. }
  646. }
  647. SmallString<64> TextToInsert = AttributeSpelling;
  648. TextToInsert += " ";
  649. SourceLocation Loc = FD->getSourceRange().getBegin();
  650. Diag(Loc, diag::note_add_deprecation_attr)
  651. << FixItHint::CreateInsertion(Loc, TextToInsert);
  652. }
  653. }
  654. void Sema::resolveParamCommandIndexes(const FullComment *FC) {
  655. if (!involvesFunctionType()) {
  656. // We already warned that \\param commands are not attached to a function
  657. // decl.
  658. return;
  659. }
  660. SmallVector<ParamCommandComment *, 8> UnresolvedParamCommands;
  661. // Comment AST nodes that correspond to \c ParamVars for which we have
  662. // found a \\param command or NULL if no documentation was found so far.
  663. SmallVector<ParamCommandComment *, 8> ParamVarDocs;
  664. ArrayRef<const ParmVarDecl *> ParamVars = getParamVars();
  665. ParamVarDocs.resize(ParamVars.size(), nullptr);
  666. // First pass over all \\param commands: resolve all parameter names.
  667. for (Comment::child_iterator I = FC->child_begin(), E = FC->child_end();
  668. I != E; ++I) {
  669. ParamCommandComment *PCC = dyn_cast<ParamCommandComment>(*I);
  670. if (!PCC || !PCC->hasParamName())
  671. continue;
  672. StringRef ParamName = PCC->getParamNameAsWritten();
  673. // Check that referenced parameter name is in the function decl.
  674. const unsigned ResolvedParamIndex = resolveParmVarReference(ParamName,
  675. ParamVars);
  676. if (ResolvedParamIndex == ParamCommandComment::VarArgParamIndex) {
  677. PCC->setIsVarArgParam();
  678. continue;
  679. }
  680. if (ResolvedParamIndex == ParamCommandComment::InvalidParamIndex) {
  681. UnresolvedParamCommands.push_back(PCC);
  682. continue;
  683. }
  684. PCC->setParamIndex(ResolvedParamIndex);
  685. if (ParamVarDocs[ResolvedParamIndex]) {
  686. SourceRange ArgRange = PCC->getParamNameRange();
  687. Diag(ArgRange.getBegin(), diag::warn_doc_param_duplicate)
  688. << ParamName << ArgRange;
  689. ParamCommandComment *PrevCommand = ParamVarDocs[ResolvedParamIndex];
  690. Diag(PrevCommand->getLocation(), diag::note_doc_param_previous)
  691. << PrevCommand->getParamNameRange();
  692. }
  693. ParamVarDocs[ResolvedParamIndex] = PCC;
  694. }
  695. // Find parameter declarations that have no corresponding \\param.
  696. SmallVector<const ParmVarDecl *, 8> OrphanedParamDecls;
  697. for (unsigned i = 0, e = ParamVarDocs.size(); i != e; ++i) {
  698. if (!ParamVarDocs[i])
  699. OrphanedParamDecls.push_back(ParamVars[i]);
  700. }
  701. // Second pass over unresolved \\param commands: do typo correction.
  702. // Suggest corrections from a set of parameter declarations that have no
  703. // corresponding \\param.
  704. for (unsigned i = 0, e = UnresolvedParamCommands.size(); i != e; ++i) {
  705. const ParamCommandComment *PCC = UnresolvedParamCommands[i];
  706. SourceRange ArgRange = PCC->getParamNameRange();
  707. StringRef ParamName = PCC->getParamNameAsWritten();
  708. Diag(ArgRange.getBegin(), diag::warn_doc_param_not_found)
  709. << ParamName << ArgRange;
  710. // All parameters documented -- can't suggest a correction.
  711. if (OrphanedParamDecls.size() == 0)
  712. continue;
  713. unsigned CorrectedParamIndex = ParamCommandComment::InvalidParamIndex;
  714. if (OrphanedParamDecls.size() == 1) {
  715. // If one parameter is not documented then that parameter is the only
  716. // possible suggestion.
  717. CorrectedParamIndex = 0;
  718. } else {
  719. // Do typo correction.
  720. CorrectedParamIndex = correctTypoInParmVarReference(ParamName,
  721. OrphanedParamDecls);
  722. }
  723. if (CorrectedParamIndex != ParamCommandComment::InvalidParamIndex) {
  724. const ParmVarDecl *CorrectedPVD = OrphanedParamDecls[CorrectedParamIndex];
  725. if (const IdentifierInfo *CorrectedII = CorrectedPVD->getIdentifier())
  726. Diag(ArgRange.getBegin(), diag::note_doc_param_name_suggestion)
  727. << CorrectedII->getName()
  728. << FixItHint::CreateReplacement(ArgRange, CorrectedII->getName());
  729. }
  730. }
  731. }
  732. bool Sema::involvesFunctionType() {
  733. if (!ThisDeclInfo)
  734. return false;
  735. if (!ThisDeclInfo->IsFilled)
  736. inspectThisDecl();
  737. return ThisDeclInfo->involvesFunctionType();
  738. }
  739. bool Sema::isFunctionDecl() {
  740. if (!ThisDeclInfo)
  741. return false;
  742. if (!ThisDeclInfo->IsFilled)
  743. inspectThisDecl();
  744. return ThisDeclInfo->getKind() == DeclInfo::FunctionKind;
  745. }
  746. bool Sema::isAnyFunctionDecl() {
  747. return isFunctionDecl() && ThisDeclInfo->CurrentDecl &&
  748. isa<FunctionDecl>(ThisDeclInfo->CurrentDecl);
  749. }
  750. bool Sema::isFunctionOrMethodVariadic() {
  751. if (!ThisDeclInfo)
  752. return false;
  753. if (!ThisDeclInfo->IsFilled)
  754. inspectThisDecl();
  755. return ThisDeclInfo->IsVariadic;
  756. }
  757. bool Sema::isObjCMethodDecl() {
  758. return isFunctionDecl() && ThisDeclInfo->CurrentDecl &&
  759. isa<ObjCMethodDecl>(ThisDeclInfo->CurrentDecl);
  760. }
  761. bool Sema::isFunctionPointerVarDecl() {
  762. if (!ThisDeclInfo)
  763. return false;
  764. if (!ThisDeclInfo->IsFilled)
  765. inspectThisDecl();
  766. if (ThisDeclInfo->getKind() == DeclInfo::VariableKind) {
  767. if (const VarDecl *VD = dyn_cast_or_null<VarDecl>(ThisDeclInfo->CurrentDecl)) {
  768. QualType QT = VD->getType();
  769. return QT->isFunctionPointerType();
  770. }
  771. }
  772. return false;
  773. }
  774. bool Sema::isObjCPropertyDecl() {
  775. if (!ThisDeclInfo)
  776. return false;
  777. if (!ThisDeclInfo->IsFilled)
  778. inspectThisDecl();
  779. return ThisDeclInfo->CurrentDecl->getKind() == Decl::ObjCProperty;
  780. }
  781. bool Sema::isTemplateOrSpecialization() {
  782. if (!ThisDeclInfo)
  783. return false;
  784. if (!ThisDeclInfo->IsFilled)
  785. inspectThisDecl();
  786. return ThisDeclInfo->getTemplateKind() != DeclInfo::NotTemplate;
  787. }
  788. bool Sema::isRecordLikeDecl() {
  789. if (!ThisDeclInfo)
  790. return false;
  791. if (!ThisDeclInfo->IsFilled)
  792. inspectThisDecl();
  793. return isUnionDecl() || isClassOrStructDecl() || isObjCInterfaceDecl() ||
  794. isObjCProtocolDecl();
  795. }
  796. bool Sema::isUnionDecl() {
  797. if (!ThisDeclInfo)
  798. return false;
  799. if (!ThisDeclInfo->IsFilled)
  800. inspectThisDecl();
  801. if (const RecordDecl *RD =
  802. dyn_cast_or_null<RecordDecl>(ThisDeclInfo->CurrentDecl))
  803. return RD->isUnion();
  804. return false;
  805. }
  806. static bool isClassOrStructDeclImpl(const Decl *D) {
  807. if (auto *record = dyn_cast_or_null<RecordDecl>(D))
  808. return !record->isUnion();
  809. return false;
  810. }
  811. bool Sema::isClassOrStructDecl() {
  812. if (!ThisDeclInfo)
  813. return false;
  814. if (!ThisDeclInfo->IsFilled)
  815. inspectThisDecl();
  816. if (!ThisDeclInfo->CurrentDecl)
  817. return false;
  818. return isClassOrStructDeclImpl(ThisDeclInfo->CurrentDecl);
  819. }
  820. bool Sema::isClassOrStructOrTagTypedefDecl() {
  821. if (!ThisDeclInfo)
  822. return false;
  823. if (!ThisDeclInfo->IsFilled)
  824. inspectThisDecl();
  825. if (!ThisDeclInfo->CurrentDecl)
  826. return false;
  827. if (isClassOrStructDeclImpl(ThisDeclInfo->CurrentDecl))
  828. return true;
  829. if (auto *ThisTypedefDecl = dyn_cast<TypedefDecl>(ThisDeclInfo->CurrentDecl)) {
  830. auto UnderlyingType = ThisTypedefDecl->getUnderlyingType();
  831. if (auto ThisElaboratedType = dyn_cast<ElaboratedType>(UnderlyingType)) {
  832. auto DesugaredType = ThisElaboratedType->desugar();
  833. if (auto *DesugaredTypePtr = DesugaredType.getTypePtrOrNull()) {
  834. if (auto *ThisRecordType = dyn_cast<RecordType>(DesugaredTypePtr)) {
  835. return isClassOrStructDeclImpl(ThisRecordType->getAsRecordDecl());
  836. }
  837. }
  838. }
  839. }
  840. return false;
  841. }
  842. bool Sema::isClassTemplateDecl() {
  843. if (!ThisDeclInfo)
  844. return false;
  845. if (!ThisDeclInfo->IsFilled)
  846. inspectThisDecl();
  847. return ThisDeclInfo->CurrentDecl &&
  848. (isa<ClassTemplateDecl>(ThisDeclInfo->CurrentDecl));
  849. }
  850. bool Sema::isFunctionTemplateDecl() {
  851. if (!ThisDeclInfo)
  852. return false;
  853. if (!ThisDeclInfo->IsFilled)
  854. inspectThisDecl();
  855. return ThisDeclInfo->CurrentDecl &&
  856. (isa<FunctionTemplateDecl>(ThisDeclInfo->CurrentDecl));
  857. }
  858. bool Sema::isObjCInterfaceDecl() {
  859. if (!ThisDeclInfo)
  860. return false;
  861. if (!ThisDeclInfo->IsFilled)
  862. inspectThisDecl();
  863. return ThisDeclInfo->CurrentDecl &&
  864. isa<ObjCInterfaceDecl>(ThisDeclInfo->CurrentDecl);
  865. }
  866. bool Sema::isObjCProtocolDecl() {
  867. if (!ThisDeclInfo)
  868. return false;
  869. if (!ThisDeclInfo->IsFilled)
  870. inspectThisDecl();
  871. return ThisDeclInfo->CurrentDecl &&
  872. isa<ObjCProtocolDecl>(ThisDeclInfo->CurrentDecl);
  873. }
  874. ArrayRef<const ParmVarDecl *> Sema::getParamVars() {
  875. if (!ThisDeclInfo->IsFilled)
  876. inspectThisDecl();
  877. return ThisDeclInfo->ParamVars;
  878. }
  879. void Sema::inspectThisDecl() {
  880. ThisDeclInfo->fill();
  881. }
  882. unsigned Sema::resolveParmVarReference(StringRef Name,
  883. ArrayRef<const ParmVarDecl *> ParamVars) {
  884. for (unsigned i = 0, e = ParamVars.size(); i != e; ++i) {
  885. const IdentifierInfo *II = ParamVars[i]->getIdentifier();
  886. if (II && II->getName() == Name)
  887. return i;
  888. }
  889. if (Name == "..." && isFunctionOrMethodVariadic())
  890. return ParamCommandComment::VarArgParamIndex;
  891. return ParamCommandComment::InvalidParamIndex;
  892. }
  893. namespace {
  894. class SimpleTypoCorrector {
  895. const NamedDecl *BestDecl;
  896. StringRef Typo;
  897. const unsigned MaxEditDistance;
  898. unsigned BestEditDistance;
  899. unsigned BestIndex;
  900. unsigned NextIndex;
  901. public:
  902. explicit SimpleTypoCorrector(StringRef Typo)
  903. : BestDecl(nullptr), Typo(Typo), MaxEditDistance((Typo.size() + 2) / 3),
  904. BestEditDistance(MaxEditDistance + 1), BestIndex(0), NextIndex(0) {}
  905. void addDecl(const NamedDecl *ND);
  906. const NamedDecl *getBestDecl() const {
  907. if (BestEditDistance > MaxEditDistance)
  908. return nullptr;
  909. return BestDecl;
  910. }
  911. unsigned getBestDeclIndex() const {
  912. assert(getBestDecl());
  913. return BestIndex;
  914. }
  915. };
  916. void SimpleTypoCorrector::addDecl(const NamedDecl *ND) {
  917. unsigned CurrIndex = NextIndex++;
  918. const IdentifierInfo *II = ND->getIdentifier();
  919. if (!II)
  920. return;
  921. StringRef Name = II->getName();
  922. unsigned MinPossibleEditDistance = abs((int)Name.size() - (int)Typo.size());
  923. if (MinPossibleEditDistance > 0 &&
  924. Typo.size() / MinPossibleEditDistance < 3)
  925. return;
  926. unsigned EditDistance = Typo.edit_distance(Name, true, MaxEditDistance);
  927. if (EditDistance < BestEditDistance) {
  928. BestEditDistance = EditDistance;
  929. BestDecl = ND;
  930. BestIndex = CurrIndex;
  931. }
  932. }
  933. } // end anonymous namespace
  934. unsigned Sema::correctTypoInParmVarReference(
  935. StringRef Typo,
  936. ArrayRef<const ParmVarDecl *> ParamVars) {
  937. SimpleTypoCorrector Corrector(Typo);
  938. for (unsigned i = 0, e = ParamVars.size(); i != e; ++i)
  939. Corrector.addDecl(ParamVars[i]);
  940. if (Corrector.getBestDecl())
  941. return Corrector.getBestDeclIndex();
  942. else
  943. return ParamCommandComment::InvalidParamIndex;
  944. }
  945. namespace {
  946. bool ResolveTParamReferenceHelper(
  947. StringRef Name,
  948. const TemplateParameterList *TemplateParameters,
  949. SmallVectorImpl<unsigned> *Position) {
  950. for (unsigned i = 0, e = TemplateParameters->size(); i != e; ++i) {
  951. const NamedDecl *Param = TemplateParameters->getParam(i);
  952. const IdentifierInfo *II = Param->getIdentifier();
  953. if (II && II->getName() == Name) {
  954. Position->push_back(i);
  955. return true;
  956. }
  957. if (const TemplateTemplateParmDecl *TTP =
  958. dyn_cast<TemplateTemplateParmDecl>(Param)) {
  959. Position->push_back(i);
  960. if (ResolveTParamReferenceHelper(Name, TTP->getTemplateParameters(),
  961. Position))
  962. return true;
  963. Position->pop_back();
  964. }
  965. }
  966. return false;
  967. }
  968. } // end anonymous namespace
  969. bool Sema::resolveTParamReference(
  970. StringRef Name,
  971. const TemplateParameterList *TemplateParameters,
  972. SmallVectorImpl<unsigned> *Position) {
  973. Position->clear();
  974. if (!TemplateParameters)
  975. return false;
  976. return ResolveTParamReferenceHelper(Name, TemplateParameters, Position);
  977. }
  978. namespace {
  979. void CorrectTypoInTParamReferenceHelper(
  980. const TemplateParameterList *TemplateParameters,
  981. SimpleTypoCorrector &Corrector) {
  982. for (unsigned i = 0, e = TemplateParameters->size(); i != e; ++i) {
  983. const NamedDecl *Param = TemplateParameters->getParam(i);
  984. Corrector.addDecl(Param);
  985. if (const TemplateTemplateParmDecl *TTP =
  986. dyn_cast<TemplateTemplateParmDecl>(Param))
  987. CorrectTypoInTParamReferenceHelper(TTP->getTemplateParameters(),
  988. Corrector);
  989. }
  990. }
  991. } // end anonymous namespace
  992. StringRef Sema::correctTypoInTParamReference(
  993. StringRef Typo,
  994. const TemplateParameterList *TemplateParameters) {
  995. SimpleTypoCorrector Corrector(Typo);
  996. CorrectTypoInTParamReferenceHelper(TemplateParameters, Corrector);
  997. if (const NamedDecl *ND = Corrector.getBestDecl()) {
  998. const IdentifierInfo *II = ND->getIdentifier();
  999. assert(II && "SimpleTypoCorrector should not return this decl");
  1000. return II->getName();
  1001. }
  1002. return StringRef();
  1003. }
  1004. InlineCommandComment::RenderKind
  1005. Sema::getInlineCommandRenderKind(StringRef Name) const {
  1006. assert(Traits.getCommandInfo(Name)->IsInlineCommand);
  1007. return llvm::StringSwitch<InlineCommandComment::RenderKind>(Name)
  1008. .Case("b", InlineCommandComment::RenderBold)
  1009. .Cases("c", "p", InlineCommandComment::RenderMonospaced)
  1010. .Cases("a", "e", "em", InlineCommandComment::RenderEmphasized)
  1011. .Case("anchor", InlineCommandComment::RenderAnchor)
  1012. .Default(InlineCommandComment::RenderNormal);
  1013. }
  1014. } // end namespace comments
  1015. } // end namespace clang