On Thu, Mar 27, 2014 at 9:40 AM, Dmitri Gribenko <[email protected]>wrote:
> Author: gribozavr > Date: Thu Mar 27 11:40:51 2014 > New Revision: 204942 > > URL: http://llvm.org/viewvc/llvm-project?rev=204942&view=rev > Log: > Comment parsing: attach comments to enums declared using the NS_ENUM macro > > Previously we would only attach comments to the typedef. > > Modified: > cfe/trunk/lib/AST/ASTContext.cpp > cfe/trunk/test/Index/annotate-comments-objc.m > cfe/trunk/test/Index/comment-to-html-xml-conversion.cpp > > Modified: cfe/trunk/lib/AST/ASTContext.cpp > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=204942&r1=204941&r2=204942&view=diff > > ============================================================================== > --- cfe/trunk/lib/AST/ASTContext.cpp (original) > +++ cfe/trunk/lib/AST/ASTContext.cpp Thu Mar 27 11:40:51 2014 > @@ -145,11 +145,23 @@ RawComment *ASTContext::getRawCommentFor > DeclLoc = D->getLocStart(); > else { > DeclLoc = D->getLocation(); > - // If location of the typedef name is in a macro, it is because being > - // declared via a macro. Try using declaration's starting location > - // as the "declaration location". > - if (DeclLoc.isMacroID() && isa<TypedefDecl>(D)) > - DeclLoc = D->getLocStart(); > + if (DeclLoc.isMacroID()) { > + if (isa<TypedefDecl>(D)) { > Should this be TypedefNameDecl? (That also covers C++11 alias declarations, which are another syntax for typedefs.) > + // If location of the typedef name is in a macro, it is because > being > + // declared via a macro. Try using declaration's starting > location as > + // the "declaration location". > + DeclLoc = D->getLocStart(); > + } else if (const TagDecl *TD = dyn_cast<TagDecl>(D)) { > + // If location of the tag decl is inside a macro, but the > spelling of > + // the tag name comes from a macro argument, it looks like a > special > + // macro like NS_ENUM is being used to define the tag decl. In > that > + // case, adjust the source location to the expansion loc so that > we can > + // attach the comment to the tag decl. > + if (SourceMgr.isMacroArgExpansion(DeclLoc) && > + TD->isCompleteDefinition()) > + DeclLoc = SourceMgr.getExpansionLoc(DeclLoc); > + } > + } > } > > // If the declaration doesn't map directly to a location in a file, we > > Modified: cfe/trunk/test/Index/annotate-comments-objc.m > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/annotate-comments-objc.m?rev=204942&r1=204941&r2=204942&view=diff > > ============================================================================== > --- cfe/trunk/test/Index/annotate-comments-objc.m (original) > +++ cfe/trunk/test/Index/annotate-comments-objc.m Thu Mar 27 11:40:51 2014 > @@ -32,6 +32,32 @@ void functionBeforeImports(void); > - (void)method1_isdoxy4; /*!< method1_isdoxy4 IS_DOXYGEN_SINGLE */ > @end > > +//===--- > +// rdar://14348912 > +// Check that we attach comments to enums declared using the NS_ENUM > macro. > +//===--- > + > +#define NS_ENUM(_type, _name) enum _name : _type _name; enum _name : _type > + > +/// An_NS_ENUM_isdoxy1 IS_DOXYGEN_SINGLE > +typedef NS_ENUM(int, An_NS_ENUM_isdoxy1) { Red, Green, Blue }; > + > +// In the implementation of attaching comments to enums declared using the > +// NS_ENUM macro, it is tempting to use the fact that enum decl is > embedded in > +// the typedef. Make sure that the heuristic is strong enough that it > does not > +// attach unrelated comments in the following cases where tag decls are > +// embedded in declarators. > + > +#define DECLARE_FUNCTION() \ > + void functionFromMacro() { \ > + typedef struct Struct_notdoxy Struct_notdoxy; \ > + } > + > +/// IS_DOXYGEN_NOT_ATTACHED > +DECLARE_FUNCTION() > + > +/// typedef_isdoxy1 IS_DOXYGEN_SINGLE > +typedef struct Struct_notdoxy *typedef_isdoxy1; > > #endif > > @@ -91,4 +117,8 @@ void functionBeforeImports(void); > // CHECK: annotate-comments-objc.m:30:9: > ObjCInstanceMethodDecl=method1_isdoxy2:{{.*}} method1_isdoxy2 > IS_DOXYGEN_SINGLE > // CHECK: annotate-comments-objc.m:31:9: > ObjCInstanceMethodDecl=method1_isdoxy3:{{.*}} method1_isdoxy3 > IS_DOXYGEN_SINGLE > // CHECK: annotate-comments-objc.m:32:9: > ObjCInstanceMethodDecl=method1_isdoxy4:{{.*}} method1_isdoxy4 > IS_DOXYGEN_SINGLE > +// CHECK: annotate-comments-objc.m:43:22: > EnumDecl=An_NS_ENUM_isdoxy1:{{.*}} An_NS_ENUM_isdoxy1 IS_DOXYGEN_SINGLE > +// CHECK: annotate-comments-objc.m:43:22: > TypedefDecl=An_NS_ENUM_isdoxy1:{{.*}} An_NS_ENUM_isdoxy1 IS_DOXYGEN_SINGLE > +// CHECK: annotate-comments-objc.m:43:22: > EnumDecl=An_NS_ENUM_isdoxy1:{{.*}} An_NS_ENUM_isdoxy1 IS_DOXYGEN_SINGLE > +// CHECK: annotate-comments-objc.m:60:32: > TypedefDecl=typedef_isdoxy1:{{.*}} typedef_isdoxy1 IS_DOXYGEN_SINGLE > > > Modified: cfe/trunk/test/Index/comment-to-html-xml-conversion.cpp > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/comment-to-html-xml-conversion.cpp?rev=204942&r1=204941&r2=204942&view=diff > > ============================================================================== > --- cfe/trunk/test/Index/comment-to-html-xml-conversion.cpp (original) > +++ cfe/trunk/test/Index/comment-to-html-xml-conversion.cpp Thu Mar 27 > 11:40:51 2014 > @@ -1015,17 +1015,5 @@ void comment_to_xml_conversion_exception > // CHECK-NEXT: (CXComment_Paragraph > // CHECK-NEXT: (CXComment_Text Text=[ Ccc.]))))] > > - > -// rdar://14348912 > -#define NS_ENUM(_type, _name) enum _name : _type _name; enum _name : _type > - > -/**! Documentation comment */ > -typedef NS_ENUM(int, Color) { Red, Green, Blue }; > -// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-1]]:22: > TypedefDecl=Color:[[@LINE-1]]:22 > -// CHECK-NEXT: CommentAST=[ > -// CHECK-NEXT: (CXComment_FullComment > -// CHECK-NEXT: (CXComment_Paragraph > -// CHECK-NEXT: (CXComment_Text Text=[! Documentation comment ])))] > - > #endif > > > > _______________________________________________ > cfe-commits mailing list > [email protected] > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits >
_______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
