xref: /llvm-project/clang/test/Index/annotate-comments-objc.m (revision b67d3702577d4a1848bce9be9887e554178a421a)
1// Run lines are sensitive to line numbers and come below the code.
2
3#ifndef HEADER
4#define HEADER
5
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_SINGLE
22@property (nonatomic, copy, readwrite) NSString *property1_isdoxy1;
23@property (nonatomic, copy, readwrite) NSString *property1_isdoxy2; ///< property1_isdoxy2 IS_DOXYGEN_SINGLE
24@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_SINGLE
28- (void)method1_isdoxy1;
29- (void)method1_isdoxy2; ///< method1_isdoxy2 IS_DOXYGEN_SINGLE
30- (void)method1_isdoxy3; /**< method1_isdoxy3 IS_DOXYGEN_SINGLE */
31- (void)method1_isdoxy4; /*!< method1_isdoxy4 IS_DOXYGEN_SINGLE */
32@end
33
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 : _type
39
40/// An_NS_ENUM_isdoxy1 IS_DOXYGEN_SINGLE
41typedef NS_ENUM(int, An_NS_ENUM_isdoxy1) { Red, Green, Blue };
42
43// In the implementation of attaching comments to enums declared using the
44// NS_ENUM macro, it is tempting to use the fact that enum decl is embedded in
45// the typedef.  Make sure that the heuristic is strong enough that it does not
46// attach unrelated comments in the following cases where tag decls are
47// 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_SINGLE
65DECLARE_FUNCTIONS
66
67/// typedef_isdoxy1 IS_DOXYGEN_SINGLE
68typedef 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 name
79struct Foo {
80  /// Vehicles IS_DOXYGEN_SINGLE
81  MYENUM(Vehicles) { Car, Motorbike, Boat} a;
82};
83
84#endif
85
86// RUN: rm -rf %t
87// RUN: mkdir %t
88// RUN: mkdir %t/module-cache
89
90// Check that we serialize comment source locations properly.
91// RUN: %clang_cc1 -emit-pch -o %t/out.pch -F %S/Inputs/Frameworks %s
92// RUN: %clang_cc1 -include-pch %t/out.pch -F %S/Inputs/Frameworks -fsyntax-only %s
93
94// RUN: c-index-test -write-pch %t/out.pch -F %S/Inputs/Frameworks %s
95// 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
96// 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
97// RUN: c-index-test -test-load-tu %t/out.pch all -F %S/Inputs/Frameworks > %t/out.c-index-pch
98
99// RUN: FileCheck %s -check-prefix=WRONG < %t/out.c-index-direct
100// RUN: FileCheck %s -check-prefix=WRONG < %t/out.c-index-modules
101// RUN: FileCheck %s -check-prefix=WRONG < %t/out.c-index-pch
102
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_DOXYGEN
109
110// Some Doxygen comments are not attached to anything.
111// WRONG-NOT: IS_DOXYGEN_NOT_ATTACHED
112
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 invalid
118// WRONG-NOT: CommentXMLInvalid
119
120// RUN: FileCheck %s < %t/out.c-index-direct
121// RUN: FileCheck %s < %t/out.c-index-modules
122// RUN: FileCheck %s < %t/out.c-index-pch
123
124// These CHECK lines are not located near the code on purpose.  This test
125// checks that documentation comments are attached to declarations correctly.
126// Adding a non-documentation comment with CHECK line between every two
127// 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_SINGLE
136// CHECK: annotate-comments-objc.m:23:50: ObjCPropertyDecl=property1_isdoxy2:{{.*}} property1_isdoxy2 IS_DOXYGEN_SINGLE
137// CHECK: annotate-comments-objc.m:24:50: ObjCPropertyDecl=property1_isdoxy3:{{.*}} property1_isdoxy3 IS_DOXYGEN_SINGLE
138// CHECK: annotate-comments-objc.m:25:50: ObjCPropertyDecl=property1_isdoxy4:{{.*}} property1_isdoxy4 IS_DOXYGEN_SINGLE
139// CHECK: annotate-comments-objc.m:28:9: ObjCInstanceMethodDecl=method1_isdoxy1:{{.*}} method1_isdoxy1 IS_DOXYGEN_SINGLE
140// CHECK: annotate-comments-objc.m:29:9: ObjCInstanceMethodDecl=method1_isdoxy2:{{.*}} method1_isdoxy2 IS_DOXYGEN_SINGLE
141// CHECK: annotate-comments-objc.m:30:9: ObjCInstanceMethodDecl=method1_isdoxy3:{{.*}} method1_isdoxy3 IS_DOXYGEN_SINGLE
142// CHECK: annotate-comments-objc.m:31:9: ObjCInstanceMethodDecl=method1_isdoxy4:{{.*}} method1_isdoxy4 IS_DOXYGEN_SINGLE
143// CHECK: annotate-comments-objc.m:41:22: EnumDecl=An_NS_ENUM_isdoxy1:{{.*}} An_NS_ENUM_isdoxy1 IS_DOXYGEN_SINGLE
144// CHECK: annotate-comments-objc.m:41:22: TypedefDecl=An_NS_ENUM_isdoxy1:{{.*}} An_NS_ENUM_isdoxy1 IS_DOXYGEN_SINGLE
145// CHECK: annotate-comments-objc.m:41:22: EnumDecl=An_NS_ENUM_isdoxy1:{{.*}} An_NS_ENUM_isdoxy1 IS_DOXYGEN_SINGLE
146// 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_SINGLE
150// 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_SINGLE
153