[PATCH] D102555: [libclang] Enhance support for source-to-source rewriting

Sam Vervaeck via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat May 15 08:46:59 PDT 2021


samvv created this revision.
samvv added reviewers: rsmith, jkorous.
Herald added a subscriber: arphaman.
samvv requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Hi! This is my first time submitting a patch to LLVM/Clang, so apologies if I'm doing anything wrong. Eager to learn.

This patch exposes some additional Rewriter methods in libclang and the Python bindings, making it possible to write simple transformations in Python. **This patch modifies the ABI signature of clang_CXRewriter_insertTextBefore.** I do not know what the policy is regarding the modification of an existing API function in libclang, so you have been warned.

- Added clang_CXRewriter_getMainFileContents
- Added clang_CXRewriter_insertTextAfter
- Added a parameter to clang_CXRewriter_insertTextBefore to control indentation
- Modified clang_CXRewriter_insertTextBefore to accept an additional `InsertIndent` argument
- Added a Rewriter class in the Python bindings
- Added `test_rewriter.py` with some unit tests for the new Python bindings
- Applied clang-format at HEAD to the modified C++ files, which caused some of the existing lines to change

I did not discuss this change over at cfe-dev because I thought the change is fairly trivial. If all changes are required to go through cfe-dev first do let me know.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D102555

Files:
  clang/bindings/python/clang/cindex.py
  clang/bindings/python/tests/cindex/test_rewriter.py
  clang/include/clang-c/Rewrite.h
  clang/tools/libclang/Rewrite.cpp
  clang/tools/libclang/libclang.exports

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D102555.345640.patch
Type: text/x-patch
Size: 8393 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210515/6385568d/attachment-0001.bin>


More information about the cfe-commits mailing list