1 // RUN: rm -rf %t
2 // RUN: split-file %s %t
3 // RUN: sed -e "s@INPUT_DIR@%/t@g" %t/reference.output.json.in >> \
4 // RUN: %t/reference.output.json
5 // RUN: %clang -extract-api --product-name=GlobalRecord -target arm64-apple-macosx \
6 // RUN: %t/input1.h %t/input2.h %t/input3.h -o %t/output.json | FileCheck -allow-empty %s
7 
8 // Generator version is not consistent across test runs, normalize it.
9 // RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
10 // RUN: %t/output.json >> %t/output-normalized.json
11 // RUN: diff %t/reference.output.json %t/output-normalized.json
12 
13 // CHECK-NOT: error:
14 // CHECK-NOT: warning:
15 
16 //--- input1.h
17 int num;
18 
19 //--- input2.h
20 /**
21  * \brief Add two numbers.
22  * \param [in]  x   A number.
23  * \param [in]  y   Another number.
24  * \param [out] res The result of x + y.
25  */
26 void add(const int x, const int y, int *res);
27 
28 //--- input3.h
29 char unavailable __attribute__((unavailable));
30 
31 //--- reference.output.json.in
32 {
33   "metadata": {
34     "formatVersion": {
35       "major": 0,
36       "minor": 5,
37       "patch": 3
38     },
39     "generator": "?"
40   },
41   "module": {
42     "name": "GlobalRecord",
43     "platform": {
44       "architecture": "arm64",
45       "operatingSystem": {
46         "minimumVersion": {
47           "major": 11,
48           "minor": 0,
49           "patch": 0
50         },
51         "name": "macosx"
52       },
53       "vendor": "apple"
54     }
55   },
56   "relationhips": [],
57   "symbols": [
58     {
59       "declarationFragments": [
60         {
61           "kind": "typeIdentifier",
62           "preciseIdentifier": "c:I",
63           "spelling": "int"
64         },
65         {
66           "kind": "text",
67           "spelling": " "
68         },
69         {
70           "kind": "identifier",
71           "spelling": "num"
72         }
73       ],
74       "identifier": {
75         "interfaceLanguage": "c",
76         "precise": "c:@num"
77       },
78       "kind": {
79         "displayName": "Global Variable",
80         "identifier": "c.var"
81       },
82       "location": {
83         "character": 5,
84         "line": 1,
85         "uri": "file://INPUT_DIR/input1.h"
86       },
87       "names": {
88         "subHeading": [
89           {
90             "kind": "identifier",
91             "spelling": "num"
92           }
93         ],
94         "title": "num"
95       }
96     },
97     {
98       "declarationFragments": [
99         {
100           "kind": "typeIdentifier",
101           "preciseIdentifier": "c:v",
102           "spelling": "void"
103         },
104         {
105           "kind": "text",
106           "spelling": " "
107         },
108         {
109           "kind": "identifier",
110           "spelling": "add"
111         },
112         {
113           "kind": "text",
114           "spelling": "("
115         },
116         {
117           "kind": "keyword",
118           "spelling": "const"
119         },
120         {
121           "kind": "text",
122           "spelling": " "
123         },
124         {
125           "kind": "typeIdentifier",
126           "preciseIdentifier": "c:I",
127           "spelling": "int"
128         },
129         {
130           "kind": "text",
131           "spelling": " "
132         },
133         {
134           "kind": "internalParam",
135           "spelling": "x"
136         },
137         {
138           "kind": "text",
139           "spelling": ", "
140         },
141         {
142           "kind": "keyword",
143           "spelling": "const"
144         },
145         {
146           "kind": "text",
147           "spelling": " "
148         },
149         {
150           "kind": "typeIdentifier",
151           "preciseIdentifier": "c:I",
152           "spelling": "int"
153         },
154         {
155           "kind": "text",
156           "spelling": " "
157         },
158         {
159           "kind": "internalParam",
160           "spelling": "y"
161         },
162         {
163           "kind": "text",
164           "spelling": ", "
165         },
166         {
167           "kind": "typeIdentifier",
168           "preciseIdentifier": "c:I",
169           "spelling": "int"
170         },
171         {
172           "kind": "text",
173           "spelling": " *"
174         },
175         {
176           "kind": "internalParam",
177           "spelling": "res"
178         },
179         {
180           "kind": "text",
181           "spelling": ")"
182         }
183       ],
184       "docComment": {
185         "lines": [
186           {
187             "range": {
188               "end": {
189                 "character": 4,
190                 "line": 1
191               },
192               "start": {
193                 "character": 4,
194                 "line": 1
195               }
196             },
197             "text": ""
198           },
199           {
200             "range": {
201               "end": {
202                 "character": 27,
203                 "line": 2
204               },
205               "start": {
206                 "character": 3,
207                 "line": 2
208               }
209             },
210             "text": " \\brief Add two numbers."
211           },
212           {
213             "range": {
214               "end": {
215                 "character": 30,
216                 "line": 3
217               },
218               "start": {
219                 "character": 3,
220                 "line": 3
221               }
222             },
223             "text": " \\param [in]  x   A number."
224           },
225           {
226             "range": {
227               "end": {
228                 "character": 36,
229                 "line": 4
230               },
231               "start": {
232                 "character": 3,
233                 "line": 4
234               }
235             },
236             "text": " \\param [in]  y   Another number."
237           },
238           {
239             "range": {
240               "end": {
241                 "character": 41,
242                 "line": 5
243               },
244               "start": {
245                 "character": 3,
246                 "line": 5
247               }
248             },
249             "text": " \\param [out] res The result of x + y."
250           },
251           {
252             "range": {
253               "end": {
254                 "character": 4,
255                 "line": 6
256               },
257               "start": {
258                 "character": 1,
259                 "line": 6
260               }
261             },
262             "text": " "
263           }
264         ]
265       },
266       "identifier": {
267         "interfaceLanguage": "c",
268         "precise": "c:@F@add"
269       },
270       "kind": {
271         "displayName": "Function",
272         "identifier": "c.func"
273       },
274       "location": {
275         "character": 6,
276         "line": 7,
277         "uri": "file://INPUT_DIR/input2.h"
278       },
279       "names": {
280         "subHeading": [
281           {
282             "kind": "identifier",
283             "spelling": "add"
284           }
285         ],
286         "title": "add"
287       },
288       "parameters": {
289         "parameters": [
290           {
291             "declarationFragments": [
292               {
293                 "kind": "keyword",
294                 "spelling": "const"
295               },
296               {
297                 "kind": "text",
298                 "spelling": " "
299               },
300               {
301                 "kind": "typeIdentifier",
302                 "preciseIdentifier": "c:I",
303                 "spelling": "int"
304               },
305               {
306                 "kind": "text",
307                 "spelling": " "
308               },
309               {
310                 "kind": "internalParam",
311                 "spelling": "x"
312               }
313             ],
314             "name": "x"
315           },
316           {
317             "declarationFragments": [
318               {
319                 "kind": "keyword",
320                 "spelling": "const"
321               },
322               {
323                 "kind": "text",
324                 "spelling": " "
325               },
326               {
327                 "kind": "typeIdentifier",
328                 "preciseIdentifier": "c:I",
329                 "spelling": "int"
330               },
331               {
332                 "kind": "text",
333                 "spelling": " "
334               },
335               {
336                 "kind": "internalParam",
337                 "spelling": "y"
338               }
339             ],
340             "name": "y"
341           },
342           {
343             "declarationFragments": [
344               {
345                 "kind": "typeIdentifier",
346                 "preciseIdentifier": "c:I",
347                 "spelling": "int"
348               },
349               {
350                 "kind": "text",
351                 "spelling": " *"
352               },
353               {
354                 "kind": "internalParam",
355                 "spelling": "res"
356               }
357             ],
358             "name": "res"
359           }
360         ],
361         "returns": [
362           {
363             "kind": "typeIdentifier",
364             "preciseIdentifier": "c:v",
365             "spelling": "void"
366           }
367         ]
368       }
369     }
370   ]
371 }
372