[Doc parsing] Add availability information to generated Comment XML.
(I still need to add a test once I figure it out).
Reviewed off-line by Doug. // rdar://12378879


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@164861 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/tools/libclang/CXComment.cpp b/tools/libclang/CXComment.cpp
index 4e26a9e..a132a0d 100644
--- a/tools/libclang/CXComment.cpp
+++ b/tools/libclang/CXComment.cpp
@@ -1170,7 +1170,62 @@
     visit(Parts.Returns);
     Result << "</ResultDiscussion>";
   }
-
+  
+  if (DI->ThisDecl->hasAttrs()) {
+    const AttrVec &Attrs = DI->ThisDecl->getAttrs();
+    for (unsigned i = 0, e = Attrs.size(); i != e;) {
+      const AvailabilityAttr *AA = dyn_cast<AvailabilityAttr>(Attrs[i++]);
+      if (!AA)
+        continue;
+      // availability attribute info.
+  
+      Result << "<Availability";
+      StringRef distribution;
+      if (AA->getPlatform()) {
+        distribution = AA->getPlatform()->getName();
+        if (distribution == "macosx")
+          distribution = "OSX";
+        else
+          distribution = "iOS";
+      }
+      
+      Result << " distribution=\"";
+      Result << distribution;
+      Result << "\">";
+      VersionTuple IntroducedInVersion = AA->getIntroduced();
+      if (!IntroducedInVersion.empty()) {
+        Result << " <IntroducedInVersion>";
+        Result << IntroducedInVersion.getAsString();
+        Result << "</IntroducedInVersion>";
+      }
+      VersionTuple DeprecatedInVersion = AA->getDeprecated();
+      if (!DeprecatedInVersion.empty()) {
+        Result << " <DeprecatedInVersion>";
+        Result << DeprecatedInVersion.getAsString();
+        Result << "</DeprecatedInVersion>";
+      }
+      VersionTuple RemovedAfterVersion = AA->getObsoleted();
+      if (!RemovedAfterVersion.empty()) {
+        Result << " <RemovedAfterVersion>";
+        Result << RemovedAfterVersion.getAsString();
+        Result << "</RemovedAfterVersion>";
+      }
+      StringRef DeprecationSummary = AA->getMessage();
+      if (!DeprecationSummary.empty()) {
+        Result << " <DeprecationSummary>";
+        Result << DeprecationSummary;
+        Result << "</DeprecationSummary>";
+      }
+      Result << " <Unavailable>";
+      if (AA->getUnavailable())
+        Result << "true";
+      else
+        Result << "false";
+      Result << "</Unavailable>";
+      Result << " </Availability>";
+    }
+  }
+  
   {
     bool StartTagEmitted = false;
     for (unsigned i = 0, e = Parts.MiscBlocks.size(); i != e; ++i) {