MARTINI: The Little Match and Replace Tool for Automatic Code Rewriting

Alister Johnson, Camille Coti, Allen D. Malony, Johannes Doerfert · The Journal of Open Source Software · 2022

Rewriting code for cleanliness, API changes, and new programming models is a common, yet time-consuming task.Localized or syntax-based changes are often mechanical and can be automated with text-based tools, like Unix's sed.However, non-localized or semantic-based changes require specialized tools that usually come with complex, hard-coded rules that require expertise in compilers.This means existing techniques for code rewriting are either too simple for complex tasks or too complex to be customized by non-expert users; in either case, developers are often forced to manually update their code instead.This work presents MARTINI, a new approach to code rewriting built on the Clang compiler, which exposes complex and semantic-driven rewrite capabilities to users in a simple and natural way.Rewrite rules are expressed as a pair of parameterized "before-and-after" code snippets in the source language, one to describe what to match and one to describe what the replacement looks like.Through this novel and user-friendly interface, programmers can automate and customize complex code changes which require a deep understanding of the language without any knowledge of compiler internals.

Read the paper · More papers on PaperTik