blob: 44536727cb34200069c288dafd63a96655ae268d [file] [log] [blame]
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +00001//===--- 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"
Benjamin Kramer2fa67ef2012-12-01 15:09:41 +000011#include "clang/AST/Attr.h"
Dmitri Gribenkoaa580812012-08-09 00:03:17 +000012#include "clang/AST/CommentCommandTraits.h"
Benjamin Kramer2fa67ef2012-12-01 15:09:41 +000013#include "clang/AST/CommentDiagnostic.h"
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +000014#include "clang/AST/Decl.h"
Dmitri Gribenko96b09862012-07-31 22:37:06 +000015#include "clang/AST/DeclTemplate.h"
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +000016#include "clang/Basic/SourceManager.h"
Dmitri Gribenko19523542012-09-29 11:40:46 +000017#include "clang/Lex/Preprocessor.h"
Dmitri Gribenko19523542012-09-29 11:40:46 +000018#include "llvm/ADT/SmallString.h"
Chandler Carruth55fc8732012-12-04 09:13:33 +000019#include "llvm/ADT/StringSwitch.h"
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +000020
21namespace clang {
22namespace comments {
23
Dmitri Gribenkoc24a76e2012-08-31 02:21:44 +000024namespace {
25#include "clang/AST/CommentHTMLTagsProperties.inc"
26} // unnamed namespace
27
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +000028Sema::Sema(llvm::BumpPtrAllocator &Allocator, const SourceManager &SourceMgr,
Dmitri Gribenko19523542012-09-29 11:40:46 +000029 DiagnosticsEngine &Diags, CommandTraits &Traits,
30 const Preprocessor *PP) :
Dmitri Gribenkoaa580812012-08-09 00:03:17 +000031 Allocator(Allocator), SourceMgr(SourceMgr), Diags(Diags), Traits(Traits),
Dmitri Gribenko19523542012-09-29 11:40:46 +000032 PP(PP), ThisDeclInfo(NULL), BriefCommand(NULL), ReturnsCommand(NULL) {
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +000033}
34
35void Sema::setDecl(const Decl *D) {
Dmitri Gribenko1ca7ecc2012-08-01 23:08:09 +000036 if (!D)
37 return;
38
39 ThisDeclInfo = new (Allocator) DeclInfo;
Fariborz Jahanianbf967be2012-10-10 18:34:52 +000040 ThisDeclInfo->CommentDecl = D;
Dmitri Gribenko651f8ce2012-08-01 23:21:57 +000041 ThisDeclInfo->IsFilled = false;
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +000042}
43
44ParagraphComment *Sema::actOnParagraphComment(
45 ArrayRef<InlineContentComment *> Content) {
46 return new (Allocator) ParagraphComment(Content);
47}
48
49BlockCommandComment *Sema::actOnBlockCommandStart(SourceLocation LocBegin,
50 SourceLocation LocEnd,
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +000051 unsigned CommandID) {
52 return new (Allocator) BlockCommandComment(LocBegin, LocEnd, CommandID);
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +000053}
54
Dmitri Gribenko7d9b5112012-08-06 19:03:12 +000055void Sema::actOnBlockCommandArgs(BlockCommandComment *Command,
56 ArrayRef<BlockCommandComment::Argument> Args) {
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +000057 Command->setArgs(Args);
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +000058}
59
Dmitri Gribenko7d9b5112012-08-06 19:03:12 +000060void Sema::actOnBlockCommandFinish(BlockCommandComment *Command,
61 ParagraphComment *Paragraph) {
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +000062 Command->setParagraph(Paragraph);
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +000063 checkBlockCommandEmptyParagraph(Command);
Dmitri Gribenko9443c572012-08-06 17:08:27 +000064 checkBlockCommandDuplicate(Command);
Dmitri Gribenko89ab7d02012-08-03 21:15:32 +000065 checkReturnsCommand(Command);
Dmitri Gribenko0bd98382012-09-22 21:47:50 +000066 checkDeprecatedCommand(Command);
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +000067}
68
69ParamCommandComment *Sema::actOnParamCommandStart(SourceLocation LocBegin,
70 SourceLocation LocEnd,
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +000071 unsigned CommandID) {
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +000072 ParamCommandComment *Command =
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +000073 new (Allocator) ParamCommandComment(LocBegin, LocEnd, CommandID);
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +000074
Dmitri Gribenko8487c522012-07-23 17:40:30 +000075 if (!isFunctionDecl())
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +000076 Diag(Command->getLocation(),
77 diag::warn_doc_param_not_attached_to_a_function_decl)
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +000078 << Command->getCommandNameRange(Traits);
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +000079
80 return Command;
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +000081}
82
Dmitri Gribenko7d9b5112012-08-06 19:03:12 +000083void Sema::actOnParamCommandDirectionArg(ParamCommandComment *Command,
84 SourceLocation ArgLocBegin,
85 SourceLocation ArgLocEnd,
86 StringRef Arg) {
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +000087 ParamCommandComment::PassDirection Direction;
88 std::string ArgLower = Arg.lower();
89 // TODO: optimize: lower Name first (need an API in SmallString for that),
90 // after that StringSwitch.
91 if (ArgLower == "[in]")
92 Direction = ParamCommandComment::In;
93 else if (ArgLower == "[out]")
94 Direction = ParamCommandComment::Out;
95 else if (ArgLower == "[in,out]" || ArgLower == "[out,in]")
96 Direction = ParamCommandComment::InOut;
97 else {
98 // Remove spaces.
99 std::string::iterator O = ArgLower.begin();
100 for (std::string::iterator I = ArgLower.begin(), E = ArgLower.end();
101 I != E; ++I) {
102 const char C = *I;
103 if (C != ' ' && C != '\n' && C != '\r' &&
104 C != '\t' && C != '\v' && C != '\f')
105 *O++ = C;
106 }
107 ArgLower.resize(O - ArgLower.begin());
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000108
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +0000109 bool RemovingWhitespaceHelped = false;
110 if (ArgLower == "[in]") {
111 Direction = ParamCommandComment::In;
112 RemovingWhitespaceHelped = true;
113 } else if (ArgLower == "[out]") {
114 Direction = ParamCommandComment::Out;
115 RemovingWhitespaceHelped = true;
116 } else if (ArgLower == "[in,out]" || ArgLower == "[out,in]") {
117 Direction = ParamCommandComment::InOut;
118 RemovingWhitespaceHelped = true;
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000119 } else {
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +0000120 Direction = ParamCommandComment::In;
121 RemovingWhitespaceHelped = false;
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000122 }
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +0000123
124 SourceRange ArgRange(ArgLocBegin, ArgLocEnd);
125 if (RemovingWhitespaceHelped)
126 Diag(ArgLocBegin, diag::warn_doc_param_spaces_in_direction)
127 << ArgRange
128 << FixItHint::CreateReplacement(
129 ArgRange,
130 ParamCommandComment::getDirectionAsString(Direction));
131 else
132 Diag(ArgLocBegin, diag::warn_doc_param_invalid_direction)
133 << ArgRange;
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000134 }
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +0000135 Command->setDirection(Direction, /* Explicit = */ true);
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +0000136}
137
Dmitri Gribenko7d9b5112012-08-06 19:03:12 +0000138void Sema::actOnParamCommandParamNameArg(ParamCommandComment *Command,
139 SourceLocation ArgLocBegin,
140 SourceLocation ArgLocEnd,
141 StringRef Arg) {
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +0000142 // Parser will not feed us more arguments than needed.
Dmitri Gribenko0eaf69d2012-07-13 19:02:42 +0000143 assert(Command->getNumArgs() == 0);
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +0000144
145 if (!Command->isDirectionExplicit()) {
146 // User didn't provide a direction argument.
147 Command->setDirection(ParamCommandComment::In, /* Explicit = */ false);
148 }
149 typedef BlockCommandComment::Argument Argument;
150 Argument *A = new (Allocator) Argument(SourceRange(ArgLocBegin,
151 ArgLocEnd),
152 Arg);
153 Command->setArgs(llvm::makeArrayRef(A, 1));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000154}
155
Dmitri Gribenko7d9b5112012-08-06 19:03:12 +0000156void Sema::actOnParamCommandFinish(ParamCommandComment *Command,
157 ParagraphComment *Paragraph) {
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000158 Command->setParagraph(Paragraph);
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +0000159 checkBlockCommandEmptyParagraph(Command);
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000160}
161
Dmitri Gribenko96b09862012-07-31 22:37:06 +0000162TParamCommandComment *Sema::actOnTParamCommandStart(SourceLocation LocBegin,
163 SourceLocation LocEnd,
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000164 unsigned CommandID) {
Dmitri Gribenko96b09862012-07-31 22:37:06 +0000165 TParamCommandComment *Command =
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000166 new (Allocator) TParamCommandComment(LocBegin, LocEnd, CommandID);
Dmitri Gribenko96b09862012-07-31 22:37:06 +0000167
Dmitri Gribenko04bf29e2012-08-06 21:31:15 +0000168 if (!isTemplateOrSpecialization())
Dmitri Gribenko96b09862012-07-31 22:37:06 +0000169 Diag(Command->getLocation(),
170 diag::warn_doc_tparam_not_attached_to_a_template_decl)
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000171 << Command->getCommandNameRange(Traits);
Dmitri Gribenko96b09862012-07-31 22:37:06 +0000172
173 return Command;
174}
175
Dmitri Gribenko7d9b5112012-08-06 19:03:12 +0000176void Sema::actOnTParamCommandParamNameArg(TParamCommandComment *Command,
177 SourceLocation ArgLocBegin,
178 SourceLocation ArgLocEnd,
179 StringRef Arg) {
Dmitri Gribenko96b09862012-07-31 22:37:06 +0000180 // Parser will not feed us more arguments than needed.
181 assert(Command->getNumArgs() == 0);
182
183 typedef BlockCommandComment::Argument Argument;
184 Argument *A = new (Allocator) Argument(SourceRange(ArgLocBegin,
185 ArgLocEnd),
186 Arg);
187 Command->setArgs(llvm::makeArrayRef(A, 1));
188
Dmitri Gribenko04bf29e2012-08-06 21:31:15 +0000189 if (!isTemplateOrSpecialization()) {
Dmitri Gribenko96b09862012-07-31 22:37:06 +0000190 // We already warned that this \\tparam is not attached to a template decl.
Dmitri Gribenko7d9b5112012-08-06 19:03:12 +0000191 return;
Dmitri Gribenko96b09862012-07-31 22:37:06 +0000192 }
193
Dmitri Gribenko1ca7ecc2012-08-01 23:08:09 +0000194 const TemplateParameterList *TemplateParameters =
195 ThisDeclInfo->TemplateParameters;
Dmitri Gribenko96b09862012-07-31 22:37:06 +0000196 SmallVector<unsigned, 2> Position;
197 if (resolveTParamReference(Arg, TemplateParameters, &Position)) {
198 Command->setPosition(copyArray(llvm::makeArrayRef(Position)));
199 llvm::StringMap<TParamCommandComment *>::iterator PrevCommandIt =
200 TemplateParameterDocs.find(Arg);
201 if (PrevCommandIt != TemplateParameterDocs.end()) {
202 SourceRange ArgRange(ArgLocBegin, ArgLocEnd);
203 Diag(ArgLocBegin, diag::warn_doc_tparam_duplicate)
204 << Arg << ArgRange;
205 TParamCommandComment *PrevCommand = PrevCommandIt->second;
206 Diag(PrevCommand->getLocation(), diag::note_doc_tparam_previous)
207 << PrevCommand->getParamNameRange();
208 }
209 TemplateParameterDocs[Arg] = Command;
Dmitri Gribenko7d9b5112012-08-06 19:03:12 +0000210 return;
Dmitri Gribenko96b09862012-07-31 22:37:06 +0000211 }
212
213 SourceRange ArgRange(ArgLocBegin, ArgLocEnd);
214 Diag(ArgLocBegin, diag::warn_doc_tparam_not_found)
215 << Arg << ArgRange;
216
217 if (!TemplateParameters || TemplateParameters->size() == 0)
Dmitri Gribenko7d9b5112012-08-06 19:03:12 +0000218 return;
Dmitri Gribenko96b09862012-07-31 22:37:06 +0000219
220 StringRef CorrectedName;
221 if (TemplateParameters->size() == 1) {
222 const NamedDecl *Param = TemplateParameters->getParam(0);
223 const IdentifierInfo *II = Param->getIdentifier();
224 if (II)
225 CorrectedName = II->getName();
226 } else {
227 CorrectedName = correctTypoInTParamReference(Arg, TemplateParameters);
228 }
229
230 if (!CorrectedName.empty()) {
231 Diag(ArgLocBegin, diag::note_doc_tparam_name_suggestion)
232 << CorrectedName
233 << FixItHint::CreateReplacement(ArgRange, CorrectedName);
234 }
235
Dmitri Gribenko7d9b5112012-08-06 19:03:12 +0000236 return;
Dmitri Gribenko96b09862012-07-31 22:37:06 +0000237}
238
Dmitri Gribenko7d9b5112012-08-06 19:03:12 +0000239void Sema::actOnTParamCommandFinish(TParamCommandComment *Command,
240 ParagraphComment *Paragraph) {
Dmitri Gribenko96b09862012-07-31 22:37:06 +0000241 Command->setParagraph(Paragraph);
242 checkBlockCommandEmptyParagraph(Command);
Dmitri Gribenko96b09862012-07-31 22:37:06 +0000243}
244
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000245InlineCommandComment *Sema::actOnInlineCommand(SourceLocation CommandLocBegin,
246 SourceLocation CommandLocEnd,
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000247 unsigned CommandID) {
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000248 ArrayRef<InlineCommandComment::Argument> Args;
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000249 StringRef CommandName = Traits.getCommandInfo(CommandID)->Name;
Dmitri Gribenko2d66a502012-07-23 16:43:01 +0000250 return new (Allocator) InlineCommandComment(
251 CommandLocBegin,
252 CommandLocEnd,
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000253 CommandID,
Dmitri Gribenko2d66a502012-07-23 16:43:01 +0000254 getInlineCommandRenderKind(CommandName),
255 Args);
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000256}
257
258InlineCommandComment *Sema::actOnInlineCommand(SourceLocation CommandLocBegin,
259 SourceLocation CommandLocEnd,
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000260 unsigned CommandID,
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000261 SourceLocation ArgLocBegin,
262 SourceLocation ArgLocEnd,
263 StringRef Arg) {
264 typedef InlineCommandComment::Argument Argument;
265 Argument *A = new (Allocator) Argument(SourceRange(ArgLocBegin,
266 ArgLocEnd),
267 Arg);
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000268 StringRef CommandName = Traits.getCommandInfo(CommandID)->Name;
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000269
Dmitri Gribenko2d66a502012-07-23 16:43:01 +0000270 return new (Allocator) InlineCommandComment(
271 CommandLocBegin,
272 CommandLocEnd,
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000273 CommandID,
Dmitri Gribenko2d66a502012-07-23 16:43:01 +0000274 getInlineCommandRenderKind(CommandName),
275 llvm::makeArrayRef(A, 1));
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000276}
277
278InlineContentComment *Sema::actOnUnknownCommand(SourceLocation LocBegin,
279 SourceLocation LocEnd,
Dmitri Gribenkob0b8a962012-09-11 19:22:03 +0000280 StringRef CommandName) {
281 unsigned CommandID = Traits.registerUnknownCommand(CommandName)->getID();
282 return actOnUnknownCommand(LocBegin, LocEnd, CommandID);
283}
284
285InlineContentComment *Sema::actOnUnknownCommand(SourceLocation LocBegin,
286 SourceLocation LocEnd,
287 unsigned CommandID) {
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000288 ArrayRef<InlineCommandComment::Argument> Args;
Dmitri Gribenko2d66a502012-07-23 16:43:01 +0000289 return new (Allocator) InlineCommandComment(
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000290 LocBegin, LocEnd, CommandID,
Dmitri Gribenko2d66a502012-07-23 16:43:01 +0000291 InlineCommandComment::RenderNormal,
292 Args);
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000293}
294
295TextComment *Sema::actOnText(SourceLocation LocBegin,
296 SourceLocation LocEnd,
297 StringRef Text) {
298 return new (Allocator) TextComment(LocBegin, LocEnd, Text);
299}
300
301VerbatimBlockComment *Sema::actOnVerbatimBlockStart(SourceLocation Loc,
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000302 unsigned CommandID) {
303 StringRef CommandName = Traits.getCommandInfo(CommandID)->Name;
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000304 return new (Allocator) VerbatimBlockComment(
305 Loc,
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000306 Loc.getLocWithOffset(1 + CommandName.size()),
307 CommandID);
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000308}
309
310VerbatimBlockLineComment *Sema::actOnVerbatimBlockLine(SourceLocation Loc,
311 StringRef Text) {
312 return new (Allocator) VerbatimBlockLineComment(Loc, Text);
313}
314
Dmitri Gribenko7d9b5112012-08-06 19:03:12 +0000315void Sema::actOnVerbatimBlockFinish(
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000316 VerbatimBlockComment *Block,
317 SourceLocation CloseNameLocBegin,
318 StringRef CloseName,
319 ArrayRef<VerbatimBlockLineComment *> Lines) {
320 Block->setCloseName(CloseName, CloseNameLocBegin);
321 Block->setLines(Lines);
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000322}
323
324VerbatimLineComment *Sema::actOnVerbatimLine(SourceLocation LocBegin,
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000325 unsigned CommandID,
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000326 SourceLocation TextBegin,
327 StringRef Text) {
328 return new (Allocator) VerbatimLineComment(
329 LocBegin,
330 TextBegin.getLocWithOffset(Text.size()),
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000331 CommandID,
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000332 TextBegin,
333 Text);
334}
335
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000336HTMLStartTagComment *Sema::actOnHTMLStartTagStart(SourceLocation LocBegin,
337 StringRef TagName) {
338 return new (Allocator) HTMLStartTagComment(LocBegin, TagName);
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000339}
340
Dmitri Gribenko7d9b5112012-08-06 19:03:12 +0000341void Sema::actOnHTMLStartTagFinish(
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000342 HTMLStartTagComment *Tag,
343 ArrayRef<HTMLStartTagComment::Attribute> Attrs,
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +0000344 SourceLocation GreaterLoc,
345 bool IsSelfClosing) {
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000346 Tag->setAttrs(Attrs);
347 Tag->setGreaterLoc(GreaterLoc);
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +0000348 if (IsSelfClosing)
349 Tag->setSelfClosing();
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000350 else if (!isHTMLEndTagForbidden(Tag->getTagName()))
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +0000351 HTMLOpenTags.push_back(Tag);
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000352}
353
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000354HTMLEndTagComment *Sema::actOnHTMLEndTag(SourceLocation LocBegin,
355 SourceLocation LocEnd,
356 StringRef TagName) {
357 HTMLEndTagComment *HET =
358 new (Allocator) HTMLEndTagComment(LocBegin, LocEnd, TagName);
359 if (isHTMLEndTagForbidden(TagName)) {
360 Diag(HET->getLocation(), diag::warn_doc_html_end_forbidden)
361 << TagName << HET->getSourceRange();
362 return HET;
Dmitri Gribenko3d986982012-07-12 23:37:09 +0000363 }
364
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +0000365 bool FoundOpen = false;
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000366 for (SmallVectorImpl<HTMLStartTagComment *>::const_reverse_iterator
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +0000367 I = HTMLOpenTags.rbegin(), E = HTMLOpenTags.rend();
368 I != E; ++I) {
369 if ((*I)->getTagName() == TagName) {
370 FoundOpen = true;
371 break;
372 }
373 }
374 if (!FoundOpen) {
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000375 Diag(HET->getLocation(), diag::warn_doc_html_end_unbalanced)
376 << HET->getSourceRange();
377 return HET;
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +0000378 }
379
380 while (!HTMLOpenTags.empty()) {
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000381 const HTMLStartTagComment *HST = HTMLOpenTags.back();
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +0000382 HTMLOpenTags.pop_back();
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000383 StringRef LastNotClosedTagName = HST->getTagName();
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +0000384 if (LastNotClosedTagName == TagName)
385 break;
386
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000387 if (isHTMLEndTagOptional(LastNotClosedTagName))
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +0000388 continue;
389
390 bool OpenLineInvalid;
391 const unsigned OpenLine = SourceMgr.getPresumedLineNumber(
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000392 HST->getLocation(),
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +0000393 &OpenLineInvalid);
394 bool CloseLineInvalid;
395 const unsigned CloseLine = SourceMgr.getPresumedLineNumber(
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000396 HET->getLocation(),
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +0000397 &CloseLineInvalid);
398
399 if (OpenLineInvalid || CloseLineInvalid || OpenLine == CloseLine)
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000400 Diag(HST->getLocation(), diag::warn_doc_html_start_end_mismatch)
401 << HST->getTagName() << HET->getTagName()
402 << HST->getSourceRange() << HET->getSourceRange();
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +0000403 else {
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000404 Diag(HST->getLocation(), diag::warn_doc_html_start_end_mismatch)
405 << HST->getTagName() << HET->getTagName()
406 << HST->getSourceRange();
407 Diag(HET->getLocation(), diag::note_doc_html_end_tag)
408 << HET->getSourceRange();
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +0000409 }
410 }
411
Dmitri Gribenko3f38bf22012-07-13 00:44:24 +0000412 return HET;
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000413}
414
415FullComment *Sema::actOnFullComment(
416 ArrayRef<BlockContentComment *> Blocks) {
Fariborz Jahanian749ace62012-10-11 23:52:50 +0000417 FullComment *FC = new (Allocator) FullComment(Blocks, ThisDeclInfo);
Dmitri Gribenko9edd2c82012-08-24 17:45:39 +0000418 resolveParamCommandIndexes(FC);
419 return FC;
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000420}
421
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +0000422void Sema::checkBlockCommandEmptyParagraph(BlockCommandComment *Command) {
Dmitri Gribenkoabcf0dc2012-09-13 20:36:01 +0000423 if (Traits.getCommandInfo(Command->getCommandID())->IsEmptyParagraphAllowed)
424 return;
425
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +0000426 ParagraphComment *Paragraph = Command->getParagraph();
427 if (Paragraph->isWhitespace()) {
428 SourceLocation DiagLoc;
Dmitri Gribenko0eaf69d2012-07-13 19:02:42 +0000429 if (Command->getNumArgs() > 0)
430 DiagLoc = Command->getArgRange(Command->getNumArgs() - 1).getEnd();
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +0000431 if (!DiagLoc.isValid())
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000432 DiagLoc = Command->getCommandNameRange(Traits).getEnd();
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +0000433 Diag(DiagLoc, diag::warn_doc_block_command_empty_paragraph)
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000434 << Command->getCommandName(Traits)
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +0000435 << Command->getSourceRange();
436 }
437}
438
Dmitri Gribenko89ab7d02012-08-03 21:15:32 +0000439void Sema::checkReturnsCommand(const BlockCommandComment *Command) {
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000440 if (!Traits.getCommandInfo(Command->getCommandID())->IsReturnsCommand)
Dmitri Gribenko89ab7d02012-08-03 21:15:32 +0000441 return;
442 if (isFunctionDecl()) {
443 if (ThisDeclInfo->ResultType->isVoidType()) {
444 unsigned DiagKind;
Fariborz Jahanianbf967be2012-10-10 18:34:52 +0000445 switch (ThisDeclInfo->CommentDecl->getKind()) {
Dmitri Gribenko89ab7d02012-08-03 21:15:32 +0000446 default:
Dmitri Gribenko88815f32012-08-06 16:29:26 +0000447 if (ThisDeclInfo->IsObjCMethod)
448 DiagKind = 3;
449 else
450 DiagKind = 0;
Dmitri Gribenko89ab7d02012-08-03 21:15:32 +0000451 break;
452 case Decl::CXXConstructor:
453 DiagKind = 1;
454 break;
455 case Decl::CXXDestructor:
456 DiagKind = 2;
457 break;
458 }
459 Diag(Command->getLocation(),
460 diag::warn_doc_returns_attached_to_a_void_function)
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000461 << Command->getCommandName(Traits)
Dmitri Gribenko89ab7d02012-08-03 21:15:32 +0000462 << DiagKind
463 << Command->getSourceRange();
464 }
465 return;
466 }
467 Diag(Command->getLocation(),
468 diag::warn_doc_returns_not_attached_to_a_function_decl)
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000469 << Command->getCommandName(Traits)
Dmitri Gribenko89ab7d02012-08-03 21:15:32 +0000470 << Command->getSourceRange();
471}
472
Dmitri Gribenko9443c572012-08-06 17:08:27 +0000473void Sema::checkBlockCommandDuplicate(const BlockCommandComment *Command) {
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000474 const CommandInfo *Info = Traits.getCommandInfo(Command->getCommandID());
Dmitri Gribenko9443c572012-08-06 17:08:27 +0000475 const BlockCommandComment *PrevCommand = NULL;
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000476 if (Info->IsBriefCommand) {
Dmitri Gribenko9443c572012-08-06 17:08:27 +0000477 if (!BriefCommand) {
478 BriefCommand = Command;
479 return;
480 }
481 PrevCommand = BriefCommand;
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000482 } else if (Info->IsReturnsCommand) {
Dmitri Gribenko9443c572012-08-06 17:08:27 +0000483 if (!ReturnsCommand) {
484 ReturnsCommand = Command;
485 return;
486 }
487 PrevCommand = ReturnsCommand;
488 } else {
489 // We don't want to check this command for duplicates.
490 return;
491 }
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000492 StringRef CommandName = Command->getCommandName(Traits);
493 StringRef PrevCommandName = PrevCommand->getCommandName(Traits);
Dmitri Gribenko9443c572012-08-06 17:08:27 +0000494 Diag(Command->getLocation(), diag::warn_doc_block_command_duplicate)
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000495 << CommandName
Dmitri Gribenko9443c572012-08-06 17:08:27 +0000496 << Command->getSourceRange();
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000497 if (CommandName == PrevCommandName)
Dmitri Gribenko9443c572012-08-06 17:08:27 +0000498 Diag(PrevCommand->getLocation(), diag::note_doc_block_command_previous)
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000499 << PrevCommandName
500 << PrevCommand->getSourceRange();
Dmitri Gribenko9443c572012-08-06 17:08:27 +0000501 else
502 Diag(PrevCommand->getLocation(),
503 diag::note_doc_block_command_previous_alias)
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000504 << PrevCommandName
505 << CommandName;
Dmitri Gribenko9443c572012-08-06 17:08:27 +0000506}
507
Dmitri Gribenko0bd98382012-09-22 21:47:50 +0000508void Sema::checkDeprecatedCommand(const BlockCommandComment *Command) {
509 if (!Traits.getCommandInfo(Command->getCommandID())->IsDeprecatedCommand)
510 return;
511
Fariborz Jahanianbf967be2012-10-10 18:34:52 +0000512 const Decl *D = ThisDeclInfo->CommentDecl;
Dmitri Gribenko0bd98382012-09-22 21:47:50 +0000513 if (!D)
514 return;
515
516 if (D->hasAttr<DeprecatedAttr>() ||
517 D->hasAttr<AvailabilityAttr>() ||
518 D->hasAttr<UnavailableAttr>())
519 return;
520
521 Diag(Command->getLocation(),
522 diag::warn_doc_deprecated_not_sync)
523 << Command->getSourceRange();
524
525 // Try to emit a fixit with a deprecation attribute.
526 if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
527 // Don't emit a Fix-It for non-member function definitions. GCC does not
528 // accept attributes on them.
529 const DeclContext *Ctx = FD->getDeclContext();
530 if ((!Ctx || !Ctx->isRecord()) &&
531 FD->doesThisDeclarationHaveABody())
532 return;
533
Dmitri Gribenko19523542012-09-29 11:40:46 +0000534 StringRef AttributeSpelling = "__attribute__((deprecated))";
535 if (PP) {
536 TokenValue Tokens[] = {
537 tok::kw___attribute, tok::l_paren, tok::l_paren,
538 PP->getIdentifierInfo("deprecated"),
539 tok::r_paren, tok::r_paren
540 };
541 StringRef MacroName = PP->getLastMacroWithSpelling(FD->getLocation(),
542 Tokens);
543 if (!MacroName.empty())
544 AttributeSpelling = MacroName;
545 }
546
547 SmallString<64> TextToInsert(" ");
548 TextToInsert += AttributeSpelling;
Dmitri Gribenko0bd98382012-09-22 21:47:50 +0000549 Diag(FD->getLocEnd(),
550 diag::note_add_deprecation_attr)
551 << FixItHint::CreateInsertion(FD->getLocEnd().getLocWithOffset(1),
Dmitri Gribenko19523542012-09-29 11:40:46 +0000552 TextToInsert);
Dmitri Gribenko0bd98382012-09-22 21:47:50 +0000553 }
554}
555
Dmitri Gribenko9edd2c82012-08-24 17:45:39 +0000556void Sema::resolveParamCommandIndexes(const FullComment *FC) {
557 if (!isFunctionDecl()) {
558 // We already warned that \\param commands are not attached to a function
559 // decl.
560 return;
561 }
562
563 llvm::SmallVector<ParamCommandComment *, 8> UnresolvedParamCommands;
564
565 // Comment AST nodes that correspond to \c ParamVars for which we have
566 // found a \\param command or NULL if no documentation was found so far.
567 llvm::SmallVector<ParamCommandComment *, 8> ParamVarDocs;
568
569 ArrayRef<const ParmVarDecl *> ParamVars = getParamVars();
570 ParamVarDocs.resize(ParamVars.size(), NULL);
571
572 // First pass over all \\param commands: resolve all parameter names.
573 for (Comment::child_iterator I = FC->child_begin(), E = FC->child_end();
574 I != E; ++I) {
575 ParamCommandComment *PCC = dyn_cast<ParamCommandComment>(*I);
576 if (!PCC || !PCC->hasParamName())
577 continue;
Fariborz Jahanian262e60c2012-10-18 21:42:42 +0000578 StringRef ParamName = PCC->getParamNameAsWritten();
Dmitri Gribenko9edd2c82012-08-24 17:45:39 +0000579
580 // Check that referenced parameter name is in the function decl.
581 const unsigned ResolvedParamIndex = resolveParmVarReference(ParamName,
582 ParamVars);
583 if (ResolvedParamIndex == ParamCommandComment::InvalidParamIndex) {
584 UnresolvedParamCommands.push_back(PCC);
585 continue;
586 }
587 PCC->setParamIndex(ResolvedParamIndex);
588 if (ParamVarDocs[ResolvedParamIndex]) {
589 SourceRange ArgRange = PCC->getParamNameRange();
590 Diag(ArgRange.getBegin(), diag::warn_doc_param_duplicate)
591 << ParamName << ArgRange;
592 ParamCommandComment *PrevCommand = ParamVarDocs[ResolvedParamIndex];
593 Diag(PrevCommand->getLocation(), diag::note_doc_param_previous)
594 << PrevCommand->getParamNameRange();
595 }
596 ParamVarDocs[ResolvedParamIndex] = PCC;
597 }
598
599 // Find parameter declarations that have no corresponding \\param.
600 llvm::SmallVector<const ParmVarDecl *, 8> OrphanedParamDecls;
601 for (unsigned i = 0, e = ParamVarDocs.size(); i != e; ++i) {
602 if (!ParamVarDocs[i])
603 OrphanedParamDecls.push_back(ParamVars[i]);
604 }
605
606 // Second pass over unresolved \\param commands: do typo correction.
607 // Suggest corrections from a set of parameter declarations that have no
608 // corresponding \\param.
609 for (unsigned i = 0, e = UnresolvedParamCommands.size(); i != e; ++i) {
610 const ParamCommandComment *PCC = UnresolvedParamCommands[i];
611
612 SourceRange ArgRange = PCC->getParamNameRange();
Fariborz Jahanian262e60c2012-10-18 21:42:42 +0000613 StringRef ParamName = PCC->getParamNameAsWritten();
Dmitri Gribenko9edd2c82012-08-24 17:45:39 +0000614 Diag(ArgRange.getBegin(), diag::warn_doc_param_not_found)
615 << ParamName << ArgRange;
616
617 // All parameters documented -- can't suggest a correction.
618 if (OrphanedParamDecls.size() == 0)
619 continue;
620
621 unsigned CorrectedParamIndex = ParamCommandComment::InvalidParamIndex;
622 if (OrphanedParamDecls.size() == 1) {
623 // If one parameter is not documented then that parameter is the only
624 // possible suggestion.
625 CorrectedParamIndex = 0;
626 } else {
627 // Do typo correction.
628 CorrectedParamIndex = correctTypoInParmVarReference(ParamName,
629 OrphanedParamDecls);
630 }
631 if (CorrectedParamIndex != ParamCommandComment::InvalidParamIndex) {
632 const ParmVarDecl *CorrectedPVD = OrphanedParamDecls[CorrectedParamIndex];
633 if (const IdentifierInfo *CorrectedII = CorrectedPVD->getIdentifier())
634 Diag(ArgRange.getBegin(), diag::note_doc_param_name_suggestion)
635 << CorrectedII->getName()
636 << FixItHint::CreateReplacement(ArgRange, CorrectedII->getName());
637 }
638 }
639}
640
Dmitri Gribenko8487c522012-07-23 17:40:30 +0000641bool Sema::isFunctionDecl() {
Dmitri Gribenko1ca7ecc2012-08-01 23:08:09 +0000642 if (!ThisDeclInfo)
643 return false;
644 if (!ThisDeclInfo->IsFilled)
Dmitri Gribenko00c59f72012-07-24 20:58:46 +0000645 inspectThisDecl();
Dmitri Gribenkoaf19a6a2012-08-02 21:45:39 +0000646 return ThisDeclInfo->getKind() == DeclInfo::FunctionKind;
Dmitri Gribenko8487c522012-07-23 17:40:30 +0000647}
648
Dmitri Gribenko04bf29e2012-08-06 21:31:15 +0000649bool Sema::isTemplateOrSpecialization() {
Dmitri Gribenko1ca7ecc2012-08-01 23:08:09 +0000650 if (!ThisDeclInfo)
651 return false;
652 if (!ThisDeclInfo->IsFilled)
Dmitri Gribenko96b09862012-07-31 22:37:06 +0000653 inspectThisDecl();
Dmitri Gribenko04bf29e2012-08-06 21:31:15 +0000654 return ThisDeclInfo->getTemplateKind() != DeclInfo::NotTemplate;
Dmitri Gribenko96b09862012-07-31 22:37:06 +0000655}
656
Dmitri Gribenko8487c522012-07-23 17:40:30 +0000657ArrayRef<const ParmVarDecl *> Sema::getParamVars() {
Dmitri Gribenko1ca7ecc2012-08-01 23:08:09 +0000658 if (!ThisDeclInfo->IsFilled)
Dmitri Gribenko00c59f72012-07-24 20:58:46 +0000659 inspectThisDecl();
Dmitri Gribenko1ca7ecc2012-08-01 23:08:09 +0000660 return ThisDeclInfo->ParamVars;
Dmitri Gribenko8487c522012-07-23 17:40:30 +0000661}
662
663void Sema::inspectThisDecl() {
Dmitri Gribenko1ca7ecc2012-08-01 23:08:09 +0000664 ThisDeclInfo->fill();
Dmitri Gribenko8487c522012-07-23 17:40:30 +0000665}
666
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +0000667unsigned Sema::resolveParmVarReference(StringRef Name,
Dmitri Gribenko8487c522012-07-23 17:40:30 +0000668 ArrayRef<const ParmVarDecl *> ParamVars) {
669 for (unsigned i = 0, e = ParamVars.size(); i != e; ++i) {
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +0000670 const IdentifierInfo *II = ParamVars[i]->getIdentifier();
671 if (II && II->getName() == Name)
672 return i;
673 }
674 return ParamCommandComment::InvalidParamIndex;
675}
676
Dmitri Gribenko96b09862012-07-31 22:37:06 +0000677namespace {
678class SimpleTypoCorrector {
679 StringRef Typo;
680 const unsigned MaxEditDistance;
681
682 const NamedDecl *BestDecl;
683 unsigned BestEditDistance;
684 unsigned BestIndex;
685 unsigned NextIndex;
686
687public:
688 SimpleTypoCorrector(StringRef Typo) :
689 Typo(Typo), MaxEditDistance((Typo.size() + 2) / 3),
690 BestDecl(NULL), BestEditDistance(MaxEditDistance + 1),
691 BestIndex(0), NextIndex(0)
692 { }
693
694 void addDecl(const NamedDecl *ND);
695
696 const NamedDecl *getBestDecl() const {
697 if (BestEditDistance > MaxEditDistance)
698 return NULL;
699
700 return BestDecl;
701 }
702
703 unsigned getBestDeclIndex() const {
704 assert(getBestDecl());
705 return BestIndex;
706 }
707};
708
709void SimpleTypoCorrector::addDecl(const NamedDecl *ND) {
710 unsigned CurrIndex = NextIndex++;
711
712 const IdentifierInfo *II = ND->getIdentifier();
713 if (!II)
714 return;
715
716 StringRef Name = II->getName();
717 unsigned MinPossibleEditDistance = abs((int)Name.size() - (int)Typo.size());
718 if (MinPossibleEditDistance > 0 &&
719 Typo.size() / MinPossibleEditDistance < 3)
720 return;
721
722 unsigned EditDistance = Typo.edit_distance(Name, true, MaxEditDistance);
723 if (EditDistance < BestEditDistance) {
724 BestEditDistance = EditDistance;
725 BestDecl = ND;
726 BestIndex = CurrIndex;
727 }
728}
729} // unnamed namespace
730
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +0000731unsigned Sema::correctTypoInParmVarReference(
732 StringRef Typo,
Dmitri Gribenko8487c522012-07-23 17:40:30 +0000733 ArrayRef<const ParmVarDecl *> ParamVars) {
Dmitri Gribenko96b09862012-07-31 22:37:06 +0000734 SimpleTypoCorrector Corrector(Typo);
735 for (unsigned i = 0, e = ParamVars.size(); i != e; ++i)
736 Corrector.addDecl(ParamVars[i]);
737 if (Corrector.getBestDecl())
738 return Corrector.getBestDeclIndex();
739 else
Dmitri Gribenko1ad23d62012-09-10 21:20:09 +0000740 return ParamCommandComment::InvalidParamIndex;
Dmitri Gribenko96b09862012-07-31 22:37:06 +0000741}
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +0000742
Dmitri Gribenko96b09862012-07-31 22:37:06 +0000743namespace {
744bool ResolveTParamReferenceHelper(
745 StringRef Name,
746 const TemplateParameterList *TemplateParameters,
747 SmallVectorImpl<unsigned> *Position) {
748 for (unsigned i = 0, e = TemplateParameters->size(); i != e; ++i) {
749 const NamedDecl *Param = TemplateParameters->getParam(i);
750 const IdentifierInfo *II = Param->getIdentifier();
751 if (II && II->getName() == Name) {
752 Position->push_back(i);
753 return true;
754 }
755
756 if (const TemplateTemplateParmDecl *TTP =
757 dyn_cast<TemplateTemplateParmDecl>(Param)) {
758 Position->push_back(i);
759 if (ResolveTParamReferenceHelper(Name, TTP->getTemplateParameters(),
760 Position))
761 return true;
762 Position->pop_back();
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +0000763 }
764 }
Dmitri Gribenko96b09862012-07-31 22:37:06 +0000765 return false;
766}
767} // unnamed namespace
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +0000768
Dmitri Gribenko96b09862012-07-31 22:37:06 +0000769bool Sema::resolveTParamReference(
770 StringRef Name,
771 const TemplateParameterList *TemplateParameters,
772 SmallVectorImpl<unsigned> *Position) {
773 Position->clear();
774 if (!TemplateParameters)
775 return false;
776
777 return ResolveTParamReferenceHelper(Name, TemplateParameters, Position);
778}
779
780namespace {
781void CorrectTypoInTParamReferenceHelper(
782 const TemplateParameterList *TemplateParameters,
783 SimpleTypoCorrector &Corrector) {
784 for (unsigned i = 0, e = TemplateParameters->size(); i != e; ++i) {
785 const NamedDecl *Param = TemplateParameters->getParam(i);
786 Corrector.addDecl(Param);
787
788 if (const TemplateTemplateParmDecl *TTP =
789 dyn_cast<TemplateTemplateParmDecl>(Param))
790 CorrectTypoInTParamReferenceHelper(TTP->getTemplateParameters(),
791 Corrector);
792 }
793}
794} // unnamed namespace
795
796StringRef Sema::correctTypoInTParamReference(
797 StringRef Typo,
798 const TemplateParameterList *TemplateParameters) {
799 SimpleTypoCorrector Corrector(Typo);
800 CorrectTypoInTParamReferenceHelper(TemplateParameters, Corrector);
801 if (const NamedDecl *ND = Corrector.getBestDecl()) {
802 const IdentifierInfo *II = ND->getIdentifier();
803 assert(II && "SimpleTypoCorrector should not return this decl");
804 return II->getName();
805 }
806 return StringRef();
Dmitri Gribenkoa5ef44f2012-07-11 21:38:39 +0000807}
808
Dmitri Gribenko2d66a502012-07-23 16:43:01 +0000809InlineCommandComment::RenderKind
810Sema::getInlineCommandRenderKind(StringRef Name) const {
Dmitri Gribenkoe4330a32012-09-10 20:32:42 +0000811 assert(Traits.getCommandInfo(Name)->IsInlineCommand);
Dmitri Gribenko2d66a502012-07-23 16:43:01 +0000812
813 return llvm::StringSwitch<InlineCommandComment::RenderKind>(Name)
814 .Case("b", InlineCommandComment::RenderBold)
815 .Cases("c", "p", InlineCommandComment::RenderMonospaced)
816 .Cases("a", "e", "em", InlineCommandComment::RenderEmphasized)
817 .Default(InlineCommandComment::RenderNormal);
818}
819
Dmitri Gribenko8d3ba232012-07-06 00:28:32 +0000820} // end namespace comments
821} // end namespace clang
822