Commit Graph

134 Commits

Author SHA1 Message Date
Haojian Wu 2a6d78b820 [find-all-symbols] Add IWYU private pragma support.
Reviewers: djasper, klimek

Subscribers: kimgr, cfe-commits, bkramer, ioeric

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

llvm-svn: 269779
2016-05-17 16:48:49 +00:00
Haojian Wu 39170d70c0 [find-all-symbols] Ignore anonymous enum declarations.
llvm-svn: 269762
2016-05-17 13:38:18 +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
Etienne Bergeron 8db5174395 [include-fixer] Fix broken dependency shared build
Summary:
The shared build is broken (again).

To repro: [Release + Shared]
```
-DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON
```

Errors:
```
tools/clang/tools/extra/include-fixer/tool/CMakeFiles/clang-include-fixer.dir/ClangIncludeFixer.cpp.o: In function `(anonymous namespace)::includeFixerMain(int, char const**)':
ClangIncludeFixer.cpp:(.text._ZN12_GLOBAL__N_116includeFixerMainEiPPKc+0xbe9): undefined reference to `clang::find_all_symbols::SymbolInfo::SymbolInfo(llvm::StringRef, clang::find_all_symbols::SymbolInfo::SymbolKind, llvm::StringRef, int, std::vector<std::pair<clang::find_all_symbols::SymbolInfo::ContextType, std::string>, std::allocator<std::pair<clang::find_all_symbols::SymbolInfo::ContextType, std::string> > > const&)'
collect2: error: ld returned 1 exit status
```

```
tools/clang/tools/extra/unittests/include-fixer/CMakeFiles/IncludeFixerTests.dir/IncludeFixerTest.cpp.o: In function `clang::include_fixer::(anonymous namespace)::runIncludeFixer(llvm::StringRef, std::vector<std::string, std::allocator<std::string> > const&)':
IncludeFixerTest.cpp:(.text._ZN5clang13include_fixer12_GLOBAL__N_1L15runIncludeFixerEN4llvm9StringRefERKSt6vectorISsSaISsEE+0x10e): undefined reference to `clang::find_all_symbols::SymbolInfo::SymbolInfo(llvm::StringRef, clang::find_all_symbols::SymbolInfo::SymbolKind, llvm::StringRef, int, std::vector<std::pair<clang::find_all_symbols::SymbolInfo::ContextType, std::string>, std::allocator<std::pair<clang::find_all_symbols::SymbolInfo::ContextType, std::string> > > const&)'
IncludeFixerTest.cpp:(.text._ZN5clang13include_fixer12_GLOBAL__N_1L15runIncludeFixerEN4llvm9StringRefERKSt6vectorISsSaISsEE+0x1dc): undefined reference to `clang::find_all_symbols::SymbolInfo::SymbolInfo(llvm::StringRef, clang::find_all_symbols::SymbolInfo::SymbolKind, llvm::StringRef, int, std::vector<std::pair<clang::find_all_symbols::SymbolInfo::ContextType, std::string>, std::allocator<std::pair<clang::find_all_symbols::SymbolInfo::ContextType, std::string> > > const&)'
IncludeFixerTest.cpp:(.text._ZN5clang13include_fixer12_GLOBAL__N_1L15runIncludeFixerEN4llvm9StringRefERKSt6vectorISsSaISsEE+0x2f3): undefined reference to `clang::find_all_symbols::SymbolInfo::SymbolInfo(llvm::StringRef, clang::find_all_symbols::SymbolInfo::SymbolKind, llvm::StringRef, int, std::vector<std::pair<clang::find_all_symbols::SymbolInfo::ContextType, std::string>, std::allocator<std::pair<clang::find_all_symbols::SymbolInfo::ContextType, std::string> > > const&)'
IncludeFixerTest.cpp:(.text._ZN5clang13include_fixer12_GLOBAL__N_1L15runIncludeFixerEN4llvm9StringRefERKSt6vectorISsSaISsEE+0x40e): undefined reference to `clang::find_all_symbols::SymbolInfo::SymbolInfo(llvm::StringRef, clang::find_all_symbols::SymbolInfo::SymbolKind, llvm::StringRef, int, std::vector<std::pair<clang::find_all_symbols::SymbolInfo::ContextType, std::string>, std::allocator<std::pair<clang::find_all_symbols::SymbolInfo::ContextType, std::string> > > const&)'
IncludeFixerTest.cpp:(.text._ZN5clang13include_fixer12_GLOBAL__N_1L15runIncludeFixerEN4llvm9StringRefERKSt6vectorISsSaISsEE+0x526): undefined reference to `clang::find_all_symbols::SymbolInfo::SymbolInfo(llvm::StringRef, clang::find_all_symbols::SymbolInfo::SymbolKind, llvm::StringRef, int, std::vector<std::pair<clang::find_all_symbols::SymbolInfo::ContextType, std::string>, std::allocator<std::pair<clang::find_all_symbols::SymbolInfo::ContextType, std::string> > > const&)'
```

Reviewers: bkramer, hokein

Subscribers: cfe-commits

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

llvm-svn: 269441
2016-05-13 17:38:22 +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
Haojian Wu 631e5f23f9 [include-fixer] Simplify unittest code.
Summary:
The InMemorySymbolIndex only constructs hard-coded Class symbols from a string
map. The patch provide a flexable way in InMemorySymbolIndex to create a custom
SymbolInfo in the include-fixer unittest.

