20 Commits

Author SHA1 Message Date
Jan Svoboda
98e6deb62c [clang][tools] Use FileEntryRef in include_cleaner::Header 2023-09-09 09:54:13 -07:00
David Goldman
9fe632ba18 [clang][HeaderSearch] Treat framework headers as Angled for suggestPath
- Rename the IsSystem flag to be IsAngled since that's how callers
  actually use the flag.

- Since frameworks by convention use <> style includes, make sure
  we treat them as Angled

Also update clangd's custom logic for frameworks accordingly.

Differential Revision: https://reviews.llvm.org/D156704
2023-08-09 15:51:02 -04:00
Haojian Wu
3b59842a72 [include-cleaner] Reorder SymbolReference fields to avoid padding space, NFC
This will bring down the size from 40 bytes to 32 bytes.

Differential Revision: https://reviews.llvm.org/D153018
2023-06-16 10:21:44 +02:00
Haojian Wu
7de541235f [include-cleaner] NFC, use const HeaderSearch when possible. 2023-06-01 15:26:19 +02:00
Kadir Cetinkaya
749c6a7083
[include-cleaner] Ranking of providers based on hints
Introduce signals to rank providers of a symbol.

Differential Revision: https://reviews.llvm.org/D139921
2023-01-23 15:22:47 +01:00
serge-sans-paille
984b800a03
Move from llvm::makeArrayRef to ArrayRef deduction guides - last part
This is a follow-up to https://reviews.llvm.org/D140896, split into
several parts as it touches a lot of files.

Differential Revision: https://reviews.llvm.org/D141298
2023-01-10 11:47:43 +01:00
Haojian Wu
bf6e655162 [include-cleaner] Filter out references that not spelled in the main file.
A HTML report of gtest after this patch:
cf05a50351/RecordTest.html

Differential Revision: https://reviews.llvm.org/D138779
2022-12-09 12:59:34 +01:00
Kadir Cetinkaya
29a8eec1f9
[include-cleaner] Make use of locateSymbol in WalkUsed and HTMLReport
Depens on D135953

Differential Revision: https://reviews.llvm.org/D138200
2022-12-06 15:03:11 +01:00
Sam McCall
d3714c2b27 [include-cleaner] Move RecordedPP::RecordedIncludes -> Includes in Types.h. NFC
Requiring everything that wants to match Includes to depend on Record is weird.
This isn't lightweight enough that it feels perfect in Types, could be its own
header instead. But pragmatically it doesn't add bad deps, and is widely used.

Differential Revision: https://reviews.llvm.org/D139014
2022-11-30 18:14:55 +01:00
Sam McCall
9961fa1653 [include-cleaner] Record whether includes are spelled with <angle> quotes
This is needed to accurately remove headers with tooling::IncludeHeaders in the
rare cases where <foo> and "foo" resolve to something different.

This is also nice to have in HTML report and command-line -print=changes output.

Differential Revision: https://reviews.llvm.org/D139018
2022-11-30 18:13:10 +01:00
Kazu Hirata
9c8a6a1627 [include-cleaner] Fix a warning
This patch fixes:

  clang-tools-extra/include-cleaner/lib/HTMLReport.cpp:240:51: error:
  missing field 'Locations' initializer
  [-Werror,-Wmissing-field-initializers]
2022-11-25 09:51:25 -08:00
Sam McCall
9d5e82e75c [include-cleaner] Make HTMLReport impl simpler/safer. NFC
Targets and Refs are 1:1, so merge them.

Don't sort Refs array we keep indices into. (Currently we're done using
those indices by the time we sort, but this is fragile)
2022-11-25 13:12:20 +01:00
Sam McCall
6a95e67323 [include-cleaner] HTMLReport shows headers that would be inserted
Demo: 7911d8251c/PathMapping.cpp.html

Header insertion doesn't actually work that well (not this patch's fault):
- we don't have ranking of locations/headers yet, so inserted header is pretty
  random
- on my system, we get a lot of absolute "/usr/bin/../include/..." paths.
  This is a HeaderSearch bug introduced in D60873 that I'll send a fix for

Differential Revision: https://reviews.llvm.org/D138676
2022-11-25 11:57:35 +01:00
Sam McCall
3e658abd41 [include-cleaner] Show details for #include directives (used/unused)
Differential Revision: https://reviews.llvm.org/D138649
2022-11-24 15:36:44 +01:00
Sam McCall
19ab2a671e [include-cleaner] Show includes matched by refs in HTML report.
Demo: 8736e64c45/ASTTests.html%25202

Differential Revision: https://reviews.llvm.org/D138219
2022-11-23 13:41:24 +01:00
Simon Pilgrim
6faf5d7245 Fix MSVC "not all control paths return a value" warning. NFC. 2022-11-17 17:19:41 +00:00
Sam McCall
2675773258 [include-cleaner] add macro symbols and implicit refs to HTML report
Demo: 8c5c5ad927/ASTTests.html

Differential Revision: https://reviews.llvm.org/D137677
2022-11-17 17:29:41 +01:00
Kadir Cetinkaya
d19ba74dee
[Includecleaner] Introduce RefType to ast walking
RefTypes are distinct categories for each reference to a symbol. They
are signals indicating strength of a reference, that'll enable different
decision making based on the finding being provided.

There are 3 kinds of ref types:
- Explicit, the reference is spelled in the code.
- Implicit, the reference is not directly visible in the code.
- Ambigious, the reference exists but can't be proven as used (e.g.
  overloads brought in by a using decl but not used by the code).

Differential Revision: https://reviews.llvm.org/D135859
2022-11-08 16:29:31 +01:00
Sam McCall
25bac38a02 [include-cleaner] Add line numbers to HTML output 2022-10-19 00:21:33 +02:00
Sam McCall
6fa0e026c8 [include-cleaner] Add include-cleaner tool, with initial HTML report
The immediate goal is to start producing an HTML report to debug and explain
include-cleaner recommendations.
For now, this includes only the lowest-level piece: a list of the references
found in the source code.

How this fits into future ideas:
 - under refs we can also show the headers providing the symbol, which includes
   match those headers etc
 - we can also annotate the #include lines with which symbols they cover, and
   add whichever includes we're suggesting too
 - the include-cleaner tool will likely have modes where it emits diagnostics
   and/or applies edits, so the HTML report is behind a flag

Differential Revision: https://reviews.llvm.org/D135956
2022-10-18 18:09:41 +02:00