aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFariborz Jahanian <fjahanian@apple.com>2012-10-01 18:42:25 +0000
committerFariborz Jahanian <fjahanian@apple.com>2012-10-01 18:42:25 +0000
commitfaab5618b5beed350d7444de97cf513ef1a42ca6 (patch)
tree60fd3cc915265951e3e883a9b70f4a6a15a0f081
parent622b6fb0a1d280c16e135c7e427b79cafffbde1f (diff)
availability in structured documents. Takes
care of comments by Dimitri and Doug. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@164957 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--bindings/xml/comment-xml-schema.rng4
-rw-r--r--include/clang/Basic/Attr.td2
-rw-r--r--test/Index/Inputs/CommentXML/valid-availability-attr-01.xml7
-rw-r--r--test/Index/annotate-comments-availability-attrs.cpp12
-rw-r--r--test/Sema/attr-availability-macosx.c6
-rw-r--r--test/Sema/attr-availability.c6
-rw-r--r--test/SemaObjC/attr-availability.m8
-rw-r--r--tools/libclang/CXComment.cpp60
8 files changed, 59 insertions, 46 deletions
diff --git a/bindings/xml/comment-xml-schema.rng b/bindings/xml/comment-xml-schema.rng
index 8302d9d369..1a2eb16441 100644
--- a/bindings/xml/comment-xml-schema.rng
+++ b/bindings/xml/comment-xml-schema.rng
@@ -80,7 +80,7 @@
<ref name="Parameters" />
</optional>
<zeroOrMore>
- <ref name="Attribute" />
+ <ref name="Availability" />
</zeroOrMore>
<optional>
<ref name="ResultDiscussion" />
@@ -287,7 +287,7 @@
</element>
</define>
- <define name="Attribute">
+ <define name="Availability">
<element name="Availability">
<attribute name="distribution">
<data type="string" />
diff --git a/include/clang/Basic/Attr.td b/include/clang/Basic/Attr.td
index 7406ce2647..67ef8be8fb 100644
--- a/include/clang/Basic/Attr.td
+++ b/include/clang/Basic/Attr.td
@@ -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/test/Index/Inputs/CommentXML/valid-availability-attr-01.xml b/test/Index/Inputs/CommentXML/valid-availability-attr-01.xml
new file mode 100644
index 0000000000..94cbc9a00f
--- /dev/null
+++ b/test/Index/Inputs/CommentXML/valid-availability-attr-01.xml
@@ -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/test/Index/annotate-comments-availability-attrs.cpp b/test/Index/annotate-comments-availability-attrs.cpp
new file mode 100644
index 0000000000..6fb99a1b5c
--- /dev/null
+++ b/test/Index/annotate-comments-availability-attrs.cpp
@@ -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>]
diff --git a/test/Sema/attr-availability-macosx.c b/test/Sema/attr-availability-macosx.c
index 781523a2e0..468e9303e7 100644
--- a/test/Sema/attr-availability-macosx.c
+++ b/test/Sema/attr-availability-macosx.c
@@ -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
diff --git a/test/Sema/attr-availability.c b/test/Sema/attr-availability.c
index b4a6f9616d..e0c541e8d8 100644
--- a/test/Sema/attr-availability.c
+++ b/test/Sema/attr-availability.c
@@ -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
diff --git a/test/SemaObjC/attr-availability.m b/test/SemaObjC/attr-availability.m
index 7c9ff0f13d..ed6b7608b9 100644
--- a/test/SemaObjC/attr-availability.m
+++ b/test/SemaObjC/attr-availability.m
@@ -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}}
}
diff --git a/tools/libclang/CXComment.cpp b/tools/libclang/CXComment.cpp
index a132a0d1ba..1e0679f22a 100644
--- a/tools/libclang/CXComment.cpp
+++ b/tools/libclang/CXComment.cpp
@@ -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) {