Commit Graph

23 Commits

Author SHA1 Message Date
Haojian Wu 9c6cb035f3 [include-fixer] Don't add missing header if the unindentified symbol isn't from the main file.
Summary:
The further solution is to add the missing header to the file where the
symbol comes from.

Reviewers: bkramer

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D20950

llvm-svn: 271660
2016-06-03 11:26:02 +00:00
Haojian Wu 17a54e3618 [include-fixer] Use YAML format in -output-headers and -insert-header mode.
Summary:
And some improvements:
* Show better error messages on unfound symbols.
* Fix a typo.

Reviewers: bkramer

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D20827

llvm-svn: 271382
2016-06-01 11:43:10 +00:00
Eric Liu 78985da8cc [include-fixer] removed unused forward declaration.
llvm-svn: 271294
2016-05-31 16:03:09 +00:00
Eric Liu 516f18e515 [include-fixer] use clang-format cleaner to insert header.
Summary: clang-format's cleanupAroundReplacements() takes care of header insertions.

Reviewers: bkramer

Subscribers: cfe-commits, hokein

Differential Revision: http://reviews.llvm.org/D20816

llvm-svn: 271287
2016-05-31 14:48:45 +00:00
Eric Liu f83187deb9 [include-fixer] use tooling::Replacements since the order of replacements don't matter anymore.
Summary: [include-fixer] use tooling::Replacements since the order of replacements don't matter anymore.

Differential Revision: http://reviews.llvm.org/D20813

llvm-svn: 271279
2016-05-31 13:52:59 +00:00
Haojian Wu eb6ce0643d [include-fixer] Code cleanup.
Summary:
* Abstract the DB setting code to a function.
* Remove the unused FallbackStyle.

Reviewers: bkramer

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D20808

llvm-svn: 271273
2016-05-31 13:23:00 +00:00
Haojian Wu 11e9bd2450 [include-fixer] Create a mode in vim integration to show multiple potential headers.
Summary:
Some changes in the patch:

* Add two commandline flags in clang-include-fixer.
* Introduce a IncludeFixerContext for the queried symbol.
* Pull out CreateReplacementsForHeader.

Reviewers: bkramer

Subscribers: klimek, cfe-commits, ioeric

Differential Revision: http://reviews.llvm.org/D20621

llvm-svn: 271258
2016-05-31 09:31:51 +00:00
Haojian Wu 218febb8eb [include-fixer] Simplify the code since we won't handle multiple includes at once.
Reviewers: bkramer

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D20581

llvm-svn: 270700
2016-05-25 14:06:12 +00:00
Benjamin Kramer ee4e522c26 [include-fixer] Fix unused variable warning in Release builds.
llvm-svn: 270082
2016-05-19 16:57:57 +00:00
Haojian Wu 0de7226236 [include-fixer] Remove an unused local variable ExistingHeaders.
llvm-svn: 270059
2016-05-19 13:23:27 +00:00
Eric Liu 702cfd1b2b [include-fixer] Sort headers after inserting new headers.
Summary: [include-fixer] Sort headers after inserting new headers.

Reviewers: bkramer

Subscribers: klimek, djasper, hokein, cfe-commits

Differential Revision: http://reviews.llvm.org/D20370

llvm-svn: 270031
2016-05-19 08:21:09 +00:00
Benjamin Kramer 6b5160a369 [include-fixer] Don't insert #includes if a fatal error occurred.
This typically happens when the user didn't setup include paths correctly
and the fixer starts adding garbage includes. Avoid that. Disable the error
limit though, as we might hit that easily with missing includes and still
want to fix those cases.

llvm-svn: 269923
2016-05-18 13:32:38 +00:00
Benjamin Kramer af34e06c69 [include-fixer] Make the "extend to the right" hack support typos without nested names in the front.
This handles cases where the initial namespace is unknown.

llvm-svn: 269758
2016-05-17 12:35:18 +00:00
Haojian Wu 57cdcb07d6 [include-fixer] Use scope contexts information to improve query.
Reviewers: bkramer

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D20205

llvm-svn: 269430
2016-05-13 15:44:16 +00:00
Benjamin Kramer a3d823336a [include-fixer] Rename XrefsDB to SymbolIndex.
It's not really containing xrefs so the name didn't fit. No functional change.

llvm-svn: 269403
2016-05-13 09:27:54 +00:00
Benjamin Kramer 79acc976ea [include-fixer] Always ignore SFINAE contexts.
This could lead to spurious includes being added for identifiers that
are supposed to be not available.

llvm-svn: 269195
2016-05-11 15:33:30 +00:00
Benjamin Kramer 3246fba975 [include-fixer] Also output the location where we found an unknown identifier.
For debugging only, makes it a bit easier when there are queries coming
out of headers.

llvm-svn: 269194
2016-05-11 15:33:28 +00:00
Benjamin Kramer 8fe4c159b5 [include-fixer] Remove unused includes and accessor.
llvm-svn: 269036
2016-05-10 10:12:00 +00:00
Benjamin Kramer ad93500c52 [include-fixer] Work around partial names in both directions.
We already handled the case where we had a nested name specifier where
parts from the beginning don't get a callback, also handle the case
where the end doesn't get a callback. This happens with function calls
in unknown namespaces.

The way we do this for now based on character data is a bit of a hack, we
may need to refine this later or fix clang to produce different callbacks.

llvm-svn: 269029
2016-05-10 08:25:31 +00:00
Benjamin Kramer c3459a5002 [include-fixer] For now, only add the first suggested include.
We used a std::set which made the picked include somewhat random (well,
lexicographically sorted). Make the behavior more consistent by always
picking the first one we found.

llvm-svn: 269028
2016-05-10 08:25:28 +00:00
Eric Liu 692aca6980 Added XrefsDBManager into include-fixer and made XrefsDB return SymbolInfo.
Summary: Added XrefsDBManager into include-fixer and made XrefsDB return SymbolInfo.

Reviewers: hokein, djasper, klimek

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D19869

llvm-svn: 268480
2016-05-04 08:22:35 +00:00
Benjamin Kramer 3a45fab72b [include-fixer] Add an option to minimize include paths.
This will always pick the shortest possible path based on -I options. Based
on the #include suggestion code for modules.

llvm-svn: 267868
2016-04-28 11:21:29 +00:00
Benjamin Kramer 6b23626192 [include-fixer] Add a prototype for a new include fixing tool.
Summary:
The goal of this tool is fairly simple, look up unknown identifiers in a
global database and add the corresponding #include line. It accomplishes
this by hooking into Sema as an ExternalSemaSource and responding to typo
correction callbacks. This means we can see the unknown identifier before
it's being munged by error recovery.

This doesn't work perfectly yet as some typo corrections don't emit
callbacks (delayed typos), but I think this is fixable. We also handle
only one include at a time as this is meant to be run directly from
the editing environment eventually. Adding multiple includes at the same
time is tricky because of error recovery.

This version only has a a dummy database, so all you can do is fixing
missing includes of <string>, but the indexer to build a database will
follow soon.

Reviewers: djasper

Subscribers: ioeric, hokein, cfe-commits

Differential Revision: http://reviews.llvm.org/D19314

llvm-svn: 266870
2016-04-20 12:43:43 +00:00