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