From 95759ff807498e79732669a2c2fa79c814342b9a Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Tue, 4 Dec 2012 00:47:33 +0000 Subject: [PATCH] Testing objective-C declarations embedded in tag of Comment XML and fixed a missing declaration of ivars private to @implementation as result of the testing. // rdar://12378714 llvm-svn: 169193 --- clang/lib/AST/DeclPrinter.cpp | 12 +- clang/test/Index/comment-objc-decls.m | 160 ++++++++++++++++++++++++++ 2 files changed, 171 insertions(+), 1 deletion(-) create mode 100644 clang/test/Index/comment-objc-decls.m diff --git a/clang/lib/AST/DeclPrinter.cpp b/clang/lib/AST/DeclPrinter.cpp index 83f38badd145..35bff1035ecf 100644 --- a/clang/lib/AST/DeclPrinter.cpp +++ b/clang/lib/AST/DeclPrinter.cpp @@ -893,7 +893,17 @@ void DeclPrinter::VisitObjCImplementationDecl(ObjCImplementationDecl *OID) { Out << "@implementation " << I << " : " << *SID; else Out << "@implementation " << I; - Out << "\n"; + + if (OID->ivar_size() > 0) { + Out << "{\n"; + Indentation += Policy.Indentation; + for (ObjCImplementationDecl::ivar_iterator I = OID->ivar_begin(), + E = OID->ivar_end(); I != E; ++I) { + Indent() << I->getType().getAsString(Policy) << ' ' << **I << ";\n"; + } + Indentation -= Policy.Indentation; + Out << "}\n"; + } VisitDeclContext(OID, false); Out << "@end"; } diff --git a/clang/test/Index/comment-objc-decls.m b/clang/test/Index/comment-objc-decls.m new file mode 100644 index 000000000000..ec989b2101ac --- /dev/null +++ b/clang/test/Index/comment-objc-decls.m @@ -0,0 +1,160 @@ +// 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 + +// rdar://12378714 + +/** + * \brief This is a protocol definition +*/ +@protocol MyProto +@optional +/** + * \brief MethodMyProto method + * \param[in] anObject input value + * \param[in] range output value is unsigned int + * \result return index + */ +- (unsigned int)MethodMyProto:(id)anObject inRange:(unsigned int)range; +/** + * \brief PropertyMyProto - This is protocol's property. +*/ +@property (copy) id PropertyMyProto; +/** + * \brief ClassMethodMyProto +*/ ++ ClassMethodMyProto; +@end +// CHECK: @protocol MyProto\n@end +// CHECK: - (unsigned int) MethodMyProto:(id)anObject inRange:(unsigned int)range +// CHECK: @optional\n@property ( readwrite,copy,atomic ) id PropertyMyProto +// CHECK: + (id) ClassMethodMyProto + +/** + * \brief NSObject is the root class. +*/ +@interface NSObject { +/** + * \brief IvarNSObject +*/ + id IvarNSObject; +} +@end +// CHECK: Declaration>@interface NSObject{\n id IvarNSObject;\n}\n@end +// CHECK: id IvarNSObject + +/** + * \brief MyClass - primary class. +*/ +@interface MyClass : NSObject +{ +/** + * \brief IvarMyClass - IvarMyClass of values. +*/ + id IvarMyClass; +} +/** + * \brief MethodMyClass is instance method. +*/ +- MethodMyClass; + +/** + * \brief ClassMethodMyClass is class method. +*/ ++ ClassMethodMyClass; + +/** + * \brief PropertyMyClass - This is class's property. +*/ +@property (copy) id PropertyMyClass; +@end +// CHECK: @interface MyClass : NSObject<MyProto> {\n id IvarMyClass;\n}\n@end +// CHECK: id IvarMyClass +// CHECK: - (id) MethodMyClass +// CHECK: + (id) ClassMethodMyClass +// CHECK: @property ( readwrite,copy,atomic ) id PropertyMyClass@interface MyClass(Category)\n@end +// CHECK: - (void) MethodMyClassCategory +// CHECK: @property ( readwrite,copy,atomic ) id PropertyMyClassCategory +// CHECK: - (id) PropertyMyClassCategory +// CHECK: - (void) setPropertyMyClassCategory:(id)arg + +/// @implementation's + +/** + * \brief implementation of MyClass class. +*/ +@implementation MyClass { +/** + * \brief IvarPrivateToMyClassImpl. +*/ + id IvarPrivateToMyClassImpl; +} +/** + * \brief MethodMyClass is instance method implementation. +*/ +- MethodMyClass { + return 0; +} + +/** + * \brief ClassMethodMyClass is class method implementation. +*/ ++ ClassMethodMyClass { + return 0; +} +@end +// CHECK: @implementation MyClass{\n id IvarPrivateToMyClassImpl;\n id _PropertyMyClass;\n}\n@end +// CHECK: id IvarPrivateToMyClassImpl +// CHECK: - (id) MethodMyClass +// CHECK: + (id) ClassMethodMyClass + +/** + * \brief MyClass (Category) is implementation of private to MyClass. +*/ +@implementation MyClass (Category) +/** + * \brief This is private to MyClass + */ +- (void)MethodMyClassCategory {} +/** + * \brief property getter +*/ +- (id) PropertyMyClassCategory { return 0; } + +/** + * \brief property setter +*/ +- (void) setPropertyMyClassCategory : (id) arg {} +@end +// CHECK: @implementation MyClass(Category)\n@end +// CHECK: - (void) MethodMyClassCategory +// CHECK: - (id) PropertyMyClassCategory +// CHECK: - (void) setPropertyMyClassCategory:(id)arg + +/** + * \brief NSObject implementation +*/ +@implementation NSObject +@end +// CHECK: @implementation NSObject@end