From 61b1db16292a3e60c03a24e58989c2317d4dcf40 Mon Sep 17 00:00:00 2001 From: Dmitri Gribenko Date: Wed, 3 Oct 2012 09:04:56 +0000 Subject: [PATCH] Comment to XML conversion: escape XML special chars correctly; use correct regex for version tuples. llvm-svn: 165104 --- clang/bindings/xml/comment-xml-schema.rng | 100 +++++++++++---------- .../CommentXML/valid-availability-attr-02.xml | 11 +++ .../Index/annotate-comments-availability-attrs.cpp | 51 +++++++---- clang/test/Index/comment-xml-schema.c | 1 + clang/tools/libclang/CXComment.cpp | 20 ++--- 5 files changed, 106 insertions(+), 77 deletions(-) create mode 100644 clang/test/Index/Inputs/CommentXML/valid-availability-attr-02.xml diff --git a/clang/bindings/xml/comment-xml-schema.rng b/clang/bindings/xml/comment-xml-schema.rng index 9cf9c3c..af1a3d8 100644 --- a/clang/bindings/xml/comment-xml-schema.rng +++ b/clang/bindings/xml/comment-xml-schema.rng @@ -293,53 +293,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -425,6 +378,59 @@ + + + + + + + + + \d+|\d+\.\d+|\d+\.\d+.\d+ + + + + + + + \d+|\d+\.\d+|\d+\.\d+.\d+ + + + + + + + \d+|\d+\.\d+|\d+\.\d+.\d+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 index 0000000..589262e --- /dev/null +++ b/clang/test/Index/Inputs/CommentXML/valid-availability-attr-02.xml @@ -0,0 +1,11 @@ + + +aaa +Aaa. + + 8.0.1 + 9.0.1 + 10.0.1 + use availability_test + + diff --git a/clang/test/Index/annotate-comments-availability-attrs.cpp b/clang/test/Index/annotate-comments-availability-attrs.cpp index 5a7e600..c596859 100644 --- a/clang/test/Index/annotate-comments-availability-attrs.cpp +++ b/clang/test/Index/annotate-comments-availability-attrs.cpp @@ -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=[cfunction_availabilityc:@F@cfunction_availability#I#d#arg10in ZZZ d1out xxx not for iOS8.09.010.0 use availability_test] +/// Aaa. +void attr_availability_1() __attribute__((availability(macosx,obsoleted=10.0,introduced=8.0,deprecated=9.0, message="use availability_test in "))) + __attribute__((availability(ios,unavailable, message="not for iOS"))); +// CHECK: annotate-comments-availability-attrs.cpp:13:6: FunctionDecl=attr_availability_1:{{.*}} FullCommentAsXML=[attr_availability_1c:@F@attr_availability_1# Aaa.not for iOS8.09.010.0use availability_test in <foo.h>] -/** - * \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=[depc:@F@dep#I#d#arg10in ZZZ d1out xxx +// CHECK: annotate-comments-availability-attrs.cpp:19:6: FunctionDecl=attr_availability_2:{{.*}} FullCommentAsXML=[attr_availability_2c:@F@attr_availability_2# Aaa.8.0.19.0.110.0.1] +/// 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=[attr_deprecated_1c:@F@attr_deprecated_1# Aaa.] + +/// Aaa. +void attr_deprecated_2() __attribute__((deprecated("message 1 "))); + +// CHECK: annotate-comments-availability-attrs.cpp:29:6: FunctionDecl=attr_deprecated_2:{{.*}} FullCommentAsXML=[attr_deprecated_2c:@F@attr_deprecated_2# Aaa.message 1 <foo.h>] + +/// Aaa. +void attr_unavailable_1() __attribute__((unavailable)); + +// CHECK: annotate-comments-availability-attrs.cpp:34:6: FunctionDecl=attr_unavailable_1:{{.*}} FullCommentAsXML=[attr_unavailable_1c:@F@attr_unavailable_1# Aaa.] + +/// Aaa. +void attr_unavailable_2() __attribute__((unavailable("message 2 "))); + +// CHECK: annotate-comments-availability-attrs.cpp:39:6: FunctionDecl=attr_unavailable_2:{{.*}} FullCommentAsXML=[attr_unavailable_2c:@F@attr_unavailable_2# Aaa.message 2 <foo.h>] -// CHECK: annotate-comments-availability-attrs.cpp:27:6: FunctionDecl=unv:{{.*}} FullCommentAsXML=[unvc:@F@unv#I#arg10in ZZZ diff --git a/clang/test/Index/comment-xml-schema.c b/clang/test/Index/comment-xml-schema.c index 7e7e331..91ea7b2 100644 --- a/clang/test/Index/comment-xml-schema.c +++ b/clang/test/Index/comment-xml-schema.c @@ -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 // diff --git a/clang/tools/libclang/CXComment.cpp b/clang/tools/libclang/CXComment.cpp index c0e5bc2..b0e190a 100644 --- a/clang/tools/libclang/CXComment.cpp +++ b/clang/tools/libclang/CXComment.cpp @@ -1180,18 +1180,18 @@ void CommentASTToXMLConverter::visitFullComment(const FullComment *C) { if (DA->getMessage().empty()) Result << ""; else { - Result << "" - << DA->getMessage() - << ""; + Result << ""; + appendToResultWithXMLEscaping(DA->getMessage()); + Result << ""; } } else if (const UnavailableAttr *UA = dyn_cast(Attrs[i])) { if (UA->getMessage().empty()) Result << ""; else { - Result << "" - << UA->getMessage() - << ""; + Result << ""; + appendToResultWithXMLEscaping(UA->getMessage()); + Result << ""; } } continue; @@ -1225,14 +1225,12 @@ void CommentASTToXMLConverter::visitFullComment(const FullComment *C) { << RemovedAfterVersion.getAsString() << ""; } - // 'deprecated' attribute. StringRef DeprecationSummary = AA->getMessage(); if (!DeprecationSummary.empty()) { - Result << " " - << DeprecationSummary - << ""; + Result << ""; + appendToResultWithXMLEscaping(DeprecationSummary); + Result << ""; } - // 'unavailable' attribute. if (AA->getUnavailable()) Result << ""; Result << ""; -- 2.7.4