clang-tools 10.0.0

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