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