xref: /llvm-project/clang/test/ExtractAPI/global_record.c (revision e05c1b46d0d3739cc48ad912dbe6e9affce05927)
1 // RUN: rm -rf %t
2 // RUN: split-file %s %t
3 // RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
4 // RUN: %t/reference.output.json.in >> %t/reference.output.json
5 // RUN: %clang -extract-api --pretty-sgf --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           "kind": "text",
74           "spelling": ";"
75         }
76       ],
77       "identifier": {
78         "interfaceLanguage": "c",
79         "precise": "c:@num"
80       },
81       "kind": {
82         "displayName": "Global Variable",
83         "identifier": "c.var"
84       },
85       "location": {
86         "position": {
87           "character": 4,
88           "line": 0
89         },
90         "uri": "file://INPUT_DIR/input.h"
91       },
92       "names": {
93         "navigator": [
94           {
95             "kind": "identifier",
96             "spelling": "num"
97           }
98         ],
99         "subHeading": [
100           {
101             "kind": "identifier",
102             "spelling": "num"
103           }
104         ],
105         "title": "num"
106       },
107       "pathComponents": [
108         "num"
109       ]
110     },
111     {
112       "accessLevel": "public",
113       "declarationFragments": [
114         {
115           "kind": "typeIdentifier",
116           "preciseIdentifier": "c:v",
117           "spelling": "void"
118         },
119         {
120           "kind": "text",
121           "spelling": " "
122         },
123         {
124           "kind": "identifier",
125           "spelling": "add"
126         },
127         {
128           "kind": "text",
129           "spelling": "("
130         },
131         {
132           "kind": "keyword",
133           "spelling": "const"
134         },
135         {
136           "kind": "text",
137           "spelling": " "
138         },
139         {
140           "kind": "typeIdentifier",
141           "preciseIdentifier": "c:I",
142           "spelling": "int"
143         },
144         {
145           "kind": "text",
146           "spelling": " "
147         },
148         {
149           "kind": "internalParam",
150           "spelling": "x"
151         },
152         {
153           "kind": "text",
154           "spelling": ", "
155         },
156         {
157           "kind": "keyword",
158           "spelling": "const"
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": "y"
176         },
177         {
178           "kind": "text",
179           "spelling": ", "
180         },
181         {
182           "kind": "typeIdentifier",
183           "preciseIdentifier": "c:I",
184           "spelling": "int"
185         },
186         {
187           "kind": "text",
188           "spelling": " * "
189         },
190         {
191           "kind": "internalParam",
192           "spelling": "res"
193         },
194         {
195           "kind": "text",
196           "spelling": ");"
197         }
198       ],
199       "docComment": {
200         "lines": [
201           {
202             "range": {
203               "end": {
204                 "character": 3,
205                 "line": 2
206               },
207               "start": {
208                 "character": 3,
209                 "line": 2
210               }
211             },
212             "text": ""
213           },
214           {
215             "range": {
216               "end": {
217                 "character": 26,
218                 "line": 3
219               },
220               "start": {
221                 "character": 2,
222                 "line": 3
223               }
224             },
225             "text": " \\brief Add two numbers."
226           },
227           {
228             "range": {
229               "end": {
230                 "character": 29,
231                 "line": 4
232               },
233               "start": {
234                 "character": 2,
235                 "line": 4
236               }
237             },
238             "text": " \\param [in]  x   A number."
239           },
240           {
241             "range": {
242               "end": {
243                 "character": 35,
244                 "line": 5
245               },
246               "start": {
247                 "character": 2,
248                 "line": 5
249               }
250             },
251             "text": " \\param [in]  y   Another number."
252           },
253           {
254             "range": {
255               "end": {
256                 "character": 40,
257                 "line": 6
258               },
259               "start": {
260                 "character": 2,
261                 "line": 6
262               }
263             },
264             "text": " \\param [out] res The result of x + y."
265           },
266           {
267             "range": {
268               "end": {
269                 "character": 3,
270                 "line": 7
271               },
272               "start": {
273                 "character": 0,
274                 "line": 7
275               }
276             },
277             "text": " "
278           }
279         ]
280       },
281       "functionSignature": {
282         "parameters": [
283           {
284             "declarationFragments": [
285               {
286                 "kind": "keyword",
287                 "spelling": "const"
288               },
289               {
290                 "kind": "text",
291                 "spelling": " "
292               },
293               {
294                 "kind": "typeIdentifier",
295                 "preciseIdentifier": "c:I",
296                 "spelling": "int"
297               },
298               {
299                 "kind": "text",
300                 "spelling": " "
301               },
302               {
303                 "kind": "internalParam",
304                 "spelling": "x"
305               }
306             ],
307             "name": "x"
308           },
309           {
310             "declarationFragments": [
311               {
312                 "kind": "keyword",
313                 "spelling": "const"
314               },
315               {
316                 "kind": "text",
317                 "spelling": " "
318               },
319               {
320                 "kind": "typeIdentifier",
321                 "preciseIdentifier": "c:I",
322                 "spelling": "int"
323               },
324               {
325                 "kind": "text",
326                 "spelling": " "
327               },
328               {
329                 "kind": "internalParam",
330                 "spelling": "y"
331               }
332             ],
333             "name": "y"
334           },
335           {
336             "declarationFragments": [
337               {
338                 "kind": "typeIdentifier",
339                 "preciseIdentifier": "c:I",
340                 "spelling": "int"
341               },
342               {
343                 "kind": "text",
344                 "spelling": " * "
345               },
346               {
347                 "kind": "internalParam",
348                 "spelling": "res"
349               }
350             ],
351             "name": "res"
352           }
353         ],
354         "returns": [
355           {
356             "kind": "typeIdentifier",
357             "preciseIdentifier": "c:v",
358             "spelling": "void"
359           }
360         ]
361       },
362       "identifier": {
363         "interfaceLanguage": "c",
364         "precise": "c:@F@add"
365       },
366       "kind": {
367         "displayName": "Function",
368         "identifier": "c.func"
369       },
370       "location": {
371         "position": {
372           "character": 5,
373           "line": 8
374         },
375         "uri": "file://INPUT_DIR/input.h"
376       },
377       "names": {
378         "navigator": [
379           {
380             "kind": "identifier",
381             "spelling": "add"
382           }
383         ],
384         "subHeading": [
385           {
386             "kind": "identifier",
387             "spelling": "add"
388           }
389         ],
390         "title": "add"
391       },
392       "pathComponents": [
393         "add"
394       ]
395     }
396   ]
397 }
398