Comment to XML conversion: escape XML special chars correctly; use correct
authorDmitri Gribenko <gribozavr@gmail.com>
Wed, 3 Oct 2012 09:04:56 +0000 (09:04 +0000)
committerDmitri Gribenko <gribozavr@gmail.com>
Wed, 3 Oct 2012 09:04:56 +0000 (09:04 +0000)
regex for version tuples.

llvm-svn: 165104

clang/bindings/xml/comment-xml-schema.rng
clang/test/Index/Inputs/CommentXML/valid-availability-attr-02.xml [new file with mode: 0644]
clang/test/Index/annotate-comments-availability-attrs.cpp
clang/test/Index/comment-xml-schema.c
clang/tools/libclang/CXComment.cpp

index 9cf9c3c..af1a3d8 100644 (file)
     </element>
   </define>
 
-  <define name="Availability">
-    <element name="Availability">
-      <attribute name="distribution">
-          <data type="string" />
-      </attribute>
-      <optional>
-        <element name="IntroducedInVersion">
-          <data type="float" />
-        </element>
-      </optional>
-      <optional>
-        <element name="DeprecatedInVersion">
-          <data type="float" />
-        </element>
-      </optional>
-      <optional>
-        <element name="RemovedAfterVersion">
-          <data type="float" />
-        </element>
-      </optional>
-      <optional>
-        <element name="DeprecationSummary">
-          <data type="string" />
-        </element>
-      </optional>
-      <optional>
-        <ref name="Unavailable" />
-      </optional>
-    </element>
-  </define>
-
-  <define name="Deprecated">
-    <element name="Deprecated">
-      <optional>
-        <data type="string" />
-      </optional>
-    </element>
-  </define>
-
-  <define name="Unavailable">
-    <element name="Unavailable">
-      <optional>
-        <data type="string" />
-      </optional>
-    </element>
-  </define>
-
   <define name="Abstract">
     <element name="Abstract">
       <zeroOrMore>
     </element>
   </define>
 
+  <define name="Availability">
+    <element name="Availability">
+      <attribute name="distribution">
+          <data type="string" />
+      </attribute>
+      <optional>
+        <element name="IntroducedInVersion">
+          <data type="string">
+            <param name="pattern">\d+|\d+\.\d+|\d+\.\d+.\d+</param>
+          </data>
+        </element>
+      </optional>
+      <optional>
+        <element name="DeprecatedInVersion">
+          <data type="string">
+            <param name="pattern">\d+|\d+\.\d+|\d+\.\d+.\d+</param>
+          </data>
+        </element>
+      </optional>
+      <optional>
+        <element name="RemovedAfterVersion">
+          <data type="string">
+            <param name="pattern">\d+|\d+\.\d+|\d+\.\d+.\d+</param>
+          </data>
+        </element>
+      </optional>
+      <optional>
+        <element name="DeprecationSummary">
+          <data type="string" />
+        </element>
+      </optional>
+      <optional>
+        <ref name="Unavailable" />
+      </optional>
+    </element>
+  </define>
+
+  <define name="Deprecated">
+    <element name="Deprecated">
+      <optional>
+        <data type="string" />
+      </optional>
+    </element>
+  </define>
+
+  <define name="Unavailable">
+    <element name="Unavailable">
+      <optional>
+        <data type="string" />
+      </optional>
+    </element>
+  </define>
+
   <define name="ResultDiscussion">
     <element name="ResultDiscussion">
       <zeroOrMore>
diff --git a/clang/test/Index/Inputs/CommentXML/valid-availability-attr-02.xml b/clang/test/Index/Inputs/CommentXML/valid-availability-attr-02.xml
new file mode 100644 (file)
index 0000000..589262e
--- /dev/null
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Function>
+<Name>aaa</Name>
+<Abstract><Para>Aaa.</Para></Abstract>
+<Availability distribution="OS X">
+  <IntroducedInVersion>8.0.1</IntroducedInVersion>
+  <DeprecatedInVersion>9.0.1</DeprecatedInVersion>
+  <RemovedAfterVersion>10.0.1</RemovedAfterVersion>
+  <DeprecationSummary>use availability_test</DeprecationSummary>
+</Availability>
+</Function>
index 5a7e600..c596859 100644 (file)
@@ -1,29 +1,42 @@
-// 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")));
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: c-index-test -test-load-source all -comments-xml-schema=%S/../../bindings/xml/comment-xml-schema.rng %s > %t/out
+// RUN: FileCheck %s < %t/out
 
