summaryrefslogtreecommitdiffstats
path: root/clang/lib/Tooling/Refactoring/Transformer.cpp
Commit message (Collapse)AuthorAgeFilesLines
* [libTooling] Move Transformer files to their own directory/library.Yitzhak Mandelbaum2019-10-101-235/+0
| | | | | | | | | | | | | | | | | | | Summary: The Transformer library has been growing inside of lib/Tooling/Refactoring. However, it's not really related to anything else in that directory. This revision moves all Transformer-related files into their own include & lib directories. A followup revision will (temporarily) add forwarding headers to help any users migrate their code to the new location. Reviewers: gribozavr Subscribers: mgorny, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D68637 llvm-svn: 374271
* [libTooling] Transformer: refine `SourceLocation` specified as anchor of ↵Yitzhak Mandelbaum2019-09-271-12/+21
| | | | | | | | | | | | | | | | | | | | | | | changes. Summary: Every change triggered by a rewrite rule is anchored at a particular location in the source code. This patch refines how that location is chosen and defines it as an explicit function so it can be shared by other Transformer implementations. This patch was inspired by a bug found by a clang tidy, wherein two changes were anchored at the same location (the expansion loc of the macro) resulting in the discarding of the second change. Reviewers: gribozavr Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D66652 llvm-svn: 373093
* [Tooling] Add a hack to work around issues with matcher binding in r368681.David L. Jones2019-08-151-2/+4
| | | | | | | | | | | | | | | | | | | | | | The change in r368681 contains a (probably unintentional) behavioral change for rewrite rules with a single matcher. Previously, the single matcher would not need to be bound (`joinCaseMatchers` returned it directly), even though a final DynTypeMatcher was created and bound by `buildMatcher`. With the new change, a single matcher will be bound, in addition to the final binding (which is now in `buildMatchers`, but happens roughly at the same point in the overall flow). This patch simply duplicates the "final matcher" trick: it creates an extra DynTypedMatcher for each rewrite rule case matcher, and unconditionally makes it bindable. This is probably not the right long-term fix, but it does allow existing code to continue to work with this interface. Subscribers: cfe-commits, gribozavr, ymandel Tags: #clang Differential Revision: https://reviews.llvm.org/D66273 llvm-svn: 368958
* [libTooling] Fix code to avoid unused-function warning after r368681.Yitzhak Mandelbaum2019-08-141-0/+2
| | | | llvm-svn: 368862
* [libTooling] In Transformer, generalize `applyFirst` to admit rules with ↵Yitzhak Mandelbaum2019-08-131-60/+47
| | | | | | | | | | | | | | | | | | | | | incompatible matchers. Summary: This patch removes an (artificial) limitation of `applyFirst`, which requires that all of the rules' matchers can be grouped together in a single `anyOf()`. This change generalizes the code to group the matchers into separate `anyOf`s based on compatibility. Correspondingly, `buildMatcher` is changed to `buildMatchers`, to allow for returning a set of matchers rather than just one. Reviewers: gribozavr Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D65877 llvm-svn: 368681
* [LibTooling] Relax Transformer to allow rewriting macro expansionsYitzhak Mandelbaum2019-07-181-34/+6
| | | | | | | | | | | | | | | | | | | | Summary: Currently, Transformer rejects any changes to source locations inside macro expansions. This change relaxes that constraint to allow rewrites when the entirety of the expansion is replaced, since that can be mapped to replacing the entirety of the expansion range in the file source. This change makes Transformer consistent with the handling of edit ranges in `clang::edit::Commit` (which is used, for example, for applying `FixItHint`s from diagnostics). Reviewers: ilya-biryukov Subscribers: gribozavr, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D64518 llvm-svn: 366473
* [LibTooling] Extend `RewriteRule` with support for adding includes.Yitzhak Mandelbaum2019-07-021-4/+22
| | | | | | | | | | | | | | | | | | Summary: This revision allows users to specify the insertion of an included directive (at the top of the file being rewritten) as part of a rewrite rule. These directives are bundled with `RewriteRule` cases, so that different cases can potentially result in different include actions. Reviewers: ilya-biryukov, gribozavr Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D63892 llvm-svn: 364917
* [LibTooling] Add Explanation parameter to `makeRule`.Yitzhak Mandelbaum2019-05-241-4/+4
| | | | | | | | | | | | | | | | | Summary: Conceptually, a single-case RewriteRule has a matcher, edit(s) and an (optional) explanation. `makeRule` previously only took the matcher and edit(s). This change adds (optional) support for the explanation. Reviewers: ilya-biryukov Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D62390 llvm-svn: 361643
* [LibTooling] Update Transformer to use RangeSelector instead of NodePart enum.Yitzhak Mandelbaum2019-05-221-89/+13
| | | | | | | | | | | | | | | | | Transformer provides an enum to indicate the range of source text to be edited. That support is now redundant with the new (and more general) RangeSelector library, so we remove the custom enum support in favor of supporting any RangeSelector. Reviewers: ilya-biryukov Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D62149 llvm-svn: 361392
* [LibTooling] Add support to Transformer for composing rules as an ordered ↵Yitzhak Mandelbaum2019-05-171-8/+105
| | | | | | | | | | | | | | | | | | | | choice. This revision updates `RewriteRule` to support multiple subrules that are interpreted as an ordered-choice (apply the first one that matches). With this feature, users can write the rules that appear later in the list of subrules knowing that previous rules' patterns *have not matched*, freeing them from reasoning about those cases in the current pattern. Reviewers: ilya-biryukov Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D61335 llvm-svn: 361037
* [LibTooling] Change Transformer's TextGenerator to a partial function.Yitzhak Mandelbaum2019-04-301-19/+21
| | | | | | | | | | | | | | | | | | | | | | Summary: Changes the signature of the TextGenerator std::function to return an Expected<std::string> instead of std::string to allow for (non-fatal) failures. Previously, we expected that any failures would be expressed with assertions. However, that's unfriendly to running the code in servers or other places that don't want their library calls to crash the program. Correspondingly, updates Transformer's handling of failures in TextGenerators and the signature of `ChangeConsumer`. Reviewers: ilya-biryukov Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D61015 llvm-svn: 359574
* [LibTooling] Fix build breakage from commit 7b7ce6683ee.Yitzhak Mandelbaum2019-04-181-1/+2
| | | | | | | | On configurations with -Werror,-Wmissing-field-initializers, the commit does not compile. This commit fixes the offending line. Original Differential Revision: https://reviews.llvm.org/D60408 llvm-svn: 358705
* [LibTooling] Extend Transformer to support multiple simultaneous changes.Yitzhak Mandelbaum2019-04-181-39/+57
| | | | | | | | | | | | | | | | Summary: This revision allows users to specify independent changes to multiple (related) sections of the input. Previously, only a single section of input could be selected for replacement. Reviewers: ilya-biryukov Reviewed By: ilya-biryukov Subscribers: jfb, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D60408 llvm-svn: 358697
* [LibTooling] Add Transformer, a library for source-to-source transformations.Yitzhak Mandelbaum2019-04-051-0/+203
| | | | | | | | | | | | | | | | Summary: Adds a basic version of Transformer, a library supporting the concise specification of clang-based source-to-source transformations. A full discussion of the end goal can be found on the cfe-dev list with subject "[RFC] Easier source-to-source transformations with clang tooling". Reviewers: ilya-biryukov Reviewed By: ilya-biryukov Subscribers: ioeric, ABataev, mgorny, jfb, jdoerfert, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D59376 llvm-svn: 357768
* Revert "[LibTooling] Add Transformer, a library for source-to-source ↵Alexey Bataev2019-04-031-204/+0
| | | | | | | | | transformations." This reverts commit r357576 to fix the problem with the cyclic dependencies between libTooling and libToolingRefactor. llvm-svn: 357612
* [LibTooling] Add Transformer, a library for source-to-source transformations.Yitzhak Mandelbaum2019-04-031-0/+204
Summary: Adds a basic version of Transformer, a library supporting the concise specification of clang-based source-to-source transformations. A full discussion of the end goal can be found on the cfe-dev list with subject "[RFC] Easier source-to-source transformations with clang tooling". Reviewers: ilya-biryukov Reviewed By: ilya-biryukov Subscribers: mgorny, jfb, jdoerfert, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D59376 llvm-svn: 357576
OpenPOWER on IntegriCloud