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