153 lines · plain
1// Run lines are sensitive to line numbers and come below the code.2 3#ifndef HEADER4#define HEADER5 6/// Comment for 'functionBeforeImports'.7void functionBeforeImports(void);8 9#import <DocCommentsA/DocCommentsA.h>10#import <DocCommentsB/DocCommentsB.h>11 12@class NSString;13 14//===---15// Check that we attach comments to properties correctly.16//===---17 18@interface MyClass {19}20 21/// property1_isdoxy1 IS_DOXYGEN_SINGLE22@property (nonatomic, copy, readwrite) NSString *property1_isdoxy1;23@property (nonatomic, copy, readwrite) NSString *property1_isdoxy2; ///< property1_isdoxy2 IS_DOXYGEN_SINGLE24@property (nonatomic, copy, readwrite) NSString *property1_isdoxy3; /**< property1_isdoxy3 IS_DOXYGEN_SINGLE */25@property (nonatomic, copy, readwrite) NSString *property1_isdoxy4; /*!< property1_isdoxy4 IS_DOXYGEN_SINGLE */26 27/// method1_isdoxy1 IS_DOXYGEN_SINGLE28- (void)method1_isdoxy1;29- (void)method1_isdoxy2; ///< method1_isdoxy2 IS_DOXYGEN_SINGLE30- (void)method1_isdoxy3; /**< method1_isdoxy3 IS_DOXYGEN_SINGLE */31- (void)method1_isdoxy4; /*!< method1_isdoxy4 IS_DOXYGEN_SINGLE */32@end33 34//===---35// Check that we attach comments to enums declared using the NS_ENUM macro.36//===---37 38#define NS_ENUM(_type, _name) enum _name : _type _name; enum _name : _type39 40/// An_NS_ENUM_isdoxy1 IS_DOXYGEN_SINGLE41typedef NS_ENUM(int, An_NS_ENUM_isdoxy1) { Red, Green, Blue };42 43// In the implementation of attaching comments to enums declared using the44// NS_ENUM macro, it is tempting to use the fact that enum decl is embedded in45// the typedef. Make sure that the heuristic is strong enough that it does not46// attach unrelated comments in the following cases where tag decls are47// embedded in declarators.48 49#define DECLARE_FUNCTIONS_COMMENTS_IN_MACRO(suffix) \50 /** functionFromMacro IS_DOXYGEN_SINGLE */ \51 void functionFromMacro(void) { \52 typedef struct Struct_notdoxy Struct_notdoxy; \53 } \54 /** functionFromMacroWithSuffix IS_DOXYGEN_SINGLE */ \55 void functionFromMacro##suffix(void) { \56 typedef struct Struct_notdoxy Struct_notdoxy; \57 }58 59DECLARE_FUNCTIONS_COMMENTS_IN_MACRO(WithSuffix)60 61#define DECLARE_FUNCTIONS \62 void functionFromMacroWithCommentFromExpansionSite(void) { typedef struct Struct_notdoxy Struct_notdoxy; }63 64/// functionFromMacroWithCommentFromExpansionSite IS_DOXYGEN_SINGLE65DECLARE_FUNCTIONS66 67/// typedef_isdoxy1 IS_DOXYGEN_SINGLE68typedef struct Struct_notdoxy *typedef_isdoxy1;69 70#define DECLARE_ENUMS(name) \71 /** enumFromMacro IS_DOXYGEN_SINGLE */ \72 enum enumFromMacro { A }; \73 /** namedEnumFromMacro IS_DOXYGEN_SINGLE */ \74 enum name { B };75 76DECLARE_ENUMS(namedEnumFromMacro)77 78#define MYENUM(name) enum name79struct Foo {80 /// Vehicles IS_DOXYGEN_SINGLE81 MYENUM(Vehicles) { Car, Motorbike, Boat} a;82};83 84#endif85 86// RUN: rm -rf %t87// RUN: mkdir %t88// RUN: mkdir %t/module-cache89 90// Check that we serialize comment source locations properly.91// RUN: %clang_cc1 -emit-pch -o %t/out.pch -F %S/Inputs/Frameworks %s92// RUN: %clang_cc1 -include-pch %t/out.pch -F %S/Inputs/Frameworks -fsyntax-only %s93 94// RUN: c-index-test -write-pch %t/out.pch -F %S/Inputs/Frameworks %s95// RUN: c-index-test -test-load-source all -comments-xml-schema=%S/../../bindings/xml/comment-xml-schema.rng %s -F %S/Inputs/Frameworks > %t/out.c-index-direct96// RUN: c-index-test -test-load-source all -comments-xml-schema=%S/../../bindings/xml/comment-xml-schema.rng %s -F %S/Inputs/Frameworks -fmodules -fmodules-cache-path=%t/module-cache > %t/out.c-index-modules97// RUN: c-index-test -test-load-tu %t/out.pch all -F %S/Inputs/Frameworks > %t/out.c-index-pch98 99// RUN: FileCheck %s -check-prefix=WRONG < %t/out.c-index-direct100// RUN: FileCheck %s -check-prefix=WRONG < %t/out.c-index-modules101// RUN: FileCheck %s -check-prefix=WRONG < %t/out.c-index-pch102 103// Declarations without Doxygen comments should not pick up some Doxygen comments.104// WRONG-NOT: notdoxy{{.*}}Comment=105// WRONG-NOT: test{{.*}}Comment=106 107// Non-Doxygen comments should not be attached to anything.108// WRONG-NOT: NOT_DOXYGEN109 110// Some Doxygen comments are not attached to anything.111// WRONG-NOT: IS_DOXYGEN_NOT_ATTACHED112 113// Ensure we don't pick up extra comments.114// WRONG-NOT: IS_DOXYGEN_START{{.*}}IS_DOXYGEN_START{{.*}}BriefComment=115// WRONG-NOT: IS_DOXYGEN_END{{.*}}IS_DOXYGEN_END{{.*}}BriefComment=116//117// Ensure that XML is not invalid118// WRONG-NOT: CommentXMLInvalid119 120// RUN: FileCheck %s < %t/out.c-index-direct121// RUN: FileCheck %s < %t/out.c-index-modules122// RUN: FileCheck %s < %t/out.c-index-pch123 124// These CHECK lines are not located near the code on purpose. This test125// checks that documentation comments are attached to declarations correctly.126// Adding a non-documentation comment with CHECK line between every two127// documentation comments will only test a single code path.128//129// CHECK-DAG: annotate-comments-objc.m:7:6: FunctionDecl=functionBeforeImports:{{.*}} BriefComment=[Comment for 'functionBeforeImports'.]130// CHECK-DAG: DocCommentsA.h:2:6: FunctionDecl=functionFromDocCommentsA1:{{.*}} BriefComment=[Comment for 'functionFromDocCommentsA1'.]131// CHECK-DAG: DocCommentsA.h:7:6: FunctionDecl=functionFromDocCommentsA2:{{.*}} BriefComment=[Comment for 'functionFromDocCommentsA2'.]132// CHECK-DAG: DocCommentsB.h:2:6: FunctionDecl=functionFromDocCommentsB1:{{.*}} BriefComment=[Comment for 'functionFromDocCommentsB1'.]133// CHECK-DAG: DocCommentsB.h:7:6: FunctionDecl=functionFromDocCommentsB2:{{.*}} BriefComment=[Comment for 'functionFromDocCommentsB2'.]134// CHECK-DAG: DocCommentsC.h:2:6: FunctionDecl=functionFromDocCommentsC:{{.*}} BriefComment=[Comment for 'functionFromDocCommentsC'.]135// CHECK: annotate-comments-objc.m:22:50: ObjCPropertyDecl=property1_isdoxy1:{{.*}} property1_isdoxy1 IS_DOXYGEN_SINGLE136// CHECK: annotate-comments-objc.m:23:50: ObjCPropertyDecl=property1_isdoxy2:{{.*}} property1_isdoxy2 IS_DOXYGEN_SINGLE137// CHECK: annotate-comments-objc.m:24:50: ObjCPropertyDecl=property1_isdoxy3:{{.*}} property1_isdoxy3 IS_DOXYGEN_SINGLE138// CHECK: annotate-comments-objc.m:25:50: ObjCPropertyDecl=property1_isdoxy4:{{.*}} property1_isdoxy4 IS_DOXYGEN_SINGLE139// CHECK: annotate-comments-objc.m:28:9: ObjCInstanceMethodDecl=method1_isdoxy1:{{.*}} method1_isdoxy1 IS_DOXYGEN_SINGLE140// CHECK: annotate-comments-objc.m:29:9: ObjCInstanceMethodDecl=method1_isdoxy2:{{.*}} method1_isdoxy2 IS_DOXYGEN_SINGLE141// CHECK: annotate-comments-objc.m:30:9: ObjCInstanceMethodDecl=method1_isdoxy3:{{.*}} method1_isdoxy3 IS_DOXYGEN_SINGLE142// CHECK: annotate-comments-objc.m:31:9: ObjCInstanceMethodDecl=method1_isdoxy4:{{.*}} method1_isdoxy4 IS_DOXYGEN_SINGLE143// CHECK: annotate-comments-objc.m:41:22: EnumDecl=An_NS_ENUM_isdoxy1:{{.*}} An_NS_ENUM_isdoxy1 IS_DOXYGEN_SINGLE144// CHECK: annotate-comments-objc.m:41:22: TypedefDecl=An_NS_ENUM_isdoxy1:{{.*}} An_NS_ENUM_isdoxy1 IS_DOXYGEN_SINGLE145// CHECK: annotate-comments-objc.m:41:22: EnumDecl=An_NS_ENUM_isdoxy1:{{.*}} An_NS_ENUM_isdoxy1 IS_DOXYGEN_SINGLE146// CHECK: annotate-comments-objc.m:59:1: FunctionDecl=functionFromMacro:{{.*}} BriefComment=[functionFromMacro IS_DOXYGEN_SINGLE]147// CHECK: annotate-comments-objc.m:59:1: FunctionDecl=functionFromMacroWithSuffix:{{.*}} BriefComment=[functionFromMacroWithSuffix IS_DOXYGEN_SINGLE]148// CHECK: annotate-comments-objc.m:65:1: FunctionDecl=functionFromMacroWithCommentFromExpansionSite:{{.*}} BriefComment=[functionFromMacroWithCommentFromExpansionSite IS_DOXYGEN_SINGLE]149// CHECK: annotate-comments-objc.m:68:32: TypedefDecl=typedef_isdoxy1:{{.*}} typedef_isdoxy1 IS_DOXYGEN_SINGLE150// CHECK: annotate-comments-objc.m:76:1: EnumDecl=enumFromMacro:{{.*}} BriefComment=[enumFromMacro IS_DOXYGEN_SINGLE]151// CHECK: annotate-comments-objc.m:76:15: EnumDecl=namedEnumFromMacro:{{.*}} BriefComment=[namedEnumFromMacro IS_DOXYGEN_SINGLE]152// CHECK: annotate-comments-objc.m:81:10: EnumDecl=Vehicles:{{.*}} Vehicles IS_DOXYGEN_SINGLE153