summaryrefslogtreecommitdiff
path: root/lib/Tooling/Refactoring.cpp
Commit message (Collapse)AuthorAgeFilesLines
* [clang] Adopt new FileManager error-returning APIsHarlan Haskins2019-08-011-1/+4
| | | | | | | | 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> git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@367616 91177308-0d34-0410-b5e6-96231b3b80d8
* 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@351636 91177308-0d34-0410-b5e6-96231b3b80d8
* Apply clang-tidy's performance-unnecessary-value-param to parts of clang.Benjamin Kramer2017-03-211-1/+1
| | | | | | No functionality change intended. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@298443 91177308-0d34-0410-b5e6-96231b3b80d8
* clang-format: Make GetStyle return Expected<FormatStyle> instead of FormatStyleAntonio Maiorano2017-01-171-4/+9
| | | | | | | | | | Change the contract of GetStyle so that it returns an error when an error occurs (i.e. when it writes to stderr), and only returns the fallback style when it can't find a configuration file. Differential Revision: https://reviews.llvm.org/D28081 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@292174 91177308-0d34-0410-b5e6-96231b3b80d8
* Deduplicate replacements by FileEntry instead of file names.Eric Liu2016-11-071-2/+4
| | | | | | | | | | | | | | | 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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@286096 91177308-0d34-0410-b5e6-96231b3b80d8
* Deduplicate sets of replacements by file names.Eric Liu2016-10-141-2/+2
| | | | | | | | | | | | | | | 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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@284219 91177308-0d34-0410-b5e6-96231b3b80d8
* Implement tooling::Replacements as a class.Eric Liu2016-08-011-6/+10
| | | | | | | | | | | | | | | | | | | 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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@277335 91177308-0d34-0410-b5e6-96231b3b80d8
* [NFC] Header cleanupMehdi Amini2016-07-181-2/+1
| | | | | | | | | | Summary: Removed unused headers, replaced some headers with forward class declarations Patch by: Eugene <claprix@yandex.ru> Differential Revision: https://reviews.llvm.org/D20100 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@275882 91177308-0d34-0410-b5e6-96231b3b80d8
* Make tooling::applyAllReplacements return llvm::Expected<string> instead of ↵Eric Liu2016-07-111-2/+6
| | | | | | | | | | | | | | | | 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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@275062 91177308-0d34-0410-b5e6-96231b3b80d8
* Avoid unnecessary std::string copies. NFC.Benjamin Kramer2016-05-291-2/+2
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@271182 91177308-0d34-0410-b5e6-96231b3b80d8
* Added formatAndApplyAllReplacements that works on multiple files in libTooling.Eric Liu2016-03-291-0/+25
| | | | | | | | | | | | | | 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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@264745 91177308-0d34-0410-b5e6-96231b3b80d8
* Introduce a PCHContainerOperations interface (NFC).Adrian Prantl2015-06-201-3/+4
| | | | | | | | | | | | | | | | A PCHContainerOperations abstract interface provides operations for creating and unwrapping containers for serialized ASTs (precompiled headers and clang modules). The default implementation is RawPCHContainerOperations, which uses a flat file for the output. The main application for this interface will be an ObjectFilePCHContainerOperations implementation that uses LLVM to wrap the module in an ELF/Mach-O/COFF container to store debug info alongside the AST. rdar://problem/20091852 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@240225 91177308-0d34-0410-b5e6-96231b3b80d8
* Refactor libTooling to reduce required dependencies.Daniel Jasper2014-10-291-261/+0
| | | | | | | | | | 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@220867 91177308-0d34-0410-b5e6-96231b3b80d8
* Tooling: Ignore file names in tooling::deduplicate.Benjamin Kramer2014-09-091-5/+19
| | | | | | | | | | | This was horribly broken due to how the sort predicate works. We would report a conflict for files with a replacement in the same position but different names if the length differed. Just ignore paths as this is often what the user wants. Files can occur with different names (due to symlinks or relative paths) and we don't ever want to do the same edit in one file twice. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@217439 91177308-0d34-0410-b5e6-96231b3b80d8
* Overload SourceManager::overrideFileContents so that unconditionally passing ↵David Blaikie2014-08-271-1/+1
| | | | | | | | | | ownership is explicitly done using unique_ptr. Only those callers who are dynamically passing ownership should need the 3 argument form. Those accepting the default ("do pass ownership") should do so explicitly with a unique_ptr now. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@216614 91177308-0d34-0410-b5e6-96231b3b80d8
* Update for LLVM api change.Rafael Espindola2014-08-271-2/+3
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@216585 91177308-0d34-0410-b5e6-96231b3b80d8
* Replace llvm::error_code with std::error_code.Rafael Espindola2014-06-121-1/+1
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@210780 91177308-0d34-0410-b5e6-96231b3b80d8
* [C++11] Use 'nullptr'. Tooling edition.Craig Topper2014-05-201-2/+2
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@209192 91177308-0d34-0410-b5e6-96231b3b80d8
* Added a const qualifier to SourceManager& parameters.Alexander Kornienko2014-03-051-5/+7
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@202964 91177308-0d34-0410-b5e6-96231b3b80d8
* Sort all the #include lines with LLVM's utils/sort_includes.py whichChandler Carruth2014-01-071-1/+1
| | | | | | | encodes the canonical rules for LLVM's style. I noticed this had drifted quite a bit when cleaning up LLVM, so wanted to clean up Clang as well. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@198686 91177308-0d34-0410-b5e6-96231b3b80d8
* Use Rewriter::overwriteChangedFiles() directlyAlp Toker2013-10-291-17/+1
| | | | | | | | | | | | | This replaces the custom code in RefactoringTool::saveRewrittenFiles() which lacked atomic file saving and error diagnostics, resolving an old FIXME from r157331. Landing this time with the proper return code, plus a very unhelpful comment cleared up. Rubber-stamped by Manuel Klimek. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@193594 91177308-0d34-0410-b5e6-96231b3b80d8
* Revert "Use Rewriter::overwriteChangedFiles() directly"Alp Toker2013-10-291-1/+17
| | | | | | | | This wasn't ready for prime time yet, seems to break tools-extra. This reverts commit r193590. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@193592 91177308-0d34-0410-b5e6-96231b3b80d8
* Use Rewriter::overwriteChangedFiles() directlyAlp Toker2013-10-291-17/+1
| | | | | | | | | The old code in RefactoringTool::saveRewrittenFiles() lacked atomic moves and diagnostics and had FIXME to this effect. Rubber-stamped by Manuel Klimek. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@193590 91177308-0d34-0410-b5e6-96231b3b80d8
* Reverted r192992 broke windows and freebsd builds.Ariel J. Bernal2013-10-181-10/+4
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@192997 91177308-0d34-0410-b5e6-96231b3b80d8
* This patch fixes replacements that are not applied when relative paths areAriel J. Bernal2013-10-181-4/+10
| | | | | | | | | | | specified. In particular it makes sure that relative paths for non-virtual files aren't made absolute. Added unittest. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@192992 91177308-0d34-0410-b5e6-96231b3b80d8
* Revert commit r192299 until find a way to account for simlinks in OS X.Ariel J. Bernal2013-10-091-10/+4
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@192313 91177308-0d34-0410-b5e6-96231b3b80d8
* This patch fixes replacements that are not applied when relative paths areAriel J. Bernal2013-10-091-7/+12
| | | | | | | | | | | specified. In particular it makes sure that relative paths for non-virtual files aren't made absolute. Added unittest test. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@192299 91177308-0d34-0410-b5e6-96231b3b80d8
* Fixed replacements for files with relative paths are not applied.Ariel J. Bernal2013-10-011-1/+12
| | | | | | | | | Replacements were no applied when using a compilation database with paths in the compilation command relative to the compile directory. This patch makes those paths abosulte. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@191776 91177308-0d34-0410-b5e6-96231b3b80d8
* Adding a vector version of clang::tooling::shiftedCodePosition().Edwin Vane2013-08-271-0/+17
| | | | | | | | | | | During the transition of clang::tooling::Replacements from std::set to std::vector, functions such as clang::tooling::applyAllReplacements() have been duplicated to take a std::vector<Replacement>. Applying this same temporary duplication to clang::tooling::shiftedCodePosition(). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@189358 91177308-0d34-0410-b5e6-96231b3b80d8
* Tweak Replacement comparisonsEdwin Vane2013-08-161-13/+14
| | | | | | | | | | * Introduce operator< to replace Replacement::Less * Make operator== and operator< on Replacements non-member functions * Change order of comparisons in operator< to do string comparisons last git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@188550 91177308-0d34-0410-b5e6-96231b3b80d8
* Adding a vector version of tooling::applyAllReplacementsEdwin Vane2013-08-131-0/+17
| | | | | | | | | | | | | One day soon, tooling::Replacements will be changed from being implemented as an std::set to being implemented as an std::vector. Until then, some new code using vectors of Replacements would enjoy having a version of applyAllReplacements that takes a vector. Differential Revision: http://llvm-reviews.chandlerc.com/D1380 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@188295 91177308-0d34-0410-b5e6-96231b3b80d8
* Fixing a conflict detection bug in tooling::deduplicateEdwin Vane2013-08-131-2/+3
| | | | | | | | | | If a Replacment is contained within the conflict range being built, the conflict range would be erroneously shortened. Now fixed. Tests updated to catch this case. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@188287 91177308-0d34-0410-b5e6-96231b3b80d8
* Introduce Replacement deduplication and conflict detection functionEdwin Vane2013-08-081-0/+44
| | | | | | | | | | | | Summary: This patch adds tooling::deduplicate() which removes duplicates from and looks for conflicts in a vector of Replacements. Differential Revision: http://llvm-reviews.chandlerc.com/D1314 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@187979 91177308-0d34-0410-b5e6-96231b3b80d8
* Constify Replacements parameter to applyAllReplacements.David Blaikie2013-07-171-4/+4
| | | | | | | | http://llvm-reviews.chandlerc.com/D1169 Patch by Guillaume Papin. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@186526 91177308-0d34-0410-b5e6-96231b3b80d8
* Update for llvm API change.Rafael Espindola2013-07-161-2/+2
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@186448 91177308-0d34-0410-b5e6-96231b3b80d8
* Let clang-format move the cursor appropriately.Daniel Jasper2013-05-211-0/+13
| | | | | | | | | With this patch, clang-format will try to keep the cursor at the original code position in editor integrations (implemented for emacs and vim). This means, after formatting, clang-format will try to keep the cursor on the same character of the same token. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@182373 91177308-0d34-0410-b5e6-96231b3b80d8
* Add a more convenient interface to use clang-format.Daniel Jasper2013-05-161-13/+44
| | | | | | | | | | | | It turns out that several implementations go through the trouble of setting up a SourceManager and Lexer and abstracting this into a function makes usage easier. Also abstracts SourceManager-independent ranges out of tooling::Refactoring and provides a convenience function to create them from line ranges. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@181997 91177308-0d34-0410-b5e6-96231b3b80d8
* Remove useless 'llvm::' qualifier from names like StringRef and others that areDmitri Gribenko2013-01-121-7/+7
| | | | | | | brought into 'clang' namespace by clang/Basic/LLVM.h git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172323 91177308-0d34-0410-b5e6-96231b3b80d8
* Allow RefactoringTool to write to memory instead of always to diskEdwin Vane2013-01-111-29/+34
| | | | | | | | | | | | | | | | | | RefactoringTool::run() always writes the result of rewrites to disk. Instead, make this optional and provide a method for getting the refactoring results in a memory buffer instead. Also made ClangTool polymorphic so RefactoringTool could inherit from it to properly express the IS-A relationship. This change also provides access to ClangTool's public interface, e.g. mapVirtualFile() which is important once refactored buffers start living in memory instead of on disk. Reviewers: klimek git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172219 91177308-0d34-0410-b5e6-96231b3b80d8
* Make DiagnosticOptions intrusively reference-counted, and make sureDouglas Gregor2012-10-231-5/+4
| | | | | | | | the various stakeholders bump up the reference count. In particular, the diagnostics engine now keeps the DiagnosticOptions object alive. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@166508 91177308-0d34-0410-b5e6-96231b3b80d8
* Split library clangRewrite into clangRewriteCore and clangRewriteFrontend.Ted Kremenek2012-09-011-1/+1
| | | | | | | This is similar to how we divide up the StaticAnalyzer libraries to separate core functionality to what is clearly associated with Frontend actions. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@163050 91177308-0d34-0410-b5e6-96231b3b80d8
* Adds a toString method to Replacement, which helps debugging.Manuel Klimek2012-05-301-0/+8
| | | | | | | | Adds missing header guards to Refactoring.h. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@157694 91177308-0d34-0410-b5e6-96231b3b80d8
* Adds the Refactoring library, which is a layer on top of the Tooling libraryManuel Klimek2012-05-231-0/+178
that allows easy refactoring across translation units. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@157331 91177308-0d34-0410-b5e6-96231b3b80d8