Documentation parsing. Some refactoring and code

improvements per Dmtiri's comments. // rdar://12379114


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@176739 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Fariborz Jahanian 2013-03-08 23:59:23 +00:00
Родитель 0183768813
Коммит b421b56d5a
5 изменённых файлов: 112 добавлений и 85 удалений

Просмотреть файл

@ -106,10 +106,10 @@ struct CommandInfo {
/// \brief True if block command is further describing a container API; such
/// as @coclass, @classdesign, etc.
unsigned IsContainerDetailCommand : 1;
unsigned IsRecordLikeDetailCommand : 1;
/// \brief True if block command is a container API; such as @interface.
unsigned IsContainerDeclarationCommand : 1;
unsigned IsRecordLikeDeclarationCommand : 1;
/// \brief True if this command is unknown. This \c CommandInfo object was
/// created during parsing.

Просмотреть файл

@ -25,8 +25,8 @@ class Command<string name> {
bit IsVerbatimLineCommand = 0;
bit IsDeclarationCommand = 0;
bit IsFunctionDeclarationCommand = 0;
bit IsContainerDetailCommand = 0;
bit IsContainerDeclarationCommand = 0;
bit IsRecordLikeDetailCommand = 0;
bit IsRecordLikeDeclarationCommand = 0;
}
class InlineCommand<string name> : Command<name> {
@ -37,6 +37,10 @@ class BlockCommand<string name> : Command<name> {
let IsBlockCommand = 1;
}
class RecordLikeDetailCommand<string name> : BlockCommand<name> {
let IsRecordLikeDetailCommand = 1;
}
class VerbatimBlockCommand<string name> : Command<name> {
let EndCommandName = name;
let IsVerbatimBlockCommand = 1;
@ -68,10 +72,10 @@ class FunctionDeclarationVerbatimLineCommand<string name> :
let IsFunctionDeclarationCommand = 1;
}
class ContainerDeclarationVerbatimLineCommand<string name> :
class RecordLikeDeclarationVerbatimLineCommand<string name> :
VerbatimLineCommand<name> {
let IsDeclarationCommand = 1;
let IsContainerDeclarationCommand = 1;
let IsRecordLikeDeclarationCommand = 1;
}
//===----------------------------------------------------------------------===//
@ -135,6 +139,18 @@ def Since : BlockCommand<"since">;
def Todo : BlockCommand<"todo">;
def Version : BlockCommand<"version">;
def Warning : BlockCommand<"warning">;
// HeaderDoc commands
def ClassDesign : RecordLikeDetailCommand<"classdesign">;
def CoClass : RecordLikeDetailCommand<"coclass">;
def Dependency : RecordLikeDetailCommand<"dependency">;
def Helper : RecordLikeDetailCommand<"helper">;
def HelperClass : RecordLikeDetailCommand<"helperclass">;
def Helps : RecordLikeDetailCommand<"helps">;
def InstanceSize : RecordLikeDetailCommand<"instancesize">;
def Ownership : RecordLikeDetailCommand<"ownership">;
def Performance : RecordLikeDetailCommand<"performance">;
def Security : RecordLikeDetailCommand<"security">;
def SuperClass : RecordLikeDetailCommand<"superclass">;
//===----------------------------------------------------------------------===//
// VerbatimBlockCommand
@ -189,11 +205,11 @@ def Typedef : DeclarationVerbatimLineCommand<"typedef">;
def Var : DeclarationVerbatimLineCommand<"var">;
// HeaderDoc commands.
def Class : ContainerDeclarationVerbatimLineCommand<"class">;
def Interface : ContainerDeclarationVerbatimLineCommand<"interface">;
def Protocol : ContainerDeclarationVerbatimLineCommand<"protocol">;
def Struct : ContainerDeclarationVerbatimLineCommand<"struct">;
def Union : ContainerDeclarationVerbatimLineCommand<"union">;
def Class : RecordLikeDeclarationVerbatimLineCommand<"class">;
def Interface : RecordLikeDeclarationVerbatimLineCommand<"interface">;
def Protocol : RecordLikeDeclarationVerbatimLineCommand<"protocol">;
def Struct : RecordLikeDeclarationVerbatimLineCommand<"struct">;
def Union : RecordLikeDeclarationVerbatimLineCommand<"union">;
def Category : DeclarationVerbatimLineCommand<"category">;
def Template : DeclarationVerbatimLineCommand<"template">;
def Function : FunctionDeclarationVerbatimLineCommand<"function">;
@ -202,37 +218,3 @@ def Callback : FunctionDeclarationVerbatimLineCommand<"callback">;
def Const : DeclarationVerbatimLineCommand<"const">;
def Constant : DeclarationVerbatimLineCommand<"constant">;
def Enum : DeclarationVerbatimLineCommand<"enum">;
def ClassDesign : BlockCommand<"classdesign"> {
let IsContainerDetailCommand = 1;
}
def CoClass : BlockCommand<"coclass"> {
let IsContainerDetailCommand = 1;
}
def Dependency : BlockCommand<"dependency"> {
let IsContainerDetailCommand = 1;
}
def Helper : BlockCommand<"helper"> {
let IsContainerDetailCommand = 1;
}
def HelperClass : BlockCommand<"helperclass"> {
let IsContainerDetailCommand = 1;
}
def Helps : BlockCommand<"helps"> {
let IsContainerDetailCommand = 1;
}
def InstanceSize : BlockCommand<"instancesize"> {
let IsContainerDetailCommand = 1;
}
def Ownership : BlockCommand<"ownership"> {
let IsContainerDetailCommand = 1;
}
def Performance : BlockCommand<"performance"> {
let IsContainerDetailCommand = 1;
}
def Security : BlockCommand<"security"> {
let IsContainerDetailCommand = 1;
}
def SuperClass : BlockCommand<"superclass"> {
let IsContainerDetailCommand = 1;
}

Просмотреть файл

@ -215,8 +215,8 @@ public:
bool isObjCMethodDecl();
bool isObjCPropertyDecl();
bool isTemplateOrSpecialization();
bool isContainerDecl();
bool isClassStructDecl();
bool isRecordLikeDecl();
bool isClassOrStructDecl();
bool isUnionDecl();
bool isObjCInterfaceDecl();
bool isObjCProtocolDecl();

Просмотреть файл

@ -95,13 +95,22 @@ void Sema::checkFunctionDeclVerbatimLine(const BlockCommandComment *Comment) {
const CommandInfo *Info = Traits.getCommandInfo(Comment->getCommandID());
if (!Info->IsFunctionDeclarationCommand)
return;
StringRef Name = Info->Name;
unsigned DiagSelect = llvm::StringSwitch<unsigned>(Name)
.Case("function", !isAnyFunctionDecl() ? 1 : 0)
.Case("method", !isObjCMethodDecl() ? 2 : 0)
.Case("callback", !isFunctionPointerVarDecl() ? 3 : 0)
.Default(0);
unsigned DiagSelect;
switch (Comment->getCommandID()) {
case CommandTraits::KCI_function:
DiagSelect = !isAnyFunctionDecl() ? 1 : 0;
break;
case CommandTraits::KCI_method:
DiagSelect = !isObjCMethodDecl() ? 2 : 0;
break;
case CommandTraits::KCI_callback:
DiagSelect = !isFunctionPointerVarDecl() ? 3 : 0;
break;
default:
DiagSelect = 0;
break;
}
if (DiagSelect)
Diag(Comment->getLocation(), diag::warn_doc_function_method_decl_mismatch)
<< Comment->getCommandMarker()
@ -111,17 +120,29 @@ void Sema::checkFunctionDeclVerbatimLine(const BlockCommandComment *Comment) {
void Sema::checkContainerDeclVerbatimLine(const BlockCommandComment *Comment) {
const CommandInfo *Info = Traits.getCommandInfo(Comment->getCommandID());
if (!Info->IsContainerDeclarationCommand)
if (!Info->IsRecordLikeDeclarationCommand)
return;
StringRef Name = Info->Name;
unsigned DiagSelect = llvm::StringSwitch<unsigned>(Name)
.Case("class", !isClassStructDecl() ? 1 : 0)
.Case("interface", !isObjCInterfaceDecl() ? 2 : 0)
.Case("protocol", !isObjCProtocolDecl() ? 3 : 0)
.Case("struct", !isClassStructDecl() ? 4 : 0)
.Case("union", !isUnionDecl() ? 5 : 0)
.Default(0);
unsigned DiagSelect;
switch (Comment->getCommandID()) {
case CommandTraits::KCI_class:
DiagSelect = !isClassOrStructDecl() ? 1 : 0;
break;
case CommandTraits::KCI_interface:
DiagSelect = !isObjCInterfaceDecl() ? 2 : 0;
break;
case CommandTraits::KCI_protocol:
DiagSelect = !isObjCProtocolDecl() ? 3 : 0;
break;
case CommandTraits::KCI_struct:
DiagSelect = !isClassOrStructDecl() ? 4 : 0;
break;
case CommandTraits::KCI_union:
DiagSelect = !isUnionDecl() ? 5 : 0;
break;
default:
DiagSelect = 0;
break;
}
if (DiagSelect)
Diag(Comment->getLocation(), diag::warn_doc_api_container_decl_mismatch)
<< Comment->getCommandMarker()
@ -131,23 +152,47 @@ void Sema::checkContainerDeclVerbatimLine(const BlockCommandComment *Comment) {
void Sema::checkContainerDecl(const BlockCommandComment *Comment) {
const CommandInfo *Info = Traits.getCommandInfo(Comment->getCommandID());
if (!Info->IsContainerDetailCommand || isContainerDecl())
if (!Info->IsRecordLikeDetailCommand || isRecordLikeDecl())
return;
StringRef Name = Info->Name;
unsigned DiagSelect = llvm::StringSwitch<unsigned>(Name)
.Case("classdesign", 1)
.Case("coclass", 2)
.Case("dependency", 3)
.Case("helper", 4)
.Case("helperclass", 5)
.Case("helps", 6)
.Case("instancesize", 7)
.Case("ownership", 8)
.Case("performance", 9)
.Case("security", 10)
.Case("superclass", 11)
.Default(0);
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;
}
if (DiagSelect)
Diag(Comment->getLocation(), diag::warn_doc_container_decl_mismatch)
<< Comment->getCommandMarker()
@ -785,12 +830,12 @@ bool Sema::isTemplateOrSpecialization() {
return ThisDeclInfo->getTemplateKind() != DeclInfo::NotTemplate;
}
bool Sema::isContainerDecl() {
bool Sema::isRecordLikeDecl() {
if (!ThisDeclInfo)
return false;
if (!ThisDeclInfo->IsFilled)
inspectThisDecl();
return isUnionDecl() || isClassStructDecl()
return isUnionDecl() || isClassOrStructDecl()
|| isObjCInterfaceDecl() || isObjCProtocolDecl();
}
@ -805,7 +850,7 @@ bool Sema::isUnionDecl() {
return false;
}
bool Sema::isClassStructDecl() {
bool Sema::isClassOrStructDecl() {
if (!ThisDeclInfo)
return false;
if (!ThisDeclInfo->IsFilled)

Просмотреть файл

@ -48,8 +48,8 @@ void EmitClangCommentCommandInfo(RecordKeeper &Records, raw_ostream &OS) {
<< Tag.getValueAsBit("IsVerbatimLineCommand") << ", "
<< Tag.getValueAsBit("IsDeclarationCommand") << ", "
<< Tag.getValueAsBit("IsFunctionDeclarationCommand") << ", "
<< Tag.getValueAsBit("IsContainerDetailCommand") << ", "
<< Tag.getValueAsBit("IsContainerDeclarationCommand") << ", "
<< Tag.getValueAsBit("IsRecordLikeDetailCommand") << ", "
<< Tag.getValueAsBit("IsRecordLikeDeclarationCommand") << ", "
<< /* IsUnknownCommand = */ "0"
<< " }";
if (i + 1 != e)