xref: /llvm-project/clang/test/ExtractAPI/enum.c (revision 80ae366592924c8a32f81f96b316595ec90ec672)
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 -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 /// Kinds of vehicles
18 enum Vehicle {
19   Bicycle,
20   Car,
21   Train, ///< Move this to the top! -Sheldon
22   Ship,
23   Airplane,
24 };
25 
26 enum Direction : unsigned char {
27   North = 0,
28   East,
29   South,
30   West
31 };
32 
33 //--- reference.output.json.in
34 {
35   "metadata": {
36     "formatVersion": {
37       "major": 0,
38       "minor": 5,
39       "patch": 3
40     },
41     "generator": "?"
42   },
43   "module": {
44     "name": "",
45     "platform": {
46       "architecture": "arm64",
47       "operatingSystem": {
48         "minimumVersion": {
49           "major": 11,
50           "minor": 0,
51           "patch": 0
52         },
53         "name": "macosx"
54       },
55       "vendor": "apple"
56     }
57   },
58   "relationships": [
59     {
60       "kind": "memberOf",
61       "source": "c:@E@Vehicle@Bicycle",
62       "target": "c:@E@Vehicle"
63     },
64     {
65       "kind": "memberOf",
66       "source": "c:@E@Vehicle@Car",
67       "target": "c:@E@Vehicle"
68     },
69     {
70       "kind": "memberOf",
71       "source": "c:@E@Vehicle@Train",
72       "target": "c:@E@Vehicle"
73     },
74     {
75       "kind": "memberOf",
76       "source": "c:@E@Vehicle@Ship",
77       "target": "c:@E@Vehicle"
78     },
79     {
80       "kind": "memberOf",
81       "source": "c:@E@Vehicle@Airplane",
82       "target": "c:@E@Vehicle"
83     },
84     {
85       "kind": "memberOf",
86       "source": "c:@E@Direction@North",
87       "target": "c:@E@Direction"
88     },
89     {
90       "kind": "memberOf",
91       "source": "c:@E@Direction@East",
92       "target": "c:@E@Direction"
93     },
94     {
95       "kind": "memberOf",
96       "source": "c:@E@Direction@South",
97       "target": "c:@E@Direction"
98     },
99     {
100       "kind": "memberOf",
101       "source": "c:@E@Direction@West",
102       "target": "c:@E@Direction"
103     }
104   ],
105   "symbols": [
106     {
107       "accessLevel": "public",
108       "declarationFragments": [
109         {
110           "kind": "keyword",
111           "spelling": "enum"
112         },
113         {
114           "kind": "text",
115           "spelling": " "
116         },
117         {
118           "kind": "identifier",
119           "spelling": "Vehicle"
120         },
121         {
122           "kind": "text",
123           "spelling": ": "
124         },
125         {
126           "kind": "typeIdentifier",
127           "preciseIdentifier": "c:i",
128           "spelling": "unsigned int"
129         }
130       ],
131       "docComment": {
132         "lines": [
133           {
134             "range": {
135               "end": {
136                 "character": 22,
137                 "line": 1
138               },
139               "start": {
140                 "character": 5,
141                 "line": 1
142               }
143             },
144             "text": "Kinds of vehicles"
145           }
146         ]
147       },
148       "identifier": {
149         "interfaceLanguage": "c",
150         "precise": "c:@E@Vehicle"
151       },
152       "kind": {
153         "displayName": "Enumeration",
154         "identifier": "c.enum"
155       },
156       "location": {
157         "position": {
158           "character": 6,
159           "line": 2
160         },
161         "uri": "file://INPUT_DIR/input.h"
162       },
163       "names": {
164         "navigator": [
165           {
166             "kind": "identifier",
167             "spelling": "Vehicle"
168           }
169         ],
170         "subHeading": [
171           {
172             "kind": "identifier",
173             "spelling": "Vehicle"
174           }
175         ],
176         "title": "Vehicle"
177       },
178       "pathComponents": [
179         "Vehicle"
180       ]
181     },
182     {
183       "accessLevel": "public",
184       "declarationFragments": [
185         {
186           "kind": "identifier",
187           "spelling": "Bicycle"
188         }
189       ],
190       "identifier": {
191         "interfaceLanguage": "c",
192         "precise": "c:@E@Vehicle@Bicycle"
193       },
194       "kind": {
195         "displayName": "Enumeration Case",
196         "identifier": "c.enum.case"
197       },
198       "location": {
199         "position": {
200           "character": 3,
201           "line": 3
202         },
203         "uri": "file://INPUT_DIR/input.h"
204       },
205       "names": {
206         "navigator": [
207           {
208             "kind": "identifier",
209             "spelling": "Bicycle"
210           }
211         ],
212         "subHeading": [
213           {
214             "kind": "identifier",
215             "spelling": "Bicycle"
216           }
217         ],
218         "title": "Bicycle"
219       },
220       "pathComponents": [
221         "Vehicle",
222         "Bicycle"
223       ]
224     },
225     {
226       "accessLevel": "public",
227       "declarationFragments": [
228         {
229           "kind": "identifier",
230           "spelling": "Car"
231         }
232       ],
233       "identifier": {
234         "interfaceLanguage": "c",
235         "precise": "c:@E@Vehicle@Car"
236       },
237       "kind": {
238         "displayName": "Enumeration Case",
239         "identifier": "c.enum.case"
240       },
241       "location": {
242         "position": {
243           "character": 3,
244           "line": 4
245         },
246         "uri": "file://INPUT_DIR/input.h"
247       },
248       "names": {
249         "navigator": [
250           {
251             "kind": "identifier",
252             "spelling": "Car"
253           }
254         ],
255         "subHeading": [
256           {
257             "kind": "identifier",
258             "spelling": "Car"
259           }
260         ],
261         "title": "Car"
262       },
263       "pathComponents": [
264         "Vehicle",
265         "Car"
266       ]
267     },
268     {
269       "accessLevel": "public",
270       "declarationFragments": [
271         {
272           "kind": "identifier",
273           "spelling": "Train"
274         }
275       ],
276       "docComment": {
277         "lines": [
278           {
279             "range": {
280               "end": {
281                 "character": 45,
282                 "line": 5
283               },
284               "start": {
285                 "character": 15,
286                 "line": 5
287               }
288             },
289             "text": "Move this to the top! -Sheldon"
290           }
291         ]
292       },
293       "identifier": {
294         "interfaceLanguage": "c",
295         "precise": "c:@E@Vehicle@Train"
296       },
297       "kind": {
298         "displayName": "Enumeration Case",
299         "identifier": "c.enum.case"
300       },
301       "location": {
302         "position": {
303           "character": 3,
304           "line": 5
305         },
306         "uri": "file://INPUT_DIR/input.h"
307       },
308       "names": {
309         "navigator": [
310           {
311             "kind": "identifier",
312             "spelling": "Train"
313           }
314         ],
315         "subHeading": [
316           {
317             "kind": "identifier",
318             "spelling": "Train"
319           }
320         ],
321         "title": "Train"
322       },
323       "pathComponents": [
324         "Vehicle",
325         "Train"
326       ]
327     },
328     {
329       "accessLevel": "public",
330       "declarationFragments": [
331         {
332           "kind": "identifier",
333           "spelling": "Ship"
334         }
335       ],
336       "identifier": {
337         "interfaceLanguage": "c",
338         "precise": "c:@E@Vehicle@Ship"
339       },
340       "kind": {
341         "displayName": "Enumeration Case",
342         "identifier": "c.enum.case"
343       },
344       "location": {
345         "position": {
346           "character": 3,
347           "line": 6
348         },
349         "uri": "file://INPUT_DIR/input.h"
350       },
351       "names": {
352         "navigator": [
353           {
354             "kind": "identifier",
355             "spelling": "Ship"
356           }
357         ],
358         "subHeading": [
359           {
360             "kind": "identifier",
361             "spelling": "Ship"
362           }
363         ],
364         "title": "Ship"
365       },
366       "pathComponents": [
367         "Vehicle",
368         "Ship"
369       ]
370     },
371     {
372       "accessLevel": "public",
373       "declarationFragments": [
374         {
375           "kind": "identifier",
376           "spelling": "Airplane"
377         }
378       ],
379       "identifier": {
380         "interfaceLanguage": "c",
381         "precise": "c:@E@Vehicle@Airplane"
382       },
383       "kind": {
384         "displayName": "Enumeration Case",
385         "identifier": "c.enum.case"
386       },
387       "location": {
388         "position": {
389           "character": 3,
390           "line": 7
391         },
392         "uri": "file://INPUT_DIR/input.h"
393       },
394       "names": {
395         "navigator": [
396           {
397             "kind": "identifier",
398             "spelling": "Airplane"
399           }
400         ],
401         "subHeading": [
402           {
403             "kind": "identifier",
404             "spelling": "Airplane"
405           }
406         ],
407         "title": "Airplane"
408       },
409       "pathComponents": [
410         "Vehicle",
411         "Airplane"
412       ]
413     },
414     {
415       "accessLevel": "public",
416       "declarationFragments": [
417         {
418           "kind": "keyword",
419           "spelling": "enum"
420         },
421         {
422           "kind": "text",
423           "spelling": " "
424         },
425         {
426           "kind": "identifier",
427           "spelling": "Direction"
428         },
429         {
430           "kind": "text",
431           "spelling": ": "
432         },
433         {
434           "kind": "typeIdentifier",
435           "preciseIdentifier": "c:c",
436           "spelling": "unsigned char"
437         }
438       ],
439       "identifier": {
440         "interfaceLanguage": "c",
441         "precise": "c:@E@Direction"
442       },
443       "kind": {
444         "displayName": "Enumeration",
445         "identifier": "c.enum"
446       },
447       "location": {
448         "position": {
449           "character": 6,
450           "line": 10
451         },
452         "uri": "file://INPUT_DIR/input.h"
453       },
454       "names": {
455         "navigator": [
456           {
457             "kind": "identifier",
458             "spelling": "Direction"
459           }
460         ],
461         "subHeading": [
462           {
463             "kind": "identifier",
464             "spelling": "Direction"
465           }
466         ],
467         "title": "Direction"
468       },
469       "pathComponents": [
470         "Direction"
471       ]
472     },
473     {
474       "accessLevel": "public",
475       "declarationFragments": [
476         {
477           "kind": "identifier",
478           "spelling": "North"
479         }
480       ],
481       "identifier": {
482         "interfaceLanguage": "c",
483         "precise": "c:@E@Direction@North"
484       },
485       "kind": {
486         "displayName": "Enumeration Case",
487         "identifier": "c.enum.case"
488       },
489       "location": {
490         "position": {
491           "character": 3,
492           "line": 11
493         },
494         "uri": "file://INPUT_DIR/input.h"
495       },
496       "names": {
497         "navigator": [
498           {
499             "kind": "identifier",
500             "spelling": "North"
501           }
502         ],
503         "subHeading": [
504           {
505             "kind": "identifier",
506             "spelling": "North"
507           }
508         ],
509         "title": "North"
510       },
511       "pathComponents": [
512         "Direction",
513         "North"
514       ]
515     },
516     {
517       "accessLevel": "public",
518       "declarationFragments": [
519         {
520           "kind": "identifier",
521           "spelling": "East"
522         }
523       ],
524       "identifier": {
525         "interfaceLanguage": "c",
526         "precise": "c:@E@Direction@East"
527       },
528       "kind": {
529         "displayName": "Enumeration Case",
530         "identifier": "c.enum.case"
531       },
532       "location": {
533         "position": {
534           "character": 3,
535           "line": 12
536         },
537         "uri": "file://INPUT_DIR/input.h"
538       },
539       "names": {
540         "navigator": [
541           {
542             "kind": "identifier",
543             "spelling": "East"
544           }
545         ],
546         "subHeading": [
547           {
548             "kind": "identifier",
549             "spelling": "East"
550           }
551         ],
552         "title": "East"
553       },
554       "pathComponents": [
555         "Direction",
556         "East"
557       ]
558     },
559     {
560       "accessLevel": "public",
561       "declarationFragments": [
562         {
563           "kind": "identifier",
564           "spelling": "South"
565         }
566       ],
567       "identifier": {
568         "interfaceLanguage": "c",
569         "precise": "c:@E@Direction@South"
570       },
571       "kind": {
572         "displayName": "Enumeration Case",
573         "identifier": "c.enum.case"
574       },
575       "location": {
576         "position": {
577           "character": 3,
578           "line": 13
579         },
580         "uri": "file://INPUT_DIR/input.h"
581       },
582       "names": {
583         "navigator": [
584           {
585             "kind": "identifier",
586             "spelling": "South"
587           }
588         ],
589         "subHeading": [
590           {
591             "kind": "identifier",
592             "spelling": "South"
593           }
594         ],
595         "title": "South"
596       },
597       "pathComponents": [
598         "Direction",
599         "South"
600       ]
601     },
602     {
603       "accessLevel": "public",
604       "declarationFragments": [
605         {
606           "kind": "identifier",
607           "spelling": "West"
608         }
609       ],
610       "identifier": {
611         "interfaceLanguage": "c",
612         "precise": "c:@E@Direction@West"
613       },
614       "kind": {
615         "displayName": "Enumeration Case",
616         "identifier": "c.enum.case"
617       },
618       "location": {
619         "position": {
620           "character": 3,
621           "line": 14
622         },
623         "uri": "file://INPUT_DIR/input.h"
624       },
625       "names": {
626         "navigator": [
627           {
628             "kind": "identifier",
629             "spelling": "West"
630           }
631         ],
632         "subHeading": [
633           {
634             "kind": "identifier",
635             "spelling": "West"
636           }
637         ],
638         "title": "West"
639       },
640       "pathComponents": [
641         "Direction",
642         "West"
643       ]
644     }
645   ]
646 }
647