Commit Graph

44 Commits

Author SHA1 Message Date
Kim Gräsman 890a3150d7 Format all return statements on their own line
This is the unadorned result of:

    git grep -En "\w.*return .*;" -- ':!tests/*' | grep-format

Having return statements on their own line makes it easier to set
breakpoints in most debuggers.

No functional change.
2023-01-07 12:27:16 +01:00
Kim Gräsman cf53880822 Add --regex option
As reported in issue #981, using std::regex in IWYU has caused a
tremendous performance regression for large mapping files containing
regex mappings.

  $ cat t.cc
  #include <string>

  # with llvm::Regex
  $ time include-what-you-use -Xiwyu --mapping_file=qt5_11.imp t.cc
  ...
  real 0m0,529s
  user 0m0,509s
  sys  0m0,020s

  # with std::regex
  $ time include-what-you-use -Xiwyu --mapping_file=qt5_11.imp t.cc
  ...
  real 0m29,870s
  user 0m29,717s
  sys  0m0,012s

qt5_11.imp contains 2300+ regex mappings, and <string> has a bunch of
includes, so this is a good testbed for regular expression engines, but
over 50x slower is not the result we were hoping for.

The reason we switched to std::regex was to get support for negative
lookaround (llvm::Regex does not have it), but exotic regexes in
mappings are pretty rare, and this is a significant performance hit.

Introduce a --regex option to select regex dialect, with documented
tradeoffs. Put the default back to LLVM's fast implementation.

This fixes issue #981.
2022-09-03 15:04:27 +02:00
Kim Gräsman 4217b5a20e Add --debug argument for disposable debug flags
Sometimes for debugging and testing, it helps to be able to tweak IWYU behavior
beyond the log verbosity.

Add a free-form --debug argument that takes a comma-separated list of flag
names. No validation is performed on these flags, they just serve as a global
switchboard to enable/disable custom behavior.

Note that these are not intended as a replacement for switches in general, just
as a support structure for quickly adding conditional debug behavior while
troubleshooting.
2022-08-28 14:58:49 +02:00
Daniel Hannon 3f456f66c2 add --comment_style option with tests 2022-05-28 11:03:47 +02:00
Kim Gräsman 8c1e9adf27 Add exit-code command-line options
Two new options:

  --error: sets the exit code to use if there are IWYU violations
  --error_always: sets the exit code to use whether there are IWYU
     violations or not

Add tests to capture all relevant combinations of

  (no warnings, warnings) x
  (--error, --error_always) x
  (explicit arguments, default values)

and make sure --error_always overrides --error.
2022-02-26 12:21:26 +01:00
Kim Gräsman b77197753c Normalize exit codes
Exit with EXIT_FAILURE if the command-line arguments are invalid or
Clang fails to parse the input. Otherwise exit with EXIT_SUCCESS.

Add tests to capture this new policy.
2022-02-26 12:21:26 +01:00
Salman Javed 75226c1ce8 Add `--update_comments` option
Fixes #75 and fixes #494.
Add `--update_comments` option to make IWYU always print the 'why'
#include comments, regardless of whether any include lines need to be
added or removed. With this change, IWYU will update the "// for xyz"
comments as the code changes, preventing the comments from becoming
stale.
2021-10-01 06:31:27 +02:00
John Bytheway b4838853e5 Remove trailing whitespace from source files 2020-05-24 14:14:59 +02:00
Tom Rix 3b10ae16a5 Add command line option --keep=<glob>
--keep is the command line equivalent to the keep pragma with globbing.
2019-03-30 15:22:35 +01:00
Kim Grasman 5e6adc8110 Remove not-yet-implemented commandline options
These do not seem to be on the roadmap.
2019-03-23 09:49:40 +01:00
Miklos Vajna 353a6da9b7 Add new --cxx17ns option
This opts in for the more concise syntax introduced in C++17: namespace
a::b { ... }.

Usage of this is especially useful in codebases where existing forward
declarations in nested namespaces already use this form: so the IWYU
suggestion for new forward declarations can be consistent with the
existing ones.

fix_includes.py already handled this, but add a test to maintain this
behavior, too.
2019-02-06 19:55:19 +01:00
Scott Ramsby 4a0cb6a526 Add option to change header ordering to place quoted local project headers first 2018-06-11 21:28:48 +02:00
Alex Kirchhoff 4275af7cec Add --no_fwd_decls option
As requested in #354.  Marks all uses as full uses.  Useful for
compliance with Google C++ Style Guide.
2017-12-19 20:55:54 +01:00
Kim Grasman dbceeb3c14 Fix inconsistent parameter names
Found by the clang-tidy check
readability-inconsistent-declaration-parameter-name

No functional change.

Based on patch by Eugene Zelenko, thanks!
2016-08-15 22:24:39 +02:00
Kim Grasman aa2dd1bb8f Whitespace changes from clang-(tidy|format)
Presumably this makes formatting more consistent.
No functional change.

