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_cc1 -extract-api -triple arm64-apple-macosx \
6 // RUN:   -x c-header %t/input.h -o %t/output.json -verify
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 //--- input.h
14 // expected-no-diagnostics
15 
16 // Global record
17 int _HiddenGlobal;
18 int exposed_global;
19 
20 // Record type
21 struct _HiddenRecord {
22   int a;
23 };
24 
25 struct ExposedRecord {
26   int a;
27 };
28 
29 // Typedef
30 typedef struct {} _HiddenTypedef;
31 typedef int ExposedTypedef;
32 typedef _HiddenTypedef ExposedTypedefToHidden;
33 
34 // Macros
35 #define _HIDDEN_MACRO 5
36 #define EXPOSED_MACRO 5
37 
38 // Symbols that start with '_' should not appear in the reference output
39 //--- reference.output.json.in
40 {
41   "metadata": {
42     "formatVersion": {
43       "major": 0,
44       "minor": 5,
45       "patch": 3
46     },
47     "generator": "?"
48   },
49   "module": {
50     "name": "",
51     "platform": {
52       "architecture": "arm64",
53       "operatingSystem": {
54         "minimumVersion": {
55           "major": 11,
56           "minor": 0,
57           "patch": 0
58         },
59         "name": "macosx"
60       },
61       "vendor": "apple"
62     }
63   },
64   "relationships": [
65     {
66       "kind": "memberOf",
67       "source": "c:@S@ExposedRecord@FI@a",
68       "target": "c:@S@ExposedRecord"
69     }
70   ],
71   "symbols": [
72     {
73       "accessLevel": "public",
74       "declarationFragments": [
75         {
76           "kind": "typeIdentifier",
77           "preciseIdentifier": "c:I",
78           "spelling": "int"
79         },
80         {
81           "kind": "text",
82           "spelling": " "
83         },
84         {
85           "kind": "identifier",
86           "spelling": "exposed_global"
87         }
88       ],
89       "identifier": {
90         "interfaceLanguage": "c",
91         "precise": "c:@exposed_global"
92       },
93       "kind": {
94         "displayName": "Global Variable",
95         "identifier": "c.var"
96       },
97       "location": {
98         "position": {
99           "character": 5,
100           "line": 5
101         },
102         "uri": "file://INPUT_DIR/input.h"
103       },
104       "names": {
105         "navigator": [
106           {
107             "kind": "identifier",
108             "spelling": "exposed_global"
109           }
110         ],
111         "subHeading": [
112           {
113             "kind": "identifier",
114             "spelling": "exposed_global"
115           }
116         ],
117         "title": "exposed_global"
118       },
119       "pathComponents": [
120         "exposed_global"
121       ]
122     },
123     {
124       "accessLevel": "public",
125       "declarationFragments": [
126         {
127           "kind": "keyword",
128           "spelling": "struct"
129         },
130         {
131           "kind": "text",
132           "spelling": " "
133         },
134         {
135           "kind": "identifier",
136           "spelling": "ExposedRecord"
137         }
138       ],
139       "identifier": {
140         "interfaceLanguage": "c",
141         "precise": "c:@S@ExposedRecord"
142       },
143       "kind": {
144         "displayName": "Structure",
145         "identifier": "c.struct"
146       },
147       "location": {
148         "position": {
149           "character": 8,
150           "line": 12
151         },
152         "uri": "file://INPUT_DIR/input.h"
153       },
154       "names": {
155         "navigator": [
156           {
157             "kind": "identifier",
158             "spelling": "ExposedRecord"
159           }
160         ],
161         "subHeading": [
162           {
163             "kind": "identifier",
164             "spelling": "ExposedRecord"
165           }
166         ],
167         "title": "ExposedRecord"
168       },
169       "pathComponents": [
170         "ExposedRecord"
171       ]
172     },
173     {
174       "accessLevel": "public",
175       "declarationFragments": [
176         {
177           "kind": "typeIdentifier",
178           "preciseIdentifier": "c:I",
179           "spelling": "int"
180         },
181         {
182           "kind": "text",
183           "spelling": " "
184         },
185         {
186           "kind": "identifier",
187           "spelling": "a"
188         }
189       ],
190       "identifier": {
191         "interfaceLanguage": "c",
192         "precise": "c:@S@ExposedRecord@FI@a"
193       },
194       "kind": {
195         "displayName": "Instance Property",
196         "identifier": "c.property"
197       },
198       "location": {
199         "position": {
200           "character": 7,
201           "line": 13
202         },
203         "uri": "file://INPUT_DIR/input.h"
204       },
205       "names": {
206         "navigator": [
207           {
208             "kind": "identifier",
209             "spelling": "a"
210           }
211         ],
212         "subHeading": [
213           {
214             "kind": "identifier",
215             "spelling": "a"
216           }
217         ],
218         "title": "a"
219       },
220       "pathComponents": [
221         "ExposedRecord",
222         "a"
223       ]
224     },
225     {
226       "accessLevel": "public",
227       "declarationFragments": [
228         {
229           "kind": "keyword",
230           "spelling": "#define"
231         },
232         {
233           "kind": "text",
234           "spelling": " "
235         },
236         {
237           "kind": "identifier",
238           "spelling": "EXPOSED_MACRO"
239         }
240       ],
241       "identifier": {
242         "interfaceLanguage": "c",
243         "precise": "c:input.h@335@macro@EXPOSED_MACRO"
244       },
245       "kind": {
246         "displayName": "Macro",
247         "identifier": "c.macro"
248       },
249       "location": {
250         "position": {
251           "character": 9,
252           "line": 23
253         },
254         "uri": "file://INPUT_DIR/input.h"
255       },
256       "names": {
257         "navigator": [
258           {
259             "kind": "identifier",
260             "spelling": "EXPOSED_MACRO"
261           }
262         ],
263         "subHeading": [
264           {
265             "kind": "identifier",
266             "spelling": "EXPOSED_MACRO"
267           }
268         ],
269         "title": "EXPOSED_MACRO"
270       },
271       "pathComponents": [
272         "EXPOSED_MACRO"
273       ]
274     },
275     {
276       "accessLevel": "public",
277       "declarationFragments": [
278         {
279           "kind": "keyword",
280           "spelling": "typedef"
281         },
282         {
283           "kind": "text",
284           "spelling": " "
285         },
286         {
287           "kind": "typeIdentifier",
288           "preciseIdentifier": "c:I",
289           "spelling": "int"
290         },
291         {
292           "kind": "text",
293           "spelling": " "
294         },
295         {
296           "kind": "identifier",
297           "spelling": "ExposedTypedef"
298         }
299       ],
300       "identifier": {
301         "interfaceLanguage": "c",
302         "precise": "c:input.h@T@ExposedTypedef"
303       },
304       "kind": {
305         "displayName": "Type Alias",
306         "identifier": "c.typealias"
307       },
308       "location": {
309         "position": {
310           "character": 13,
311           "line": 18
312         },
313         "uri": "file://INPUT_DIR/input.h"
314       },
315       "names": {
316         "navigator": [
317           {
318             "kind": "identifier",
319             "spelling": "ExposedTypedef"
320           }
321         ],
322         "subHeading": [
323           {
324             "kind": "identifier",
325             "spelling": "ExposedTypedef"
326           }
327         ],
328         "title": "ExposedTypedef"
329       },
330       "pathComponents": [
331         "ExposedTypedef"
332       ],
333       "type": "c:I"
334     },
335     {
336       "accessLevel": "public",
337       "declarationFragments": [
338         {
339           "kind": "keyword",
340           "spelling": "typedef"
341         },
342         {
343           "kind": "text",
344           "spelling": " "
345         },
346         {
347           "kind": "typeIdentifier",
348           "preciseIdentifier": "c:@SA@_HiddenTypedef",
349           "spelling": "_HiddenTypedef"
350         },
351         {
352           "kind": "text",
353           "spelling": " "
354         },
355         {
356           "kind": "identifier",
357           "spelling": "ExposedTypedefToHidden"
358         }
359       ],
360       "identifier": {
361         "interfaceLanguage": "c",
362         "precise": "c:input.h@T@ExposedTypedefToHidden"
363       },
364       "kind": {
365         "displayName": "Type Alias",
366         "identifier": "c.typealias"
367       },
368       "location": {
369         "position": {
370           "character": 24,
371           "line": 19
372         },
373         "uri": "file://INPUT_DIR/input.h"
374       },
375       "names": {
376         "navigator": [
377           {
378             "kind": "identifier",
379             "spelling": "ExposedTypedefToHidden"
380           }
381         ],
382         "subHeading": [
383           {
384             "kind": "identifier",
385             "spelling": "ExposedTypedefToHidden"
386           }
387         ],
388         "title": "ExposedTypedefToHidden"
389       },
390       "pathComponents": [
391         "ExposedTypedefToHidden"
392       ],
393       "type": "c:@SA@_HiddenTypedef"
394     }
395   ]
396 }
397