CommentSema.cpp 39 KB

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