This is an archive of the discontinued LLVM Phabricator instance.

[Tooling][RFC] Introduce Stencil library to simplify source code generation in refactorings.
AbandonedPublic

Authored by ymandel on Jan 18 2019, 1:40 PM.

Details

Reviewers
None
Summary

REQUEST FOR COMMENT: this is not intended (yet) as a proper revision. It complements the design document for Transformer:
https://docs.google.com/document/d/1ppw0RhjwsrbBcHYhI85pe6ISDbA6r5d00ot3N8cQWeQ/edit?usp=sharing

The key point of this revision is to share the APIs and tests. I include the code as well so that readers can run the unittests and potentially experiment w/ the library as well. Based on the outcome of discussion here, I will break this revision into multiple subsequent revisions for proper review.

This revision introduces three libraries:

  1. Stencil, which is designed to complement the AST matchers in support of writing source-to-source transformations. A stencil is similar in spirit to a format string: it is composed of a series of raw text strings, references to node ids (bound in a corresponding matcher) and helper code-generation operations. A stencil can be applied to a match result and uses that result to find all nodes referenced in the stencil and then produce a source string.
  2. Transformer, which provides a concise syntax for specifying code transformations. This library is the main focus of the document mentioned above.
  3. TransformerTidy, which provides a simple way to create a ClangTidy class from any Transformer rewrite rule.

Event Timeline

ymandel created this revision.Jan 18 2019, 1:40 PM
jfb added a subscriber: dcoughlin.Jan 18 2019, 1:57 PM
ymandel updated this revision to Diff 185301.Feb 5 2019, 7:08 AM
ymandel edited the summary of this revision. (Show Details)

Added the Transformer and TransformerTidy libraries and corresponding tests.

Herald added a project: Restricted Project. · View Herald TranscriptFeb 5 2019, 7:08 AM
Herald added a subscriber: mgorny. · View Herald Transcript
ymandel updated this revision to Diff 186667.Feb 13 2019, 7:51 AM

Added two example uses of Transformer in clang-tidy.

Specifically, updated readability-delete-null-pointer and readability-else-after-return checks to use Transformer. In both cases, we do not maintain 100% fidelity with original check. In particular, Transformer does not preserve whitespace as carefully as those checks were implemented. We have updated the tests to make clear the differences.

See also: https://lists.llvm.org/pipermail/cfe-dev/2019-February/061414.html
How are these two RFC's/API's supposed to interact/coexist/etc?

ymandel abandoned this revision.May 21 2019, 6:21 AM

This ideas in this revisions are gradually being committed.