This is based on an original patch by Eugene Zelenko, thanks!
2016-08-15 22:04:47 +02:00
Kim Grasman e58967a2ec Make header guards consistent
- Remove DEVTOOLS_MAINTENANCE_ from header guards, that was a
  now-unnecessary Googleism

- Fix header guard to match filename in all production code

- Fix header guard to match path in all tests
2016-05-25 22:17:31 +02:00
Kim Grasman 5ec95a6d1c Add --no_comments switch
This switch suppresses why-comments in output.
2016-03-01 19:56:48 +01:00
Kim Gräsman 1cb495599c Fix issue 181: Align why comments to any width
Add a --max_line_length switch to control desired line length.

Patch by Fabian Gruber, thanks!
2015-04-25 09:20:21 +00:00
Kim Gräsman 7703c4c80a Add verbosity level 8 and use it for mappings. 2015-03-02 20:41:01 +00:00
Kim Gräsman 0b15a83af9 Fix issue 157: Return different exit codes. 2014-11-30 09:26:43 +00:00
Kim Gräsman 452df335a0 Fix issue 126: Precompiled-headers support with --prefix_header_includes
IWYU now supports a new --pch_in_code switch which indicates the first
include directive in the translation unit is a precompiled header.
Precompiled headers are treated as prefix headers, even though they
were not specified on the command-line, but they can never be removed.
Finally, they sort first in include lists generated by IWYU, because
most compilers require the PCH to be included before anything else.
2014-04-27 20:35:44 +00:00
Volodymyr Sapsai 8821f57d94 Handle --version option (issue #106). 2014-02-23 00:31:52 +00:00
Volodymyr Sapsai d30ef5a05f Add --prefix_header_includes option (fixes issue #112).
--prefix_header_includes controls presence of includes and forward declarations
involving files included via command-line option -include. Issue is reported by
Max Dyckhoff.
2013-12-15 12:33:18 +00:00
Kim Gräsman d4c3ca6213 Add switch to suppress hard-coded default mappings
--no_default_mappings will cause IWYU not to add the default GCC-oriented mappings, to make it easier to build custom mapping suites for other toolchains.
2013-03-07 15:40:22 +00:00
Kim Gräsman 15ca18b2b4 Remove executable path from mapping search path.
This obviates the need to pass the executable path through IwyuAction into InitGlobals
2013-02-26 19:12:31 +00:00
Volodymyr Sapsai f8fd069e44 Fixed file heading comments not matching the filename (issue #83). Patch by Ryan Pavlik.
Also made the length of the first line to be 80 characters where possible.
2012-11-25 22:09:37 +00:00
Volodymyr Sapsai 40999861b2 Enhanced search paths of mapping files. Patch by Kim Gräsman.
Search for mapping files:
- in the current working directory;
- in the directory where IWYU executable is located;
- in the directory where another discovered mapping file is located.
2012-11-25 21:26:06 +00:00
Volodymyr Sapsai a6c6e5238c Read private to public mappings from external file. Patch by Kim Gräsman. 2012-10-14 22:39:30 +00:00
csilvers+iwyu c23f0b9eef Some refactoring to straighten out dependencies.
This was motivated by an attempt to understand how iwyu_ast_util.cc
depended on iwyu_output, which turned out to be the use of VERRS.
I split the VERRS definition out into a separate iwyu_verrs module.
In the fallout from this I discovered some circular dependencies
that this CL attempts to disentangle.

R=csilvers
DELTA=603  (349 added, 222 deleted, 32 changed)


Revision created by MOE tool push_codebase.
MOE_MIGRATION=3892
2011-12-01 02:30:18 +00:00
csilvers+iwyu 256da9418d Include-what-you-use fixit -- run iwyu on itself to fix up includes (part 2).
R=csilvers
DELTA=51  (3 added, 47 deleted, 1 changed)


Revision created by MOE tool push_codebase.
MOE_MIGRATION=1736
2011-05-04 18:32:59 +00:00
csilvers+iwyu 5ca17d139e Include-what-you-use fixit -- fix #includes on iwyu itself.
R=csilvers
DELTA=123  (22 added, 5 deleted, 96 changed)


Revision created by MOE tool push_codebase.
MOE_MIGRATION=1732
2011-05-04 18:30:53 +00:00
csilvers+iwyu 3d55404056 Include-what-you-use fixes by running it on itself.
R=dsturtevant,csilvers
	DELTA=215  (135 added, 45 deleted, 35 changed)


Revision created by MOE tool push_codebase.
MOE_MIGRATION=1731
2011-05-04 18:29:59 +00:00
csilvers+iwyu 110d647867 Distinguish properly between system and user include
directories as specified on the compiler line, when deciding
whether to use "" or <>.  Hard-code in some rules for google3
where we don't do it quite right.

To fully fix the associated bug, I also noticed that our cfoo
<-> foo.h mappings was missing stddef.h, which is defined in a
different place from other headers.  I added it in.

R=wan,dsturtevant
DELTA=161  (69 added, 20 deleted, 72 changed)


Revision created by MOE tool push_codebase.
MOE_MIGRATION=1597
2011-04-26 23:21:51 +00:00
csilvers+iwyu 926fa38b98 Allow include-what-you-use to run in
--transitive_includes_only mode (controlled by a flag).  In
this mode, we will throw out suggestions that file a #include
file b if file b is not visible in file a's transitive
includes; that is, all we do is move indirect includes to
direct includes, we never add a 'totally new' include.

While it's certainly possible for a 'totally new' include
suggestion to be correct, in our experience it's much more
commonly an iwyu error, usually because iwyu associates a use
with the wrong file.  We control this by a flag so the user
can decide themselves whether they care more about false
positives or false negatives.

R=dsturtevant
DELTA=132  (123 added, 2 deleted, 7 changed)


Revision created by MOE tool push_codebase.
MOE_MIGRATION=1592
2011-04-26 23:13:25 +00:00
csilvers+iwyu 54eef2afa3 Reorganize the commandline flags by storing them in a globally
accessible 'commandlineflags' struct.  This replaces the
rather ad-hoc collection of variables and functions, spread
across 3 different files, that we have now.  The motivation is
adding a new commandline flag that I want to be visible in yet
a fourth file; I figured that was a good time to consolidate.
Now iwyu_globals holds everything.

R=wan,dsturtevant
DELTA=306  (161 added, 112 deleted, 33 changed)


Revision created by MOE tool push_codebase.
MOE_MIGRATION=1591
2011-04-26 23:12:44 +00:00
csilvers+iwyu ed381497a3 Add a test to protect against syntax errors in main(). Also
test some main()-invariant logic while I'm at it.

DELTA=19  (16 added, 0 deleted, 3 changed)


Revision created by MOE tool push_codebase.
MOE_MIGRATION=1409
2011-04-13 03:11:35 +00:00
csilvers+iwyu 37c67ac363 I was not correctly getting the location for member-exprs. I
thought I was saying the location is where the . (or ->) is,
which is what I want, but clang doesn't actually expose that.
So I have go through some hoops to try to figure it out.

We were actually seeing a problem with this when running:

blaze build --host_cpu=k8 --compile_only -k --crosstool_top=//third_party/llvm/crosstool --plugin=//devtools/maintenance/include_what_you_use:run_iwyu //gws/plugins/local/src:enhanced_listing_ad

It has 'msg_->MSG_foo' in it, where MSG_foo is a macro.  We
were attributing this use to the file defining MSG_foo, rather
than to us.  With this change, we properly attribute it to us.

R=dsturtevant
DELTA=150  (125 added, 6 deleted, 19 changed)


Revision created by MOE tool push_codebase.
MOE_MIGRATION=1347
2011-04-12 05:00:17 +00:00
csilvers+iwyu 19c814a187 Make the caches global. That will make it easier to re-use
them for typedefs.

R=dsturtevant
DELTA=40  (26 added, 10 deleted, 4 changed)


Revision created by MOE tool push_codebase.
MOE_MIGRATION=1273
2011-04-06 20:06:56 +00:00
csilvers+iwyu eb68790ba7 Redo the rest of the clang changes that had gotten pushed around r63, but had been accidentally reverted with some of these other updates.
Revision created by MOE tool push_codebase.
MOE_MIGRATION=921
2011-03-18 07:00:52 +00:00
csilvers+iwyu fceb41ff6f I decided it's more maintainable to mock the include-search-paths rather than trying to use the driver in iwyu_test.cc, with its mock .cc file and everything.
Revision created by MOE tool push_codebase.
MOE_MIGRATION=920
2011-03-18 07:00:41 +00:00
csilvers+iwyu a88e680b04 I knew that there would be trouble if I tried to call
HasMapping before mappings were finalized.  And indeed, the
glob mappings were being left out.  I solve this by doing the
reexport-protection check after mappins are finalized, in the
preprocessor.

While in the area, I added a few include-picker mappings that
had been inadvertently omitted before, or discovered in
testing.  In particular, glob defines its own size_t, which is
weird; we don't want to depend on glob for size_t.

R=dsturtevant
DELTA=141  (129 added, 2 deleted, 10 changed)


Revision created by MOE tool push_codebase.
MOE_MIGRATION=889
2011-03-18 02:51:02 +00:00
csilvers f6028e2d4a Patch to get system search paths from clang rather than hard-coding
them.  Provided by paul.hol...@gmail.com.  Addresses
   http://code.google.com/p/include-what-you-use/issues/detail?id=12
2011-03-08 22:06:43 +00:00
csilvers 000a1fff6d Fixes to get code to compile under MSVC 10. Submitted by pichet2...:
http://code.google.com/p/include-what-you-use/issues/detail?id=7
with small changes by csilvers to encapsulate all arch-specific
information in one file, port.h.

Reviewed by csilvers
2011-02-08 06:12:32 +00:00
csilvers dee92b5e0a Initial release! Grains of salt not included. 2011-02-04 22:28:15 +00:00