Reviewers: bkramer

Subscribers: cfe-commits

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

llvm-svn: 269427
2016-05-13 15:17:17 +00:00
Haojian Wu db98f1d9c9 [find-all-symbols] Add EnumDecl type in YAML traits.
llvm-svn: 269422
2016-05-13 14:53:10 +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
Haojian Wu 22014750b4 [find-all-symbols] Add enum type support.
Summary:
Also change enums defined in SymbolInfo to scoped enums to avoid
conflicts.

Reviewers: bkramer

Subscribers: cfe-commits, ioeric

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

llvm-svn: 269401
2016-05-13 09:15:37 +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
Haojian Wu 075ba119b2 [find-all-symbols] Save relative file path for each symbol.
Summary:
The HeaderSearch::suggestPathToFileForDiagnostics used in include-fixer
doesn't work well with absolute file path, it assumes a relative file
path based on header searching path.

So saving relative file path to make include-fixer get the most
appropriate header path.

Reviewers: bkramer

Subscribers: cfe-commits

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

llvm-svn: 269173
2016-05-11 11:50:08 +00:00
Haojian Wu 1a352d564f [find-all-symbols] Slim SymbolInfo.
Summary:
SymbolInfo has some optional fields, which is a bad-smell
implementation. For now, we

* remove the optional field since we don't need them (we can probably
  add them back if we actually need them in the future)
* make SymbolInfo to be a class.

By this change, the code is more simplified.

Reviewers: klimek

Subscribers: cfe-commits, ioeric, bkramer

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

llvm-svn: 269162
2016-05-11 08:38:21 +00:00
Benjamin Kramer 8fd85a5788 [include-fixer] Default to YAML db, it's much more useful than the fixed dummy db.
llvm-svn: 269043
2016-05-10 11:35:47 +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 5471829351 [include-fixer] Emit some terminal output so users can see that the tool is working.
llvm-svn: 269030
2016-05-10 08:36:56 +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
Benjamin Kramer b6aed5f441 [include-fixer] Autodetect yaml databases in parent directories.
This looks for find_all_symbols_db.yaml in all parent directories of the
source file (like we do for compile_commands.json) so we don't have to
pass the path manually.

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

llvm-svn: 268920
2016-05-09 14:14:55 +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
Haojian Wu a315dcb3da [include-fixer] Abstract includeFixerMain function.
llvm-svn: 268371
2016-05-03 08:38:35 +00:00
Eugene Zelenko a54a212d9d [include-fixer] Fix Clang-tidy modernize-use-override and some Include What You Use warnings.
Differential revision: http://reviews.llvm.org/D19755

llvm-svn: 268262
2016-05-02 17:49:00 +00:00
Benjamin Kramer 683e592ff3 [find-all-symbols] Parallelize the merge step.
There is still more parallelism to get here because we synchonize on the
actual uniquing but just doing YAML parsing in parallel already gives a
significant speedup.

Merging all symbols in LLVM+clang+compiler-rt+lld+libc++, 48 cores.
before: 201.55s user 1.47s system 99% cpu 3:23.04 total
after:  276.99s user 7.63s system 838% cpu 33.947 total

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

llvm-svn: 268037
2016-04-29 12:46:27 +00:00
Benjamin Kramer 4f3c985edd Make run-find-all-symbols executable.
llvm-svn: 268022
2016-04-29 10:33:11 +00:00
Benjamin Kramer 027163e98b [find-all-symbols] Fix racy yaml file writing.
If multiple find-all-symbols processes access the temporary directory
simultaneously with two files with the same name they would collide and
create a broken yaml file. Fix this by using the safe createUniqueFile
API from LLVM instead.

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

llvm-svn: 268021
2016-04-29 10:16:28 +00:00
Haojian Wu e5966e7309 [find-all-symbols] Save absolute file path instead of relative file path in SymbolInfo.
Reviewers: bkramer

Subscribers: cfe-commits

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

llvm-svn: 268019
2016-04-29 09:45:09 +00:00
Haojian Wu d8c12badad [include-fixer] Add Yaml database integration.
Reviewers: bkramer

Subscribers: cfe-commits, klimek, djasper

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

llvm-svn: 268017
2016-04-29 09:23:38 +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
Simon Pilgrim b9f255878e Wdocumentation fix
llvm-svn: 267786
2016-04-27 20:43:32 +00:00
Benjamin Kramer bac3a96389 [find-all-symbols] Clean up dependencies, fixing cmake shared build.
llvm-svn: 267738
2016-04-27 16:50:17 +00:00
Haojian Wu f875acbd77 [include-fixer] Add a find-all-symbols tool for include-fixer.
Summary:
The find-all-symbols tool generates a yaml symbol database for
include-fixer.

The symbol matcher is originally written by Xiaoyi Liu.

Reviewers: bkramer, djasper

Subscribers: cfe-commits, klimek, ioeric

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

llvm-svn: 267719
2016-04-27 14:27:05 +00:00
Benjamin Kramer f412e9029d Clean up the include fixer 'driver' a bit and make the database configurable.
Also add a test for it. The library is covered by unit tests, the driver
was not.

llvm-svn: 267718
2016-04-27 14:24:32 +00:00
Haojian Wu 9cba1b52ef Fix cast compiler warning message in include-fixer.
Reviewers: bkramer

Subscribers: cfe-commits

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

llvm-svn: 266970
2016-04-21 09:16:32 +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