/// \endcode
unsigned IsDeclarationCommand : 1;
- /// \brief True if verbatim-like line command is a function declaraton.
+ /// \brief True if verbatim-like line command is a function declaration.
unsigned IsFunctionDeclarationCommand : 1;
+
+ /// \brief True if block command is further describing a container API; such
+ /// as @coclass, @classdesign, etc.
+ unsigned IsContainerDetailCommand : 1;
+
+ /// \brief True if block command is a container API; such as @interface.
+ unsigned IsContainerDeclarationCommand : 1;
/// \brief True if this command is unknown. This \c CommandInfo object was
/// created during parsing.
bit IsVerbatimLineCommand = 0;
bit IsDeclarationCommand = 0;
bit IsFunctionDeclarationCommand = 0;
+ bit IsContainerDetailCommand = 0;
+ bit IsContainerDeclarationCommand = 0;
}
class InlineCommand<string name> : Command<name> {
let IsFunctionDeclarationCommand = 1;
}
+class ContainerDeclarationVerbatimLineCommand<string name> :
+ VerbatimLineCommand<name> {
+ let IsDeclarationCommand = 1;
+ let IsContainerDeclarationCommand = 1;
+}
+
//===----------------------------------------------------------------------===//
// InlineCommand
//===----------------------------------------------------------------------===//
def Var : DeclarationVerbatimLineCommand<"var">;
// HeaderDoc commands.
-def Class : DeclarationVerbatimLineCommand<"class">;
-def Interface : DeclarationVerbatimLineCommand<"interface">;
-def Protocol : DeclarationVerbatimLineCommand<"protocol">;
+def Class : ContainerDeclarationVerbatimLineCommand<"class">;
+def Interface : ContainerDeclarationVerbatimLineCommand<"interface">;
+def Protocol : ContainerDeclarationVerbatimLineCommand<"protocol">;
+def Struct : ContainerDeclarationVerbatimLineCommand<"struct">;
+def Union : ContainerDeclarationVerbatimLineCommand<"union">;
def Category : DeclarationVerbatimLineCommand<"category">;
def Template : DeclarationVerbatimLineCommand<"template">;
def Function : FunctionDeclarationVerbatimLineCommand<"function">;
def Callback : FunctionDeclarationVerbatimLineCommand<"callback">;
def Const : DeclarationVerbatimLineCommand<"const">;
def Constant : DeclarationVerbatimLineCommand<"constant">;
-def Struct : DeclarationVerbatimLineCommand<"struct">;
-def Union : DeclarationVerbatimLineCommand<"union">;
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;
+}
void checkDeprecatedCommand(const BlockCommandComment *Comment);
void checkFunctionDeclVerbatimLine(const BlockCommandComment *Comment);
+
+ void checkContainerDeclVerbatimLine(const BlockCommandComment *Comment);
+
+ void checkContainerDecl(const BlockCommandComment *Comment);
/// Resolve parameter names to parameter indexes in function declaration.
/// Emit diagnostics about unknown parametrs.
bool isObjCMethodDecl();
bool isObjCPropertyDecl();
bool isTemplateOrSpecialization();
+ bool isContainerDecl();
+ bool isClassStructDecl();
+ bool isUnionDecl();
+ bool isObjCInterfaceDecl();
+ bool isObjCProtocolDecl();
ArrayRef<const ParmVarDecl *> getParamVars();
"%select{a function|an Objective-C method|a pointer to function}2 declaration">,
InGroup<Documentation>, DefaultIgnore;
+def warn_doc_api_container_decl_mismatch : Warning<
+ "'%select{\\|@}0%select{class|interface|protocol|struct|union}1' "
+ "command should not be used in a comment attached to a "
+ "non-%select{class|interface|protocol|struct|union}2 declaration">,
+ InGroup<Documentation>, DefaultIgnore;
+
+def warn_doc_container_decl_mismatch : Warning<
+ "'%select{\\|@}0%select{classdesign|coclass|dependency|helper"
+ "|helperclass|helps|instancesize|ownership|performance|security|superclass}1' "
+ "command should not be used in a comment attached to a non-container declaration">,
+ InGroup<Documentation>, DefaultIgnore;
+
def warn_doc_param_duplicate : Warning<
"parameter '%0' is already documented">,
InGroup<Documentation>, DefaultIgnore;
SourceLocation LocEnd,
unsigned CommandID,
CommandMarkerKind CommandMarker) {
- return new (Allocator) BlockCommandComment(LocBegin, LocEnd, CommandID,
- CommandMarker);
+ BlockCommandComment *BC = new (Allocator) BlockCommandComment(LocBegin, LocEnd,
+ CommandID,
+ CommandMarker);
+ checkContainerDecl(BC);
+ return BC;
}
void Sema::actOnBlockCommandArgs(BlockCommandComment *Command,
<< (DiagSelect-1) << (DiagSelect-1)
<< Comment->getSourceRange();
}
+
+void Sema::checkContainerDeclVerbatimLine(const BlockCommandComment *Comment) {
+ const CommandInfo *Info = Traits.getCommandInfo(Comment->getCommandID());
+ if (!Info->IsContainerDeclarationCommand)
+ 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);
+
+ 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());
+ if (!Info->IsContainerDetailCommand || isContainerDecl())
+ 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);
+
+ if (DiagSelect)
+ Diag(Comment->getLocation(), diag::warn_doc_container_decl_mismatch)
+ << Comment->getCommandMarker()
+ << (DiagSelect-1)
+ << Comment->getSourceRange();
+}
void Sema::actOnParamCommandDirectionArg(ParamCommandComment *Command,
SourceLocation ArgLocBegin,
TextBegin,
Text);
checkFunctionDeclVerbatimLine(VL);
+ checkContainerDeclVerbatimLine(VL);
return VL;
}
return ThisDeclInfo->getTemplateKind() != DeclInfo::NotTemplate;
}
+bool Sema::isContainerDecl() {
+ if (!ThisDeclInfo)
+ return false;
+ if (!ThisDeclInfo->IsFilled)
+ inspectThisDecl();
+ return isUnionDecl() || isClassStructDecl()
+ || isObjCInterfaceDecl() || isObjCProtocolDecl();
+}
+
+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;
+}
+
+bool Sema::isClassStructDecl() {
+ if (!ThisDeclInfo)
+ return false;
+ if (!ThisDeclInfo->IsFilled)
+ inspectThisDecl();
+ return ThisDeclInfo->CurrentDecl &&
+ isa<RecordDecl>(ThisDeclInfo->CurrentDecl) &&
+ !isUnionDecl();
+}
+
+bool Sema::isObjCInterfaceDecl() {
+ if (!ThisDeclInfo)
+ return false;
+ if (!ThisDeclInfo->IsFilled)
+ inspectThisDecl();
+ return ThisDeclInfo->CurrentDecl &&
+ isa<ObjCInterfaceDecl>(ThisDeclInfo->CurrentDecl);
+}
+
+bool Sema::isObjCProtocolDecl() {
+ if (!ThisDeclInfo)
+ return false;
+ if (!ThisDeclInfo->IsFilled)
+ inspectThisDecl();
+ return ThisDeclInfo->CurrentDecl &&
+ isa<ObjCProtocolDecl>(ThisDeclInfo->CurrentDecl);
+}
+
ArrayRef<const ParmVarDecl *> Sema::getParamVars() {
if (!ThisDeclInfo->IsFilled)
inspectThisDecl();
// expected-warning@+1 {{empty paragraph passed to '@param' command}}
///@param x@param y
int test_nocrash13(int x, int y);
+
+// rdar://12379114
+// expected-warning@+2 {{'@union' command should not be used in a comment attached to a non-union declaration}}
+/*!
+ @union U This is new
+*/
+struct U { int iS; };
+
+/*!
+ @union U1
+*/
+union U1 {int i; };
+
+// expected-warning@+2 {{'@struct' command should not be used in a comment attached to a non-struct declaration}}
+/*!
+ @struct S2
+*/
+union S2 {};
+
+/*!
+ @class C1
+*/
+class C1;
+
+/*!
+ @struct S3;
+*/
+class S3;
typedef id ID;
- (unsigned) Base64EncodeEx : (ID)Arg;
@end
+
+// rdar://12379114
+// expected-warning@+5 {{'@interface' command should not be used in a comment attached to a non-interface declaration}}
+// expected-warning@+5 {{'@classdesign' command should not be used in a comment attached to a non-container declaration}}
+// expected-warning@+5 {{'@coclass' command should not be used in a comment attached to a non-container declaration}}
+@interface NSObject @end
+/*!
+@interface IOCommandGate
+@classdesign Multiple paragraphs go here.
+@coclass myCoClass
+*/
+
+typedef id OBJ;
+@interface IOCommandGate : NSObject {
+ OBJ iv;
+}
+@end
+
+// expected-warning@+2 {{'@protocol' command should not be used in a comment attached to a non-protocol declaration}}
+/*!
+@protocol PROTO
+*/
+struct S;
+
+/*!
+ @interface NSArray This is an array
+*/
+@class NSArray;
+@interface NSArray @end
+
+/*!
+@interface NSMutableArray
+@super NSArray
+*/
+@interface NSMutableArray : NSArray @end
+
+/*!
+ @protocol MyProto
+*/
+@protocol MyProto @end
+
+// expected-warning@+2 {{'@protocol' command should not be used in a comment attached to a non-protocol declaration}}
+/*!
+ @protocol MyProto
+*/
+@interface INTF <MyProto> @end
+
+// expected-warning@+2 {{'@struct' command should not be used in a comment attached to a non-struct declaration}}
+/*!
+ @struct S1 THIS IS IT
+*/
+@interface S1 @end
<< Tag.getValueAsBit("IsVerbatimLineCommand") << ", "
<< Tag.getValueAsBit("IsDeclarationCommand") << ", "
<< Tag.getValueAsBit("IsFunctionDeclarationCommand") << ", "
+ << Tag.getValueAsBit("IsContainerDetailCommand") << ", "
+ << Tag.getValueAsBit("IsContainerDeclarationCommand") << ", "
<< /* IsUnknownCommand = */ "0"
<< " }";
if (i + 1 != e)