xref: /llvm-project/clang/test/ExtractAPI/emit-symbol-graph/multi_file.c (revision b31414bf4f9898f7817a9fcf8a91f62ec26f3eaf)
1 // RUN: rm -rf %t
2 // RUN: mkdir %t
3 // RUN: split-file %s %t
4 // RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
5 // RUN: %t/reference.main.json.in >> %t/reference.main.json
6 // RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
7 // RUN: %t/reference.test.json.in >> %t/reference.test.json
8 // RUN: %clang_cc1 %t/test.c %t/main.c -emit-symbol-graph --pretty-sgf \
9 // RUN:   --symbol-graph-dir=%t/SymbolGraphs --product-name=multifile_test -triple=x86_64-apple-macosx12.0.0
10 
11 // Test main.json
12 // Generator version is not consistent across test runs, normalize it.
13 // RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
14 // RUN: %t/SymbolGraphs/main.c.symbols.json > %t/output-normalized.json
15 // RUN: diff %t/reference.main.json %t/output-normalized.json
16 
17 // Test test.json
18 // Generator version is not consistent across test runs, normalize it.
19 // RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
20 // RUN: %t/SymbolGraphs/test.c.symbols.json > %t/output-normalized.json
21 // RUN: diff %t/reference.test.json %t/output-normalized.json
22 
23 // CHECK-NOT: error:
24 // CHECK-NOT: warning:
25 
26 //--- test.h
27 #ifndef TEST_H
28 #define TEST_H
29 
30 #define testmarcro1 32
31 #define testmacro2 42
32 
33 int testfunc (int param1, int param2);
34 void testfunc2 ();
35 #endif /* TEST_H */
36 
37 //--- test.c
38 #include "test.h"
39 
40 int testfunc(int param1, int param2) { return param1 + param2; }
41 
42 void testfunc2() {}
43 
44 //--- main.c
45 #include "test.h"
46 
47 int main ()
48 {
49   testfunc2();
50   return 0;
51 }
52 
53 //--- reference.main.json.in
54 {
55   "metadata": {
56     "formatVersion": {
57       "major": 0,
58       "minor": 5,
59       "patch": 3
60     },
61     "generator": "?"
62   },
63   "module": {
64     "name": "multifile_test",
65     "platform": {
66       "architecture": "x86_64",
67       "operatingSystem": {
68         "name": "macosx"
69       },
70       "vendor": "apple"
71     }
72   },
73   "relationships": [],
74   "symbols": [
75     {
76       "accessLevel": "public",
77       "declarationFragments": [
78         {
79           "kind": "typeIdentifier",
80           "preciseIdentifier": "c:I",
81           "spelling": "int"
82         },
83         {
84           "kind": "text",
85           "spelling": " "
86         },
87         {
88           "kind": "identifier",
89           "spelling": "testfunc"
90         },
91         {
92           "kind": "text",
93           "spelling": "("
94         },
95         {
96           "kind": "typeIdentifier",
97           "preciseIdentifier": "c:I",
98           "spelling": "int"
99         },
100         {
101           "kind": "text",
102           "spelling": " "
103         },
104         {
105           "kind": "internalParam",
106           "spelling": "param1"
107         },
108         {
109           "kind": "text",
110           "spelling": ", "
111         },
112         {
113           "kind": "typeIdentifier",
114           "preciseIdentifier": "c:I",
115           "spelling": "int"
116         },
117         {
118           "kind": "text",
119           "spelling": " "
120         },
121         {
122           "kind": "internalParam",
123           "spelling": "param2"
124         },
125         {
126           "kind": "text",
127           "spelling": ");"
128         }
129       ],
130       "functionSignature": {
131         "parameters": [
132           {
133             "declarationFragments": [
134               {
135                 "kind": "typeIdentifier",
136                 "preciseIdentifier": "c:I",
137                 "spelling": "int"
138               },
139               {
140                 "kind": "text",
141                 "spelling": " "
142               },
143               {
144                 "kind": "internalParam",
145                 "spelling": "param1"
146               }
147             ],
148             "name": "param1"
149           },
150           {
151             "declarationFragments": [
152               {
153                 "kind": "typeIdentifier",
154                 "preciseIdentifier": "c:I",
155                 "spelling": "int"
156               },
157               {
158                 "kind": "text",
159                 "spelling": " "
160               },
161               {
162                 "kind": "internalParam",
163                 "spelling": "param2"
164               }
165             ],
166             "name": "param2"
167           }
168         ],
169         "returns": [
170           {
171             "kind": "typeIdentifier",
172             "preciseIdentifier": "c:I",
173             "spelling": "int"
174           }
175         ]
176       },
177       "identifier": {
178         "interfaceLanguage": "c",
179         "precise": "c:@F@testfunc"
180       },
181       "kind": {
182         "displayName": "Function",
183         "identifier": "c.func"
184       },
185       "location": {
186         "position": {
187           "character": 4,
188           "line": 6
189         },
190         "uri": "file://INPUT_DIR/test.h"
191       },
192       "names": {
193         "navigator": [
194           {
195             "kind": "identifier",
196             "spelling": "testfunc"
197           }
198         ],
199         "subHeading": [
200           {
201             "kind": "identifier",
202             "spelling": "testfunc"
203           }
204         ],
205         "title": "testfunc"
206       },
207       "pathComponents": [
208         "testfunc"
209       ]
210     },
211     {
212       "accessLevel": "public",
213       "declarationFragments": [
214         {
215           "kind": "typeIdentifier",
216           "preciseIdentifier": "c:v",
217           "spelling": "void"
218         },
219         {
220           "kind": "text",
221           "spelling": " "
222         },
223         {
224           "kind": "identifier",
225           "spelling": "testfunc2"
226         },
227         {
228           "kind": "text",
229           "spelling": "();"
230         }
231       ],
232       "functionSignature": {
233         "returns": [
234           {
235             "kind": "typeIdentifier",
236             "preciseIdentifier": "c:v",
237             "spelling": "void"
238           }
239         ]
240       },
241       "identifier": {
242         "interfaceLanguage": "c",
243         "precise": "c:@F@testfunc2"
244       },
245       "kind": {
246         "displayName": "Function",
247         "identifier": "c.func"
248       },
249       "location": {
250         "position": {
251           "character": 5,
252           "line": 7
253         },
254         "uri": "file://INPUT_DIR/test.h"
255       },
256       "names": {
257         "navigator": [
258           {
259             "kind": "identifier",
260             "spelling": "testfunc2"
261           }
262         ],
263         "subHeading": [
264           {
265             "kind": "identifier",
266             "spelling": "testfunc2"
267           }
268         ],
269         "title": "testfunc2"
270       },
271       "pathComponents": [
272         "testfunc2"
273       ]
274     },
275     {
276       "accessLevel": "public",
277       "declarationFragments": [
278         {
279           "kind": "typeIdentifier",
280           "preciseIdentifier": "c:I",
281           "spelling": "int"
282         },
283         {
284           "kind": "text",
285           "spelling": " "
286         },
287         {
288           "kind": "identifier",
289           "spelling": "main"
290         },
291         {
292           "kind": "text",
293           "spelling": "();"
294         }
295       ],
296       "functionSignature": {
297         "returns": [
298           {
299             "kind": "typeIdentifier",
300             "preciseIdentifier": "c:I",
301             "spelling": "int"
302           }
303         ]
304       },
305       "identifier": {
306         "interfaceLanguage": "c",
307         "precise": "c:@F@main"
308       },
309       "kind": {
310         "displayName": "Function",
311         "identifier": "c.func"
312       },
313       "location": {
314         "position": {
315           "character": 4,
316           "line": 2
317         },
318         "uri": "file://INPUT_DIR/main.c"
319       },
320       "names": {
321         "navigator": [
322           {
323             "kind": "identifier",
324             "spelling": "main"
325           }
326         ],
327         "subHeading": [
328           {
329             "kind": "identifier",
330             "spelling": "main"
331           }
332         ],
333         "title": "main"
334       },
335       "pathComponents": [
336         "main"
337       ]
338     },
339     {
340       "accessLevel": "public",
341       "declarationFragments": [
342         {
343           "kind": "keyword",
344           "spelling": "#define"
345         },
346         {
347           "kind": "text",
348           "spelling": " "
349         },
350         {
351           "kind": "identifier",
352           "spelling": "testmarcro1"
353         }
354       ],
355       "identifier": {
356         "interfaceLanguage": "c",
357         "precise": "c:test.h@39@macro@testmarcro1"
358       },
359       "kind": {
360         "displayName": "Macro",
361         "identifier": "c.macro"
362       },
363       "location": {
364         "position": {
365           "character": 8,
366           "line": 3
367         },
368         "uri": "file://INPUT_DIR/test.h"
369       },
370       "names": {
371         "navigator": [
372           {
373             "kind": "identifier",
374             "spelling": "testmarcro1"
375           }
376         ],
377         "subHeading": [
378           {
379             "kind": "identifier",
380             "spelling": "testmarcro1"
381           }
382         ],
383         "title": "testmarcro1"
384       },
385       "pathComponents": [
386         "testmarcro1"
387       ]
388     },
389     {
390       "accessLevel": "public",
391       "declarationFragments": [
392         {
393           "kind": "keyword",
394           "spelling": "#define"
395         },
396         {
397           "kind": "text",
398           "spelling": " "
399         },
400         {
401           "kind": "identifier",
402           "spelling": "testmacro2"
403         }
404       ],
405       "identifier": {
406         "interfaceLanguage": "c",
407         "precise": "c:test.h@62@macro@testmacro2"
408       },
409       "kind": {
410         "displayName": "Macro",
411         "identifier": "c.macro"
412       },
413       "location": {
414         "position": {
415           "character": 8,
416           "line": 4
417         },
418         "uri": "file://INPUT_DIR/test.h"
419       },
420       "names": {
421         "navigator": [
422           {
423             "kind": "identifier",
424             "spelling": "testmacro2"
425           }
426         ],
427         "subHeading": [
428           {
429             "kind": "identifier",
430             "spelling": "testmacro2"
431           }
432         ],
433         "title": "testmacro2"
434       },
435       "pathComponents": [
436         "testmacro2"
437       ]
438     }
439   ]
440 }
441 //--- reference.test.json.in
442 {
443   "metadata": {
444     "formatVersion": {
445       "major": 0,
446       "minor": 5,
447       "patch": 3
448     },
449     "generator": "?"
450   },
451   "module": {
452     "name": "multifile_test",
453     "platform": {
454       "architecture": "x86_64",
455       "operatingSystem": {
456         "name": "macosx"
457       },
458       "vendor": "apple"
459     }
460   },
461   "relationships": [],
462   "symbols": [
463     {
464       "accessLevel": "public",
465       "declarationFragments": [
466         {
467           "kind": "typeIdentifier",
468           "preciseIdentifier": "c:I",
469           "spelling": "int"
470         },
471         {
472           "kind": "text",
473           "spelling": " "
474         },
475         {
476           "kind": "identifier",
477           "spelling": "testfunc"
478         },
479         {
480           "kind": "text",
481           "spelling": "("
482         },
483         {
484           "kind": "typeIdentifier",
485           "preciseIdentifier": "c:I",
486           "spelling": "int"
487         },
488         {
489           "kind": "text",
490           "spelling": " "
491         },
492         {
493           "kind": "internalParam",
494           "spelling": "param1"
495         },
496         {
497           "kind": "text",
498           "spelling": ", "
499         },
500         {
501           "kind": "typeIdentifier",
502           "preciseIdentifier": "c:I",
503           "spelling": "int"
504         },
505         {
506           "kind": "text",
507           "spelling": " "
508         },
509         {
510           "kind": "internalParam",
511           "spelling": "param2"
512         },
513         {
514           "kind": "text",
515           "spelling": ");"
516         }
517       ],
518       "functionSignature": {
519         "parameters": [
520           {
521             "declarationFragments": [
522               {
523                 "kind": "typeIdentifier",
524                 "preciseIdentifier": "c:I",
525                 "spelling": "int"
526               },
527               {
528                 "kind": "text",
529                 "spelling": " "
530               },
531               {
532                 "kind": "internalParam",
533                 "spelling": "param1"
534               }
535             ],
536             "name": "param1"
537           },
538           {
539             "declarationFragments": [
540               {
541                 "kind": "typeIdentifier",
542                 "preciseIdentifier": "c:I",
543                 "spelling": "int"
544               },
545               {
546                 "kind": "text",
547                 "spelling": " "
548               },
549               {
550                 "kind": "internalParam",
551                 "spelling": "param2"
552               }
553             ],
554             "name": "param2"
555           }
556         ],
557         "returns": [
558           {
559             "kind": "typeIdentifier",
560             "preciseIdentifier": "c:I",
561             "spelling": "int"
562           }
563         ]
564       },
565       "identifier": {
566         "interfaceLanguage": "c",
567         "precise": "c:@F@testfunc"
568       },
569       "kind": {
570         "displayName": "Function",
571         "identifier": "c.func"
572       },
573       "location": {
574         "position": {
575           "character": 4,
576           "line": 6
577         },
578         "uri": "file://INPUT_DIR/test.h"
579       },
580       "names": {
581         "navigator": [
582           {
583             "kind": "identifier",
584             "spelling": "testfunc"
585           }
586         ],
587         "subHeading": [
588           {
589             "kind": "identifier",
590             "spelling": "testfunc"
591           }
592         ],
593         "title": "testfunc"
594       },
595       "pathComponents": [
596         "testfunc"
597       ]
598     },
599     {
600       "accessLevel": "public",
601       "declarationFragments": [
602         {
603           "kind": "typeIdentifier",
604           "preciseIdentifier": "c:v",
605           "spelling": "void"
606         },
607         {
608           "kind": "text",
609           "spelling": " "
610         },
611         {
612           "kind": "identifier",
613           "spelling": "testfunc2"
614         },
615         {
616           "kind": "text",
617           "spelling": "();"
618         }
619       ],
620       "functionSignature": {
621         "returns": [
622           {
623             "kind": "typeIdentifier",
624             "preciseIdentifier": "c:v",
625             "spelling": "void"
626           }
627         ]
628       },
629       "identifier": {
630         "interfaceLanguage": "c",
631         "precise": "c:@F@testfunc2"
632       },
633       "kind": {
634         "displayName": "Function",
635         "identifier": "c.func"
636       },
637       "location": {
638         "position": {
639           "character": 5,
640           "line": 7
641         },
642         "uri": "file://INPUT_DIR/test.h"
643       },
644       "names": {
645         "navigator": [
646           {
647             "kind": "identifier",
648             "spelling": "testfunc2"
649           }
650         ],
651         "subHeading": [
652           {
653             "kind": "identifier",
654             "spelling": "testfunc2"
655           }
656         ],
657         "title": "testfunc2"
658       },
659       "pathComponents": [
660         "testfunc2"
661       ]
662     },
663     {
664       "accessLevel": "public",
665       "declarationFragments": [
666         {
667           "kind": "keyword",
668           "spelling": "#define"
669         },
670         {
671           "kind": "text",
672           "spelling": " "
673         },
674         {
675           "kind": "identifier",
676           "spelling": "testmarcro1"
677         }
678       ],
679       "identifier": {
680         "interfaceLanguage": "c",
681         "precise": "c:test.h@39@macro@testmarcro1"
682       },
683       "kind": {
684         "displayName": "Macro",
685         "identifier": "c.macro"
686       },
687       "location": {
688         "position": {
689           "character": 8,
690           "line": 3
691         },
692         "uri": "file://INPUT_DIR/test.h"
693       },
694       "names": {
695         "navigator": [
696           {
697             "kind": "identifier",
698             "spelling": "testmarcro1"
699           }
700         ],
701         "subHeading": [
702           {
703             "kind": "identifier",
704             "spelling": "testmarcro1"
705           }
706         ],
707         "title": "testmarcro1"
708       },
709       "pathComponents": [
710         "testmarcro1"
711       ]
712     },
713     {
714       "accessLevel": "public",
715       "declarationFragments": [
716         {
717           "kind": "keyword",
718           "spelling": "#define"
719         },
720         {
721           "kind": "text",
722           "spelling": " "
723         },
724         {
725           "kind": "identifier",
726           "spelling": "testmacro2"
727         }
728       ],
729       "identifier": {
730         "interfaceLanguage": "c",
731         "precise": "c:test.h@62@macro@testmacro2"
732       },
733       "kind": {
734         "displayName": "Macro",
735         "identifier": "c.macro"
736       },
737       "location": {
738         "position": {
739           "character": 8,
740           "line": 4
741         },
742         "uri": "file://INPUT_DIR/test.h"
743       },
744       "names": {
745         "navigator": [
746           {
747             "kind": "identifier",
748             "spelling": "testmacro2"
749           }
750         ],
751         "subHeading": [
752           {
753             "kind": "identifier",
754             "spelling": "testmacro2"
755           }
756         ],
757         "title": "testmacro2"
758       },
759       "pathComponents": [
760         "testmacro2"
761       ]
762     }
763   ]
764 }
765