2013-03-06 03:52:24 +08:00
|
|
|
//===--- CommentSema.cpp - Doxygen comment semantic analysis --------------===//
|
2012-07-06 08:28:32 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2012-07-06 08:28:32 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "clang/AST/CommentSema.h"
|
2012-12-01 23:09:41 +08:00
|
|
|
#include "clang/AST/Attr.h"
|
2012-08-09 08:03:17 +08:00
|
|
|
#include "clang/AST/CommentCommandTraits.h"
|
2012-12-01 23:09:41 +08:00
|
|
|
#include "clang/AST/CommentDiagnostic.h"
|
2012-07-12 05:38:39 +08:00
|
|
|
#include "clang/AST/Decl.h"
|
2012-08-01 06:37:06 +08:00
|
|
|
#include "clang/AST/DeclTemplate.h"
|
2020-02-18 06:55:49 +08:00
|
|
|
#include "clang/Basic/LLVM.h"
|
2012-07-12 05:38:39 +08:00
|
|
|
#include "clang/Basic/SourceManager.h"
|
2012-09-29 19:40:46 +08:00
|
|
|
#include "clang/Lex/Preprocessor.h"
|
|
|
|
#include "llvm/ADT/SmallString.h"
|
2012-12-04 17:13:33 +08:00
|
|
|
#include "llvm/ADT/StringSwitch.h"
|
2012-07-06 08:28:32 +08:00
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
namespace comments {
|
|
|
|
|
2012-08-31 10:21:44 +08:00
|
|
|
namespace {
|
|
|
|
#include "clang/AST/CommentHTMLTagsProperties.inc"
|
2016-02-11 03:11:58 +08:00
|
|
|
} // end anonymous namespace
|
2012-08-31 10:21:44 +08:00
|
|
|
|
2012-07-12 05:38:39 +08:00
|
|
|
Sema::Sema(llvm::BumpPtrAllocator &Allocator, const SourceManager &SourceMgr,
|
2012-09-29 19:40:46 +08:00
|
|
|
DiagnosticsEngine &Diags, CommandTraits &Traits,
|
|
|
|
const Preprocessor *PP) :
|
2012-08-09 08:03:17 +08:00
|
|
|
Allocator(Allocator), SourceMgr(SourceMgr), Diags(Diags), Traits(Traits),
|
2014-05-12 13:36:57 +08:00
|
|
|
PP(PP), ThisDeclInfo(nullptr), BriefCommand(nullptr),
|
|
|
|
HeaderfileCommand(nullptr) {
|
2012-07-12 05:38:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void Sema::setDecl(const Decl *D) {
|
2012-08-02 07:08:09 +08:00
|
|
|
if (!D)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ThisDeclInfo = new (Allocator) DeclInfo;
|
2012-10-11 02:34:52 +08:00
|
|
|
ThisDeclInfo->CommentDecl = D;
|
2012-08-02 07:21:57 +08:00
|
|
|
ThisDeclInfo->IsFilled = false;
|
2012-07-06 08:28:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ParagraphComment *Sema::actOnParagraphComment(
|
|
|
|
ArrayRef<InlineContentComment *> Content) {
|
|
|
|
return new (Allocator) ParagraphComment(Content);
|
|
|
|
}
|
|
|
|
|
2013-03-05 07:06:15 +08:00
|
|
|
BlockCommandComment *Sema::actOnBlockCommandStart(
|
|
|
|
SourceLocation LocBegin,
|
|
|
|
SourceLocation LocEnd,
|
|
|
|
unsigned CommandID,
|
|
|
|
CommandMarkerKind CommandMarker) {
|
2013-03-08 07:33:11 +08:00
|
|
|
BlockCommandComment *BC = new (Allocator) BlockCommandComment(LocBegin, LocEnd,
|
|
|
|
CommandID,
|
|
|
|
CommandMarker);
|
|
|
|
checkContainerDecl(BC);
|
|
|
|
return BC;
|
2012-07-06 08:28:32 +08:00
|
|
|
}
|
|
|
|
|
2012-08-07 03:03:12 +08:00
|
|
|
void Sema::actOnBlockCommandArgs(BlockCommandComment *Command,
|
|
|
|
ArrayRef<BlockCommandComment::Argument> Args) {
|
2012-07-06 08:28:32 +08:00
|
|
|
Command->setArgs(Args);
|
|
|
|
}
|
|
|
|
|
2012-08-07 03:03:12 +08:00
|
|
|
void Sema::actOnBlockCommandFinish(BlockCommandComment *Command,
|
|
|
|
ParagraphComment *Paragraph) {
|
2012-07-06 08:28:32 +08:00
|
|
|
Command->setParagraph(Paragraph);
|
2012-07-12 05:38:39 +08:00
|
|
|
checkBlockCommandEmptyParagraph(Command);
|
2012-08-07 01:08:27 +08:00
|
|
|
checkBlockCommandDuplicate(Command);
|
2014-01-28 01:55:43 +08:00
|
|
|
if (ThisDeclInfo) {
|
|
|
|
// These checks only make sense if the comment is attached to a
|
|
|
|
// declaration.
|
|
|
|
checkReturnsCommand(Command);
|
|
|
|
checkDeprecatedCommand(Command);
|
|
|
|
}
|
2012-07-06 08:28:32 +08:00
|
|
|
}
|
|
|
|
|
2013-03-05 07:06:15 +08:00
|
|
|
ParamCommandComment *Sema::actOnParamCommandStart(
|
|
|
|
SourceLocation LocBegin,
|
|
|
|
SourceLocation LocEnd,
|
|
|
|
unsigned CommandID,
|
|
|
|
CommandMarkerKind CommandMarker) {
|
2012-07-12 05:38:39 +08:00
|
|
|
ParamCommandComment *Command =
|
2013-03-05 07:06:15 +08:00
|
|
|
new (Allocator) ParamCommandComment(LocBegin, LocEnd, CommandID,
|
|
|
|
CommandMarker);
|
2012-07-12 05:38:39 +08:00
|
|
|
|
2017-04-21 22:17:49 +08:00
|
|
|
if (!isFunctionDecl() && !isFunctionOrBlockPointerVarLikeDecl())
|
2012-07-12 05:38:39 +08:00
|
|
|
Diag(Command->getLocation(),
|
|
|
|
diag::warn_doc_param_not_attached_to_a_function_decl)
|
2013-03-05 07:06:15 +08:00
|
|
|
<< CommandMarker
|
2012-09-11 04:32:42 +08:00
|
|
|
<< Command->getCommandNameRange(Traits);
|
2012-07-12 05:38:39 +08:00
|
|
|
|
|
|
|
return Command;
|
2012-07-06 08:28:32 +08:00
|
|
|
}
|
|
|
|
|
2013-03-05 09:05:07 +08:00
|
|
|
void Sema::checkFunctionDeclVerbatimLine(const BlockCommandComment *Comment) {
|
|
|
|
const CommandInfo *Info = Traits.getCommandInfo(Comment->getCommandID());
|
2013-03-06 06:46:07 +08:00
|
|
|
if (!Info->IsFunctionDeclarationCommand)
|
|
|
|
return;
|
2013-03-09 07:59:23 +08:00
|
|
|
|
|
|
|
unsigned DiagSelect;
|
|
|
|
switch (Comment->getCommandID()) {
|
|
|
|
case CommandTraits::KCI_function:
|
2013-06-20 02:08:03 +08:00
|
|
|
DiagSelect = (!isAnyFunctionDecl() && !isFunctionTemplateDecl())? 1 : 0;
|
2013-03-09 07:59:23 +08:00
|
|
|
break;
|
2013-03-19 07:45:52 +08:00
|
|
|
case CommandTraits::KCI_functiongroup:
|
2013-06-20 02:08:03 +08:00
|
|
|
DiagSelect = (!isAnyFunctionDecl() && !isFunctionTemplateDecl())? 2 : 0;
|
2013-03-19 07:45:52 +08:00
|
|
|
break;
|
2013-03-09 07:59:23 +08:00
|
|
|
case CommandTraits::KCI_method:
|
2013-03-19 07:45:52 +08:00
|
|
|
DiagSelect = !isObjCMethodDecl() ? 3 : 0;
|
|
|
|
break;
|
|
|
|
case CommandTraits::KCI_methodgroup:
|
|
|
|
DiagSelect = !isObjCMethodDecl() ? 4 : 0;
|
2013-03-09 07:59:23 +08:00
|
|
|
break;
|
|
|
|
case CommandTraits::KCI_callback:
|
2013-03-19 07:45:52 +08:00
|
|
|
DiagSelect = !isFunctionPointerVarDecl() ? 5 : 0;
|
2013-03-09 07:59:23 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
DiagSelect = 0;
|
|
|
|
break;
|
|
|
|
}
|
2013-03-07 01:36:51 +08:00
|
|
|
if (DiagSelect)
|
|
|
|
Diag(Comment->getLocation(), diag::warn_doc_function_method_decl_mismatch)
|
|
|
|
<< Comment->getCommandMarker()
|
|
|
|
<< (DiagSelect-1) << (DiagSelect-1)
|
2013-03-05 09:05:07 +08:00
|
|
|
<< Comment->getSourceRange();
|
|
|
|
}
|
2013-12-18 03:28:18 +08:00
|
|
|
|
2013-03-08 07:33:11 +08:00
|
|
|
void Sema::checkContainerDeclVerbatimLine(const BlockCommandComment *Comment) {
|
|
|
|
const CommandInfo *Info = Traits.getCommandInfo(Comment->getCommandID());
|
2013-03-09 07:59:23 +08:00
|
|
|
if (!Info->IsRecordLikeDeclarationCommand)
|
2013-03-08 07:33:11 +08:00
|
|
|
return;
|
2013-03-09 07:59:23 +08:00
|
|
|
unsigned DiagSelect;
|
|
|
|
switch (Comment->getCommandID()) {
|
|
|
|
case CommandTraits::KCI_class:
|
2020-02-18 06:55:49 +08:00
|
|
|
DiagSelect =
|
|
|
|
(!isClassOrStructOrTagTypedefDecl() && !isClassTemplateDecl()) ? 1
|
|
|
|
: 0;
|
2013-05-21 07:40:39 +08:00
|
|
|
// Allow @class command on @interface declarations.
|
|
|
|
// FIXME. Currently, \class and @class are indistinguishable. So,
|
|
|
|
// \class is also allowed on an @interface declaration
|
|
|
|
if (DiagSelect && Comment->getCommandMarker() && isObjCInterfaceDecl())
|
|
|
|
DiagSelect = 0;
|
2013-03-09 07:59:23 +08:00
|
|
|
break;
|
|
|
|
case CommandTraits::KCI_interface:
|
|
|
|
DiagSelect = !isObjCInterfaceDecl() ? 2 : 0;
|
|
|
|
break;
|
|
|
|
case CommandTraits::KCI_protocol:
|
|
|
|
DiagSelect = !isObjCProtocolDecl() ? 3 : 0;
|
|
|
|
break;
|
|
|
|
case CommandTraits::KCI_struct:
|
2020-02-18 06:55:49 +08:00
|
|
|
DiagSelect = !isClassOrStructOrTagTypedefDecl() ? 4 : 0;
|
2013-03-09 07:59:23 +08:00
|
|
|
break;
|
|
|
|
case CommandTraits::KCI_union:
|
|
|
|
DiagSelect = !isUnionDecl() ? 5 : 0;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
DiagSelect = 0;
|
|
|
|
break;
|
|
|
|
}
|
2013-03-08 07:33:11 +08:00
|
|
|
if (DiagSelect)
|
|
|
|
Diag(Comment->getLocation(), diag::warn_doc_api_container_decl_mismatch)
|
|
|
|
<< Comment->getCommandMarker()
|
|
|
|
<< (DiagSelect-1) << (DiagSelect-1)
|
|
|
|
<< Comment->getSourceRange();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Sema::checkContainerDecl(const BlockCommandComment *Comment) {
|
|
|
|
const CommandInfo *Info = Traits.getCommandInfo(Comment->getCommandID());
|
2013-03-09 07:59:23 +08:00
|
|
|
if (!Info->IsRecordLikeDetailCommand || isRecordLikeDecl())
|
2013-03-08 07:33:11 +08:00
|
|
|
return;
|
2013-03-09 07:59:23 +08:00
|
|
|
unsigned DiagSelect;
|
|
|
|
switch (Comment->getCommandID()) {
|
|
|
|
case CommandTraits::KCI_classdesign:
|
|
|
|
DiagSelect = 1;
|
|
|
|
break;
|
|
|
|
case CommandTraits::KCI_coclass:
|
|
|
|
DiagSelect = 2;
|
|
|
|
break;
|
|
|
|
case CommandTraits::KCI_dependency:
|
|
|
|
DiagSelect = 3;
|
|
|
|
break;
|
|
|
|
case CommandTraits::KCI_helper:
|
|
|
|
DiagSelect = 4;
|
|
|
|
break;
|
|
|
|
case CommandTraits::KCI_helperclass:
|
|
|
|
DiagSelect = 5;
|
|
|
|
break;
|
|
|
|
case CommandTraits::KCI_helps:
|
|
|
|
DiagSelect = 6;
|
|
|
|
break;
|
|
|
|
case CommandTraits::KCI_instancesize:
|
|
|
|
DiagSelect = 7;
|
|
|
|
break;
|
|
|
|
case CommandTraits::KCI_ownership:
|
|
|
|
DiagSelect = 8;
|
|
|
|
break;
|
|
|
|
case CommandTraits::KCI_performance:
|
|
|
|
DiagSelect = 9;
|
|
|
|
break;
|
|
|
|
case CommandTraits::KCI_security:
|
|
|
|
DiagSelect = 10;
|
|
|
|
break;
|
|
|
|
case CommandTraits::KCI_superclass:
|
|
|
|
DiagSelect = 11;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
DiagSelect = 0;
|
|
|
|
break;
|
|
|
|
}
|
2013-03-08 07:33:11 +08:00
|
|
|
if (DiagSelect)
|
|
|
|
Diag(Comment->getLocation(), diag::warn_doc_container_decl_mismatch)
|
|
|
|
<< Comment->getCommandMarker()
|
|
|
|
<< (DiagSelect-1)
|
|
|
|
<< Comment->getSourceRange();
|
|
|
|
}
|
2013-03-05 09:05:07 +08:00
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Turn a string into the corresponding PassDirection or -1 if it's not
|
2013-11-11 00:26:43 +08:00
|
|
|
/// valid.
|
|
|
|
static int getParamPassDirection(StringRef Arg) {
|
|
|
|
return llvm::StringSwitch<int>(Arg)
|
|
|
|
.Case("[in]", ParamCommandComment::In)
|
|
|
|
.Case("[out]", ParamCommandComment::Out)
|
|
|
|
.Cases("[in,out]", "[out,in]", ParamCommandComment::InOut)
|
|
|
|
.Default(-1);
|
|
|
|
}
|
|
|
|
|
2012-08-07 03:03:12 +08:00
|
|
|
void Sema::actOnParamCommandDirectionArg(ParamCommandComment *Command,
|
|
|
|
SourceLocation ArgLocBegin,
|
|
|
|
SourceLocation ArgLocEnd,
|
|
|
|
StringRef Arg) {
|
2012-07-12 05:38:39 +08:00
|
|
|
std::string ArgLower = Arg.lower();
|
2013-11-11 00:26:43 +08:00
|
|
|
int Direction = getParamPassDirection(ArgLower);
|
2012-07-12 05:38:39 +08:00
|
|
|
|
2013-11-11 00:26:43 +08:00
|
|
|
if (Direction == -1) {
|
|
|
|
// Try again with whitespace removed.
|
2021-10-18 04:50:29 +08:00
|
|
|
llvm::erase_if(ArgLower, clang::isWhitespace);
|
2013-11-11 00:26:43 +08:00
|
|
|
Direction = getParamPassDirection(ArgLower);
|
2012-07-12 05:38:39 +08:00
|
|
|
|
|
|
|
SourceRange ArgRange(ArgLocBegin, ArgLocEnd);
|
2013-11-11 00:26:43 +08:00
|
|
|
if (Direction != -1) {
|
|
|
|
const char *FixedName = ParamCommandComment::getDirectionAsString(
|
|
|
|
(ParamCommandComment::PassDirection)Direction);
|
2012-07-12 05:38:39 +08:00
|
|
|
Diag(ArgLocBegin, diag::warn_doc_param_spaces_in_direction)
|
2013-11-11 00:26:43 +08:00
|
|
|
<< ArgRange << FixItHint::CreateReplacement(ArgRange, FixedName);
|
|
|
|
} else {
|
|
|
|
Diag(ArgLocBegin, diag::warn_doc_param_invalid_direction) << ArgRange;
|
|
|
|
Direction = ParamCommandComment::In; // Sane fall back.
|
|
|
|
}
|
2012-07-06 08:28:32 +08:00
|
|
|
}
|
2013-11-11 00:26:43 +08:00
|
|
|
Command->setDirection((ParamCommandComment::PassDirection)Direction,
|
|
|
|
/*Explicit=*/true);
|
2012-07-12 05:38:39 +08:00
|
|
|
}
|
|
|
|
|
2012-08-07 03:03:12 +08:00
|
|
|
void Sema::actOnParamCommandParamNameArg(ParamCommandComment *Command,
|
|
|
|
SourceLocation ArgLocBegin,
|
|
|
|
SourceLocation ArgLocEnd,
|
|
|
|
StringRef Arg) {
|
2012-07-12 05:38:39 +08:00
|
|
|
// Parser will not feed us more arguments than needed.
|
2012-07-14 03:02:42 +08:00
|
|
|
assert(Command->getNumArgs() == 0);
|
2012-07-12 05:38:39 +08:00
|
|
|
|
|
|
|
if (!Command->isDirectionExplicit()) {
|
|
|
|
// User didn't provide a direction argument.
|
|
|
|
Command->setDirection(ParamCommandComment::In, /* Explicit = */ false);
|
|
|
|
}
|
|
|
|
typedef BlockCommandComment::Argument Argument;
|
|
|
|
Argument *A = new (Allocator) Argument(SourceRange(ArgLocBegin,
|
|
|
|
ArgLocEnd),
|
|
|
|
Arg);
|
|
|
|
Command->setArgs(llvm::makeArrayRef(A, 1));
|
2012-07-06 08:28:32 +08:00
|
|
|
}
|
|
|
|
|
2012-08-07 03:03:12 +08:00
|
|
|
void Sema::actOnParamCommandFinish(ParamCommandComment *Command,
|
|
|
|
ParagraphComment *Paragraph) {
|
2012-07-06 08:28:32 +08:00
|
|
|
Command->setParagraph(Paragraph);
|
2012-07-12 05:38:39 +08:00
|
|
|
checkBlockCommandEmptyParagraph(Command);
|
2012-07-06 08:28:32 +08:00
|
|
|
}
|
|
|
|
|
2013-03-05 07:06:15 +08:00
|
|
|
TParamCommandComment *Sema::actOnTParamCommandStart(
|
|
|
|
SourceLocation LocBegin,
|
|
|
|
SourceLocation LocEnd,
|
|
|
|
unsigned CommandID,
|
|
|
|
CommandMarkerKind CommandMarker) {
|
2012-08-01 06:37:06 +08:00
|
|
|
TParamCommandComment *Command =
|
2013-03-05 07:06:15 +08:00
|
|
|
new (Allocator) TParamCommandComment(LocBegin, LocEnd, CommandID,
|
|
|
|
CommandMarker);
|
2012-08-01 06:37:06 +08:00
|
|
|
|
2012-08-07 05:31:15 +08:00
|
|
|
if (!isTemplateOrSpecialization())
|
2012-08-01 06:37:06 +08:00
|
|
|
Diag(Command->getLocation(),
|
|
|
|
diag::warn_doc_tparam_not_attached_to_a_template_decl)
|
2013-03-05 07:06:15 +08:00
|
|
|
<< CommandMarker
|
2012-09-11 04:32:42 +08:00
|
|
|
<< Command->getCommandNameRange(Traits);
|
2012-08-01 06:37:06 +08:00
|
|
|
|
|
|
|
return Command;
|
|
|
|
}
|
|
|
|
|
2012-08-07 03:03:12 +08:00
|
|
|
void Sema::actOnTParamCommandParamNameArg(TParamCommandComment *Command,
|
|
|
|
SourceLocation ArgLocBegin,
|
|
|
|
SourceLocation ArgLocEnd,
|
|
|
|
StringRef Arg) {
|
2012-08-01 06:37:06 +08:00
|
|
|
// Parser will not feed us more arguments than needed.
|
|
|
|
assert(Command->getNumArgs() == 0);
|
|
|
|
|
|
|
|
typedef BlockCommandComment::Argument Argument;
|
|
|
|
Argument *A = new (Allocator) Argument(SourceRange(ArgLocBegin,
|
|
|
|
ArgLocEnd),
|
|
|
|
Arg);
|
|
|
|
Command->setArgs(llvm::makeArrayRef(A, 1));
|
|
|
|
|
2012-08-07 05:31:15 +08:00
|
|
|
if (!isTemplateOrSpecialization()) {
|
2012-08-01 06:37:06 +08:00
|
|
|
// We already warned that this \\tparam is not attached to a template decl.
|
2012-08-07 03:03:12 +08:00
|
|
|
return;
|
2012-08-01 06:37:06 +08:00
|
|
|
}
|
|
|
|
|
2012-08-02 07:08:09 +08:00
|
|
|
const TemplateParameterList *TemplateParameters =
|
|
|
|
ThisDeclInfo->TemplateParameters;
|
2012-08-01 06:37:06 +08:00
|
|
|
SmallVector<unsigned, 2> Position;
|
|
|
|
if (resolveTParamReference(Arg, TemplateParameters, &Position)) {
|
|
|
|
Command->setPosition(copyArray(llvm::makeArrayRef(Position)));
|
2013-11-11 00:55:11 +08:00
|
|
|
TParamCommandComment *&PrevCommand = TemplateParameterDocs[Arg];
|
|
|
|
if (PrevCommand) {
|
2012-08-01 06:37:06 +08:00
|
|
|
SourceRange ArgRange(ArgLocBegin, ArgLocEnd);
|
|
|
|
Diag(ArgLocBegin, diag::warn_doc_tparam_duplicate)
|
|
|
|
<< Arg << ArgRange;
|
|
|
|
Diag(PrevCommand->getLocation(), diag::note_doc_tparam_previous)
|
|
|
|
<< PrevCommand->getParamNameRange();
|
|
|
|
}
|
2013-11-11 00:55:11 +08:00
|
|
|
PrevCommand = Command;
|
2012-08-07 03:03:12 +08:00
|
|
|
return;
|
2012-08-01 06:37:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
SourceRange ArgRange(ArgLocBegin, ArgLocEnd);
|
|
|
|
Diag(ArgLocBegin, diag::warn_doc_tparam_not_found)
|
|
|
|
<< Arg << ArgRange;
|
|
|
|
|
|
|
|
if (!TemplateParameters || TemplateParameters->size() == 0)
|
2012-08-07 03:03:12 +08:00
|
|
|
return;
|
2012-08-01 06:37:06 +08:00
|
|
|
|
|
|
|
StringRef CorrectedName;
|
|
|
|
if (TemplateParameters->size() == 1) {
|
|
|
|
const NamedDecl *Param = TemplateParameters->getParam(0);
|
|
|
|
const IdentifierInfo *II = Param->getIdentifier();
|
|
|
|
if (II)
|
|
|
|
CorrectedName = II->getName();
|
|
|
|
} else {
|
|
|
|
CorrectedName = correctTypoInTParamReference(Arg, TemplateParameters);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!CorrectedName.empty()) {
|
|
|
|
Diag(ArgLocBegin, diag::note_doc_tparam_name_suggestion)
|
|
|
|
<< CorrectedName
|
|
|
|
<< FixItHint::CreateReplacement(ArgRange, CorrectedName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-07 03:03:12 +08:00
|
|
|
void Sema::actOnTParamCommandFinish(TParamCommandComment *Command,
|
|
|
|
ParagraphComment *Paragraph) {
|
2012-08-01 06:37:06 +08:00
|
|
|
Command->setParagraph(Paragraph);
|
|
|
|
checkBlockCommandEmptyParagraph(Command);
|
|
|
|
}
|
|
|
|
|
2012-07-06 08:28:32 +08:00
|
|
|
InlineCommandComment *Sema::actOnInlineCommand(SourceLocation CommandLocBegin,
|
|
|
|
SourceLocation CommandLocEnd,
|
2012-09-11 04:32:42 +08:00
|
|
|
unsigned CommandID) {
|
2012-07-06 08:28:32 +08:00
|
|
|
ArrayRef<InlineCommandComment::Argument> Args;
|
2012-09-11 04:32:42 +08:00
|
|
|
StringRef CommandName = Traits.getCommandInfo(CommandID)->Name;
|
2012-07-24 00:43:01 +08:00
|
|
|
return new (Allocator) InlineCommandComment(
|
|
|
|
CommandLocBegin,
|
|
|
|
CommandLocEnd,
|
2012-09-11 04:32:42 +08:00
|
|
|
CommandID,
|
2012-07-24 00:43:01 +08:00
|
|
|
getInlineCommandRenderKind(CommandName),
|
|
|
|
Args);
|
2012-07-06 08:28:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
InlineCommandComment *Sema::actOnInlineCommand(SourceLocation CommandLocBegin,
|
|
|
|
SourceLocation CommandLocEnd,
|
2012-09-11 04:32:42 +08:00
|
|
|
unsigned CommandID,
|
2012-07-06 08:28:32 +08:00
|
|
|
SourceLocation ArgLocBegin,
|
|
|
|
SourceLocation ArgLocEnd,
|
|
|
|
StringRef Arg) {
|
|
|
|
typedef InlineCommandComment::Argument Argument;
|
|
|
|
Argument *A = new (Allocator) Argument(SourceRange(ArgLocBegin,
|
|
|
|
ArgLocEnd),
|
|
|
|
Arg);
|
2012-09-11 04:32:42 +08:00
|
|
|
StringRef CommandName = Traits.getCommandInfo(CommandID)->Name;
|
2012-07-06 08:28:32 +08:00
|
|
|
|
2012-07-24 00:43:01 +08:00
|
|
|
return new (Allocator) InlineCommandComment(
|
|
|
|
CommandLocBegin,
|
|
|
|
CommandLocEnd,
|
2012-09-11 04:32:42 +08:00
|
|
|
CommandID,
|
2012-07-24 00:43:01 +08:00
|
|
|
getInlineCommandRenderKind(CommandName),
|
|
|
|
llvm::makeArrayRef(A, 1));
|
2012-07-06 08:28:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
InlineContentComment *Sema::actOnUnknownCommand(SourceLocation LocBegin,
|
|
|
|
SourceLocation LocEnd,
|
2012-09-12 03:22:03 +08:00
|
|
|
StringRef CommandName) {
|
|
|
|
unsigned CommandID = Traits.registerUnknownCommand(CommandName)->getID();
|
|
|
|
return actOnUnknownCommand(LocBegin, LocEnd, CommandID);
|
|
|
|
}
|
|
|
|
|
|
|
|
InlineContentComment *Sema::actOnUnknownCommand(SourceLocation LocBegin,
|
|
|
|
SourceLocation LocEnd,
|
|
|
|
unsigned CommandID) {
|
2012-07-06 08:28:32 +08:00
|
|
|
ArrayRef<InlineCommandComment::Argument> Args;
|
2012-07-24 00:43:01 +08:00
|
|
|
return new (Allocator) InlineCommandComment(
|
2012-09-11 04:32:42 +08:00
|
|
|
LocBegin, LocEnd, CommandID,
|
2012-07-24 00:43:01 +08:00
|
|
|
InlineCommandComment::RenderNormal,
|
|
|
|
Args);
|
2012-07-06 08:28:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TextComment *Sema::actOnText(SourceLocation LocBegin,
|
|
|
|
SourceLocation LocEnd,
|
|
|
|
StringRef Text) {
|
|
|
|
return new (Allocator) TextComment(LocBegin, LocEnd, Text);
|
|
|
|
}
|
|
|
|
|
|
|
|
VerbatimBlockComment *Sema::actOnVerbatimBlockStart(SourceLocation Loc,
|
2012-09-11 04:32:42 +08:00
|
|
|
unsigned CommandID) {
|
|
|
|
StringRef CommandName = Traits.getCommandInfo(CommandID)->Name;
|
2012-07-06 08:28:32 +08:00
|
|
|
return new (Allocator) VerbatimBlockComment(
|
|
|
|
Loc,
|
2012-09-11 04:32:42 +08:00
|
|
|
Loc.getLocWithOffset(1 + CommandName.size()),
|
|
|
|
CommandID);
|
2012-07-06 08:28:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
VerbatimBlockLineComment *Sema::actOnVerbatimBlockLine(SourceLocation Loc,
|
|
|
|
StringRef Text) {
|
|
|
|
return new (Allocator) VerbatimBlockLineComment(Loc, Text);
|
|
|
|
}
|
|
|
|
|
2012-08-07 03:03:12 +08:00
|
|
|
void Sema::actOnVerbatimBlockFinish(
|
2012-07-06 08:28:32 +08:00
|
|
|
VerbatimBlockComment *Block,
|
|
|
|
SourceLocation CloseNameLocBegin,
|
|
|
|
StringRef CloseName,
|
|
|
|
ArrayRef<VerbatimBlockLineComment *> Lines) {
|
|
|
|
Block->setCloseName(CloseName, CloseNameLocBegin);
|
|
|
|
Block->setLines(Lines);
|
|
|
|
}
|
|
|
|
|
|
|
|
VerbatimLineComment *Sema::actOnVerbatimLine(SourceLocation LocBegin,
|
2012-09-11 04:32:42 +08:00
|
|
|
unsigned CommandID,
|
2012-07-06 08:28:32 +08:00
|
|
|
SourceLocation TextBegin,
|
|
|
|
StringRef Text) {
|
2013-03-06 03:40:47 +08:00
|
|
|
VerbatimLineComment *VL = new (Allocator) VerbatimLineComment(
|
2012-07-06 08:28:32 +08:00
|
|
|
LocBegin,
|
|
|
|
TextBegin.getLocWithOffset(Text.size()),
|
2012-09-11 04:32:42 +08:00
|
|
|
CommandID,
|
2012-07-06 08:28:32 +08:00
|
|
|
TextBegin,
|
|
|
|
Text);
|
2013-03-06 03:40:47 +08:00
|
|
|
checkFunctionDeclVerbatimLine(VL);
|
2013-03-08 07:33:11 +08:00
|
|
|
checkContainerDeclVerbatimLine(VL);
|
2013-03-06 03:40:47 +08:00
|
|
|
return VL;
|
2012-07-06 08:28:32 +08:00
|
|
|
}
|
|
|
|
|
2012-07-13 08:44:24 +08:00
|
|
|
HTMLStartTagComment *Sema::actOnHTMLStartTagStart(SourceLocation LocBegin,
|
|
|
|
StringRef TagName) {
|
|
|
|
return new (Allocator) HTMLStartTagComment(LocBegin, TagName);
|
2012-07-06 08:28:32 +08:00
|
|
|
}
|
|
|
|
|
2012-08-07 03:03:12 +08:00
|
|
|
void Sema::actOnHTMLStartTagFinish(
|
2012-07-13 08:44:24 +08:00
|
|
|
HTMLStartTagComment *Tag,
|
|
|
|
ArrayRef<HTMLStartTagComment::Attribute> Attrs,
|
2012-07-12 05:38:39 +08:00
|
|
|
SourceLocation GreaterLoc,
|
|
|
|
bool IsSelfClosing) {
|
2012-07-06 08:28:32 +08:00
|
|
|
Tag->setAttrs(Attrs);
|
|
|
|
Tag->setGreaterLoc(GreaterLoc);
|
2012-07-12 05:38:39 +08:00
|
|
|
if (IsSelfClosing)
|
|
|
|
Tag->setSelfClosing();
|
2012-07-13 08:44:24 +08:00
|
|
|
else if (!isHTMLEndTagForbidden(Tag->getTagName()))
|
2012-07-12 05:38:39 +08:00
|
|
|
HTMLOpenTags.push_back(Tag);
|
2012-07-06 08:28:32 +08:00
|
|
|
}
|
|
|
|
|
2012-07-13 08:44:24 +08:00
|
|
|
HTMLEndTagComment *Sema::actOnHTMLEndTag(SourceLocation LocBegin,
|
|
|
|
SourceLocation LocEnd,
|
|
|
|
StringRef TagName) {
|
|
|
|
HTMLEndTagComment *HET =
|
|
|
|
new (Allocator) HTMLEndTagComment(LocBegin, LocEnd, TagName);
|
|
|
|
if (isHTMLEndTagForbidden(TagName)) {
|
|
|
|
Diag(HET->getLocation(), diag::warn_doc_html_end_forbidden)
|
|
|
|
<< TagName << HET->getSourceRange();
|
2014-05-01 05:54:30 +08:00
|
|
|
HET->setIsMalformed();
|
2012-07-13 08:44:24 +08:00
|
|
|
return HET;
|
2012-07-13 07:37:09 +08:00
|
|
|
}
|
|
|
|
|
2012-07-12 05:38:39 +08:00
|
|
|
bool FoundOpen = false;
|
2012-07-13 08:44:24 +08:00
|
|
|
for (SmallVectorImpl<HTMLStartTagComment *>::const_reverse_iterator
|
2012-07-12 05:38:39 +08:00
|
|
|
I = HTMLOpenTags.rbegin(), E = HTMLOpenTags.rend();
|
|
|
|
I != E; ++I) {
|
|
|
|
if ((*I)->getTagName() == TagName) {
|
|
|
|
FoundOpen = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!FoundOpen) {
|
2012-07-13 08:44:24 +08:00
|
|
|
Diag(HET->getLocation(), diag::warn_doc_html_end_unbalanced)
|
|
|
|
<< HET->getSourceRange();
|
2014-05-01 05:54:30 +08:00
|
|
|
HET->setIsMalformed();
|
2012-07-13 08:44:24 +08:00
|
|
|
return HET;
|
2012-07-12 05:38:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
while (!HTMLOpenTags.empty()) {
|
2014-04-22 18:59:13 +08:00
|
|
|
HTMLStartTagComment *HST = HTMLOpenTags.pop_back_val();
|
2012-07-13 08:44:24 +08:00
|
|
|
StringRef LastNotClosedTagName = HST->getTagName();
|
2014-04-22 18:59:13 +08:00
|
|
|
if (LastNotClosedTagName == TagName) {
|
2014-05-01 05:54:30 +08:00
|
|
|
// If the start tag is malformed, end tag is malformed as well.
|
|
|
|
if (HST->isMalformed())
|
|
|
|
HET->setIsMalformed();
|
2012-07-12 05:38:39 +08:00
|
|
|
break;
|
2014-04-22 18:59:13 +08:00
|
|
|
}
|
2012-07-12 05:38:39 +08:00
|
|
|
|
2012-07-13 08:44:24 +08:00
|
|
|
if (isHTMLEndTagOptional(LastNotClosedTagName))
|
2012-07-12 05:38:39 +08:00
|
|
|
continue;
|
|
|
|
|
|
|
|
bool OpenLineInvalid;
|
|
|
|
const unsigned OpenLine = SourceMgr.getPresumedLineNumber(
|
2012-07-13 08:44:24 +08:00
|
|
|
HST->getLocation(),
|
2012-07-12 05:38:39 +08:00
|
|
|
&OpenLineInvalid);
|
|
|
|
bool CloseLineInvalid;
|
|
|
|
const unsigned CloseLine = SourceMgr.getPresumedLineNumber(
|
2012-07-13 08:44:24 +08:00
|
|
|
HET->getLocation(),
|
2012-07-12 05:38:39 +08:00
|
|
|
&CloseLineInvalid);
|
|
|
|
|
2014-04-22 18:59:13 +08:00
|
|
|
if (OpenLineInvalid || CloseLineInvalid || OpenLine == CloseLine) {
|
2012-07-13 08:44:24 +08:00
|
|
|
Diag(HST->getLocation(), diag::warn_doc_html_start_end_mismatch)
|
|
|
|
<< HST->getTagName() << HET->getTagName()
|
|
|
|
<< HST->getSourceRange() << HET->getSourceRange();
|
2014-05-01 05:54:30 +08:00
|
|
|
HST->setIsMalformed();
|
2014-04-22 18:59:13 +08:00
|
|
|
} else {
|
2012-07-13 08:44:24 +08:00
|
|
|
Diag(HST->getLocation(), diag::warn_doc_html_start_end_mismatch)
|
|
|
|
<< HST->getTagName() << HET->getTagName()
|
|
|
|
<< HST->getSourceRange();
|
|
|
|
Diag(HET->getLocation(), diag::note_doc_html_end_tag)
|
|
|
|
<< HET->getSourceRange();
|
2014-05-01 05:54:30 +08:00
|
|
|
HST->setIsMalformed();
|
2012-07-12 05:38:39 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-13 08:44:24 +08:00
|
|
|
return HET;
|
2012-07-06 08:28:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
FullComment *Sema::actOnFullComment(
|
|
|
|
ArrayRef<BlockContentComment *> Blocks) {
|
2012-10-12 07:52:50 +08:00
|
|
|
FullComment *FC = new (Allocator) FullComment(Blocks, ThisDeclInfo);
|
2012-08-25 01:45:39 +08:00
|
|
|
resolveParamCommandIndexes(FC);
|
2014-04-22 18:59:13 +08:00
|
|
|
|
|
|
|
// Complain about HTML tags that are not closed.
|
|
|
|
while (!HTMLOpenTags.empty()) {
|
|
|
|
HTMLStartTagComment *HST = HTMLOpenTags.pop_back_val();
|
|
|
|
if (isHTMLEndTagOptional(HST->getTagName()))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
Diag(HST->getLocation(), diag::warn_doc_html_missing_end_tag)
|
|
|
|
<< HST->getTagName() << HST->getSourceRange();
|
2014-05-01 05:54:30 +08:00
|
|
|
HST->setIsMalformed();
|
2014-04-22 18:59:13 +08:00
|
|
|
}
|
|
|
|
|
2012-08-25 01:45:39 +08:00
|
|
|
return FC;
|
2012-07-06 08:28:32 +08:00
|
|
|
}
|
|
|
|
|
2012-07-12 05:38:39 +08:00
|
|
|
void Sema::checkBlockCommandEmptyParagraph(BlockCommandComment *Command) {
|
2012-09-14 04:36:01 +08:00
|
|
|
if (Traits.getCommandInfo(Command->getCommandID())->IsEmptyParagraphAllowed)
|
|
|
|
return;
|
|
|
|
|
2012-07-12 05:38:39 +08:00
|
|
|
ParagraphComment *Paragraph = Command->getParagraph();
|
|
|
|
if (Paragraph->isWhitespace()) {
|
|
|
|
SourceLocation DiagLoc;
|
2012-07-14 03:02:42 +08:00
|
|
|
if (Command->getNumArgs() > 0)
|
|
|
|
DiagLoc = Command->getArgRange(Command->getNumArgs() - 1).getEnd();
|
2012-07-12 05:38:39 +08:00
|
|
|
if (!DiagLoc.isValid())
|
2012-09-11 04:32:42 +08:00
|
|
|
DiagLoc = Command->getCommandNameRange(Traits).getEnd();
|
2012-07-12 05:38:39 +08:00
|
|
|
Diag(DiagLoc, diag::warn_doc_block_command_empty_paragraph)
|
2013-03-05 07:06:15 +08:00
|
|
|
<< Command->getCommandMarker()
|
2012-09-11 04:32:42 +08:00
|
|
|
<< Command->getCommandName(Traits)
|
2012-07-12 05:38:39 +08:00
|
|
|
<< Command->getSourceRange();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-04 05:15:32 +08:00
|
|
|
void Sema::checkReturnsCommand(const BlockCommandComment *Command) {
|
2012-09-11 04:32:42 +08:00
|
|
|
if (!Traits.getCommandInfo(Command->getCommandID())->IsReturnsCommand)
|
2012-08-04 05:15:32 +08:00
|
|
|
return;
|
2014-01-28 01:55:43 +08:00
|
|
|
|
|
|
|
assert(ThisDeclInfo && "should not call this check on a bare comment");
|
|
|
|
|
2017-04-26 21:09:28 +08:00
|
|
|
// We allow the return command for all @properties because it can be used
|
|
|
|
// to document the value that the property getter returns.
|
|
|
|
if (isObjCPropertyDecl())
|
|
|
|
return;
|
2017-04-21 22:17:49 +08:00
|
|
|
if (isFunctionDecl() || isFunctionOrBlockPointerVarLikeDecl()) {
|
2019-09-03 02:24:33 +08:00
|
|
|
assert(!ThisDeclInfo->ReturnType.isNull() &&
|
|
|
|
"should have a valid return type");
|
2014-01-26 00:55:45 +08:00
|
|
|
if (ThisDeclInfo->ReturnType->isVoidType()) {
|
2012-08-04 05:15:32 +08:00
|
|
|
unsigned DiagKind;
|
2012-10-11 02:34:52 +08:00
|
|
|
switch (ThisDeclInfo->CommentDecl->getKind()) {
|
2012-08-04 05:15:32 +08:00
|
|
|
default:
|
2012-08-07 00:29:26 +08:00
|
|
|
if (ThisDeclInfo->IsObjCMethod)
|
|
|
|
DiagKind = 3;
|
|
|
|
else
|
|
|
|
DiagKind = 0;
|
2012-08-04 05:15:32 +08:00
|
|
|
break;
|
|
|
|
case Decl::CXXConstructor:
|
|
|
|
DiagKind = 1;
|
|
|
|
break;
|
|
|
|
case Decl::CXXDestructor:
|
|
|
|
DiagKind = 2;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
Diag(Command->getLocation(),
|
|
|
|
diag::warn_doc_returns_attached_to_a_void_function)
|
2013-03-05 07:06:15 +08:00
|
|
|
<< Command->getCommandMarker()
|
2012-09-11 04:32:42 +08:00
|
|
|
<< Command->getCommandName(Traits)
|
2012-08-04 05:15:32 +08:00
|
|
|
<< DiagKind
|
|
|
|
<< Command->getSourceRange();
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2013-12-18 03:28:18 +08:00
|
|
|
|
2012-08-04 05:15:32 +08:00
|
|
|
Diag(Command->getLocation(),
|
|
|
|
diag::warn_doc_returns_not_attached_to_a_function_decl)
|
2013-03-05 07:06:15 +08:00
|
|
|
<< Command->getCommandMarker()
|
2012-09-11 04:32:42 +08:00
|
|
|
<< Command->getCommandName(Traits)
|
2012-08-04 05:15:32 +08:00
|
|
|
<< Command->getSourceRange();
|
|
|
|
}
|
|
|
|
|
2012-08-07 01:08:27 +08:00
|
|
|
void Sema::checkBlockCommandDuplicate(const BlockCommandComment *Command) {
|
2012-09-11 04:32:42 +08:00
|
|
|
const CommandInfo *Info = Traits.getCommandInfo(Command->getCommandID());
|
2014-05-12 13:36:57 +08:00
|
|
|
const BlockCommandComment *PrevCommand = nullptr;
|
2012-09-11 04:32:42 +08:00
|
|
|
if (Info->IsBriefCommand) {
|
2012-08-07 01:08:27 +08:00
|
|
|
if (!BriefCommand) {
|
|
|
|
BriefCommand = Command;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
PrevCommand = BriefCommand;
|
2013-02-01 07:12:39 +08:00
|
|
|
} else if (Info->IsHeaderfileCommand) {
|
|
|
|
if (!HeaderfileCommand) {
|
|
|
|
HeaderfileCommand = Command;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
PrevCommand = HeaderfileCommand;
|
2012-08-07 01:08:27 +08:00
|
|
|
} else {
|
|
|
|
// We don't want to check this command for duplicates.
|
|
|
|
return;
|
|
|
|
}
|
2012-09-11 04:32:42 +08:00
|
|
|
StringRef CommandName = Command->getCommandName(Traits);
|
|
|
|
StringRef PrevCommandName = PrevCommand->getCommandName(Traits);
|
2012-08-07 01:08:27 +08:00
|
|
|
Diag(Command->getLocation(), diag::warn_doc_block_command_duplicate)
|
2013-03-05 07:06:15 +08:00
|
|
|
<< Command->getCommandMarker()
|
2012-09-11 04:32:42 +08:00
|
|
|
<< CommandName
|
2012-08-07 01:08:27 +08:00
|
|
|
<< Command->getSourceRange();
|
2012-09-11 04:32:42 +08:00
|
|
|
if (CommandName == PrevCommandName)
|
2012-08-07 01:08:27 +08:00
|
|
|
Diag(PrevCommand->getLocation(), diag::note_doc_block_command_previous)
|
2013-03-05 07:06:15 +08:00
|
|
|
<< PrevCommand->getCommandMarker()
|
2012-09-11 04:32:42 +08:00
|
|
|
<< PrevCommandName
|
|
|
|
<< PrevCommand->getSourceRange();
|
2012-08-07 01:08:27 +08:00
|
|
|
else
|
|
|
|
Diag(PrevCommand->getLocation(),
|
|
|
|
diag::note_doc_block_command_previous_alias)
|
2013-03-05 07:06:15 +08:00
|
|
|
<< PrevCommand->getCommandMarker()
|
2012-09-11 04:32:42 +08:00
|
|
|
<< PrevCommandName
|
|
|
|
<< CommandName;
|
2012-08-07 01:08:27 +08:00
|
|
|
}
|
|
|
|
|
2012-09-23 05:47:50 +08:00
|
|
|
void Sema::checkDeprecatedCommand(const BlockCommandComment *Command) {
|
|
|
|
if (!Traits.getCommandInfo(Command->getCommandID())->IsDeprecatedCommand)
|
|
|
|
return;
|
|
|
|
|
2014-01-28 01:55:43 +08:00
|
|
|
assert(ThisDeclInfo && "should not call this check on a bare comment");
|
|
|
|
|
2012-10-11 02:34:52 +08:00
|
|
|
const Decl *D = ThisDeclInfo->CommentDecl;
|
2012-09-23 05:47:50 +08:00
|
|
|
if (!D)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (D->hasAttr<DeprecatedAttr>() ||
|
|
|
|
D->hasAttr<AvailabilityAttr>() ||
|
|
|
|
D->hasAttr<UnavailableAttr>())
|
|
|
|
return;
|
|
|
|
|
2019-12-11 01:32:28 +08:00
|
|
|
Diag(Command->getLocation(), diag::warn_doc_deprecated_not_sync)
|
|
|
|
<< Command->getSourceRange() << Command->getCommandMarker();
|
2012-09-23 05:47:50 +08:00
|
|
|
|
|
|
|
// Try to emit a fixit with a deprecation attribute.
|
|
|
|
if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
|
|
|
|
// Don't emit a Fix-It for non-member function definitions. GCC does not
|
|
|
|
// accept attributes on them.
|
|
|
|
const DeclContext *Ctx = FD->getDeclContext();
|
|
|
|
if ((!Ctx || !Ctx->isRecord()) &&
|
|
|
|
FD->doesThisDeclarationHaveABody())
|
|
|
|
return;
|
|
|
|
|
2020-04-07 00:55:33 +08:00
|
|
|
const LangOptions &LO = FD->getLangOpts();
|
2019-12-11 01:32:30 +08:00
|
|
|
const bool DoubleSquareBracket = LO.CPlusPlus14 || LO.C2x;
|
|
|
|
StringRef AttributeSpelling =
|
|
|
|
DoubleSquareBracket ? "[[deprecated]]" : "__attribute__((deprecated))";
|
2012-09-29 19:40:46 +08:00
|
|
|
if (PP) {
|
2019-12-11 01:32:30 +08:00
|
|
|
// Try to find a replacement macro:
|
|
|
|
// - In C2x/C++14 we prefer [[deprecated]].
|
|
|
|
// - If not found or an older C/C++ look for __attribute__((deprecated)).
|
|
|
|
StringRef MacroName;
|
|
|
|
if (DoubleSquareBracket) {
|
|
|
|
TokenValue Tokens[] = {tok::l_square, tok::l_square,
|
|
|
|
PP->getIdentifierInfo("deprecated"),
|
|
|
|
tok::r_square, tok::r_square};
|
|
|
|
MacroName = PP->getLastMacroWithSpelling(FD->getLocation(), Tokens);
|
|
|
|
if (!MacroName.empty())
|
|
|
|
AttributeSpelling = MacroName;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (MacroName.empty()) {
|
|
|
|
TokenValue Tokens[] = {
|
|
|
|
tok::kw___attribute, tok::l_paren,
|
|
|
|
tok::l_paren, PP->getIdentifierInfo("deprecated"),
|
|
|
|
tok::r_paren, tok::r_paren};
|
|
|
|
StringRef MacroName =
|
|
|
|
PP->getLastMacroWithSpelling(FD->getLocation(), Tokens);
|
|
|
|
if (!MacroName.empty())
|
|
|
|
AttributeSpelling = MacroName;
|
|
|
|
}
|
2012-09-29 19:40:46 +08:00
|
|
|
}
|
|
|
|
|
2019-12-11 01:32:29 +08:00
|
|
|
SmallString<64> TextToInsert = AttributeSpelling;
|
|
|
|
TextToInsert += " ";
|
|
|
|
SourceLocation Loc = FD->getSourceRange().getBegin();
|
|
|
|
Diag(Loc, diag::note_add_deprecation_attr)
|
|
|
|
<< FixItHint::CreateInsertion(Loc, TextToInsert);
|
2012-09-23 05:47:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-25 01:45:39 +08:00
|
|
|
void Sema::resolveParamCommandIndexes(const FullComment *FC) {
|
|
|
|
if (!isFunctionDecl()) {
|
|
|
|
// We already warned that \\param commands are not attached to a function
|
|
|
|
// decl.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-01-13 03:30:44 +08:00
|
|
|
SmallVector<ParamCommandComment *, 8> UnresolvedParamCommands;
|
2012-08-25 01:45:39 +08:00
|
|
|
|
|
|
|
// Comment AST nodes that correspond to \c ParamVars for which we have
|
|
|
|
// found a \\param command or NULL if no documentation was found so far.
|
2013-01-13 03:30:44 +08:00
|
|
|
SmallVector<ParamCommandComment *, 8> ParamVarDocs;
|
2012-08-25 01:45:39 +08:00
|
|
|
|
|
|
|
ArrayRef<const ParmVarDecl *> ParamVars = getParamVars();
|
2014-05-12 13:36:57 +08:00
|
|
|
ParamVarDocs.resize(ParamVars.size(), nullptr);
|
2012-08-25 01:45:39 +08:00
|
|
|
|
|
|
|
// First pass over all \\param commands: resolve all parameter names.
|
|
|
|
for (Comment::child_iterator I = FC->child_begin(), E = FC->child_end();
|
|
|
|
I != E; ++I) {
|
|
|
|
ParamCommandComment *PCC = dyn_cast<ParamCommandComment>(*I);
|
|
|
|
if (!PCC || !PCC->hasParamName())
|
|
|
|
continue;
|
2012-10-19 05:42:42 +08:00
|
|
|
StringRef ParamName = PCC->getParamNameAsWritten();
|
2012-08-25 01:45:39 +08:00
|
|
|
|
|
|
|
// Check that referenced parameter name is in the function decl.
|
|
|
|
const unsigned ResolvedParamIndex = resolveParmVarReference(ParamName,
|
|
|
|
ParamVars);
|
2013-06-24 12:41:32 +08:00
|
|
|
if (ResolvedParamIndex == ParamCommandComment::VarArgParamIndex) {
|
|
|
|
PCC->setIsVarArgParam();
|
|
|
|
continue;
|
|
|
|
}
|
2012-08-25 01:45:39 +08:00
|
|
|
if (ResolvedParamIndex == ParamCommandComment::InvalidParamIndex) {
|
|
|
|
UnresolvedParamCommands.push_back(PCC);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
PCC->setParamIndex(ResolvedParamIndex);
|
|
|
|
if (ParamVarDocs[ResolvedParamIndex]) {
|
|
|
|
SourceRange ArgRange = PCC->getParamNameRange();
|
|
|
|
Diag(ArgRange.getBegin(), diag::warn_doc_param_duplicate)
|
|
|
|
<< ParamName << ArgRange;
|
|
|
|
ParamCommandComment *PrevCommand = ParamVarDocs[ResolvedParamIndex];
|
|
|
|
Diag(PrevCommand->getLocation(), diag::note_doc_param_previous)
|
|
|
|
<< PrevCommand->getParamNameRange();
|
|
|
|
}
|
|
|
|
ParamVarDocs[ResolvedParamIndex] = PCC;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Find parameter declarations that have no corresponding \\param.
|
2013-01-13 03:30:44 +08:00
|
|
|
SmallVector<const ParmVarDecl *, 8> OrphanedParamDecls;
|
2012-08-25 01:45:39 +08:00
|
|
|
for (unsigned i = 0, e = ParamVarDocs.size(); i != e; ++i) {
|
|
|
|
if (!ParamVarDocs[i])
|
|
|
|
OrphanedParamDecls.push_back(ParamVars[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Second pass over unresolved \\param commands: do typo correction.
|
|
|
|
// Suggest corrections from a set of parameter declarations that have no
|
|
|
|
// corresponding \\param.
|
|
|
|
for (unsigned i = 0, e = UnresolvedParamCommands.size(); i != e; ++i) {
|
|
|
|
const ParamCommandComment *PCC = UnresolvedParamCommands[i];
|
|
|
|
|
|
|
|
SourceRange ArgRange = PCC->getParamNameRange();
|
2012-10-19 05:42:42 +08:00
|
|
|
StringRef ParamName = PCC->getParamNameAsWritten();
|
2012-08-25 01:45:39 +08:00
|
|
|
Diag(ArgRange.getBegin(), diag::warn_doc_param_not_found)
|
|
|
|
<< ParamName << ArgRange;
|
|
|
|
|
|
|
|
// All parameters documented -- can't suggest a correction.
|
|
|
|
if (OrphanedParamDecls.size() == 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
unsigned CorrectedParamIndex = ParamCommandComment::InvalidParamIndex;
|
|
|
|
if (OrphanedParamDecls.size() == 1) {
|
|
|
|
// If one parameter is not documented then that parameter is the only
|
|
|
|
// possible suggestion.
|
|
|
|
CorrectedParamIndex = 0;
|
|
|
|
} else {
|
|
|
|
// Do typo correction.
|
|
|
|
CorrectedParamIndex = correctTypoInParmVarReference(ParamName,
|
|
|
|
OrphanedParamDecls);
|
|
|
|
}
|
|
|
|
if (CorrectedParamIndex != ParamCommandComment::InvalidParamIndex) {
|
|
|
|
const ParmVarDecl *CorrectedPVD = OrphanedParamDecls[CorrectedParamIndex];
|
|
|
|
if (const IdentifierInfo *CorrectedII = CorrectedPVD->getIdentifier())
|
|
|
|
Diag(ArgRange.getBegin(), diag::note_doc_param_name_suggestion)
|
|
|
|
<< CorrectedII->getName()
|
|
|
|
<< FixItHint::CreateReplacement(ArgRange, CorrectedII->getName());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-24 01:40:30 +08:00
|
|
|
bool Sema::isFunctionDecl() {
|
2012-08-02 07:08:09 +08:00
|
|
|
if (!ThisDeclInfo)
|
|
|
|
return false;
|
|
|
|
if (!ThisDeclInfo->IsFilled)
|
2012-07-25 04:58:46 +08:00
|
|
|
inspectThisDecl();
|
2012-08-03 05:45:39 +08:00
|
|
|
return ThisDeclInfo->getKind() == DeclInfo::FunctionKind;
|
2012-07-24 01:40:30 +08:00
|
|
|
}
|
2013-03-06 06:46:07 +08:00
|
|
|
|
2013-03-06 07:20:29 +08:00
|
|
|
bool Sema::isAnyFunctionDecl() {
|
|
|
|
return isFunctionDecl() && ThisDeclInfo->CurrentDecl &&
|
|
|
|
isa<FunctionDecl>(ThisDeclInfo->CurrentDecl);
|
|
|
|
}
|
2013-06-24 12:41:32 +08:00
|
|
|
|
|
|
|
bool Sema::isFunctionOrMethodVariadic() {
|
2017-10-07 04:51:04 +08:00
|
|
|
if (!isFunctionDecl() || !ThisDeclInfo->CurrentDecl)
|
2013-06-24 12:41:32 +08:00
|
|
|
return false;
|
|
|
|
if (const FunctionDecl *FD =
|
|
|
|
dyn_cast<FunctionDecl>(ThisDeclInfo->CurrentDecl))
|
|
|
|
return FD->isVariadic();
|
2014-03-19 21:59:36 +08:00
|
|
|
if (const FunctionTemplateDecl *FTD =
|
|
|
|
dyn_cast<FunctionTemplateDecl>(ThisDeclInfo->CurrentDecl))
|
|
|
|
return FTD->getTemplatedDecl()->isVariadic();
|
2013-06-24 12:41:32 +08:00
|
|
|
if (const ObjCMethodDecl *MD =
|
|
|
|
dyn_cast<ObjCMethodDecl>(ThisDeclInfo->CurrentDecl))
|
|
|
|
return MD->isVariadic();
|
2017-10-07 04:51:04 +08:00
|
|
|
if (const TypedefNameDecl *TD =
|
|
|
|
dyn_cast<TypedefNameDecl>(ThisDeclInfo->CurrentDecl)) {
|
|
|
|
QualType Type = TD->getUnderlyingType();
|
|
|
|
if (Type->isFunctionPointerType() || Type->isBlockPointerType())
|
|
|
|
Type = Type->getPointeeType();
|
|
|
|
if (const auto *FT = Type->getAs<FunctionProtoType>())
|
|
|
|
return FT->isVariadic();
|
|
|
|
}
|
2013-06-24 12:41:32 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-03-06 06:46:07 +08:00
|
|
|
bool Sema::isObjCMethodDecl() {
|
|
|
|
return isFunctionDecl() && ThisDeclInfo->CurrentDecl &&
|
|
|
|
isa<ObjCMethodDecl>(ThisDeclInfo->CurrentDecl);
|
|
|
|
}
|
2013-06-24 09:33:34 +08:00
|
|
|
|
2013-03-06 06:46:07 +08:00
|
|
|
bool Sema::isFunctionPointerVarDecl() {
|
2013-03-06 03:40:47 +08:00
|
|
|
if (!ThisDeclInfo)
|
|
|
|
return false;
|
|
|
|
if (!ThisDeclInfo->IsFilled)
|
|
|
|
inspectThisDecl();
|
|
|
|
if (ThisDeclInfo->getKind() == DeclInfo::VariableKind) {
|
|
|
|
if (const VarDecl *VD = dyn_cast_or_null<VarDecl>(ThisDeclInfo->CurrentDecl)) {
|
|
|
|
QualType QT = VD->getType();
|
|
|
|
return QT->isFunctionPointerType();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2013-12-18 03:28:18 +08:00
|
|
|
|
2017-04-21 22:17:49 +08:00
|
|
|
bool Sema::isFunctionOrBlockPointerVarLikeDecl() {
|
|
|
|
if (!ThisDeclInfo)
|
|
|
|
return false;
|
|
|
|
if (!ThisDeclInfo->IsFilled)
|
|
|
|
inspectThisDecl();
|
|
|
|
if (ThisDeclInfo->getKind() != DeclInfo::VariableKind ||
|
|
|
|
!ThisDeclInfo->CurrentDecl)
|
|
|
|
return false;
|
|
|
|
QualType QT;
|
|
|
|
if (const auto *VD = dyn_cast<DeclaratorDecl>(ThisDeclInfo->CurrentDecl))
|
|
|
|
QT = VD->getType();
|
|
|
|
else if (const auto *PD =
|
|
|
|
dyn_cast<ObjCPropertyDecl>(ThisDeclInfo->CurrentDecl))
|
|
|
|
QT = PD->getType();
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
// We would like to warn about the 'returns'/'param' commands for
|
|
|
|
// variables that don't directly specify the function type, so type aliases
|
|
|
|
// can be ignored.
|
|
|
|
if (QT->getAs<TypedefType>())
|
|
|
|
return false;
|
2019-09-03 02:24:33 +08:00
|
|
|
if (const auto *P = QT->getAs<PointerType>())
|
|
|
|
if (P->getPointeeType()->getAs<TypedefType>())
|
|
|
|
return false;
|
|
|
|
if (const auto *P = QT->getAs<BlockPointerType>())
|
|
|
|
if (P->getPointeeType()->getAs<TypedefType>())
|
|
|
|
return false;
|
2017-04-21 22:17:49 +08:00
|
|
|
return QT->isFunctionPointerType() || QT->isBlockPointerType();
|
|
|
|
}
|
|
|
|
|
2013-02-27 08:46:06 +08:00
|
|
|
bool Sema::isObjCPropertyDecl() {
|
|
|
|
if (!ThisDeclInfo)
|
|
|
|
return false;
|
|
|
|
if (!ThisDeclInfo->IsFilled)
|
|
|
|
inspectThisDecl();
|
|
|
|
return ThisDeclInfo->CurrentDecl->getKind() == Decl::ObjCProperty;
|
|
|
|
}
|
2012-07-24 01:40:30 +08:00
|
|
|
|
2012-08-07 05:31:15 +08:00
|
|
|
bool Sema::isTemplateOrSpecialization() {
|
2012-08-02 07:08:09 +08:00
|
|
|
if (!ThisDeclInfo)
|
|
|
|
return false;
|
|
|
|
if (!ThisDeclInfo->IsFilled)
|
2012-08-01 06:37:06 +08:00
|
|
|
inspectThisDecl();
|
2012-08-07 05:31:15 +08:00
|
|
|
return ThisDeclInfo->getTemplateKind() != DeclInfo::NotTemplate;
|
2012-08-01 06:37:06 +08:00
|
|
|
}
|
|
|
|
|
2013-03-09 07:59:23 +08:00
|
|
|
bool Sema::isRecordLikeDecl() {
|
2013-03-08 07:33:11 +08:00
|
|
|
if (!ThisDeclInfo)
|
|
|
|
return false;
|
|
|
|
if (!ThisDeclInfo->IsFilled)
|
|
|
|
inspectThisDecl();
|
2013-12-18 03:28:18 +08:00
|
|
|
return isUnionDecl() || isClassOrStructDecl() || isObjCInterfaceDecl() ||
|
|
|
|
isObjCProtocolDecl();
|
2013-03-08 07:33:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Sema::isUnionDecl() {
|
|
|
|
if (!ThisDeclInfo)
|
|
|
|
return false;
|
|
|
|
if (!ThisDeclInfo->IsFilled)
|
|
|
|
inspectThisDecl();
|
|
|
|
if (const RecordDecl *RD =
|
|
|
|
dyn_cast_or_null<RecordDecl>(ThisDeclInfo->CurrentDecl))
|
|
|
|
return RD->isUnion();
|
|
|
|
return false;
|
|
|
|
}
|
2020-02-18 06:55:49 +08:00
|
|
|
static bool isClassOrStructDeclImpl(const Decl *D) {
|
|
|
|
if (auto *record = dyn_cast_or_null<RecordDecl>(D))
|
|
|
|
return !record->isUnion();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2013-12-18 03:28:18 +08:00
|
|
|
|
2013-03-09 07:59:23 +08:00
|
|
|
bool Sema::isClassOrStructDecl() {
|
2013-03-08 07:33:11 +08:00
|
|
|
if (!ThisDeclInfo)
|
|
|
|
return false;
|
|
|
|
if (!ThisDeclInfo->IsFilled)
|
|
|
|
inspectThisDecl();
|
2020-02-18 06:55:49 +08:00
|
|
|
|
|
|
|
if (!ThisDeclInfo->CurrentDecl)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return isClassOrStructDeclImpl(ThisDeclInfo->CurrentDecl);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Sema::isClassOrStructOrTagTypedefDecl() {
|
|
|
|
if (!ThisDeclInfo)
|
|
|
|
return false;
|
|
|
|
if (!ThisDeclInfo->IsFilled)
|
|
|
|
inspectThisDecl();
|
|
|
|
|
|
|
|
if (!ThisDeclInfo->CurrentDecl)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (isClassOrStructDeclImpl(ThisDeclInfo->CurrentDecl))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (auto *ThisTypedefDecl = dyn_cast<TypedefDecl>(ThisDeclInfo->CurrentDecl)) {
|
|
|
|
auto UnderlyingType = ThisTypedefDecl->getUnderlyingType();
|
|
|
|
if (auto ThisElaboratedType = dyn_cast<ElaboratedType>(UnderlyingType)) {
|
|
|
|
auto DesugaredType = ThisElaboratedType->desugar();
|
|
|
|
if (auto *DesugaredTypePtr = DesugaredType.getTypePtrOrNull()) {
|
|
|
|
if (auto *ThisRecordType = dyn_cast<RecordType>(DesugaredTypePtr)) {
|
|
|
|
return isClassOrStructDeclImpl(ThisRecordType->getAsRecordDecl());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2013-03-08 07:33:11 +08:00
|
|
|
}
|
2013-12-18 03:28:18 +08:00
|
|
|
|
2013-06-20 02:08:03 +08:00
|
|
|
bool Sema::isClassTemplateDecl() {
|
|
|
|
if (!ThisDeclInfo)
|
|
|
|
return false;
|
|
|
|
if (!ThisDeclInfo->IsFilled)
|
|
|
|
inspectThisDecl();
|
|
|
|
return ThisDeclInfo->CurrentDecl &&
|
|
|
|
(isa<ClassTemplateDecl>(ThisDeclInfo->CurrentDecl));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Sema::isFunctionTemplateDecl() {
|
|
|
|
if (!ThisDeclInfo)
|
|
|
|
return false;
|
|
|
|
if (!ThisDeclInfo->IsFilled)
|
|
|
|
inspectThisDecl();
|
|
|
|
return ThisDeclInfo->CurrentDecl &&
|
2013-12-18 03:28:18 +08:00
|
|
|
(isa<FunctionTemplateDecl>(ThisDeclInfo->CurrentDecl));
|
2013-06-20 02:08:03 +08:00
|
|
|
}
|
2013-03-08 07:33:11 +08:00
|
|
|
|
|
|
|
bool Sema::isObjCInterfaceDecl() {
|
|
|
|
if (!ThisDeclInfo)
|
|
|
|
return false;
|
|
|
|
if (!ThisDeclInfo->IsFilled)
|
|
|
|
inspectThisDecl();
|
|
|
|
return ThisDeclInfo->CurrentDecl &&
|
|
|
|
isa<ObjCInterfaceDecl>(ThisDeclInfo->CurrentDecl);
|
|
|
|
}
|
2013-12-18 03:28:18 +08:00
|
|
|
|
2013-03-08 07:33:11 +08:00
|
|
|
bool Sema::isObjCProtocolDecl() {
|
|
|
|
if (!ThisDeclInfo)
|
|
|
|
return false;
|
|
|
|
if (!ThisDeclInfo->IsFilled)
|
|
|
|
inspectThisDecl();
|
|
|
|
return ThisDeclInfo->CurrentDecl &&
|
|
|
|
isa<ObjCProtocolDecl>(ThisDeclInfo->CurrentDecl);
|
|
|
|
}
|
2013-12-18 03:28:18 +08:00
|
|
|
|
2012-07-24 01:40:30 +08:00
|
|
|
ArrayRef<const ParmVarDecl *> Sema::getParamVars() {
|
2012-08-02 07:08:09 +08:00
|
|
|
if (!ThisDeclInfo->IsFilled)
|
2012-07-25 04:58:46 +08:00
|
|
|
inspectThisDecl();
|
2012-08-02 07:08:09 +08:00
|
|
|
return ThisDeclInfo->ParamVars;
|
2012-07-24 01:40:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void Sema::inspectThisDecl() {
|
2012-08-02 07:08:09 +08:00
|
|
|
ThisDeclInfo->fill();
|
2012-07-24 01:40:30 +08:00
|
|
|
}
|
|
|
|
|
2012-07-12 05:38:39 +08:00
|
|
|
unsigned Sema::resolveParmVarReference(StringRef Name,
|
2012-07-24 01:40:30 +08:00
|
|
|
ArrayRef<const ParmVarDecl *> ParamVars) {
|
|
|
|
for (unsigned i = 0, e = ParamVars.size(); i != e; ++i) {
|
2012-07-12 05:38:39 +08:00
|
|
|
const IdentifierInfo *II = ParamVars[i]->getIdentifier();
|
|
|
|
if (II && II->getName() == Name)
|
|
|
|
return i;
|
|
|
|
}
|
2013-06-24 12:41:32 +08:00
|
|
|
if (Name == "..." && isFunctionOrMethodVariadic())
|
|
|
|
return ParamCommandComment::VarArgParamIndex;
|
2012-07-12 05:38:39 +08:00
|
|
|
return ParamCommandComment::InvalidParamIndex;
|
|
|
|
}
|
|
|
|
|
2012-08-01 06:37:06 +08:00
|
|
|
namespace {
|
|
|
|
class SimpleTypoCorrector {
|
2016-08-29 05:33:30 +08:00
|
|
|
const NamedDecl *BestDecl;
|
|
|
|
|
2012-08-01 06:37:06 +08:00
|
|
|
StringRef Typo;
|
|
|
|
const unsigned MaxEditDistance;
|
|
|
|
|
|
|
|
unsigned BestEditDistance;
|
|
|
|
unsigned BestIndex;
|
|
|
|
unsigned NextIndex;
|
|
|
|
|
|
|
|
public:
|
2016-08-29 05:33:30 +08:00
|
|
|
explicit SimpleTypoCorrector(StringRef Typo)
|
|
|
|
: BestDecl(nullptr), Typo(Typo), MaxEditDistance((Typo.size() + 2) / 3),
|
|
|
|
BestEditDistance(MaxEditDistance + 1), BestIndex(0), NextIndex(0) {}
|
2012-08-01 06:37:06 +08:00
|
|
|
|
|
|
|
void addDecl(const NamedDecl *ND);
|
|
|
|
|
|
|
|
const NamedDecl *getBestDecl() const {
|
|
|
|
if (BestEditDistance > MaxEditDistance)
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
2012-08-01 06:37:06 +08:00
|
|
|
|
|
|
|
return BestDecl;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned getBestDeclIndex() const {
|
|
|
|
assert(getBestDecl());
|
|
|
|
return BestIndex;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
void SimpleTypoCorrector::addDecl(const NamedDecl *ND) {
|
|
|
|
unsigned CurrIndex = NextIndex++;
|
|
|
|
|
|
|
|
const IdentifierInfo *II = ND->getIdentifier();
|
|
|
|
if (!II)
|
|
|
|
return;
|
|
|
|
|
|
|
|
StringRef Name = II->getName();
|
|
|
|
unsigned MinPossibleEditDistance = abs((int)Name.size() - (int)Typo.size());
|
|
|
|
if (MinPossibleEditDistance > 0 &&
|
|
|
|
Typo.size() / MinPossibleEditDistance < 3)
|
|
|
|
return;
|
|
|
|
|
|
|
|
unsigned EditDistance = Typo.edit_distance(Name, true, MaxEditDistance);
|
|
|
|
if (EditDistance < BestEditDistance) {
|
|
|
|
BestEditDistance = EditDistance;
|
|
|
|
BestDecl = ND;
|
|
|
|
BestIndex = CurrIndex;
|
|
|
|
}
|
|
|
|
}
|
2016-02-11 03:11:58 +08:00
|
|
|
} // end anonymous namespace
|
2012-08-01 06:37:06 +08:00
|
|
|
|
2012-07-12 05:38:39 +08:00
|
|
|
unsigned Sema::correctTypoInParmVarReference(
|
|
|
|
StringRef Typo,
|
2012-07-24 01:40:30 +08:00
|
|
|
ArrayRef<const ParmVarDecl *> ParamVars) {
|
2012-08-01 06:37:06 +08:00
|
|
|
SimpleTypoCorrector Corrector(Typo);
|
|
|
|
for (unsigned i = 0, e = ParamVars.size(); i != e; ++i)
|
|
|
|
Corrector.addDecl(ParamVars[i]);
|
|
|
|
if (Corrector.getBestDecl())
|
|
|
|
return Corrector.getBestDeclIndex();
|
|
|
|
else
|
2012-09-11 05:20:09 +08:00
|
|
|
return ParamCommandComment::InvalidParamIndex;
|
2012-08-01 06:37:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
bool ResolveTParamReferenceHelper(
|
|
|
|
StringRef Name,
|
|
|
|
const TemplateParameterList *TemplateParameters,
|
|
|
|
SmallVectorImpl<unsigned> *Position) {
|
|
|
|
for (unsigned i = 0, e = TemplateParameters->size(); i != e; ++i) {
|
|
|
|
const NamedDecl *Param = TemplateParameters->getParam(i);
|
|
|
|
const IdentifierInfo *II = Param->getIdentifier();
|
|
|
|
if (II && II->getName() == Name) {
|
|
|
|
Position->push_back(i);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (const TemplateTemplateParmDecl *TTP =
|
|
|
|
dyn_cast<TemplateTemplateParmDecl>(Param)) {
|
|
|
|
Position->push_back(i);
|
|
|
|
if (ResolveTParamReferenceHelper(Name, TTP->getTemplateParameters(),
|
|
|
|
Position))
|
|
|
|
return true;
|
|
|
|
Position->pop_back();
|
2012-07-12 05:38:39 +08:00
|
|
|
}
|
|
|
|
}
|
2012-08-01 06:37:06 +08:00
|
|
|
return false;
|
|
|
|
}
|
2016-02-11 03:11:58 +08:00
|
|
|
} // end anonymous namespace
|
2012-07-12 05:38:39 +08:00
|
|
|
|
2012-08-01 06:37:06 +08:00
|
|
|
bool Sema::resolveTParamReference(
|
|
|
|
StringRef Name,
|
|
|
|
const TemplateParameterList *TemplateParameters,
|
|
|
|
SmallVectorImpl<unsigned> *Position) {
|
|
|
|
Position->clear();
|
|
|
|
if (!TemplateParameters)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return ResolveTParamReferenceHelper(Name, TemplateParameters, Position);
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
void CorrectTypoInTParamReferenceHelper(
|
|
|
|
const TemplateParameterList *TemplateParameters,
|
|
|
|
SimpleTypoCorrector &Corrector) {
|
|
|
|
for (unsigned i = 0, e = TemplateParameters->size(); i != e; ++i) {
|
|
|
|
const NamedDecl *Param = TemplateParameters->getParam(i);
|
|
|
|
Corrector.addDecl(Param);
|
|
|
|
|
|
|
|
if (const TemplateTemplateParmDecl *TTP =
|
|
|
|
dyn_cast<TemplateTemplateParmDecl>(Param))
|
|
|
|
CorrectTypoInTParamReferenceHelper(TTP->getTemplateParameters(),
|
|
|
|
Corrector);
|
|
|
|
}
|
|
|
|
}
|
2016-02-11 03:11:58 +08:00
|
|
|
} // end anonymous namespace
|
2012-08-01 06:37:06 +08:00
|
|
|
|
|
|
|
StringRef Sema::correctTypoInTParamReference(
|
|
|
|
StringRef Typo,
|
|
|
|
const TemplateParameterList *TemplateParameters) {
|
|
|
|
SimpleTypoCorrector Corrector(Typo);
|
|
|
|
CorrectTypoInTParamReferenceHelper(TemplateParameters, Corrector);
|
|
|
|
if (const NamedDecl *ND = Corrector.getBestDecl()) {
|
|
|
|
const IdentifierInfo *II = ND->getIdentifier();
|
|
|
|
assert(II && "SimpleTypoCorrector should not return this decl");
|
|
|
|
return II->getName();
|
|
|
|
}
|
|
|
|
return StringRef();
|
2012-07-12 05:38:39 +08:00
|
|
|
}
|
|
|
|
|
2012-07-24 00:43:01 +08:00
|
|
|
InlineCommandComment::RenderKind
|
|
|
|
Sema::getInlineCommandRenderKind(StringRef Name) const {
|
2012-09-11 04:32:42 +08:00
|
|
|
assert(Traits.getCommandInfo(Name)->IsInlineCommand);
|
2012-07-24 00:43:01 +08:00
|
|
|
|
|
|
|
return llvm::StringSwitch<InlineCommandComment::RenderKind>(Name)
|
|
|
|
.Case("b", InlineCommandComment::RenderBold)
|
|
|
|
.Cases("c", "p", InlineCommandComment::RenderMonospaced)
|
|
|
|
.Cases("a", "e", "em", InlineCommandComment::RenderEmphasized)
|
2019-12-21 21:47:52 +08:00
|
|
|
.Case("anchor", InlineCommandComment::RenderAnchor)
|
2012-07-24 00:43:01 +08:00
|
|
|
.Default(InlineCommandComment::RenderNormal);
|
|
|
|
}
|
|
|
|
|
2012-07-06 08:28:32 +08:00
|
|
|
} // end namespace comments
|
|
|
|
} // end namespace clang
|