xref: /llvm-project/clang/test/ExtractAPI/enum.c (revision 671709f0e7d49826fd0908be2c9aed07debf5bc9)
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 /// Kinds of vehicles
15 enum Vehicle {
16   Bicycle,
17   Car,
18   Train, ///< Move this to the top! -Sheldon
19   Ship,
20   Airplane,
21 };
22 
23 enum Direction : unsigned char {
24   North = 0,
25   East,
26   South,
27   West
28 };
29 
30 enum {
31   Constant = 1
32 };
33 
34 enum {
35   OtherConstant = 2
36 };
37 // expected-no-diagnostics
38 
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:@E@Vehicle@Bicycle",
68       "target": "c:@E@Vehicle",
69       "targetFallback": "Vehicle"
70     },
71     {
72       "kind": "memberOf",
73       "source": "c:@E@Vehicle@Car",
74       "target": "c:@E@Vehicle",
75       "targetFallback": "Vehicle"
76     },
77     {
78       "kind": "memberOf",
79       "source": "c:@E@Vehicle@Train",
80       "target": "c:@E@Vehicle",
81       "targetFallback": "Vehicle"
82     },
83     {
84       "kind": "memberOf",
85       "source": "c:@E@Vehicle@Ship",
86       "target": "c:@E@Vehicle",
87       "targetFallback": "Vehicle"
88     },
89     {
90       "kind": "memberOf",
91       "source": "c:@E@Vehicle@Airplane",
92       "target": "c:@E@Vehicle",
93       "targetFallback": "Vehicle"
94     },
95     {
96       "kind": "memberOf",
97       "source": "c:@E@Direction@North",
98       "target": "c:@E@Direction",
99       "targetFallback": "Direction"
100     },
101     {
102       "kind": "memberOf",
103       "source": "c:@E@Direction@East",
104       "target": "c:@E@Direction",
105       "targetFallback": "Direction"
106     },
107     {
108       "kind": "memberOf",
109       "source": "c:@E@Direction@South",
110       "target": "c:@E@Direction",
111       "targetFallback": "Direction"
112     },
113     {
114       "kind": "memberOf",
115       "source": "c:@E@Direction@West",
116       "target": "c:@E@Direction",
117       "targetFallback": "Direction"
118     },
119     {
120       "kind": "memberOf",
121       "source": "c:@Ea@Constant@Constant",
122       "target": "c:@Ea@Constant",
123       "targetFallback": "enum (unnamed)"
124     },
125     {
126       "kind": "memberOf",
127       "source": "c:@Ea@OtherConstant@OtherConstant",
128       "target": "c:@Ea@OtherConstant",
129       "targetFallback": "enum (unnamed)"
130     }
131   ],
132   "symbols": [
133     {
134       "accessLevel": "public",
135       "declarationFragments": [
136         {
137           "kind": "keyword",
138           "spelling": "enum"
139         },
140         {
141           "kind": "text",
142           "spelling": " "
143         },
144         {
145           "kind": "identifier",
146           "spelling": "Vehicle"
147         },
148         {
149           "kind": "text",
150           "spelling": ": "
151         },
152         {
153           "kind": "typeIdentifier",
154           "preciseIdentifier": "c:i",
155           "spelling": "unsigned int"
156         }
157       ],
158       "docComment": {
159         "lines": [
160           {
161             "range": {
162               "end": {
163                 "character": 22,
164                 "line": 1
165               },
166               "start": {
167                 "character": 5,
168                 "line": 1
169               }
170             },
171             "text": "Kinds of vehicles"
172           }
173         ]
174       },
175       "identifier": {
176         "interfaceLanguage": "c",
177         "precise": "c:@E@Vehicle"
178       },
179       "kind": {
180         "displayName": "Enumeration",
181         "identifier": "c.enum"
182       },
183       "location": {
184         "position": {
185           "character": 6,
186           "line": 2
187         },
188         "uri": "file://INPUT_DIR/input.h"
189       },
190       "names": {
191         "navigator": [
192           {
193             "kind": "identifier",
194             "spelling": "Vehicle"
195           }
196         ],
197         "subHeading": [
198           {
199             "kind": "identifier",
200             "spelling": "Vehicle"
201           }
202         ],
203         "title": "Vehicle"
204       },
205       "pathComponents": [
206         "Vehicle"
207       ]
208     },
209     {
210       "accessLevel": "public",
211       "declarationFragments": [
212         {
213           "kind": "identifier",
214           "spelling": "Bicycle"
215         }
216       ],
217       "identifier": {
218         "interfaceLanguage": "c",
219         "precise": "c:@E@Vehicle@Bicycle"
220       },
221       "kind": {
222         "displayName": "Enumeration Case",
223         "identifier": "c.enum.case"
224       },
225       "location": {
226         "position": {
227           "character": 3,
228           "line": 3
229         },
230         "uri": "file://INPUT_DIR/input.h"
231       },
232       "names": {
233         "navigator": [
234           {
235             "kind": "identifier",
236             "spelling": "Bicycle"
237           }
238         ],
239         "subHeading": [
240           {
241             "kind": "identifier",
242             "spelling": "Bicycle"
243           }
244         ],
245         "title": "Bicycle"
246       },
247       "pathComponents": [
248         "Vehicle",
249         "Bicycle"
250       ]
251     },
252     {
253       "accessLevel": "public",
254       "declarationFragments": [
255         {
256           "kind": "identifier",
257           "spelling": "Car"
258         }
259       ],
260       "identifier": {
261         "interfaceLanguage": "c",
262         "precise": "c:@E@Vehicle@Car"
263       },
264       "kind": {
265         "displayName": "Enumeration Case",
266         "identifier": "c.enum.case"
267       },
268       "location": {
269         "position": {
270           "character": 3,
271           "line": 4
272         },
273         "uri": "file://INPUT_DIR/input.h"
274       },
275       "names": {
276         "navigator": [
277           {
278             "kind": "identifier",
279             "spelling": "Car"
280           }
281         ],
282         "subHeading": [
283           {
284             "kind": "identifier",
285             "spelling": "Car"
286           }
287         ],
288         "title": "Car"
289       },
290       "pathComponents": [
291         "Vehicle",
292         "Car"
293       ]
294     },
295     {
296       "accessLevel": "public",
297       "declarationFragments": [
298         {
299           "kind": "identifier",
300           "spelling": "Train"
301         }
302       ],
303       "docComment": {
304         "lines": [
305           {
306             "range": {
307               "end": {
308                 "character": 45,
309                 "line": 5
310               },
311               "start": {
312                 "character": 15,
313                 "line": 5
314               }
315             },
316             "text": "Move this to the top! -Sheldon"
317           }
318         ]
319       },
320       "identifier": {
321         "interfaceLanguage": "c",
322         "precise": "c:@E@Vehicle@Train"
323       },
324       "kind": {
325         "displayName": "Enumeration Case",
326         "identifier": "c.enum.case"
327       },
328       "location": {
329         "position": {
330           "character": 3,
331           "line": 5
332         },
333         "uri": "file://INPUT_DIR/input.h"
334       },
335       "names": {
336         "navigator": [
337           {
338             "kind": "identifier",
339             "spelling": "Train"
340           }
341         ],
342         "subHeading": [
343           {
344             "kind": "identifier",
345             "spelling": "Train"
346           }
347         ],
348         "title": "Train"
349       },
350       "pathComponents": [
351         "Vehicle",
352         "Train"
353       ]
354     },
355     {
356       "accessLevel": "public",
357       "declarationFragments": [
358         {
359           "kind": "identifier",
360           "spelling": "Ship"
361         }
362       ],
363       "identifier": {
364         "interfaceLanguage": "c",
365         "precise": "c:@E@Vehicle@Ship"
366       },
367       "kind": {
368         "displayName": "Enumeration Case",
369         "identifier": "c.enum.case"
370       },
371       "location": {
372         "position": {
373           "character": 3,
374           "line": 6
375         },
376         "uri": "file://INPUT_DIR/input.h"
377       },
378       "names": {
379         "navigator": [
380           {
381             "kind": "identifier",
382             "spelling": "Ship"
383           }
384         ],
385         "subHeading": [
386           {
387             "kind": "identifier",
388             "spelling": "Ship"
389           }
390         ],
391         "title": "Ship"
392       },
393       "pathComponents": [
394         "Vehicle",
395         "Ship"
396       ]
397     },
398     {
399       "accessLevel": "public",
400       "declarationFragments": [
401         {
402           "kind": "identifier",
403           "spelling": "Airplane"
404         }
405       ],
406       "identifier": {
407         "interfaceLanguage": "c",
408         "precise": "c:@E@Vehicle@Airplane"
409       },
410       "kind": {
411         "displayName": "Enumeration Case",
412         "identifier": "c.enum.case"
413       },
414       "location": {
415         "position": {
416           "character": 3,
417           "line": 7
418         },
419         "uri": "file://INPUT_DIR/input.h"
420       },
421       "names": {
422         "navigator": [
423           {
424             "kind": "identifier",
425             "spelling": "Airplane"
426           }
427         ],
428         "subHeading": [
429           {
430             "kind": "identifier",
431             "spelling": "Airplane"
432           }
433         ],
434         "title": "Airplane"
435       },
436       "pathComponents": [
437         "Vehicle",
438         "Airplane"
439       ]
440     },
441     {
442       "accessLevel": "public",
443       "declarationFragments": [
444         {
445           "kind": "keyword",
446           "spelling": "enum"
447         },
448         {
449           "kind": "text",
450           "spelling": " "
451         },
452         {
453           "kind": "identifier",
454           "spelling": "Direction"
455         },
456         {
457           "kind": "text",
458           "spelling": ": "
459         },
460         {
461           "kind": "typeIdentifier",
462           "preciseIdentifier": "c:c",
463           "spelling": "unsigned char"
464         }
465       ],
466       "identifier": {
467         "interfaceLanguage": "c",
468         "precise": "c:@E@Direction"
469       },
470       "kind": {
471         "displayName": "Enumeration",
472         "identifier": "c.enum"
473       },
474       "location": {
475         "position": {
476           "character": 6,
477           "line": 10
478         },
479         "uri": "file://INPUT_DIR/input.h"
480       },
481       "names": {
482         "navigator": [
483           {
484             "kind": "identifier",
485             "spelling": "Direction"
486           }
487         ],
488         "subHeading": [
489           {
490             "kind": "identifier",
491             "spelling": "Direction"
492           }
493         ],
494         "title": "Direction"
495       },
496       "pathComponents": [
497         "Direction"
498       ]
499     },
500     {
501       "accessLevel": "public",
502       "declarationFragments": [
503         {
504           "kind": "identifier",
505           "spelling": "North"
506         }
507       ],
508       "identifier": {
509         "interfaceLanguage": "c",
510         "precise": "c:@E@Direction@North"
511       },
512       "kind": {
513         "displayName": "Enumeration Case",
514         "identifier": "c.enum.case"
515       },
516       "location": {
517         "position": {
518           "character": 3,
519           "line": 11
520         },
521         "uri": "file://INPUT_DIR/input.h"
522       },
523       "names": {
524         "navigator": [
525           {
526             "kind": "identifier",
527             "spelling": "North"
528           }
529         ],
530         "subHeading": [
531           {
532             "kind": "identifier",
533             "spelling": "North"
534           }
535         ],
536         "title": "North"
537       },
538       "pathComponents": [
539         "Direction",
540         "North"
541       ]
542     },
543     {
544       "accessLevel": "public",
545       "declarationFragments": [
546         {
547           "kind": "identifier",
548           "spelling": "East"
549         }
550       ],
551       "identifier": {
552         "interfaceLanguage": "c",
553         "precise": "c:@E@Direction@East"
554       },
555       "kind": {
556         "displayName": "Enumeration Case",
557         "identifier": "c.enum.case"
558       },
559       "location": {
560         "position": {
561           "character": 3,
562           "line": 12
563         },
564         "uri": "file://INPUT_DIR/input.h"
565       },
566       "names": {
567         "navigator": [
568           {
569             "kind": "identifier",
570             "spelling": "East"
571           }
572         ],
573         "subHeading": [
574           {
575             "kind": "identifier",
576             "spelling": "East"
577           }
578         ],
579         "title": "East"
580       },
581       "pathComponents": [
582         "Direction",
583         "East"
584       ]
585     },
586     {
587       "accessLevel": "public",
588       "declarationFragments": [
589         {
590           "kind": "identifier",
591           "spelling": "South"
592         }
593       ],
594       "identifier": {
595         "interfaceLanguage": "c",
596         "precise": "c:@E@Direction@South"
597       },
598       "kind": {
599         "displayName": "Enumeration Case",
600         "identifier": "c.enum.case"
601       },
602       "location": {
603         "position": {
604           "character": 3,
605           "line": 13
606         },
607         "uri": "file://INPUT_DIR/input.h"
608       },
609       "names": {
610         "navigator": [
611           {
612             "kind": "identifier",
613             "spelling": "South"
614           }
615         ],
616         "subHeading": [
617           {
618             "kind": "identifier",
619             "spelling": "South"
620           }
621         ],
622         "title": "South"
623       },
624       "pathComponents": [
625         "Direction",
626         "South"
627       ]
628     },
629     {
630       "accessLevel": "public",
631       "declarationFragments": [
632         {
633           "kind": "identifier",
634           "spelling": "West"
635         }
636       ],
637       "identifier": {
638         "interfaceLanguage": "c",
639         "precise": "c:@E@Direction@West"
640       },
641       "kind": {
642         "displayName": "Enumeration Case",
643         "identifier": "c.enum.case"
644       },
645       "location": {
646         "position": {
647           "character": 3,
648           "line": 14
649         },
650         "uri": "file://INPUT_DIR/input.h"
651       },
652       "names": {
653         "navigator": [
654           {
655             "kind": "identifier",
656             "spelling": "West"
657           }
658         ],
659         "subHeading": [
660           {
661             "kind": "identifier",
662             "spelling": "West"
663           }
664         ],
665         "title": "West"
666       },
667       "pathComponents": [
668         "Direction",
669         "West"
670       ]
671     },
672     {
673       "accessLevel": "public",
674       "declarationFragments": [
675         {
676           "kind": "keyword",
677           "spelling": "enum"
678         },
679         {
680           "kind": "text",
681           "spelling": ": "
682         },
683         {
684           "kind": "typeIdentifier",
685           "preciseIdentifier": "c:i",
686           "spelling": "unsigned int"
687         }
688       ],
689       "identifier": {
690         "interfaceLanguage": "c",
691         "precise": "c:@Ea@Constant"
692       },
693       "kind": {
694         "displayName": "Enumeration",
695         "identifier": "c.enum"
696       },
697       "location": {
698         "position": {
699           "character": 1,
700           "line": 17
701         },
702         "uri": "file://INPUT_DIR/input.h"
703       },
704       "names": {
705         "navigator": [
706           {
707             "kind": "identifier",
708             "spelling": "enum (unnamed)"
709           }
710         ],
711         "title": "enum (unnamed)"
712       },
713       "pathComponents": [
714         "enum (unnamed)"
715       ]
716     },
717     {
718       "accessLevel": "public",
719       "declarationFragments": [
720         {
721           "kind": "identifier",
722           "spelling": "Constant"
723         }
724       ],
725       "identifier": {
726         "interfaceLanguage": "c",
727         "precise": "c:@Ea@Constant@Constant"
728       },
729       "kind": {
730         "displayName": "Enumeration Case",
731         "identifier": "c.enum.case"
732       },
733       "location": {
734         "position": {
735           "character": 3,
736           "line": 18
737         },
738         "uri": "file://INPUT_DIR/input.h"
739       },
740       "names": {
741         "navigator": [
742           {
743             "kind": "identifier",
744             "spelling": "Constant"
745           }
746         ],
747         "subHeading": [
748           {
749             "kind": "identifier",
750             "spelling": "Constant"
751           }
752         ],
753         "title": "Constant"
754       },
755       "pathComponents": [
756         "enum (unnamed)",
757         "Constant"
758       ]
759     },
760     {
761       "accessLevel": "public",
762       "declarationFragments": [
763         {
764           "kind": "keyword",
765           "spelling": "enum"
766         },
767         {
768           "kind": "text",
769           "spelling": ": "
770         },
771         {
772           "kind": "typeIdentifier",
773           "preciseIdentifier": "c:i",
774           "spelling": "unsigned int"
775         }
776       ],
777       "identifier": {
778         "interfaceLanguage": "c",
779         "precise": "c:@Ea@OtherConstant"
780       },
781       "kind": {
782         "displayName": "Enumeration",
783         "identifier": "c.enum"
784       },
785       "location": {
786         "position": {
787           "character": 1,
788           "line": 21
789         },
790         "uri": "file://INPUT_DIR/input.h"
791       },
792       "names": {
793         "navigator": [
794           {
795             "kind": "identifier",
796             "spelling": "enum (unnamed)"
797           }
798         ],
799         "title": "enum (unnamed)"
800       },
801       "pathComponents": [
802         "enum (unnamed)"
803       ]
804     },
805     {
806       "accessLevel": "public",
807       "declarationFragments": [
808         {
809           "kind": "identifier",
810           "spelling": "OtherConstant"
811         }
812       ],
813       "identifier": {
814         "interfaceLanguage": "c",
815         "precise": "c:@Ea@OtherConstant@OtherConstant"
816       },
817       "kind": {
818         "displayName": "Enumeration Case",
819         "identifier": "c.enum.case"
820       },
821       "location": {
822         "position": {
823           "character": 3,
824           "line": 22
825         },
826         "uri": "file://INPUT_DIR/input.h"
827       },
828       "names": {
829         "navigator": [
830           {
831             "kind": "identifier",
832             "spelling": "OtherConstant"
833           }
834         ],
835         "subHeading": [
836           {
837             "kind": "identifier",
838             "spelling": "OtherConstant"
839           }
840         ],
841         "title": "OtherConstant"
842       },
843       "pathComponents": [
844         "enum (unnamed)",
845         "OtherConstant"
846       ]
847     }
848   ]
849 }
850