1//===-- CanonicalIncludes.h - remap #include headers-------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "CanonicalIncludes.h"
10#include "clang/Basic/FileEntry.h"
11#include "clang/Basic/LangOptions.h"
12#include "llvm/ADT/StringRef.h"
13#include "llvm/Support/Path.h"
14
15namespace clang {
16namespace clangd {
17namespace {
18const std::pair<llvm::StringRef, llvm::StringRef> IncludeMappings[] = {
19 {"include/__stdarg___gnuc_va_list.h", "<cstdarg>"},
20 {"include/__stdarg___va_copy.h", "<cstdarg>"},
21 {"include/__stdarg_va_arg.h", "<cstdarg>"},
22 {"include/__stdarg_va_copy.h", "<cstdarg>"},
23 {"include/__stdarg_va_list.h", "<cstdarg>"},
24 {"include/__stddef_max_align_t.h", "<cstddef>"},
25 {"include/__stddef_null.h", "<cstddef>"},
26 {"include/__stddef_nullptr_t.h", "<cstddef>"},
27 {"include/__stddef_offsetof.h", "<cstddef>"},
28 {"include/__stddef_ptrdiff_t.h", "<cstddef>"},
29 {"include/__stddef_rsize_t.h", "<cstddef>"},
30 {"include/__stddef_size_t.h", "<cstddef>"},
31 {"include/__stddef_unreachable.h", "<cstddef>"},
32 {"include/__stddef_wchar_t.h", "<cstddef>"},
33 {"include/__stddef_wint_t.h", "<cstddef>"},
34 {"include/__wmmintrin_aes.h", "<wmmintrin.h>"},
35 {"include/__wmmintrin_pclmul.h", "<wmmintrin.h>"},
36 {"include/adxintrin.h", "<immintrin.h>"},
37 {"include/ammintrin.h", "<ammintrin.h>"},
38 {"include/avx2intrin.h", "<immintrin.h>"},
39 {"include/avx512bwintrin.h", "<immintrin.h>"},
40 {"include/avx512cdintrin.h", "<immintrin.h>"},
41 {"include/avx512dqintrin.h", "<immintrin.h>"},
42 {"include/avx512erintrin.h", "<immintrin.h>"},
43 {"include/avx512fintrin.h", "<immintrin.h>"},
44 {"include/avx512ifmaintrin.h", "<immintrin.h>"},
45 {"include/avx512ifmavlintrin.h", "<immintrin.h>"},
46 {"include/avx512pfintrin.h", "<immintrin.h>"},
47 {"include/avx512vbmiintrin.h", "<immintrin.h>"},
48 {"include/avx512vbmivlintrin.h", "<immintrin.h>"},
49 {"include/avx512vlbwintrin.h", "<immintrin.h>"},
50 {"include/avx512vlcdintrin.h", "<immintrin.h>"},
51 {"include/avx512vldqintrin.h", "<immintrin.h>"},
52 {"include/avx512vlintrin.h", "<immintrin.h>"},
53 {"include/avxintrin.h", "<immintrin.h>"},
54 {"include/bmi2intrin.h", "<x86intrin.h>"},
55 {"include/bmiintrin.h", "<x86intrin.h>"},
56 {"include/emmintrin.h", "<emmintrin.h>"},
57 {"include/f16cintrin.h", "<emmintrin.h>"},
58 {"include/float.h", "<cfloat>"},
59 {"include/fma4intrin.h", "<x86intrin.h>"},
60 {"include/fmaintrin.h", "<immintrin.h>"},
61 {"include/fxsrintrin.h", "<immintrin.h>"},
62 {"include/ia32intrin.h", "<x86intrin.h>"},
63 {"include/immintrin.h", "<immintrin.h>"},
64 {"include/inttypes.h", "<cinttypes>"},
65 {"include/limits.h", "<climits>"},
66 {"include/lzcntintrin.h", "<x86intrin.h>"},
67 {"include/mm3dnow.h", "<mm3dnow.h>"},
68 {"include/mm_malloc.h", "<mm_malloc.h>"},
69 {"include/mmintrin.h", "<mmintrin>"},
70 {"include/mwaitxintrin.h", "<x86intrin.h>"},
71 {"include/pkuintrin.h", "<immintrin.h>"},
72 {"include/pmmintrin.h", "<pmmintrin.h>"},
73 {"include/popcntintrin.h", "<popcntintrin.h>"},
74 {"include/prfchwintrin.h", "<x86intrin.h>"},
75 {"include/rdseedintrin.h", "<x86intrin.h>"},
76 {"include/rtmintrin.h", "<immintrin.h>"},
77 {"include/shaintrin.h", "<immintrin.h>"},
78 {"include/smmintrin.h", "<smmintrin.h>"},
79 {"include/stdalign.h", "<cstdalign>"},
80 {"include/stdarg.h", "<cstdarg>"},
81 {"include/stdbool.h", "<cstdbool>"},
82 {"include/stddef.h", "<cstddef>"},
83 {"include/stdint.h", "<cstdint>"},
84 {"include/tbmintrin.h", "<x86intrin.h>"},
85 {"include/tmmintrin.h", "<tmmintrin.h>"},
86 {"include/wmmintrin.h", "<wmmintrin.h>"},
87 {"include/x86intrin.h", "<x86intrin.h>"},
88 {"include/xmmintrin.h", "<xmmintrin.h>"},
89 {"include/xopintrin.h", "<x86intrin.h>"},
90 {"include/xsavecintrin.h", "<immintrin.h>"},
91 {"include/xsaveintrin.h", "<immintrin.h>"},
92 {"include/xsaveoptintrin.h", "<immintrin.h>"},
93 {"include/xsavesintrin.h", "<immintrin.h>"},
94 {"include/xtestintrin.h", "<immintrin.h>"},
95 {"include/_G_config.h", "<cstdio>"},
96 {"include/assert.h", "<cassert>"},
97 {"algorithm", "<algorithm>"},
98 {"valarray", "<valarray>"},
99 {"array", "<array>"},
100 {"atomic", "<atomic>"},
101 {"backward/auto_ptr.h", "<memory>"},
102 {"backward/binders.h", "<string>"},
103 {"bits/algorithmfwd.h", "<algorithm>"},
104 {"bits/alloc_traits.h", "<memory>"},
105 {"bits/allocated_ptr.h", "<memory>"},
106 {"bits/allocator.h", "<allocator>"},
107 {"bits/atomic_base.h", "<atomic>"},
108 {"bits/atomic_lockfree_defines.h", "<exception>"},
109 {"bits/atomic_futex.h", "<atomic>"},
110 {"bits/basic_ios.h", "<ios>"},
111 {"bits/basic_ios.tcc", "<ios>"},
112 {"bits/basic_string.h", "<string>"},
113 {"bits/basic_string.tcc", "<string>"},
114 {"bits/char_traits.h", "<string>"},
115 {"bits/codecvt.h", "<locale>"},
116 {"bits/concept_check.h", "<numeric>"},
117 {"bits/cpp_type_traits.h", "<cmath>"},
118 {"bits/cxxabi_forced.h", "<cxxabi.h>"},
119 {"bits/deque.tcc", "<deque>"},
120 {"bits/exception.h", "<exception>"},
121 {"bits/exception_defines.h", "<exception>"},
122 {"bits/exception_ptr.h", "<exception>"},
123 {"bits/forward_list.h", "<forward_list>"},
124 {"bits/forward_list.tcc", "<forward_list>"},
125 {"bits/fstream.tcc", "<fstream>"},
126 {"bits/functexcept.h", "<list>"},
127 {"bits/functional_hash.h", "<functional>"},
128 {"bits/gslice.h", "<valarray>"},
129 {"bits/gslice_array.h", "<valarray>"},
130 {"bits/hash_bytes.h", "<typeinfo>"},
131 {"bits/hashtable.h", "<unordered_set>"},
132 {"bits/hashtable_policy.h", "<unordered_set>"},
133 {"bits/indirect_array.h", "<valarray>"},
134 {"bits/invoke.h", "<functional>"},
135 {"bits/ios_base.h", "<ios>"},
136 {"bits/istream.tcc", "<istream>"},
137 {"bits/list.tcc", "<list>"},
138 {"bits/locale_classes.h", "<locale>"},
139 {"bits/locale_classes.tcc", "<locale>"},
140 {"bits/locale_conv.h", "<locale>"},
141 {"bits/locale_facets.h", "<locale>"},
142 {"bits/locale_facets.tcc", "<locale>"},
143 {"bits/locale_facets_nonio.h", "<locale>"},
144 {"bits/locale_facets_nonio.tcc", "<locale>"},
145 {"bits/localefwd.h", "<locale>"},
146 {"bits/mask_array.h", "<valarray>"},
147 {"bits/memoryfwd.h", "<memory>"},
148 {"bits/move.h", "<utility>"},
149 {"bits/nested_exception.h", "<exception>"},
150 {"bits/ostream.tcc", "<ostream>"},
151 {"bits/ostream_insert.h", "<ostream>"},
152 {"bits/parse_numbers.h", "<chrono>"},
153 {"bits/postypes.h", "<ios>"},
154 {"bits/predefined_ops.h", "<algorithm>"},
155 {"bits/ptr_traits.h", "<memory>"},
156 {"bits/quoted_string.h", "<iomanip>"},
157 {"bits/random.h", "<random>"},
158 {"bits/random.tcc", "<random>"},
159 {"bits/range_access.h", "<iterator>"},
160 {"bits/refwrap.h", "<functional>"},
161 {"bits/regex.h", "<regex>"},
162 {"bits/regex_automaton.h", "<regex>"},
163 {"bits/regex_compiler.h", "<regex>"},
164 {"bits/regex_constants.h", "<regex>"},
165 {"bits/regex_cursor.h", "<regex>"},
166 {"bits/regex_error.h", "<regex>"},
167 {"bits/regex_executor.h", "<regex>"},
168 {"bits/regex_grep_matcher.h", "<regex>"},
169 {"bits/regex_grep_matcher.tcc", "<regex>"},
170 {"bits/regex_nfa.h", "<regex>"},
171 {"bits/regex_scanner.h", "<regex>"},
172 {"bits/shared_ptr.h", "<memory>"},
173 {"bits/shared_ptr_base.h", "<memory>"},
174 {"bits/shared_ptr_atomic.h", "<atomic>"},
175 {"bits/slice_array.h", "<valarray>"},
176 {"bits/sstream.tcc", "<sstream>"},
177 {"bits/std_abs.h", "<cmath>"},
178 {"bits/std_function.h", "<functional>"},
179 {"bits/std_mutex.h", "<mutex>"},
180 {"bits/stl_algo.h", "<algorithm>"},
181 {"bits/stl_algobase.h", "<algorithm>"},
182 {"bits/stl_bvector.h", "<vector>"},
183 {"bits/stl_construct.h", "<deque>"},
184 {"bits/stl_deque.h", "<deque>"},
185 {"bits/stl_function.h", "<functional>"},
186 {"bits/stl_heap.h", "<heap>"},
187 {"bits/stl_iterator.h", "<iterator>"},
188 {"bits/stl_iterator_base_funcs.h", "<iterator>"},
189 {"bits/stl_iterator_base_types.h", "<iterator>"},
190 {"bits/stl_list.h", "<list>"},
191 {"bits/stl_map.h", "<map>"},
192 {"bits/stl_multimap.h", "<map>"},
193 {"bits/stl_multiset.h", "<set>"},
194 {"bits/stl_numeric.h", "<numeric>"},
195 {"bits/stl_pair.h", "<utility>"},
196 {"bits/stl_queue.h", "<queue>"},
197 {"bits/stl_raw_storage_iter.h", "<memory>"},
198 {"bits/stl_relops.h", "<utility>"},
199 {"bits/stl_set.h", "<set>"},
200 {"bits/stl_stack.h", "<stack>"},
201 {"bits/stl_tempbuf.h", "<memory>"},
202 {"bits/stl_tree.h", "<map>"},
203 {"bits/stl_uninitialized.h", "<memory>"},
204 {"bits/stl_vector.h", "<vector>"},
205 {"bits/stream_iterator.h", "<iterator>"},
206 {"bits/streambuf.tcc", "<streambuf>"},
207 {"bits/streambuf_iterator.h", "<iterator>"},
208 {"bits/stringfwd.h", "<string>"},
209 {"bits/uniform_int_dist.h", "<random>"},
210 {"bits/unique_ptr.h", "<memory>"},
211 {"bits/unordered_map.h", "<unordered_map>"},
212 {"bits/unordered_set.h", "<unordered_set>"},
213 {"bits/uses_allocator.h", "<memory>"},
214 {"bits/valarray_after.h", "<valarray>"},
215 {"bits/valarray_array.h", "<valarray>"},
216 {"bits/valarray_array.tcc", "<valarray>"},
217 {"bits/valarray_before.h", "<valarray>"},
218 {"bits/vector.tcc", "<vector>"},
219 {"bitset", "<bitset>"},
220 {"ccomplex", "<ccomplex>"},
221 {"cctype", "<cctype>"},
222 {"cerrno", "<cerrno>"},
223 {"cfenv", "<cfenv>"},
224 {"cfloat", "<cfloat>"},
225 {"chrono", "<chrono>"},
226 {"cinttypes", "<cinttypes>"},
227 {"climits", "<climits>"},
228 {"clocale", "<clocale>"},
229 {"cmath", "<cmath>"},
230 {"complex", "<complex>"},
231 {"complex.h", "<complex.h>"},
232 {"condition_variable", "<condition_variable>"},
233 {"csetjmp", "<csetjmp>"},
234 {"csignal", "<csignal>"},
235 {"cstdalign", "<cstdalign>"},
236 {"cstdarg", "<cstdarg>"},
237 {"cstdbool", "<cstdbool>"},
238 {"cstdint", "<cstdint>"},
239 {"cstdio", "<cstdio>"},
240 {"cstdlib", "<cstdlib>"},
241 {"cstring", "<cstring>"},
242 {"ctgmath", "<ctgmath>"},
243 {"ctime", "<ctime>"},
244 {"cwchar", "<cwchar>"},
245 {"cwctype", "<cwctype>"},
246 {"cxxabi.h", "<cxxabi.h>"},
247 {"debug/debug.h", "<numeric>"},
248 {"debug/map.h", "<map>"},
249 {"debug/multimap.h", "<multimap>"},
250 {"debug/multiset.h", "<multiset>"},
251 {"debug/set.h", "<set>"},
252 {"deque", "<deque>"},
253 {"exception", "<exception>"},
254 {"ext/alloc_traits.h", "<deque>"},
255 {"ext/atomicity.h", "<memory>"},
256 {"ext/concurrence.h", "<memory>"},
257 {"ext/new_allocator.h", "<string>"},
258 {"ext/numeric_traits.h", "<list>"},
259 {"ext/string_conversions.h", "<string>"},
260 {"ext/type_traits.h", "<cmath>"},
261 {"fenv.h", "<fenv.h>"},
262 {"forward_list", "<forward_list>"},
263 {"fstream", "<fstream>"},
264 {"functional", "<functional>"},
265 {"future", "<future>"},
266 {"initializer_list", "<initializer_list>"},
267 {"iomanip", "<iomanip>"},
268 {"ios", "<ios>"},
269 {"iosfwd", "<iosfwd>"},
270 {"iostream", "<iostream>"},
271 {"istream", "<istream>"},
272 {"iterator", "<iterator>"},
273 {"limits", "<limits>"},
274 {"list", "<list>"},
275 {"locale", "<locale>"},
276 {"map", "<map>"},
277 {"memory", "<memory>"},
278 {"shared_mutex", "<shared_mutex>"},
279 {"mutex", "<mutex>"},
280 {"new", "<new>"},
281 {"numeric", "<numeric>"},
282 {"ostream", "<ostream>"},
283 {"queue", "<queue>"},
284 {"random", "<random>"},
285 {"ratio", "<ratio>"},
286 {"regex", "<regex>"},
287 {"scoped_allocator", "<scoped_allocator>"},
288 {"set", "<set>"},
289 {"sstream", "<sstream>"},
290 {"stack", "<stack>"},
291 {"stdexcept", "<stdexcept>"},
292 {"streambuf", "<streambuf>"},
293 {"string", "<string>"},
294 {"system_error", "<system_error>"},
295 {"tgmath.h", "<tgmath.h>"},
296 {"thread", "<thread>"},
297 {"tuple", "<tuple>"},
298 {"type_traits", "<type_traits>"},
299 {"typeindex", "<typeindex>"},
300 {"typeinfo", "<typeinfo>"},
301 {"unordered_map", "<unordered_map>"},
302 {"unordered_set", "<unordered_set>"},
303 {"utility", "<utility>"},
304 {"vector", "<vector>"},
305 {"include/complex.h", "<complex.h>"},
306 {"include/ctype.h", "<cctype>"},
307 {"include/errno.h", "<cerrno>"},
308 {"include/fenv.h", "<fenv.h>"},
309 {"include/libio.h", "<cstdio>"},
310 {"include/locale.h", "<clocale>"},
311 {"include/math.h", "<cmath>"},
312 {"include/setjmp.h", "<csetjmp>"},
313 {"include/signal.h", "<csignal>"},
314 {"include/stdio.h", "<cstdio>"},
315 {"include/stdlib.h", "<cstdlib>"},
316 {"include/string.h", "<cstring>"},
317 {"include/time.h", "<ctime>"},
318 {"include/wchar.h", "<cwchar>"},
319 {"include/wctype.h", "<cwctype>"},
320 {"bits/cmathcalls.h", "<complex.h>"},
321 {"bits/errno.h", "<cerrno>"},
322 {"bits/fenv.h", "<fenv.h>"},
323 {"bits/huge_val.h", "<cmath>"},
324 {"bits/huge_valf.h", "<cmath>"},
325 {"bits/huge_vall.h", "<cmath>"},
326 {"bits/inf.h", "<cmath>"},
327 {"bits/local_lim.h", "<climits>"},
328 {"bits/locale.h", "<clocale>"},
329 {"bits/mathcalls.h", "<math.h>"},
330 {"bits/mathdef.h", "<cmath>"},
331 {"bits/nan.h", "<cmath>"},
332 {"bits/posix1_lim.h", "<climits>"},
333 {"bits/posix2_lim.h", "<climits>"},
334 {"bits/setjmp.h", "<csetjmp>"},
335 {"bits/sigaction.h", "<csignal>"},
336 {"bits/sigcontext.h", "<csignal>"},
337 {"bits/siginfo.h", "<csignal>"},
338 {"bits/signum.h", "<csignal>"},
339 {"bits/sigset.h", "<csignal>"},
340 {"bits/sigstack.h", "<csignal>"},
341 {"bits/stdint-intn.h", "<cstdint>"},
342 {"bits/stdint-uintn.h", "<cstdint>"},
343 {"bits/stdio_lim.h", "<cstdio>"},
344 {"bits/sys_errlist.h", "<cstdio>"},
345 {"bits/time.h", "<ctime>"},
346 {"bits/timex.h", "<ctime>"},
347 {"bits/typesizes.h", "<cstdio>"},
348 {"bits/wchar.h", "<cwchar>"},
349 {"bits/wordsize.h", "<csetjmp>"},
350 {"bits/xopen_lim.h", "<climits>"},
351 {"include/xlocale.h", "<cstring>"},
352 {"bits/atomic_word.h", "<memory>"},
353 {"bits/basic_file.h", "<fstream>"},
354 {"bits/c\\+\\+allocator.h", "<string>"},
355 {"bits/c\\+\\+config.h", "<cstddef>"},
356 {"bits/c\\+\\+io.h", "<ios>"},
357 {"bits/c\\+\\+locale.h", "<locale>"},
358 {"bits/cpu_defines.h", "<iosfwd>"},
359 {"bits/ctype_base.h", "<locale>"},
360 {"bits/cxxabi_tweaks.h", "<cxxabi.h>"},
361 {"bits/error_constants.h", "<system_error>"},
362 {"bits/gthr-default.h", "<memory>"},
363 {"bits/gthr.h", "<memory>"},
364 {"bits/opt_random.h", "<random>"},
365 {"bits/os_defines.h", "<iosfwd>"},
366 // GNU C headers
367 {"include/aio.h", "<aio.h>"},
368 {"include/aliases.h", "<aliases.h>"},
369 {"include/alloca.h", "<alloca.h>"},
370 {"include/ar.h", "<ar.h>"},
371 {"include/argp.h", "<argp.h>"},
372 {"include/argz.h", "<argz.h>"},
373 {"include/arpa/nameser.h", "<resolv.h>"},
374 {"include/arpa/nameser_compat.h", "<resolv.h>"},
375 {"include/byteswap.h", "<byteswap.h>"},
376 {"include/cpio.h", "<cpio.h>"},
377 {"include/crypt.h", "<crypt.h>"},
378 {"include/dirent.h", "<dirent.h>"},
379 {"include/dlfcn.h", "<dlfcn.h>"},
380 {"include/elf.h", "<elf.h>"},
381 {"include/endian.h", "<endian.h>"},
382 {"include/envz.h", "<envz.h>"},
383 {"include/err.h", "<err.h>"},
384 {"include/error.h", "<error.h>"},
385 {"include/execinfo.h", "<execinfo.h>"},
386 {"include/fcntl.h", "<fcntl.h>"},
387 {"include/features.h", "<features.h>"},
388 {"include/fmtmsg.h", "<fmtmsg.h>"},
389 {"include/fnmatch.h", "<fnmatch.h>"},
390 {"include/fstab.h", "<fstab.h>"},
391 {"include/fts.h", "<fts.h>"},
392 {"include/ftw.h", "<ftw.h>"},
393 {"include/gconv.h", "<gconv.h>"},
394 {"include/getopt.h", "<getopt.h>"},
395 {"include/glob.h", "<glob.h>"},
396 {"include/grp.h", "<grp.h>"},
397 {"include/gshadow.h", "<gshadow.h>"},
398 {"include/iconv.h", "<iconv.h>"},
399 {"include/ifaddrs.h", "<ifaddrs.h>"},
400 {"include/kdb.h", "<kdb.h>"},
401 {"include/langinfo.h", "<langinfo.h>"},
402 {"include/libgen.h", "<libgen.h>"},
403 {"include/libintl.h", "<libintl.h>"},
404 {"include/link.h", "<link.h>"},
405 {"include/malloc.h", "<malloc.h>"},
406 {"include/mcheck.h", "<mcheck.h>"},
407 {"include/memory.h", "<memory.h>"},
408 {"include/mntent.h", "<mntent.h>"},
409 {"include/monetary.h", "<monetary.h>"},
410 {"include/mqueue.h", "<mqueue.h>"},
411 {"include/netdb.h", "<netdb.h>"},
412 {"include/netinet/in.h", "<netinet/in.h>"},
413 {"include/nl_types.h", "<nl_types.h>"},
414 {"include/nss.h", "<nss.h>"},
415 {"include/obstack.h", "<obstack.h>"},
416 {"include/panel.h", "<panel.h>"},
417 {"include/paths.h", "<paths.h>"},
418 {"include/printf.h", "<printf.h>"},
419 {"include/profile.h", "<profile.h>"},
420 {"include/pthread.h", "<pthread.h>"},
421 {"include/pty.h", "<pty.h>"},
422 {"include/pwd.h", "<pwd.h>"},
423 {"include/re_comp.h", "<re_comp.h>"},
424 {"include/regex.h", "<regex.h>"},
425 {"include/regexp.h", "<regexp.h>"},
426 {"include/resolv.h", "<resolv.h>"},
427 {"include/rpc/netdb.h", "<netdb.h>"},
428 {"include/sched.h", "<sched.h>"},
429 {"include/search.h", "<search.h>"},
430 {"include/semaphore.h", "<semaphore.h>"},
431 {"include/sgtty.h", "<sgtty.h>"},
432 {"include/shadow.h", "<shadow.h>"},
433 {"include/spawn.h", "<spawn.h>"},
434 {"include/stab.h", "<stab.h>"},
435 {"include/stdc-predef.h", "<stdc-predef.h>"},
436 {"include/stdio_ext.h", "<stdio_ext.h>"},
437 {"include/strings.h", "<strings.h>"},
438 {"include/stropts.h", "<stropts.h>"},
439 {"include/sudo_plugin.h", "<sudo_plugin.h>"},
440 {"include/sysexits.h", "<sysexits.h>"},
441 {"include/tar.h", "<tar.h>"},
442 {"include/tcpd.h", "<tcpd.h>"},
443 {"include/term.h", "<term.h>"},
444 {"include/term_entry.h", "<term_entry.h>"},
445 {"include/termcap.h", "<termcap.h>"},
446 {"include/termios.h", "<termios.h>"},
447 {"include/thread_db.h", "<thread_db.h>"},
448 {"include/tic.h", "<tic.h>"},
449 {"include/ttyent.h", "<ttyent.h>"},
450 {"include/uchar.h", "<uchar.h>"},
451 {"include/ucontext.h", "<ucontext.h>"},
452 {"include/ulimit.h", "<ulimit.h>"},
453 {"include/unctrl.h", "<unctrl.h>"},
454 {"include/unistd.h", "<unistd.h>"},
455 {"include/utime.h", "<utime.h>"},
456 {"include/utmp.h", "<utmp.h>"},
457 {"include/utmpx.h", "<utmpx.h>"},
458 {"include/values.h", "<values.h>"},
459 {"include/wordexp.h", "<wordexp.h>"},
460 {"fpu_control.h", "<fpu_control.h>"},
461 {"ieee754.h", "<ieee754.h>"},
462 {"gnu/lib-names.h", "<gnu/lib-names.h>"},
463 {"gnu/libc-version.h", "<gnu/libc-version.h>"},
464 {"gnu/option-groups.h", "<gnu/option-groups.h>"},
465 {"gnu/stubs-32.h", "<gnu/stubs-32.h>"},
466 {"gnu/stubs-64.h", "<gnu/stubs-64.h>"},
467 {"gnu/stubs-x32.h", "<gnu/stubs-x32.h>"},
468 {"include/rpc/auth_des.h", "<rpc/auth_des.h>"},
469 {"include/rpc/rpc_msg.h", "<rpc/rpc_msg.h>"},
470 {"include/rpc/pmap_clnt.h", "<rpc/pmap_clnt.h>"},
471 {"include/rpc/rpc.h", "<rpc/rpc.h>"},
472 {"include/rpc/types.h", "<rpc/types.h>"},
473 {"include/rpc/auth_unix.h", "<rpc/auth_unix.h>"},
474 {"include/rpc/key_prot.h", "<rpc/key_prot.h>"},
475 {"include/rpc/pmap_prot.h", "<rpc/pmap_prot.h>"},
476 {"include/rpc/auth.h", "<rpc/auth.h>"},
477 {"include/rpc/svc_auth.h", "<rpc/svc_auth.h>"},
478 {"include/rpc/xdr.h", "<rpc/xdr.h>"},
479 {"include/rpc/pmap_rmt.h", "<rpc/pmap_rmt.h>"},
480 {"include/rpc/des_crypt.h", "<rpc/des_crypt.h>"},
481 {"include/rpc/svc.h", "<rpc/svc.h>"},
482 {"include/rpc/rpc_des.h", "<rpc/rpc_des.h>"},
483 {"include/rpc/clnt.h", "<rpc/clnt.h>"},
484 {"include/scsi/scsi.h", "<scsi/scsi.h>"},
485 {"include/scsi/sg.h", "<scsi/sg.h>"},
486 {"include/scsi/scsi_ioctl.h", "<scsi/scsi_ioctl>"},
487 {"include/netrose/rose.h", "<netrose/rose.h>"},
488 {"include/nfs/nfs.h", "<nfs/nfs.h>"},
489 {"include/netatalk/at.h", "<netatalk/at.h>"},
490 {"include/netinet/ether.h", "<netinet/ether.h>"},
491 {"include/netinet/icmp6.h", "<netinet/icmp6.h>"},
492 {"include/netinet/if_ether.h", "<netinet/if_ether.h>"},
493 {"include/netinet/if_fddi.h", "<netinet/if_fddi.h>"},
494 {"include/netinet/if_tr.h", "<netinet/if_tr.h>"},
495 {"include/netinet/igmp.h", "<netinet/igmp.h>"},
496 {"include/netinet/in_systm.h", "<netinet/in_systm.h>"},
497 {"include/netinet/ip.h", "<netinet/ip.h>"},
498 {"include/netinet/ip6.h", "<netinet/ip6.h>"},
499 {"include/netinet/ip_icmp.h", "<netinet/ip_icmp.h>"},
500 {"include/netinet/tcp.h", "<netinet/tcp.h>"},
501 {"include/netinet/udp.h", "<netinet/udp.h>"},
502 {"include/netrom/netrom.h", "<netrom/netrom.h>"},
503 {"include/protocols/routed.h", "<protocols/routed.h>"},
504 {"include/protocols/rwhod.h", "<protocols/rwhod.h>"},
505 {"include/protocols/talkd.h", "<protocols/talkd.h>"},
506 {"include/protocols/timed.h", "<protocols/timed.h>"},
507 {"include/rpcsvc/klm_prot.x", "<rpcsvc/klm_prot.x>"},
508 {"include/rpcsvc/rstat.h", "<rpcsvc/rstat.h>"},
509 {"include/rpcsvc/spray.x", "<rpcsvc/spray.x>"},
510 {"include/rpcsvc/nlm_prot.x", "<rpcsvc/nlm_prot.x>"},
511 {"include/rpcsvc/nis_callback.x", "<rpcsvc/nis_callback.x>"},
512 {"include/rpcsvc/yp.h", "<rpcsvc/yp.h>"},
513 {"include/rpcsvc/yp.x", "<rpcsvc/yp.x>"},
514 {"include/rpcsvc/nfs_prot.h", "<rpcsvc/nfs_prot.h>"},
515 {"include/rpcsvc/rex.h", "<rpcsvc/rex.h>"},
516 {"include/rpcsvc/yppasswd.h", "<rpcsvc/yppasswd.h>"},
517 {"include/rpcsvc/rex.x", "<rpcsvc/rex.x>"},
518 {"include/rpcsvc/nis_tags.h", "<rpcsvc/nis_tags.h>"},
519 {"include/rpcsvc/nis_callback.h", "<rpcsvc/nis_callback.h>"},
520 {"include/rpcsvc/nfs_prot.x", "<rpcsvc/nfs_prot.x>"},
521 {"include/rpcsvc/bootparam_prot.x", "<rpcsvc/bootparam_prot.x>"},
522 {"include/rpcsvc/rusers.x", "<rpcsvc/rusers.x>"},
523 {"include/rpcsvc/rquota.x", "<rpcsvc/rquota.x>"},
524 {"include/rpcsvc/nis.h", "<rpcsvc/nis.h>"},
525 {"include/rpcsvc/nislib.h", "<rpcsvc/nislib.h>"},
526 {"include/rpcsvc/ypupd.h", "<rpcsvc/ypupd.h>"},
527 {"include/rpcsvc/bootparam.h", "<rpcsvc/bootparam.h>"},
528 {"include/rpcsvc/spray.h", "<rpcsvc/spray.h>"},
529 {"include/rpcsvc/key_prot.h", "<rpcsvc/key_prot.h>"},
530 {"include/rpcsvc/klm_prot.h", "<rpcsvc/klm_prot.h>"},
531 {"include/rpcsvc/sm_inter.h", "<rpcsvc/sm_inter.h>"},
532 {"include/rpcsvc/nlm_prot.h", "<rpcsvc/nlm_prot.h>"},
533 {"include/rpcsvc/yp_prot.h", "<rpcsvc/yp_prot.h>"},
534 {"include/rpcsvc/ypclnt.h", "<rpcsvc/ypclnt.h>"},
535 {"include/rpcsvc/rstat.x", "<rpcsvc/rstat.x>"},
536 {"include/rpcsvc/rusers.h", "<rpcsvc/rusers.h>"},
537 {"include/rpcsvc/key_prot.x", "<rpcsvc/key_prot.x>"},
538 {"include/rpcsvc/sm_inter.x", "<rpcsvc/sm_inter.x>"},
539 {"include/rpcsvc/rquota.h", "<rpcsvc/rquota.h>"},
540 {"include/rpcsvc/nis.x", "<rpcsvc/nis.x>"},
541 {"include/rpcsvc/bootparam_prot.h", "<rpcsvc/bootparam_prot.h>"},
542 {"include/rpcsvc/mount.h", "<rpcsvc/mount.h>"},
543 {"include/rpcsvc/mount.x", "<rpcsvc/mount.x>"},
544 {"include/rpcsvc/nis_object.x", "<rpcsvc/nis_object.x>"},
545 {"include/rpcsvc/yppasswd.x", "<rpcsvc/yppasswd.x>"},
546 {"sys/acct.h", "<sys/acct.h>"},
547 {"sys/auxv.h", "<sys/auxv.h>"},
548 {"sys/cdefs.h", "<sys/cdefs.h>"},
549 {"sys/debugreg.h", "<sys/debugreg.h>"},
550 {"sys/dir.h", "<sys/dir.h>"},
551 {"sys/elf.h", "<sys/elf.h>"},
552 {"sys/epoll.h", "<sys/epoll.h>"},
553 {"sys/eventfd.h", "<sys/eventfd.h>"},
554 {"sys/fanotify.h", "<sys/fanotify.h>"},
555 {"sys/file.h", "<sys/file.h>"},
556 {"sys/fsuid.h", "<sys/fsuid.h>"},
557 {"sys/gmon.h", "<sys/gmon.h>"},
558 {"sys/gmon_out.h", "<sys/gmon_out.h>"},
559 {"sys/inotify.h", "<sys/inotify.h>"},
560 {"sys/io.h", "<sys/io.h>"},
561 {"sys/ioctl.h", "<sys/ioctl.h>"},
562 {"sys/ipc.h", "<sys/ipc.h>"},
563 {"sys/kd.h", "<sys/kd.h>"},
564 {"sys/kdaemon.h", "<sys/kdaemon.h>"},
565 {"sys/klog.h", "<sys/klog.h>"},
566 {"sys/mman.h", "<sys/mman.h>"},
567 {"sys/mount.h", "<sys/mount.h>"},
568 {"sys/msg.h", "<sys/msg.h>"},
569 {"sys/mtio.h", "<sys/mtio.h>"},
570 {"sys/param.h", "<sys/param.h>"},
571 {"sys/pci.h", "<sys/pci.h>"},
572 {"sys/perm.h", "<sys/perm.h>"},
573 {"sys/personality.h", "<sys/personality.h>"},
574 {"sys/poll.h", "<sys/poll.h>"},
575 {"sys/prctl.h", "<sys/prctl.h>"},
576 {"sys/procfs.h", "<sys/procfs.h>"},
577 {"sys/profil.h", "<sys/profil.h>"},
578 {"sys/ptrace.h", "<sys/ptrace.h>"},
579 {"sys/queue.h", "<sys/queue.h>"},
580 {"sys/quota.h", "<sys/quota.h>"},
581 {"sys/raw.h", "<sys/raw.h>"},
582 {"sys/reboot.h", "<sys/reboot.h>"},
583 {"sys/reg.h", "<sys/reg.h>"},
584 {"sys/resource.h", "<sys/resource.h>"},
585 {"sys/select.h", "<sys/select.h>"},
586 {"sys/sem.h", "<sys/sem.h>"},
587 {"sys/sendfile.h", "<sys/sendfile.h>"},
588 {"sys/shm.h", "<sys/shm.h>"},
589 {"sys/signalfd.h", "<sys/signalfd.h>"},
590 {"sys/socket.h", "<sys/socket.h>"},
591 {"sys/stat.h", "<sys/stat.h>"},
592 {"sys/statfs.h", "<sys/statfs.h>"},
593 {"sys/statvfs.h", "<sys/statvfs.h>"},
594 {"sys/swap.h", "<sys/swap.h>"},
595 {"sys/syscall.h", "<sys/syscall.h>"},
596 {"sys/sysctl.h", "<sys/sysctl.h>"},
597 {"sys/sysinfo.h", "<sys/sysinfo.h>"},
598 {"sys/syslog.h", "<sys/syslog.h>"},
599 {"sys/sysmacros.h", "<sys/sysmacros.h>"},
600 {"sys/termios.h", "<sys/termios.h>"},
601 {"sys/time.h", "<sys/select.h>"},
602 {"sys/timeb.h", "<sys/timeb.h>"},
603 {"sys/timerfd.h", "<sys/timerfd.h>"},
604 {"sys/times.h", "<sys/times.h>"},
605 {"sys/timex.h", "<sys/timex.h>"},
606 {"sys/ttychars.h", "<sys/ttychars.h>"},
607 {"sys/ttydefaults.h", "<sys/ttydefaults.h>"},
608 {"sys/types.h", "<sys/types.h>"},
609 {"sys/ucontext.h", "<sys/ucontext.h>"},
610 {"sys/uio.h", "<sys/uio.h>"},
611 {"sys/un.h", "<sys/un.h>"},
612 {"sys/user.h", "<sys/user.h>"},
613 {"sys/ustat.h", "<sys/ustat.h>"},
614 {"sys/utsname.h", "<sys/utsname.h>"},
615 {"sys/vlimit.h", "<sys/vlimit.h>"},
616 {"sys/vm86.h", "<sys/vm86.h>"},
617 {"sys/vtimes.h", "<sys/vtimes.h>"},
618 {"sys/wait.h", "<sys/wait.h>"},
619 {"sys/xattr.h", "<sys/xattr.h>"},
620 {"bits/epoll.h", "<sys/epoll.h>"},
621 {"bits/eventfd.h", "<sys/eventfd.h>"},
622 {"bits/inotify.h", "<sys/inotify.h>"},
623 {"bits/ipc.h", "<sys/ipc.h>"},
624 {"bits/ipctypes.h", "<sys/ipc.h>"},
625 {"bits/mman-linux.h", "<sys/mman.h>"},
626 {"bits/mman.h", "<sys/mman.h>"},
627 {"bits/msq.h", "<sys/msg.h>"},
628 {"bits/resource.h", "<sys/resource.h>"},
629 {"bits/sem.h", "<sys/sem.h>"},
630 {"bits/shm.h", "<sys/shm.h>"},
631 {"bits/signalfd.h", "<sys/signalfd.h>"},
632 {"bits/statfs.h", "<sys/statfs.h>"},
633 {"bits/statvfs.h", "<sys/statvfs.h>"},
634 {"bits/timerfd.h", "<sys/timerfd.h>"},
635 {"bits/utsname.h", "<sys/utsname.h>"},
636 {"bits/auxv.h", "<sys/auxv.h>"},
637 {"bits/byteswap-16.h", "<byteswap.h>"},
638 {"bits/byteswap.h", "<byteswap.h>"},
639 {"bits/confname.h", "<unistd.h>"},
640 {"bits/dirent.h", "<dirent.h>"},
641 {"bits/dlfcn.h", "<dlfcn.h>"},
642 {"bits/elfclass.h", "<link.h>"},
643 {"bits/endian.h", "<endian.h>"},
644 {"bits/environments.h", "<unistd.h>"},
645 {"bits/fcntl-linux.h", "<fcntl.h>"},
646 {"bits/fcntl.h", "<fcntl.h>"},
647 {"bits/in.h", "<netinet/in.h>"},
648 {"bits/ioctl-types.h", "<sys/ioctl.h>"},
649 {"bits/ioctls.h", "<sys/ioctl.h>"},
650 {"bits/link.h", "<link.h>"},
651 {"bits/mqueue.h", "<mqueue.h>"},
652 {"bits/netdb.h", "<netdb.h>"},
653 {"bits/param.h", "<sys/param.h>"},
654 {"bits/poll.h", "<sys/poll.h>"},
655 {"bits/posix_opt.h", "<bits/posix_opt.h>"},
656 {"bits/pthreadtypes.h", "<pthread.h>"},
657 {"bits/sched.h", "<sched.h>"},
658 {"bits/select.h", "<sys/select.h>"},
659 {"bits/semaphore.h", "<semaphore.h>"},
660 {"bits/sigthread.h", "<pthread.h>"},
661 {"bits/sockaddr.h", "<sys/socket.h>"},
662 {"bits/socket.h", "<sys/socket.h>"},
663 {"bits/socket_type.h", "<sys/socket.h>"},
664 {"bits/stab.def", "<stab.h>"},
665 {"bits/stat.h", "<sys/stat.h>"},
666 {"bits/stropts.h", "<stropts.h>"},
667 {"bits/syscall.h", "<sys/syscall.h>"},
668 {"bits/syslog-path.h", "<sys/syslog.h>"},
669 {"bits/termios.h", "<termios.h>"},
670 {"bits/types.h", "<sys/types.h>"},
671 {"bits/types/siginfo_t.h", "<sys/siginfo.h>"},
672 {"bits/types/struct_itimerspec.h", "<sys/time.h>"},
673 {"bits/types/struct_rusage.h", "<sys/resource.h>"},
674 {"bits/uio.h", "<sys/uio.h>"},
675 {"bits/ustat.h", "<sys/ustat.h>"},
676 {"bits/utmp.h", "<utmp.h>"},
677 {"bits/utmpx.h", "<utmpx.h>"},
678 {"bits/waitflags.h", "<sys/wait.h>"},
679 {"bits/waitstatus.h", "<sys/wait.h>"},
680 {"bits/xtitypes.h", "<stropts.h>"},
681};
682
683} // namespace
684
685/// The maximum number of path components in a key from StdSuffixHeaderMapping.
686/// Used to minimize the number of lookups in suffix path mappings.
687constexpr int MaxSuffixComponents = 3;
688
689llvm::StringRef CanonicalIncludes::mapHeader(llvm::StringRef HeaderPath) const {
690 if (!StdSuffixHeaderMapping)
691 return "";
692
693 int Components = 1;
694
695 // FIXME: check that this works on Windows and add tests.
696 for (auto It = llvm::sys::path::rbegin(path: HeaderPath),
697 End = llvm::sys::path::rend(path: HeaderPath);
698 It != End && Components <= MaxSuffixComponents; ++It, ++Components) {
699 auto SubPath = HeaderPath.substr(Start: It->data() - HeaderPath.begin());
700 auto MappingIt = StdSuffixHeaderMapping->find(Key: SubPath);
701 if (MappingIt != StdSuffixHeaderMapping->end())
702 return MappingIt->second;
703 }
704 return "";
705}
706
707void CanonicalIncludes::addSystemHeadersMapping(const LangOptions &Language) {
708 // FIXME: remove the std header mapping once we support ambiguous symbols, now
709 // it serves as a fallback to disambiguate:
710 // - symbols with multiple headers (e.g. std::move)
711 static const auto *SystemHeaderMap = [] {
712 const size_t Size = sizeof(IncludeMappings) / sizeof(IncludeMappings[0]);
713 auto *HeaderMap = new llvm::StringMap<llvm::StringRef>(Size);
714 for (size_t I = 0; I < Size; I++) {
715 auto Result = HeaderMap->insert(KV: IncludeMappings[I]);
716 (void)Result;
717
718 assert(Result.second && "Duplicate in include mappings");
719 }
720 return HeaderMap;
721 }();
722
723 // Check MaxSuffixComponents constant is correct.
724 assert(llvm::all_of(SystemHeaderMap->keys(), [](llvm::StringRef Path) {
725 return std::distance(
726 llvm::sys::path::begin(Path, llvm::sys::path::Style::posix),
727 llvm::sys::path::end(Path)) <= MaxSuffixComponents;
728 }));
729 // ... and precise.
730 assert(llvm::any_of(SystemHeaderMap->keys(), [](llvm::StringRef Path) {
731 return std::distance(
732 llvm::sys::path::begin(Path, llvm::sys::path::Style::posix),
733 llvm::sys::path::end(Path)) == MaxSuffixComponents;
734 }));
735
736 // FIXME: Suffix mapping contains invalid entries for C, so only enable it for
737 // CPP.
738 if (Language.CPlusPlus)
739 StdSuffixHeaderMapping = SystemHeaderMap;
740}
741
742} // namespace clangd
743} // namespace clang
744

source code of clang-tools-extra/clangd/index/CanonicalIncludes.cpp