xref: /llvm-project/clang/test/ExtractAPI/methods.cpp (revision 209a1e8dfdf1c104dd53b50eb196d6bc0dd01659)
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 class Foo {
15   int getCount();
16 
17   void setLength(int length) noexcept;
18 
19 public:
20   static double getFoo();
21 
22 protected:
23   constexpr int getBar() const;
24 };
25 /// expected-no-diagnostics
26 
27 //--- reference.output.json.in
28 {
29   "metadata": {
30     "formatVersion": {
31       "major": 0,
32       "minor": 5,
33       "patch": 3
34     },
35     "generator": "?"
36   },
37   "module": {
38     "name": "",
39     "platform": {
40       "architecture": "arm64",
41       "operatingSystem": {
42         "minimumVersion": {
43           "major": 11,
44           "minor": 0,
45           "patch": 0
46         },
47         "name": "macosx"
48       },
49       "vendor": "apple"
50     }
51   },
52   "relationships": [
53     {
54       "kind": "memberOf",
55       "source": "c:@S@Foo@F@getCount#",
56       "target": "c:@S@Foo",
57       "targetFallback": "Foo"
58     },
59     {
60       "kind": "memberOf",
61       "source": "c:@S@Foo@F@setLength#I#",
62       "target": "c:@S@Foo",
63       "targetFallback": "Foo"
64     },
65     {
66       "kind": "memberOf",
67       "source": "c:@S@Foo@F@getBar#1",
68       "target": "c:@S@Foo",
69       "targetFallback": "Foo"
70     },
71     {
72       "kind": "memberOf",
73       "source": "c:@S@Foo@F@getFoo#S",
74       "target": "c:@S@Foo",
75       "targetFallback": "Foo"
76     }
77   ],
78   "symbols": [
79     {
80       "accessLevel": "public",
81       "declarationFragments": [
82         {
83           "kind": "keyword",
84           "spelling": "class"
85         },
86         {
87           "kind": "text",
88           "spelling": " "
89         },
90         {
91           "kind": "identifier",
92           "spelling": "Foo"
93         },
94         {
95           "kind": "text",
96           "spelling": ";"
97         }
98       ],
99       "identifier": {
100         "interfaceLanguage": "c++",
101         "precise": "c:@S@Foo"
102       },
103       "kind": {
104         "displayName": "Class",
105         "identifier": "c++.class"
106       },
107       "location": {
108         "position": {
109           "character": 6,
110           "line": 0
111         },
112         "uri": "file://INPUT_DIR/input.h"
113       },
114       "names": {
115         "navigator": [
116           {
117             "kind": "identifier",
118             "spelling": "Foo"
119           }
120         ],
121         "subHeading": [
122           {
123             "kind": "identifier",
124             "spelling": "Foo"
125           }
126         ],
127         "title": "Foo"
128       },
129       "pathComponents": [
130         "Foo"
131       ]
132     },
133     {
134       "accessLevel": "private",
135       "declarationFragments": [
136         {
137           "kind": "typeIdentifier",
138           "preciseIdentifier": "c:I",
139           "spelling": "int"
140         },
141         {
142           "kind": "text",
143           "spelling": " "
144         },
145         {
146           "kind": "identifier",
147           "spelling": "getCount"
148         },
149         {
150           "kind": "text",
151           "spelling": "();"
152         }
153       ],
154       "functionSignature": {
155         "returns": [
156           {
157             "kind": "typeIdentifier",
158             "preciseIdentifier": "c:I",
159             "spelling": "int"
160           }
161         ]
162       },
163       "identifier": {
164         "interfaceLanguage": "c++",
165         "precise": "c:@S@Foo@F@getCount#"
166       },
167       "kind": {
168         "displayName": "Instance Method",
169         "identifier": "c++.method"
170       },
171       "location": {
172         "position": {
173           "character": 6,
174           "line": 1
175         },
176         "uri": "file://INPUT_DIR/input.h"
177       },
178       "names": {
179         "navigator": [
180           {
181             "kind": "identifier",
182             "spelling": "getCount"
183           }
184         ],
185         "subHeading": [
186           {
187             "kind": "identifier",
188             "spelling": "getCount"
189           }
190         ],
191         "title": "getCount"
192       },
193       "pathComponents": [
194         "Foo",
195         "getCount"
196       ]
197     },
198     {
199       "accessLevel": "private",
200       "declarationFragments": [
201         {
202           "kind": "typeIdentifier",
203           "preciseIdentifier": "c:v",
204           "spelling": "void"
205         },
206         {
207           "kind": "text",
208           "spelling": " "
209         },
210         {
211           "kind": "identifier",
212           "spelling": "setLength"
213         },
214         {
215           "kind": "text",
216           "spelling": "("
217         },
218         {
219           "kind": "typeIdentifier",
220           "preciseIdentifier": "c:I",
221           "spelling": "int"
222         },
223         {
224           "kind": "text",
225           "spelling": " "
226         },
227         {
228           "kind": "internalParam",
229           "spelling": "length"
230         },
231         {
232           "kind": "text",
233           "spelling": ")"
234         },
235         {
236           "kind": "text",
237           "spelling": " "
238         },
239         {
240           "kind": "keyword",
241           "spelling": "noexcept"
242         },
243         {
244           "kind": "text",
245           "spelling": ";"
246         }
247       ],
248       "functionSignature": {
249         "parameters": [
250           {
251             "declarationFragments": [
252               {
253                 "kind": "typeIdentifier",
254                 "preciseIdentifier": "c:I",
255                 "spelling": "int"
256               },
257               {
258                 "kind": "text",
259                 "spelling": " "
260               },
261               {
262                 "kind": "internalParam",
263                 "spelling": "length"
264               }
265             ],
266             "name": "length"
267           }
268         ],
269         "returns": [
270           {
271             "kind": "typeIdentifier",
272             "preciseIdentifier": "c:v",
273             "spelling": "void"
274           }
275         ]
276       },
277       "identifier": {
278         "interfaceLanguage": "c++",
279         "precise": "c:@S@Foo@F@setLength#I#"
280       },
281       "kind": {
282         "displayName": "Instance Method",
283         "identifier": "c++.method"
284       },
285       "location": {
286         "position": {
287           "character": 7,
288           "line": 3
289         },
290         "uri": "file://INPUT_DIR/input.h"
291       },
292       "names": {
293         "navigator": [
294           {
295             "kind": "identifier",
296             "spelling": "setLength"
297           }
298         ],
299         "subHeading": [
300           {
301             "kind": "identifier",
302             "spelling": "setLength"
303           }
304         ],
305         "title": "setLength"
306       },
307       "pathComponents": [
308         "Foo",
309         "setLength"
310       ]
311     },
312     {
313       "accessLevel": "protected",
314       "declarationFragments": [
315         {
316           "kind": "keyword",
317           "spelling": "constexpr"
318         },
319         {
320           "kind": "text",
321           "spelling": " "
322         },
323         {
324           "kind": "typeIdentifier",
325           "preciseIdentifier": "c:I",
326           "spelling": "int"
327         },
328         {
329           "kind": "text",
330           "spelling": " "
331         },
332         {
333           "kind": "identifier",
334           "spelling": "getBar"
335         },
336         {
337           "kind": "text",
338           "spelling": "() "
339         },
340         {
341           "kind": "keyword",
342           "spelling": "const"
343         },
344         {
345           "kind": "text",
346           "spelling": ";"
347         }
348       ],
349       "functionSignature": {
350         "returns": [
351           {
352             "kind": "typeIdentifier",
353             "preciseIdentifier": "c:I",
354             "spelling": "int"
355           }
356         ]
357       },
358       "identifier": {
359         "interfaceLanguage": "c++",
360         "precise": "c:@S@Foo@F@getBar#1"
361       },
362       "kind": {
363         "displayName": "Instance Method",
364         "identifier": "c++.method"
365       },
366       "location": {
367         "position": {
368           "character": 16,
369           "line": 9
370         },
371         "uri": "file://INPUT_DIR/input.h"
372       },
373       "names": {
374         "navigator": [
375           {
376             "kind": "identifier",
377             "spelling": "getBar"
378           }
379         ],
380         "subHeading": [
381           {
382             "kind": "identifier",
383             "spelling": "getBar"
384           }
385         ],
386         "title": "getBar"
387       },
388       "pathComponents": [
389         "Foo",
390         "getBar"
391       ]
392     },
393     {
394       "accessLevel": "public",
395       "declarationFragments": [
396         {
397           "kind": "keyword",
398           "spelling": "static"
399         },
400         {
401           "kind": "text",
402           "spelling": " "
403         },
404         {
405           "kind": "typeIdentifier",
406           "preciseIdentifier": "c:d",
407           "spelling": "double"
408         },
409         {
410           "kind": "text",
411           "spelling": " "
412         },
413         {
414           "kind": "identifier",
415           "spelling": "getFoo"
416         },
417         {
418           "kind": "text",
419           "spelling": "();"
420         }
421       ],
422       "functionSignature": {
423         "returns": [
424           {
425             "kind": "typeIdentifier",
426             "preciseIdentifier": "c:d",
427             "spelling": "double"
428           }
429         ]
430       },
431       "identifier": {
432         "interfaceLanguage": "c++",
433         "precise": "c:@S@Foo@F@getFoo#S"
434       },
435       "kind": {
436         "displayName": "Static Method",
437         "identifier": "c++.type.method"
438       },
439       "location": {
440         "position": {
441           "character": 16,
442           "line": 6
443         },
444         "uri": "file://INPUT_DIR/input.h"
445       },
446       "names": {
447         "navigator": [
448           {
449             "kind": "identifier",
450             "spelling": "getFoo"
451           }
452         ],
453         "subHeading": [
454           {
455             "kind": "identifier",
456             "spelling": "getFoo"
457           }
458         ],
459         "title": "getFoo"
460       },
461       "pathComponents": [
462         "Foo",
463         "getFoo"
464       ]
465     }
466   ]
467 }
468