From: Fariborz Jahanian Date: Fri, 8 Mar 2013 23:59:23 +0000 (+0000) Subject: Documentation parsing. Some refactoring and code X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b421b56d5a83c5bcae576b714ebd9df7b745368d;p=clang 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 --- diff --git a/include/clang/AST/CommentCommandTraits.h b/include/clang/AST/CommentCommandTraits.h index 0dfeea0cb9..9eb99d506b 100644 --- a/include/clang/AST/CommentCommandTraits.h +++ b/include/clang/AST/CommentCommandTraits.h @@ -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. diff --git a/include/clang/AST/CommentCommands.td b/include/clang/AST/CommentCommands.td index ed5927cc0d..e217834227 100644 --- a/include/clang/AST/CommentCommands.td +++ b/include/clang/AST/CommentCommands.td @@ -25,8 +25,8 @@ class Command { bit IsVerbatimLineCommand = 0; bit IsDeclarationCommand = 0; bit IsFunctionDeclarationCommand = 0; - bit IsContainerDetailCommand = 0; - bit IsContainerDeclarationCommand = 0; + bit IsRecordLikeDetailCommand = 0; + bit IsRecordLikeDeclarationCommand = 0; } class InlineCommand : Command { @@ -37,6 +37,10 @@ class BlockCommand : Command { let IsBlockCommand = 1; } +class RecordLikeDetailCommand : BlockCommand { + let IsRecordLikeDetailCommand = 1; +} + class VerbatimBlockCommand : Command { let EndCommandName = name; let IsVerbatimBlockCommand = 1; @@ -68,10 +72,10 @@ class FunctionDeclarationVerbatimLineCommand : let IsFunctionDeclarationCommand = 1; } -class ContainerDeclarationVerbatimLineCommand : +class RecordLikeDeclarationVerbatimLineCommand : VerbatimLineCommand { 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; -} diff --git a/include/clang/AST/CommentSema.h b/include/clang/AST/CommentSema.h index 8294a816c0..15e454dcc3 100644 --- a/include/clang/AST/CommentSema.h +++ b/include/clang/AST/CommentSema.h @@ -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(); diff --git a/lib/AST/CommentSema.cpp b/lib/AST/CommentSema.cpp index 0ca6fb1a11..e6367c9755 100644 --- a/lib/AST/CommentSema.cpp +++ b/lib/AST/CommentSema.cpp @@ -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(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(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(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) diff --git a/utils/TableGen/ClangCommentCommandInfoEmitter.cpp b/utils/TableGen/ClangCommentCommandInfoEmitter.cpp index f90cef3719..ebb0427d7c 100644 --- a/utils/TableGen/ClangCommentCommandInfoEmitter.cpp +++ b/utils/TableGen/ClangCommentCommandInfoEmitter.cpp @@ -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)