<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Jun 2, 2011, at 10:32 AM, Manuel Klimek wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div>+cfe-dev, -cfe-commits</div><div><br></div><div>As requested by Chris I have reverted the Tooling stuff, and am bumping this thread on cfe-dev.</div></blockquote><div><br></div><div>Hi Manuel,</div><div><br></div><div>Sorry for the delay, I've been swamped with WWDC and trying to catch up on a huge backlog caused by it.</div><div><br></div><blockquote type="cite"><div>Please find the original mail proposing the patch sent to cfe-commits on May 23rd inlined below.</div>
<div><br></div><div>References to the original threads:</div><div>Proposal: <a href="http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20110523/042163.html">http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20110523/042163.html</a></div>
<div>Commit: <a href="http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20110530/042375.html">http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20110530/042375.html</a></div><div><br></div><div>Patches produced by the example tool sent out (has not got feedback yet):</div>
<div>Clang: <a href="http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20110523/042212.html">http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20110523/042212.html</a></div><div>LLVM: <a href="http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20110523/121387.html">http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20110523/121387.html</a></div>
<meta http-equiv="content-type" content="text/html; charset=utf-8"><meta http-equiv="content-type" content="text/html; charset=utf-8"><meta http-equiv="content-type" content="text/html; charset=utf-8"><meta http-equiv="content-type" content="text/html; charset=utf-8"><div>
<br></div><div>More context on why this is useful: when writing code transformation tools to do large scale changes on libraries with clang, we noticed that a lot of the code we wrote was "unrolled" matching of tree structures on the AST, which required a lot of dynamic casting and deeply nested control flow structures.</div></blockquote><div><br></div><div>Ok, I agree that our current infrastructure for pattern matching ASTs is... ehh... "suboptimal" ;-). I'm really thrilled you guys are working on improving this.</div><div><br></div><div><blockquote type="cite"><div>The future work (as outlined to some extend in the original email) is to build up code transformation tools (including the standard refactoring tools we know from other languages) and libraries to make it easy for developers to contribute both generally useful tools and make it easy to write one-off tools for cleanup transformations on larger code bases.</div></blockquote><div><div><br></div></div><div>This goal is really really fantastic, something that I've been hoping that Clang would grow into from the very beginning.</div></div><br><blockquote type="cite">
<div>The library we implemented based on those findings allows a very declarative way of expressing interesting parts of the AST that you want to work on, with a callback mechanism to have an imperative part that does the actual transformation. The way this library uses templates to build up a reverse hierarchy of the clang AST allows us to expand the library of matchers without needing to manually copy the structure of the AST while still providing full compile time type checking.</div>
<div>We have used this library for many internal transformations (one more broadly applicable of them being included as an example tool), and Nico may be able to explain more how he's using the infrastructure for Chromium.</div>
</blockquote><br></div><div>My primary concern with this work is that it is built as a series of *compile-time* code constructs. This means that someone working on a rewriter needs to rebuild the clang executable to do this. Instead of doing this as a compile-time construct, have you considered building this as an extensible pattern matching tool where the pattern and replacement can be specified at runtime? I'm envisioning something like a "regular expression for an AST". You don't need to rebuild grep every time you want to search for something new in text.</div><div><br></div><div>Even in the case where compiled-in code is required, having a more dynamic matcher would greatly simplify the code doing the matching. Have you considered this approach?</div><div><br></div><div>-Chris</div><br></body></html>