+// Ensure that XML we generate is not invalid.
+// RUN: FileCheck %s -check-prefix=WRONG < %t/out
+// WRONG-NOT: CommentXMLInvalid
 
-// 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/></Availability><Availability distribution="OS X"><IntroducedInVersion>8.0</IntroducedInVersion><DeprecatedInVersion>9.0</DeprecatedInVersion><RemovedAfterVersion>10.0</RemovedAfterVersion> <DeprecationSummary>use availability_test</DeprecationSummary></Availability></Function>]
+/// Aaa.
+void attr_availability_1() __attribute__((availability(macosx,obsoleted=10.0,introduced=8.0,deprecated=9.0, message="use availability_test in <foo.h>")))
+                           __attribute__((availability(ios,unavailable, message="not for iOS")));
 
+// CHECK: annotate-comments-availability-attrs.cpp:13:6: FunctionDecl=attr_availability_1:{{.*}} FullCommentAsXML=[<Function file="{{[^"]+}}annotate-comments-availability-attrs.cpp" line="13" column="6"><Name>attr_availability_1</Name><USR>c:@F@attr_availability_1#</USR><Abstract><Para> Aaa.</Para></Abstract><Availability distribution="iOS"><DeprecationSummary>not for iOS</DeprecationSummary><Unavailable/></Availability><Availability distribution="OS X"><IntroducedInVersion>8.0</IntroducedInVersion><DeprecatedInVersion>9.0</DeprecatedInVersion><RemovedAfterVersion>10.0</RemovedAfterVersion><DeprecationSummary>use availability_test in &lt;foo.h&gt;</DeprecationSummary></Availability></Function>]
 
-/**
- * \param[in] arg1 ZZZ
- * \param[out] d xxx
- */
-void dep(int arg1, double d) __attribute__((deprecated));
+/// Aaa.
+void attr_availability_2() __attribute__((availability(macosx,obsoleted=10.0.1,introduced=8.0.1,deprecated=9.0.1)));
 
-// CHECK: annotate-comments-availability-attrs.cpp:19:6: FunctionDecl=dep:{{.*}} FullCommentAsXML=[<Function file="{{.*}}annotate-comments-availability-attrs.cpp" line="19" column="6"><Name>dep</Name><USR>c:@F@dep#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><Deprecated/></Function>
+// CHECK: annotate-comments-availability-attrs.cpp:19:6: FunctionDecl=attr_availability_2:{{.*}} FullCommentAsXML=[<Function file="{{[^"]+}}annotate-comments-availability-attrs.cpp" line="19" column="6"><Name>attr_availability_2</Name><USR>c:@F@attr_availability_2#</USR><Abstract><Para> Aaa.</Para></Abstract><Availability distribution="OS X"><IntroducedInVersion>8.0.1</IntroducedInVersion><DeprecatedInVersion>9.0.1</DeprecatedInVersion><RemovedAfterVersion>10.0.1</RemovedAfterVersion></Availability></Function>]
 
+/// Aaa.
+void attr_deprecated_1() __attribute__((deprecated));
 
-/**
- * \param[in] arg1 ZZZ
- */
-void unv(int arg1) __attribute__((unavailable));
+// CHECK: annotate-comments-availability-attrs.cpp:24:6: FunctionDecl=attr_deprecated_1:{{.*}} FullCommentAsXML=[<Function file="{{[^"]+}}annotate-comments-availability-attrs.cpp" line="24" column="6"><Name>attr_deprecated_1</Name><USR>c:@F@attr_deprecated_1#</USR><Abstract><Para> Aaa.</Para></Abstract><Deprecated/></Function>]
+
+/// Aaa.
+void attr_deprecated_2() __attribute__((deprecated("message 1 <foo.h>")));
+
+// CHECK: annotate-comments-availability-attrs.cpp:29:6: FunctionDecl=attr_deprecated_2:{{.*}} FullCommentAsXML=[<Function file="{{[^"]+}}annotate-comments-availability-attrs.cpp" line="29" column="6"><Name>attr_deprecated_2</Name><USR>c:@F@attr_deprecated_2#</USR><Abstract><Para> Aaa.</Para></Abstract><Deprecated>message 1 &lt;foo.h&gt;</Deprecated></Function>]
+
+/// Aaa.
+void attr_unavailable_1() __attribute__((unavailable));
+
+// CHECK: annotate-comments-availability-attrs.cpp:34:6: FunctionDecl=attr_unavailable_1:{{.*}} FullCommentAsXML=[<Function file="{{[^"]+}}annotate-comments-availability-attrs.cpp" line="34" column="6"><Name>attr_unavailable_1</Name><USR>c:@F@attr_unavailable_1#</USR><Abstract><Para> Aaa.</Para></Abstract><Unavailable/></Function>]
+
+/// Aaa.
+void attr_unavailable_2() __attribute__((unavailable("message 2 <foo.h>")));
+
+// CHECK: annotate-comments-availability-attrs.cpp:39:6: FunctionDecl=attr_unavailable_2:{{.*}} FullCommentAsXML=[<Function file="{{[^"]+}}annotate-comments-availability-attrs.cpp" line="39" column="6"><Name>attr_unavailable_2</Name><USR>c:@F@attr_unavailable_2#</USR><Abstract><Para> Aaa.</Para></Abstract><Unavailable>message 2 &lt;foo.h&gt;</Unavailable></Function>]
 
