From 41170b55ba635afb806394d44f2b7f1f6095df37 Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Fri, 25 Jan 2013 22:48:32 +0000 Subject: [PATCH] Attach enum's documentation to its typedef if latter does not have one of its own. // rdar://13067629 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173516 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/ASTContext.cpp | 10 +++++++++ test/Index/annotate-comments-typedef.m | 30 ++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 test/Index/annotate-comments-typedef.m diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index 0b771745fd..b0cea14788 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -434,6 +434,16 @@ comments::FullComment *ASTContext::getCommentForDecl( } } } + else if (const TypedefDecl *TD = dyn_cast(D)) { + QualType QT = TD->getUnderlyingType(); + if (const EnumType *ET = QT->getAs()) { + if (const EnumDecl *ED = ET->getDecl()) + if (comments::FullComment *FC = getCommentForDecl(ED, PP)) { + comments::FullComment *CFC = cloneFullComment(FC, D); + return CFC; + } + } + } return NULL; } diff --git a/test/Index/annotate-comments-typedef.m b/test/Index/annotate-comments-typedef.m new file mode 100644 index 0000000000..0a87a7d8c3 --- /dev/null +++ b/test/Index/annotate-comments-typedef.m @@ -0,0 +1,30 @@ +// 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 +// rdar://13067629 + +// Ensure that XML we generate is not invalid. +// RUN: FileCheck %s -check-prefix=WRONG < %t/out +// WRONG-NOT: CommentXMLInvalid + +/** Documentation for NSUInteger */ +typedef unsigned int NSUInteger; + +/** Documentation for MyEnum */ +typedef enum : NSUInteger { + MyEnumFoo, /**< value Foo */ + MyEnumBar, /**< value Bar */ + MyEnumBaz, /**< value Baz */ +} MyEnum; +// CHECK: TypedefDecl=MyEnum:[[@LINE-1]]:3 (Definition) FullCommentAsHTML=[

Documentation for MyEnum

] FullCommentAsXML=[<anonymous>c:@EA@MyEnumtypedef enum MyEnum MyEnum Documentation for MyEnum ] CommentXMLValid + + +/** Documentation for E */ +enum E { + MyEnumFoo, /**< value Foo */ + MyEnumBar, /**< value Bar */ + MyEnumBaz, /**< value Baz */ +}; +typedef enum E E_T; +// CHECK: TypedefDecl=E_T:[[@LINE-1]]:16 (Definition) FullCommentAsHTML=[

Documentation for E

] FullCommentAsXML=[Ec:@E@Etypedef enum E E_T Documentation for E ] CommentXMLValid