summaryrefslogtreecommitdiffstats
path: root/clang/lib/Tooling/Core/Replacement.cpp
Commit message (Collapse)AuthorAgeFilesLines
* [clang] Adopt new FileManager error-returning APIsHarlan Haskins2019-08-011-5/+6
| | | | | | | Update the callers of FileManager::getFile and FileManager::getDirectory to handle the new llvm::ErrorOr-returning methods. Signed-off-by: Harlan Haskins <harlan@apple.com> llvm-svn: 367616
* Switch to cantFail(), since it does the same assertion.Stephen Hines2019-02-061-6/+5
| | | | | | | | | | | | Reviewers: cfe-commits, lhames Reviewed By: lhames Subscribers: hintonda, klimek, pirama Differential Revision: https://reviews.llvm.org/D36806 llvm-svn: 353318
* Update the file headers across all of the LLVM projects in the monorepoChandler Carruth2019-01-191-4/+3
| | | | | | | | | | | | | | | | | to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
* Lift VFS from clang to llvm (NFC)Jonas Devlieghere2018-10-101-3/+3
| | | | | | | | | | | | | | | | | | | This patch moves the virtual file system form clang to llvm so it can be used by more projects. Concretely the patch: - Moves VirtualFileSystem.{h|cpp} from clang/Basic to llvm/Support. - Moves the corresponding unit test from clang to llvm. - Moves the vfs namespace from clang::vfs to llvm::vfs. - Formats the lines affected by this change, mostly this is the result of the added llvm namespace. RFC on the mailing list: http://lists.llvm.org/pipermail/llvm-dev/2018-October/126657.html Differential revision: https://reviews.llvm.org/D52783 llvm-svn: 344140
* llvm::sort(C.begin(), C.end(), ...) -> llvm::sort(C, ...)Fangrui Song2018-09-261-6/+5
| | | | | | | | | | | | | | Summary: The convenience wrapper in STLExtras is available since rL342102. Reviewers: rsmith, #clang, dblaikie Reviewed By: rsmith, #clang Subscribers: mgrang, arphaman, kadircet, cfe-commits Differential Revision: https://reviews.llvm.org/D52576 llvm-svn: 343147
* Fix typos in clangAlexander Kornienko2018-04-061-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Found via codespell -q 3 -I ../clang-whitelist.txt Where whitelist consists of: archtype cas classs checkk compres definit frome iff inteval ith lod methode nd optin ot pres statics te thru Patch by luzpaz! (This is a subset of D44188 that applies cleanly with a few files that have dubious fixes reverted.) Differential revision: https://reviews.llvm.org/D44188 llvm-svn: 329399
* [clang] Change std::sort to llvm::sort in response to r327219Mandeep Singh Grang2018-03-271-5/+5
| | | | | | | | | | | r327219 added wrappers to std::sort which randomly shuffle the container before sorting. This will help in uncovering non-determinism caused due to undefined sorting order of objects having the same key. To make use of that infrastructure we need to invoke llvm::sort instead of std::sort. llvm-svn: 328636
* [Tooling] Fix some Clang-tidy modernize and Include What You Use warnings; ↵Eugene Zelenko2018-03-141-14/+43
| | | | | | other minor fixes (NFC). llvm-svn: 327573
* Switch to consumeError(), since this can crash otherwise.Stephen Hines2017-08-151-1/+1
| | | | | | | | | | | | | | | | | Summary: If assertions are disabled, but LLVM_ABI_BREAKING_CHANGES is enabled, this will cause an issue with an unchecked Success. Switching to consumeError() is the correct way to bypass the check. Reviewers: llvm-commits, cfe-commits, arphaman Reviewed By: arphaman Subscribers: arphaman, klimek, pirama Differential Revision: https://reviews.llvm.org/D36728 llvm-svn: 310958
* Make llvm::Error generated from replacement interfaces more specific.Eric Liu2016-11-221-20/+35
| | | | | | | | | | | | | | | | | Summary: The new error information contains the type of error (e.g. overlap or bad file path) and the replacement(s) that is causing the error. This enables us to resolve some errors. For example, for insertion at the same location conflict, we need to know the existing replacement which conflicts with the new replacement in order to calculate the new position to be insert before/after the existing replacement (for merging). Reviewers: klimek, bkramer Subscribers: djasper, cfe-commits Differential Revision: https://reviews.llvm.org/D26853 llvm-svn: 287639
* Deduplicate replacements by FileEntry instead of file names.Eric Liu2016-11-071-3/+8
| | | | | | | | | | | | | | | Summary: The current version does not deduplicate equivalent file paths correctly. For example, a relative path and an absolute path are considered inequivalent. Comparing FileEnry addresses these issues. Reviewers: djasper Subscribers: alexshap, klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D26288 llvm-svn: 286096
* Remove redundant calls to std::string::data()Malcolm Parsons2016-11-031-1/+1
| | | | | | | | | | Reviewers: aaron.ballman, mehdi_amini, dblaikie Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D26276 llvm-svn: 285899
* Deduplicate sets of replacements by file names.Eric Liu2016-10-141-7/+10
| | | | | | | | | | | | | | | Summary: If there are multiple <File, Replacements> pairs with the same file path after removing dots, we only keep one pair (with path after dots being removed) and discard the rest. Reviewers: djasper Subscribers: klimek, hokein, bkramer, cfe-commits Differential Revision: https://reviews.llvm.org/D25565 llvm-svn: 284219
* Add missing std::move in Replacements::addAlexander Shaposhnikov2016-09-301-1/+1
| | | | | | | | | | | This diff adds std::move to avoid copying of the Replacement NewR in the method Replacements::add. Test plan: make -j8 check-all Differential revision: https://reviews.llvm.org/D25049 llvm-svn: 282949
* Trying to buildbot failures caused by r282577.Eric Liu2016-09-281-1/+6
| | | | llvm-svn: 282583
* Merge conflicting replacements when they are order-independent.Eric Liu2016-09-281-8/+99
| | | | | | | | | | | | | | | | | | | | | | Summary: Now two replacements are considered order-independent if applying them in either order produces the same result. These include (but not restricted to) replacements that: - don't overlap (being directly adjacent is fine) and - are overlapping deletions. - are insertions at the same offset and applying them in either order has the same effect, i.e. X + Y = Y + X if one inserts text X and the other inserts text Y. Discussion about this design can be found in D24717 Reviewers: djasper, klimek Subscribers: omtcyfz, cfe-commits Differential Revision: https://reviews.llvm.org/D24800 llvm-svn: 282577
* Recommit r281457 "Supports adding insertion around non-insertion replacements".Eric Liu2016-09-191-12/+34
| | | | | | | | | | | | | | Summary: Diff to r281457: - added a test case `CalculateRangesOfInsertionAroundReplacement`. Reviewers: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D24606 llvm-svn: 281891
* When replacements have the same offset, make replacements with smaller ↵Eric Liu2016-09-171-9/+3
| | | | | | | | | | | | | | | | | length order first in the set. Summary: No behavioral change intended. The change makes iterating the replacements set more intuitive in Replacements class implementation. Previously, insertion is ordered before an deletion/replacement with the same offset, which is counter-intuitive for implementation, especially for a followup patch to support adding insertions around replacements. With the current ordering, we only need to make `applyAllReplacements` iterate the replacements set reversely when applying them so that deletion/replacement is still applied before insertion with the same offset. Reviewers: klimek, djasper Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D24663 llvm-svn: 281819
* Revert r281457 "Supports adding insertion around non-insertion replacements."Artem Belevich2016-09-141-33/+11
| | | | | | Commit was breaking our internal tests. llvm-svn: 281557
* Supports adding insertion around non-insertion replacements.Eric Liu2016-09-141-11/+33
| | | | | | | | | | | | | | | | | | | | Summary: Extend `tooling::Replacements::add()` to support adding order-independent replacements. Two replacements are considered order-independent if one of the following conditions is true: - They do not overlap. (This is already supported.) - One replacement is insertion, and the other is a replacement with length > 0, and the insertion is adjecent to but not contained in the other replacement. In this case, the replacement should always change the original code instead of the inserted text. Reviewers: klimek, djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D24515 llvm-svn: 281457
* Fixes calculateRangesAfterReplacements crash when Replacements is empty.Eric Liu2016-08-081-0/+2
| | | | | | | | | | Reviewers: klimek, djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D23264 llvm-svn: 278004
* Fix bug in conflict check for Replacements::add().Manuel Klimek2016-08-031-7/+8
| | | | | | | We would not detect conflicts when inserting insertions at the same offset as previously contained replacements. llvm-svn: 277603
* Fix quadratic runtime when adding items to tooling::Replacements.Manuel Klimek2016-08-031-18/+48
| | | | | | | | | | | Previously, we would search through all replacements when inserting a new one to check for overlaps. Instead, make use of the fact that we already have a set of replacments without overlaps to find the potential overlap with lower_bound. Differential Revision: https://reviews.llvm.org/D23119 llvm-svn: 277597
* Implement tooling::Replacements as a class.Eric Liu2016-08-011-203/+159
| | | | | | | | | | | | | | | | | | | Summary: - Implement clang::tooling::Replacements as a class to provide interfaces to control how replacements for a single file are combined and provide guarantee on the order of replacements being applied. - tooling::Replacements only contains replacements for the same file now. Use std::map<std::string, tooling::Replacements> to represent multi-file replacements. - Error handling for the interface change will be improved in followup patches. Reviewers: djasper, klimek Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D21748 llvm-svn: 277335
* [NFC] Header cleanupMehdi Amini2016-07-181-1/+0
| | | | | | | | | | Summary: Removed unused headers, replaced some headers with forward class declarations Patch by: Eugene <claprix@yandex.ru> Differential Revision: https://reviews.llvm.org/D20100 llvm-svn: 275882
* Make tooling::applyAllReplacements return llvm::Expected<string> instead of ↵Eric Liu2016-07-111-3/+7
| | | | | | | | | | | | | | | | empty string to indicate potential error. Summary: return llvm::Expected<> to carry error status and error information. This is the first step towards introducing "Error" into tooling::Replacements. Reviewers: djasper, klimek Subscribers: ioeric, klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D21601 llvm-svn: 275062
* Trying to fix a buffer overflow that broke buildbot ↵Eric Liu2016-06-211-1/+1
| | | | | | sanitizer-x86_64-linux-fast/builds/13946. llvm-svn: 273319
* Added calculateRangesAfterReplaments() to calculate affacted ranges in the ↵Eric Liu2016-06-211-2/+38
| | | | | | | | | | | | | | | | new code. Summary: Added calculateRangesAfterReplaments() to calculate original ranges as well as newly affacted ranges in the new code. Reviewers: klimek, djasper Subscribers: cfe-commits, klimek Differential Revision: http://reviews.llvm.org/D21547 llvm-svn: 273290
* Added formatAndApplyAllReplacements that works on multiple files in libTooling.Eric Liu2016-03-291-9/+14
| | | | | | | | | | | | | | Summary: formatAndApplyAllReplacements takes a set of Replacements, applies them on a Rewriter, and reformats the changed code. Reviewers: klimek, djasper Subscribers: ioeric, klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D17852 llvm-svn: 264745
* Add functions to apply replacements and reformat them.Manuel Klimek2016-03-011-2/+15
| | | | | | | | | | | | | | | | This is a commonly useful feature to have, and we have implemented it multiple times with different kinds of bugs. This implementation centralizes the idea in a set of functions that we can then use from the various tools. Reverts r262234, which is a revert of r262232, and puts the functions into FOrmat.h, as they are closely coupled to clang-format, and we otherwise introduce a cyclic dependency between libFormat and libTooling. Patch by Eric Liu. llvm-svn: 262323
* Revert "Implement new interfaces for code-formatting when applying ↵Manuel Klimek2016-02-291-43/+2
| | | | | | | | replacements." This reverts commit r262232. llvm-svn: 262234
* Implement new interfaces for code-formatting when applying replacements.Manuel Klimek2016-02-291-2/+43
| | | | | | Patch by Eric Liu. llvm-svn: 262232
* Fix calculation of shifted cursor/code positions. Specifically supportDaniel Jasper2015-11-231-21/+19
| | | | | | | | | the case where a specific range is replaced by new text. Previously, the calculation would shift any position from within a replaced region to the first character after the region. This is undersirable, e.g. for clang-format's include sorting. llvm-svn: 253859
* [Tooling] Remove dead code.Benjamin Kramer2015-10-061-9/+1
| | | | | | | | | | It took me some time to figure out why this is not working as expected: std:error_code converts to true if there is an error. This means we never ever took the generated absolute path, which happens to be the right thing anyways as it properly works with virtual files. Just remove the whole thing, relative paths are covered by existing tooling tests. llvm-svn: 249408
* [VFS] Port applyAllReplacements to InMemoryFileSystem.Benjamin Kramer2015-10-061-8/+7
| | | | llvm-svn: 249388
* Fix bad iterator access.Daniel Jasper2015-09-231-1/+2
| | | | llvm-svn: 248375
* clang-format: Add initial #include sorting capabilities.Daniel Jasper2015-09-231-0/+132
| | | | | | | | | To implement this nicely, add a function that merges two sets of replacements that are meant to be done in sequence. This functionality will also be useful for other applications, e.g. formatting the result of clang-tidy fixes. llvm-svn: 248367
* Tooling: When applying a set of replacements, do deletions beforeDaniel Jasper2015-06-161-1/+6
| | | | | | | | insertions. It is unlikely to be the intention to delete parts of newly inserted code. To do so, changed sorting Replacements at the same offset to have decreasing length. llvm-svn: 239809
* Allow replacements created from token ranges to specify language options.Manuel Klimek2015-06-031-7/+10
| | | | | | | | The default language options will lead to incorrect replacements in C++ code, for example when trying to replace nested name specifiers ending in "::". llvm-svn: 238922
* Fix bug in Replacement's toString on Windows (missing flush).Manuel Klimek2015-04-201-4/+4
| | | | | | Adapt function to LLVM coding style. llvm-svn: 235286
* Refactor libTooling to reduce required dependencies.Daniel Jasper2014-10-291-0/+289
This moves classes for storing and applying replacements to separate files. These classes specifically are used by clang-format which doesn't have any other dependencies on clangAST. Thereby, the size of clang-format's binary can be cut roughly in half and its build time sped up. llvm-svn: 220867
OpenPOWER on IntegriCloud