This is an archive of the discontinued LLVM Phabricator instance.

[libclang] Enhance support for source-to-source rewriting
Needs ReviewPublic

Authored by samvv on May 15 2021, 8:46 AM.

Details

Reviewers
rsmith
jkorous
Summary

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@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.

Diff Detail

Event Timeline

samvv created this revision.May 15 2021, 8:46 AM
samvv requested review of this revision.May 15 2021, 8:46 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 15 2021, 8:46 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
samvv updated this revision to Diff 345641.May 15 2021, 8:52 AM

Attempt at re-running clang-format-13.

jkorous resigned from this revision.Jan 21 2022, 3:48 PM

I'm not expert on this to review but I'm interested as a user. @samvv are you still working on this? Do you have any input from the community?

ggeorgakoudis no currently not. It has been stale for about a year. I also don't have a lot of time to to follow up right now, but I'll try to help if there is anything I can do.

  • Original Message --------