HeaderDoc: Support more of HeaderDoc documentation 
commands; top level tags such as @interface and
their 2nd level tags such as @coclass, etc.
// rdar://12379114


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@176667 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/CommentSema.cpp b/lib/AST/CommentSema.cpp
index 68a9ebb..0ca6fb1 100644
--- a/lib/AST/CommentSema.cpp
+++ b/lib/AST/CommentSema.cpp
@@ -52,8 +52,11 @@
                                       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,
@@ -105,6 +108,52 @@
     << (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,
@@ -362,6 +411,7 @@
                               TextBegin,
                               Text);
   checkFunctionDeclVerbatimLine(VL);
+  checkContainerDeclVerbatimLine(VL);
   return VL;
 }
 
@@ -735,6 +785,54 @@
   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();