8 Commits

Author SHA1 Message Date
Haojian Wu
4702d8d9cf [include-cleaner] Print the line number of removal #includes.
I found that this information is helpful when using this tool.

Reviewed By: kadircet

Differential Revision: https://reviews.llvm.org/D139715
2022-12-14 10:52:13 +01:00
Haojian Wu
14af1ad4ee [include-cleaner] Add two command-line flags to the include-cleaner
category.
2022-12-05 12:20:34 +01:00
Sam McCall
1a8dd74258 [include-cleaner] clang-include-cleaner can print/apply edits
This adds command-line flags to the tool:
+ -print: prints changed source code
+ -print=changes: prints headers added/removed
+ -edit: rewrites code in place
+ -insert=0/-remove=0: disables additions/deletions for the above

These are supported by a couple of new functions dumped into Analysis:
analyze() sits on top of walkUsed and makes used/unused decisions for
Includes. fixIncludes() applies those results to source code.

Differential Revision: https://reviews.llvm.org/D139013
2022-12-02 13:16:58 +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
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
Fangrui Song
f962dafbbd [include-cleaner] Fix -DBUILD_SHARED_LIBS=on build
and apply an include-cleaner fix for the tool itself:)

addPPCallbacks requires the vtable of PPChainedCallbacks and needs a clangLex
dependency.
2022-11-18 00:56:04 +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
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