availability in structured documents. Takes
authorFariborz Jahanian <fjahanian@apple.com>
Mon, 1 Oct 2012 18:42:25 +0000 (18:42 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Mon, 1 Oct 2012 18:42:25 +0000 (18:42 +0000)
care of comments by Dimitri and Doug.

llvm-svn: 164957

clang/bindings/xml/comment-xml-schema.rng
clang/include/clang/Basic/Attr.td
clang/test/Index/Inputs/CommentXML/valid-availability-attr-01.xml [new file with mode: 0644]
clang/test/Index/annotate-comments-availability-attrs.cpp [new file with mode: 0644]
clang/test/Sema/attr-availability-macosx.c
clang/test/Sema/attr-availability.c
clang/test/SemaObjC/attr-availability.m
clang/tools/libclang/CXComment.cpp

index 8302d9d..1a2eb16 100644 (file)
@@ -80,7 +80,7 @@
         <ref name="Parameters" />
       </optional>
       <zeroOrMore>
-        <ref name="Attribute" />
+        <ref name="Availability" />
       </zeroOrMore>
       <optional>
         <ref name="ResultDiscussion" />
     </element>
   </define>
 
-  <define name="Attribute">
+  <define name="Availability">
     <element name="Availability">
       <attribute name="distribution">
           <data type="string" />
index 7406ce2..67ef8be 100644 (file)
@@ -190,7 +190,7 @@ def Availability : InheritableAttr {
 [{static llvm::StringRef getPrettyPlatformName(llvm::StringRef Platform) {
     return llvm::StringSwitch<llvm::StringRef>(Platform)
              .Case("ios", "iOS")
-             .Case("macosx", "Mac OS X")
+             .Case("macosx", "OS X")
              .Default(llvm::StringRef());
 } }];
 }
diff --git a/clang/test/Index/Inputs/CommentXML/valid-availability-attr-01.xml b/clang/test/Index/Inputs/CommentXML/valid-availability-attr-01.xml
new file mode 100644 (file)
index 0000000..94cbc9a
--- /dev/null
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Availability distribution="OS X">
+  <IntroducedInVersion>8.0</IntroducedInVersion>
+  <DeprecatedInVersion>9.0</DeprecatedInVersion>
+  <RemovedAfterVersion>10.0</RemovedAfterVersion> 
+  <DeprecationSummary>use availability_test</DeprecationSummary>
+</Availability>
diff --git a/clang/test/Index/annotate-comments-availability-attrs.cpp b/clang/test/Index/annotate-comments-availability-attrs.cpp
new file mode 100644 (file)
index 0000000..6fb99a1
--- /dev/null
@@ -0,0 +1,12 @@
+// RUN: c-index-test -test-load-source all -comments-xml-schema=%S/../../bindings/xml/comment-xml-schema.rng %s | FileCheck %s
+// rdar://12378879
+
+/**
+ * \param[in] arg1 ZZZ
+ * \param[out] d xxx
+*/
+void cfunction_availability(int arg1, double d) __attribute__((availability(macosx,obsoleted=10.0,introduced=8.0,deprecated=9.0, message="use availability_test")))
+                                                __attribute__((availability(ios,unavailable, message="not for iOS")));
+
+
+// CHECK: annotate-comments-availability-attrs.cpp:8:6: FunctionDecl=cfunction_availability:{{.*}} FullCommentAsXML=[<Function file="{{.*}}annotate-comments-availability-attrs.cpp" line="8" column="6"><Name>cfunction_availability</Name><USR>c:@F@cfunction_availability#I#d#</USR><Parameters><Parameter><Name>arg1</Name><Index>0</Index><Direction isExplicit="1">in</Direction><Discussion><Para> ZZZ </Para></Discussion></Parameter><Parameter><Name>d</Name><Index>1</Index><Direction isExplicit="1">out</Direction><Discussion><Para> xxx</Para></Discussion></Parameter></Parameters><Availability distribution="iOS"> <DeprecationSummary>not for iOS</DeprecationSummary><Unavailable>true</Unavailable></Availability><Availability distribution="OS X"><IntroducedInVersion>8.0</IntroducedInVersion><DeprecatedInVersion>9.0</DeprecatedInVersion><RemovedAfterVersion>10.0</RemovedAfterVersion> <DeprecationSummary>use availability_test</DeprecationSummary></Availability></Function>]
index 781523a..468e930 100644 (file)
@@ -10,10 +10,10 @@ void f5(int) __attribute__((availability(ios,introduced=3.2), availability(macos
 void test() {
   f0(0);
   f1(0);
-  f2(0); // expected-warning{{'f2' is deprecated: first deprecated in Mac OS X 10.5}}
+  f2(0); // expected-warning{{'f2' is deprecated: first deprecated in OS X 10.5}}
   f3(0);
-  f4(0); // expected-error{{f4' is unavailable: obsoleted in Mac OS X 10.5}}
-  f5(0); // expected-error{{'f5' is unavailable: not available on Mac OS X}}
+  f4(0); // expected-error{{f4' is unavailable: obsoleted in OS X 10.5}}
+  f5(0); // expected-error{{'f5' is unavailable: not available on OS X}}
 }
 
 // rdar://10535640
index b4a6f96..e0c541e 100644 (file)
@@ -1,6 +1,6 @@
 // RUN: %clang_cc1 -triple x86_64-apple-darwin9 -fsyntax-only -verify %s
 
-void f0() __attribute__((availability(macosx,introduced=10.4,deprecated=10.2))); // expected-warning{{feature cannot be deprecated in Mac OS X version 10.2 before it was introduced in version 10.4; attribute ignored}}
+void f0() __attribute__((availability(macosx,introduced=10.4,deprecated=10.2))); // expected-warning{{feature cannot be deprecated in OS X version 10.2 before it was introduced in version 10.4; attribute ignored}}
 void f1() __attribute__((availability(ios,obsoleted=2.1,deprecated=3.0)));  // expected-warning{{feature cannot be obsoleted in iOS version 2.1 before it was deprecated in version 3.0; attribute ignored}}
 void f2() __attribute__((availability(ios,introduced=2.1,deprecated=2.1)));
 
@@ -14,8 +14,8 @@ extern void
 ATSFontGetPostScriptName(int flags) __attribute__((availability(macosx,introduced=8.0,obsoleted=9.0, message="use ATSFontGetFullPostScriptName"))); // expected-note {{function has been explicitly marked unavailable here}}
 
 void test_10095131() {
-  ATSFontGetName("Hello"); // expected-warning {{'ATSFontGetName' is deprecated: first deprecated in Mac OS X 9.0 - use CTFontCopyFullName}}
-  ATSFontGetPostScriptName(100); // expected-error {{'ATSFontGetPostScriptName' is unavailable: obsoleted in Mac OS X 9.0 - use ATSFontGetFullPostScriptName}}
+  ATSFontGetName("Hello"); // expected-warning {{'ATSFontGetName' is deprecated: first deprecated in OS X 9.0 - use CTFontCopyFullName}}
+  ATSFontGetPostScriptName(100); // expected-error {{'ATSFontGetPostScriptName' is unavailable: obsoleted in OS X 9.0 - use ATSFontGetFullPostScriptName}}
 }
 
 // rdar://10711037
index 7c9ff0f..ed6b760 100644 (file)
@@ -14,8 +14,8 @@
 @end
 
 void f(A *a, B *b) {
-  [a method]; // expected-warning{{'method' is deprecated: first deprecated in Mac OS X 10.2}}
-  [b method]; // expected-warning {{'method' is deprecated: first deprecated in Mac OS X 10.2}}
-  [a proto_method]; // expected-warning{{'proto_method' is deprecated: first deprecated in Mac OS X 10.2}}
-  [b proto_method]; // expected-warning{{'proto_method' is deprecated: first deprecated in Mac OS X 10.2}}
+  [a method]; // expected-warning{{'method' is deprecated: first deprecated in OS X 10.2}}
+  [b method]; // expected-warning {{'method' is deprecated: first deprecated in OS X 10.2}}
+  [a proto_method]; // expected-warning{{'proto_method' is deprecated: first deprecated in OS X 10.2}}
+  [b proto_method]; // expected-warning{{'proto_method' is deprecated: first deprecated in OS X 10.2}}
 }
index a132a0d..1e0679f 100644 (file)
@@ -1173,59 +1173,53 @@ void CommentASTToXMLConverter::visitFullComment(const FullComment *C) {
   
   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++]);
+    for (unsigned i = 0, e = Attrs.size(); i != e; i++) {
+      const AvailabilityAttr *AA = dyn_cast<AvailabilityAttr>(Attrs[i]);
       if (!AA)
         continue;
-      // availability attribute info.
-  
+
+      // 'availability' attribute.
       Result << "<Availability";
-      StringRef distribution;
+      StringRef Distribution;
       if (AA->getPlatform()) {
-        distribution = AA->getPlatform()->getName();
-        if (distribution == "macosx")
-          distribution = "OSX";
-        else
-          distribution = "iOS";
+        Distribution = AvailabilityAttr::getPrettyPlatformName(
+                                        AA->getPlatform()->getName());
+        if (Distribution.empty())
+          Distribution = AA->getPlatform()->getName();
       }
-      
-      Result << " distribution=\"";
-      Result << distribution;
-      Result << "\">";
+      Result << " distribution=\"" << Distribution << "\">";
       VersionTuple IntroducedInVersion = AA->getIntroduced();
       if (!IntroducedInVersion.empty()) {
-        Result << " <IntroducedInVersion>";
-        Result << IntroducedInVersion.getAsString();
-        Result << "</IntroducedInVersion>";
+        Result << "<IntroducedInVersion>"
+               << IntroducedInVersion.getAsString()
+               << "</IntroducedInVersion>";
       }
       VersionTuple DeprecatedInVersion = AA->getDeprecated();
       if (!DeprecatedInVersion.empty()) {
-        Result << " <DeprecatedInVersion>";
-        Result << DeprecatedInVersion.getAsString();
-        Result << "</DeprecatedInVersion>";
+        Result << "<DeprecatedInVersion>"
+               << DeprecatedInVersion.getAsString()
+               << "</DeprecatedInVersion>";
       }
       VersionTuple RemovedAfterVersion = AA->getObsoleted();
       if (!RemovedAfterVersion.empty()) {
-        Result << " <RemovedAfterVersion>";
-        Result << RemovedAfterVersion.getAsString();
-        Result << "</RemovedAfterVersion>";
+        Result << "<RemovedAfterVersion>"
+               << RemovedAfterVersion.getAsString()
+               << "</RemovedAfterVersion>";
       }
+      // 'deprecated' attribute.
       StringRef DeprecationSummary = AA->getMessage();
       if (!DeprecationSummary.empty()) {
-        Result << " <DeprecationSummary>";
-        Result << DeprecationSummary;
-        Result << "</DeprecationSummary>";
+        Result << " <DeprecationSummary>"
+               << DeprecationSummary
+               << "</DeprecationSummary>";
       }
-      Result << " <Unavailable>";
+      // 'unavailable' attribute.
       if (AA->getUnavailable())
-        Result << "true";
-      else
-        Result << "false";
-      Result << "</Unavailable>";
-      Result << " </Availability>";
+        Result << "<Unavailable>true</Unavailable>";
+      Result << "</Availability>";
     }
   }
-  
+
   {
     bool StartTagEmitted = false;
     for (unsigned i = 0, e = Parts.MiscBlocks.size(); i != e; ++i) {