r176739 - Documentation parsing. Some refactoring and code
Fariborz Jahanian
fjahanian at apple.com
Fri Mar 8 15:59:23 PST 2013
Author: fjahanian
Date: Fri Mar 8 17:59:23 2013
New Revision: 176739
URL: http://llvm.org/viewvc/llvm-project?rev=176739&view=rev
Log:
Documentation parsing. Some refactoring and code
improvements per Dmtiri's comments. // rdar://12379114
Modified:
cfe/trunk/include/clang/AST/CommentCommandTraits.h
cfe/trunk/include/clang/AST/CommentCommands.td
cfe/trunk/include/clang/AST/CommentSema.h
cfe/trunk/lib/AST/CommentSema.cpp
cfe/trunk/utils/TableGen/ClangCommentCommandInfoEmitter.cpp
Modified: cfe/trunk/include/clang/AST/CommentCommandTraits.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/CommentCommandTraits.h?rev=176739&r1=176738&r2=176739&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/CommentCommandTraits.h (original)
+++ cfe/trunk/include/clang/AST/CommentCommandTraits.h Fri Mar 8 17:59:23 2013
@@ -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.
Modified: cfe/trunk/include/clang/AST/CommentCommands.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/CommentCommands.td?rev=176739&r1=176738&r2=176739&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/CommentCommands.td (original)
+++ cfe/trunk/include/clang/AST/CommentCommands.td Fri Mar 8 17:59:23 2013
@@ -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> : Comman
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 FunctionDeclarationVerbatimLineCom
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 : DeclarationVerbatimLineC
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 : FunctionDeclarationVerba
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;
-}
Modified: cfe/trunk/include/clang/AST/CommentSema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/CommentSema.h?rev=176739&r1=176738&r2=176739&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/CommentSema.h (original)
+++ cfe/trunk/include/clang/AST/CommentSema.h Fri Mar 8 17:59:23 2013
@@ -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();
Modified: cfe/trunk/lib/AST/CommentSema.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/CommentSema.cpp?rev=176739&r1=176738&r2=176739&view=diff
==============================================================================
--- cfe/trunk/lib/AST/CommentSema.cpp (original)
+++ cfe/trunk/lib/AST/CommentSema.cpp Fri Mar 8 17:59:23 2013
@@ -95,13 +95,22 @@ void Sema::checkFunctionDeclVerbatimLine
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
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::checkContainerDeclVerbatimLin
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)
Modified: cfe/trunk/utils/TableGen/ClangCommentCommandInfoEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/utils/TableGen/ClangCommentCommandInfoEmitter.cpp?rev=176739&r1=176738&r2=176739&view=diff
==============================================================================
--- cfe/trunk/utils/TableGen/ClangCommentCommandInfoEmitter.cpp (original)
+++ cfe/trunk/utils/TableGen/ClangCommentCommandInfoEmitter.cpp Fri Mar 8 17:59:23 2013
@@ -48,8 +48,8 @@ void EmitClangCommentCommandInfo(RecordK
<< 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)
More information about the cfe-commits
mailing list