xref: /aosp_15_r20/external/clang/test/Index/annotate-comments-objc.m (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li// Run lines are sensitive to line numbers and come below the code.
2*67e74705SXin Li
3*67e74705SXin Li#ifndef HEADER
4*67e74705SXin Li#define HEADER
5*67e74705SXin Li
6*67e74705SXin Li/// Comment for 'functionBeforeImports'.
7*67e74705SXin Livoid functionBeforeImports(void);
8*67e74705SXin Li
9*67e74705SXin Li#import <DocCommentsA/DocCommentsA.h>
10*67e74705SXin Li#import <DocCommentsB/DocCommentsB.h>
11*67e74705SXin Li
12*67e74705SXin Li@class NSString;
13*67e74705SXin Li
14*67e74705SXin Li//===---
15*67e74705SXin Li// rdar://14258334
16*67e74705SXin Li// Check that we attach comments to properties correctly.
17*67e74705SXin Li//===---
18*67e74705SXin Li
19*67e74705SXin Li@interface MyClass {
20*67e74705SXin Li}
21*67e74705SXin Li
22*67e74705SXin Li/// property1_isdoxy1 IS_DOXYGEN_SINGLE
23*67e74705SXin Li@property (nonatomic, copy, readwrite) NSString *property1_isdoxy1;
24*67e74705SXin Li@property (nonatomic, copy, readwrite) NSString *property1_isdoxy2; ///< property1_isdoxy2 IS_DOXYGEN_SINGLE
25*67e74705SXin Li@property (nonatomic, copy, readwrite) NSString *property1_isdoxy3; /**< property1_isdoxy3 IS_DOXYGEN_SINGLE */
26*67e74705SXin Li@property (nonatomic, copy, readwrite) NSString *property1_isdoxy4; /*!< property1_isdoxy4 IS_DOXYGEN_SINGLE */
27*67e74705SXin Li
28*67e74705SXin Li/// method1_isdoxy1 IS_DOXYGEN_SINGLE
29*67e74705SXin Li- (void)method1_isdoxy1;
30*67e74705SXin Li- (void)method1_isdoxy2; ///< method1_isdoxy2 IS_DOXYGEN_SINGLE
31*67e74705SXin Li- (void)method1_isdoxy3; /**< method1_isdoxy3 IS_DOXYGEN_SINGLE */
32*67e74705SXin Li- (void)method1_isdoxy4; /*!< method1_isdoxy4 IS_DOXYGEN_SINGLE */
33*67e74705SXin Li@end
34*67e74705SXin Li
35*67e74705SXin Li//===---
36*67e74705SXin Li// rdar://14348912
37*67e74705SXin Li// Check that we attach comments to enums declared using the NS_ENUM macro.
38*67e74705SXin Li//===---
39*67e74705SXin Li
40*67e74705SXin Li#define NS_ENUM(_type, _name) enum _name : _type _name; enum _name : _type
41*67e74705SXin Li
42*67e74705SXin Li/// An_NS_ENUM_isdoxy1 IS_DOXYGEN_SINGLE
43*67e74705SXin Litypedef NS_ENUM(int, An_NS_ENUM_isdoxy1) { Red, Green, Blue };
44*67e74705SXin Li
45*67e74705SXin Li// In the implementation of attaching comments to enums declared using the
46*67e74705SXin Li// NS_ENUM macro, it is tempting to use the fact that enum decl is embedded in
47*67e74705SXin Li// the typedef.  Make sure that the heuristic is strong enough that it does not
48*67e74705SXin Li// attach unrelated comments in the following cases where tag decls are
49*67e74705SXin Li// embedded in declarators.
50*67e74705SXin Li
51*67e74705SXin Li#define DECLARE_FUNCTION() \
52*67e74705SXin Li    void functionFromMacro() { \
53*67e74705SXin Li      typedef struct Struct_notdoxy Struct_notdoxy; \
54*67e74705SXin Li    }
55*67e74705SXin Li
56*67e74705SXin Li/// IS_DOXYGEN_NOT_ATTACHED
57*67e74705SXin LiDECLARE_FUNCTION()
58*67e74705SXin Li
59*67e74705SXin Li/// typedef_isdoxy1 IS_DOXYGEN_SINGLE
60*67e74705SXin Litypedef struct Struct_notdoxy *typedef_isdoxy1;
61*67e74705SXin Li
62*67e74705SXin Li#endif
63*67e74705SXin Li
64*67e74705SXin Li// RUN: rm -rf %t
65*67e74705SXin Li// RUN: mkdir %t
66*67e74705SXin Li// RUN: mkdir %t/module-cache
67*67e74705SXin Li
68*67e74705SXin Li// Check that we serialize comment source locations properly.
69*67e74705SXin Li// RUN: %clang_cc1 -emit-pch -o %t/out.pch -F %S/Inputs/Frameworks %s
70*67e74705SXin Li// RUN: %clang_cc1 -include-pch %t/out.pch -F %S/Inputs/Frameworks -fsyntax-only %s
71*67e74705SXin Li
72*67e74705SXin Li// RUN: c-index-test -write-pch %t/out.pch -F %S/Inputs/Frameworks %s
73*67e74705SXin Li// 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-direct
74*67e74705SXin Li// 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-modules
75*67e74705SXin Li// RUN: c-index-test -test-load-tu %t/out.pch all -F %S/Inputs/Frameworks > %t/out.c-index-pch
76*67e74705SXin Li
77*67e74705SXin Li// RUN: FileCheck %s -check-prefix=WRONG < %t/out.c-index-direct
78*67e74705SXin Li// RUN: FileCheck %s -check-prefix=WRONG < %t/out.c-index-modules
79*67e74705SXin Li// RUN: FileCheck %s -check-prefix=WRONG < %t/out.c-index-pch
80*67e74705SXin Li
81*67e74705SXin Li// Declarations without Doxygen comments should not pick up some Doxygen comments.
82*67e74705SXin Li// WRONG-NOT: notdoxy{{.*}}Comment=
83*67e74705SXin Li// WRONG-NOT: test{{.*}}Comment=
84*67e74705SXin Li
85*67e74705SXin Li// Non-Doxygen comments should not be attached to anything.
86*67e74705SXin Li// WRONG-NOT: NOT_DOXYGEN
87*67e74705SXin Li
88*67e74705SXin Li// Some Doxygen comments are not attached to anything.
89*67e74705SXin Li// WRONG-NOT: IS_DOXYGEN_NOT_ATTACHED
90*67e74705SXin Li
91*67e74705SXin Li// Ensure we don't pick up extra comments.
92*67e74705SXin Li// WRONG-NOT: IS_DOXYGEN_START{{.*}}IS_DOXYGEN_START{{.*}}BriefComment=
93*67e74705SXin Li// WRONG-NOT: IS_DOXYGEN_END{{.*}}IS_DOXYGEN_END{{.*}}BriefComment=
94*67e74705SXin Li//
95*67e74705SXin Li// Ensure that XML is not invalid
96*67e74705SXin Li// WRONG-NOT: CommentXMLInvalid
97*67e74705SXin Li
98*67e74705SXin Li// RUN: FileCheck %s < %t/out.c-index-direct
99*67e74705SXin Li// RUN: FileCheck %s < %t/out.c-index-modules
100*67e74705SXin Li// RUN: FileCheck %s < %t/out.c-index-pch
101*67e74705SXin Li
102*67e74705SXin Li// These CHECK lines are not located near the code on purpose.  This test
103*67e74705SXin Li// checks that documentation comments are attached to declarations correctly.
104*67e74705SXin Li// Adding a non-documentation comment with CHECK line between every two
105*67e74705SXin Li// documentation comments will only test a single code path.
106*67e74705SXin Li//
107*67e74705SXin Li// CHECK-DAG: annotate-comments-objc.m:7:6: FunctionDecl=functionBeforeImports:{{.*}} BriefComment=[Comment for 'functionBeforeImports'.]
108*67e74705SXin Li// CHECK-DAG: DocCommentsA.h:2:6: FunctionDecl=functionFromDocCommentsA1:{{.*}} BriefComment=[Comment for 'functionFromDocCommentsA1'.]
109*67e74705SXin Li// CHECK-DAG: DocCommentsA.h:7:6: FunctionDecl=functionFromDocCommentsA2:{{.*}} BriefComment=[Comment for 'functionFromDocCommentsA2'.]
110*67e74705SXin Li// CHECK-DAG: DocCommentsB.h:2:6: FunctionDecl=functionFromDocCommentsB1:{{.*}} BriefComment=[Comment for 'functionFromDocCommentsB1'.]
111*67e74705SXin Li// CHECK-DAG: DocCommentsB.h:7:6: FunctionDecl=functionFromDocCommentsB2:{{.*}} BriefComment=[Comment for 'functionFromDocCommentsB2'.]
112*67e74705SXin Li// CHECK-DAG: DocCommentsC.h:2:6: FunctionDecl=functionFromDocCommentsC:{{.*}} BriefComment=[Comment for 'functionFromDocCommentsC'.]
113*67e74705SXin Li// CHECK: annotate-comments-objc.m:23:50: ObjCPropertyDecl=property1_isdoxy1:{{.*}} property1_isdoxy1 IS_DOXYGEN_SINGLE
114*67e74705SXin Li// CHECK: annotate-comments-objc.m:24:50: ObjCPropertyDecl=property1_isdoxy2:{{.*}} property1_isdoxy2 IS_DOXYGEN_SINGLE
115*67e74705SXin Li// CHECK: annotate-comments-objc.m:25:50: ObjCPropertyDecl=property1_isdoxy3:{{.*}} property1_isdoxy3 IS_DOXYGEN_SINGLE
116*67e74705SXin Li// CHECK: annotate-comments-objc.m:26:50: ObjCPropertyDecl=property1_isdoxy4:{{.*}} property1_isdoxy4 IS_DOXYGEN_SINGLE
117*67e74705SXin Li// CHECK: annotate-comments-objc.m:29:9: ObjCInstanceMethodDecl=method1_isdoxy1:{{.*}} method1_isdoxy1 IS_DOXYGEN_SINGLE
118*67e74705SXin Li// CHECK: annotate-comments-objc.m:30:9: ObjCInstanceMethodDecl=method1_isdoxy2:{{.*}} method1_isdoxy2 IS_DOXYGEN_SINGLE
119*67e74705SXin Li// CHECK: annotate-comments-objc.m:31:9: ObjCInstanceMethodDecl=method1_isdoxy3:{{.*}} method1_isdoxy3 IS_DOXYGEN_SINGLE
120*67e74705SXin Li// CHECK: annotate-comments-objc.m:32:9: ObjCInstanceMethodDecl=method1_isdoxy4:{{.*}} method1_isdoxy4 IS_DOXYGEN_SINGLE
121*67e74705SXin Li// CHECK: annotate-comments-objc.m:43:22: EnumDecl=An_NS_ENUM_isdoxy1:{{.*}} An_NS_ENUM_isdoxy1 IS_DOXYGEN_SINGLE
122*67e74705SXin Li// CHECK: annotate-comments-objc.m:43:22: TypedefDecl=An_NS_ENUM_isdoxy1:{{.*}} An_NS_ENUM_isdoxy1 IS_DOXYGEN_SINGLE
123*67e74705SXin Li// CHECK: annotate-comments-objc.m:43:22: EnumDecl=An_NS_ENUM_isdoxy1:{{.*}} An_NS_ENUM_isdoxy1 IS_DOXYGEN_SINGLE
124*67e74705SXin Li// CHECK: annotate-comments-objc.m:60:32: TypedefDecl=typedef_isdoxy1:{{.*}} typedef_isdoxy1 IS_DOXYGEN_SINGLE
125*67e74705SXin Li
126