17 Commits

Author SHA1 Message Date
Kadir Cetinkaya
b76cc30e15
[include-cleaner] Respect IWYU pragmas during analyze
Fixes https://github.com/llvm/llvm-project/issues/59541.

Differential Revision: https://reviews.llvm.org/D140380
2022-12-20 10:47:22 +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
Haojian Wu
526fb5fae7 [include-cleaner] Fix walkUsed only report a single macro ref.
The fix 962343a979d51cea9363167e9121c446abbdfdbc was reverted during a
rebase of a later patch. Added a test.
2022-12-09 12:12:16 +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
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
Haojian Wu
962343a979 [include-cleaner] Fix walkUsed only report a single macro ref. 2022-11-28 10:12:10 +01: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
e5739eb4f8
[include-cleaner] Defer decl->stdlib conversion into decl->location conversion
We preserve decls for stdlib symbols after this patch in symbol. That
way we have a more unified view of stdlib and regular decls and can provide
reacher information in applications.

Differential Revision: https://reviews.llvm.org/D138134
2022-11-16 16:52:39 +01:00
Haojian Wu
e000c2bce7 [include-cleaner] NFC, move the macro location fixme to findHeaders. 2022-11-11 14:55:29 +01:00
Sam McCall
7943169273 [clang-include-cleaner] make SymbolLocation a real class, move FindHeaders
- replace SymbolLocation std::variant with enum-exposing version similar to
  those in types.cpp. There's no appropriate implementation file, added
  LocateSymbol.cpp in anticipation of locateDecl/locateMacro.
- FindHeaders is not part of the public Analysis interface, so should not
  be implemented/tested there (just code organization)
- rename findIncludeHeaders->findHeaders to avoid confusion with Include concept

Differential Revision: https://reviews.llvm.org/D137825
2022-11-11 13:41:54 +01:00
Sam McCall
61c2276cb2 [include-cleaner] verbatimSpelling->verbatim, clean up some silly init-lists. NFC 2022-11-11 12:10:12 +01:00
Haojian Wu
7795548048 [include-cleaner] Initial version for the "Location=>Header" step
This patch implements the initial version of "Location => Header" step:

- define the interface;
- integrate into the existing workflow, and use the PragmaIncludes;

Differential Revision: https://reviews.llvm.org/D137320
2022-11-11 10:34:22 +01:00
Sam McCall
c333b92b72 [include-cleaner] Missing changes from 38cccb906603 2022-11-08 20:18:10 +01:00
Sam McCall
38cccb9066 [include-cleaner] pass through recorded macro refs in walkUsed
Differential Revision: https://reviews.llvm.org/D137644
2022-11-08 20:10:39 +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
3e067d4e59 [include-cleaner] Move vocabulary types into separate header for layering. NFC 2022-10-25 19:01:59 +02:00
Kadir Cetinkaya
ce286eccac
[IncludeCleaner] Add public API
Introduces walkUsed, a very simple version of the public API to enable
incremental development on rest of the pieces.

Differential Revision: https://reviews.llvm.org/D136293
2022-10-24 17:06:15 +02:00