Commit Graph

79 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
Daniel Hannon 67942da411 clarify purpose of --update_comments in help screen and manpages 2022-05-28 11:03:40 +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
Kim Gräsman 50fe9f1455 Use CHECK_UNREACHABLE_ for unreachable code 2022-02-20 16:28:21 +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
Alexey Storozhev 42825de9fa Fix reference-to-temporary in header-search
The map range iterator returns a `const pair<const string, ...>&`, not the
expected `const pair<string, ...>&`, and the compiler helpfully converts
to a temporary. Make the types match.

Found by Clang's -Wrange-loop-construct
2020-11-30 18:12:02 +01:00
Andrea Bocci 53487d2097 Add explicit conversion from llvm::StringRef to std::string
llvm/llvm-project@777180a makes the llvm::StringRef conversion operator
to std::string explicit.
These changes add a call to the str() method to perform the conversion.

Signed-off-by: Andrea Bocci <andrea.bocci@cern.ch>
2020-03-03 21:44:35 +01:00
Kim Grasman 7c2ec8f05b Rename port.h -> iwyu_port.h 2019-12-26 16:12:02 +01:00
Kim Grasman 550d9affbe Always keep .moc #includes
.moc files are handled by a separate Qt preprocessor called 'moc', which
expands them into C++ code.

They are not C++ in and of themselves, and can't be safely analyzed by
IWYU. The moc preprocessor allegedly suggests to remove unused .moc
includes, so we should leave them alone.

Implement this by pretending '--keep="*.moc"' was passed on the
command-line.

Fixes issue #721.
2019-12-21 10:02:52 +01: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 f7e1900619 Fix misspecified getopt has_arg flags
Several options were incorrectly marked with 'optional_argument', which
means they can take a value argument, but don't have to. We don't have
any options like that.

Fixes issue #663.
2019-03-23 09:49:40 +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
EugeneZelenko eb7f5d1ef0 Fix Clang-tidy warnings
- readability-redundant-member-init warnings
- modernize nested templates; '> >'
- modernize-use-default warnings
2016-11-16 21:04:24 +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 5b61a55190 Fix #310: Replace Each with C++11 range for loops
The Each construct was nice, but it's outlived its usefulness, the range for
loops are both easier to read and write.

For iteration over maps, we consistently use 'auto' to avoid repeating the map
value type.
2016-07-11 07:19:51 +02:00
Flamefire 23119ba66a Use absolute paths to build include names
This has been a long-standing issue with IWYU (see issues #5, #271 and
probably others) where ConvertToQuotedInclude generates absolute paths
if IWYU is invoked with the current directory different from the source
file path.

This patch moves most path building to use absolute paths and path of
the includer (rather than the cwd) to produce better results.
2016-06-08 08:23:26 +02:00
EugeneZelenko e05d81f32d Fix some Clang-tidy warnings
NULL/0 -> nullptr
C standard library include -> C++ counterparts
Occasional use of auto
Explicit strcmp return value check
Remove unused usings
Closing comments for anonymous namespaces
2016-06-07 21:49:33 +02:00
Flamefire 6cf6b76a43 Remove CanonicalizeFilePath and add NormalizeDirPath 2016-05-18 20:54:58 +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 Grasman b8069259e7 Remove excess blank lines and wordsmith a comment 2015-11-23 20:55:41 +01:00
Kim Grasman 7c700e8ca5 Fix #210: Avoid mis-stripping of same path prefix
If two paths in the header search set shared the same prefix, IWYU would
sometimes pick the wrong one and produce an invalid quoted include. For
example:

Header search path: /a/foo, /a/foobar
File path: /a/foobar/header.h

This would yield "bar/header.h", as "/a/foo" was considered a basename of
the file path.

We fix this by ensuring all search path entries end with "/" up-front.

I didn't add a test for this, because an end-to-end test would be almost
nonsensical. Once we get the unit test suite up and running, I'd like to
add a test for this there instead.
2015-11-23 20:51:50 +01:00
Kim Grasman ff7e873ec9 Fix #232: Pick up revision from Git instead of SVN
Print Git revision as 'git:<sha1>' to make it somewhat clearer that it's a
Git commit hash. Ideally we'd include the full repo URL, but it gets too
long: https://github.com/include-what-you-use/include-what-you-use.git.
2015-11-18 21:36:12 +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 0b15a83af9 Fix issue 157: Return different exit codes. 2014-11-30 09:26:43 +00:00
Kim Gräsman cfb96548c0 Have USAGE list switches in alphabetical order.
We broke that (unstated) convention with --prefix_header_includes
and --pch_in_code.
2014-09-14 09:13:11 +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 f4fd3cd94d Fix indentation in ParseIwyuCommandlineFlags. No functional change intended. 2014-02-23 00:41:21 +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 04e3b75adb Clean up handling of mapping file search paths. The current policy is to treat --mapping_file switches as relative to the current dir or absolute. Ref directives are evaluated relative to the current directory and then relative to the containing mapping file, and multiple levels of refs build up the mapping file search path incrementally.
- Remove hard-coded mapping search path in iwyu_globals.cc
- Remove AddMappingFileSearchPath
- Add private AddMappingsFromFile to handle search path building
- Push search path scanning out into free function FindFileInSearchPath
- Less, but more focused logging.
- Fix indentation in iwyu_include_picker.cc
- Simplify parsing code by making current_node a Node* instead of a Node&
2013-02-26 21:32:24 +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
Kim Gräsman b46124b1d1 Fix issue #93. Restore default mappings for GCC
- iwyu.gcc.imp is no longer added automatically if no mapping file is specified
- Instead, the defaults are hard-coded in iwyu_include_picker.cc
- Fix some 80-column overruns
2013-02-15 06:04:44 +00:00
Volodymyr Sapsai 29f9348328 Change <opts> to <iwyu_opts> in usage text (issue #85). 2013-01-07 21:38:14 +00:00
Volodymyr Sapsai 3a4b90ed85 Change executable file name in help to 'include-what-you-use'. Patch by Kim Gräsman. 2012-12-23 13:44:51 +00:00
Volodymyr Sapsai 5944806a41 Added default mapping file. Patch by Kim Gräsman.
The --mapping_file argument now defaults to "iwyu.gcc.imp" if no other
mapping files are provided.
2012-12-02 15:12:25 +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
Volodymyr Sapsai 3a3b25260d Added getopt_long for Windows (resolves issue #52).
getopt, getopt_long implementation by Kim Gräsman.
2012-08-11 18:15:00 +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 a15c84b30c Don't ask me why, but the automated system I use for updating patches wants to undo Paul Holden's latest patches and then re-apply them. I'm sure there's a way to skip doing that, but I don't know what it is, so I'm going to let it do its thing. This is step 2 (the re-apply).
Revision created by MOE tool push_codebase.
MOE_MIGRATION=2806
2011-08-01 20:58:24 +00:00
csilvers+iwyu 60272bf071 Don't ask me why, but the automated system I use for updating patches wants to undo Paul Holden's latest patches and then re-apply them. I'm sure there's a way to skip doing that, but I don't know what it is, so I'm going to let it do its thing. This is step 1 (the revert).
Revision created by MOE tool push_codebase.
MOE_MIGRATION=2805
2011-08-01 20:57:19 +00:00