-// CHECK: annotate-comments-availability-attrs.cpp:27:6: FunctionDecl=unv:{{.*}} FullCommentAsXML=[<Function file="{{.*}}annotate-comments-availability-attrs.cpp" line="27" column="6"><Name>unv</Name><USR>c:@F@unv#I#</USR><Parameters><Parameter><Name>arg1</Name><Index>0</Index><Direction isExplicit="1">in</Direction><Discussion><Para> ZZZ </Para></Discussion></Parameter></Parameters><Unavailable/></Function>
index 7e7e331..91ea7b2 100644 (file)
@@ -13,6 +13,7 @@
 // RUN: xmllint --noout --relaxng %S/../../bindings/xml/comment-xml-schema.rng %S/Inputs/CommentXML/valid-function-09.xml
 //
 // RUN: xmllint --noout --relaxng %S/../../bindings/xml/comment-xml-schema.rng %S/Inputs/CommentXML/valid-availability-attr-01.xml
+// RUN: xmllint --noout --relaxng %S/../../bindings/xml/comment-xml-schema.rng %S/Inputs/CommentXML/valid-availability-attr-02.xml
 // RUN: xmllint --noout --relaxng %S/../../bindings/xml/comment-xml-schema.rng %S/Inputs/CommentXML/valid-deprecated-attr.xml
 // RUN: xmllint --noout --relaxng %S/../../bindings/xml/comment-xml-schema.rng %S/Inputs/CommentXML/valid-unavailable-attr.xml
 //
index c0e5bc2..b0e190a 100644 (file)
@@ -1180,18 +1180,18 @@ void CommentASTToXMLConverter::visitFullComment(const FullComment *C) {
           if (DA->getMessage().empty())
             Result << "<Deprecated/>";
           else {
-            Result << "<Deprecated>"
-                   << DA->getMessage()
-                   << "</Deprecated>";
+            Result << "<Deprecated>";
+            appendToResultWithXMLEscaping(DA->getMessage());
+            Result << "</Deprecated>";
           }
         }
         else if (const UnavailableAttr *UA = dyn_cast<UnavailableAttr>(Attrs[i])) {
           if (UA->getMessage().empty())
             Result << "<Unavailable/>";
           else {
-            Result << "<Unavailable>"
-                   << UA->getMessage()
-                   << "</Unavailable>";
+            Result << "<Unavailable>";
+            appendToResultWithXMLEscaping(UA->getMessage());
+            Result << "</Unavailable>";
           }
         }
         continue;
@@ -1225,14 +1225,12 @@ void CommentASTToXMLConverter::visitFullComment(const FullComment *C) {
                << RemovedAfterVersion.getAsString()
                << "</RemovedAfterVersion>";
       }
-      // 'deprecated' attribute.
       StringRef DeprecationSummary = AA->getMessage();
       if (!DeprecationSummary.empty()) {
-        Result << " <DeprecationSummary>"
-               << DeprecationSummary
-               << "</DeprecationSummary>";
+        Result << "<DeprecationSummary>";
+        appendToResultWithXMLEscaping(DeprecationSummary);
+        Result << "</DeprecationSummary>";
       }
-      // 'unavailable' attribute.
       if (AA->getUnavailable())
         Result << "<Unavailable/>";
       Result << "</Availability>";