<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><br><div><div>On Jan 7, 2014, at 12:12 PM, Manuel Klimek <<a href="mailto:klimek@google.com">klimek@google.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Jan 7, 2014 at 5:16 PM, Christian Schafmeister<span class="Apple-converted-space"> </span><span dir="ltr"><<a href="mailto:chris.schaf@verizon.net" target="_blank">chris.schaf@verizon.net</a>></span><span class="Apple-converted-space"> </span>wrote:<br><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;"><div style="word-wrap: break-word;"><div>Hey folks,</div><div><br></div><div><br></div><div>I’ve written a new Common Lisp environment/compiler over the past two years. </div><div>It uses LLVM as the back-end (by exposing the LLVM C++ library to Common Lisp) and interoperates with C++ in that it has a template library like boost::python for exposing arbitrary C++ classes/functions to Common Lisp. </div><div><br></div><div>I want to do some automated refactoring to improve my C++ code so I’m exposing the Clang ASTMatcher and Refactoring libraries.</div><div><br></div><div>I also think it would be really cool to write refactoring tools in a dynamic language like Lisp - without all the exhausting boilerplate required by the C++ approach.</div></div></blockquote><div><br></div><div>C++ refactoring tools actually don't require that much boilerplate… </div></div></div></div></div></blockquote><div><br></div>Sorry, my statement sounded like a criticism - I never mean to criticize - these languages are what they are. </div><div>I was just speaking about my feelings from writing a few simple refactoring tools in C++ and my motivations for implementing a Common Lisp compiler and writing refactoring tools in Common Lisp. I’m a new convert to Common Lisp - I just discovered it two years ago and most of my experience with it is writing a self-hosting compiler.</div><div><br></div><div><br></div><div><blockquote type="cite"><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div> </div><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;"><div style="word-wrap: break-word;"><div>So I’m exposing the Clang AST library to this Common Lisp environment with the goal of writing a general tool for writing C++ refactoring tools in Common Lisp.</div><div><br></div><div>My goal is to mimic C++ ASTMatchers like:</div><div><b style="color: rgb(34, 34, 34);"><br></b></div><div><b style="color: rgb(34, 34, 34);">recordDecl(hasDescendant(</b></div><div><b style="color: rgb(34, 34, 34);"> <span class="Apple-converted-space"> </span>ifStmt(hasTrueExpression(</b></div><div><b style="color: rgb(34, 34, 34);"> <span class="Apple-converted-space"> </span>expr(hasDescendant(</b></div><div><b style="color: rgb(34, 34, 34);"> <span class="Apple-converted-space"> </span>ifStmt()))))))</b></div><div><br></div><div>Using S-expressions: <b>(record-decl (has-descendent (if-stmt (has-true-expression (expr (has-descendant( if-stmt))))))) </b> </div><div><br></div><div>And the source-to-source translation code will be small lambda functions that use the resulting MatchResults.</div><div><br></div><div>That way I don’t have to write a lot of documentation :-).</div><div><br></div><div>Currently I’m looking at calling the ASTMatcher/Dynamic/VariantValue interface to build ASTMatchers from S-expressions - does that sound like a good idea - or is there a better approach I should be exploring?</div></div></blockquote><div><br></div><div>Well, if your boost shim can already match "arbitrary C++ classes / functions", then it should in principle be able to expose the AST matchers as is (without the need to go through the dynamic parsing).</div><div>After all, the matchers are mostly just template functions :)</div></div></div></div></div></blockquote><div><br></div>I was trying to figure out how to do that at first but the ASTMatchers looked more exotic than just simple functions.</div><div><br></div><div>For instance “namedDecl” has the type internal::VariadicDynCastAllOfMatcher<Decl,NamedDecl></div><div><div>VariadicDynCastAllOfMatcher is defined as:</div><div><br></div><div>template <typename SourceT, typename TargetT></div><div>class VariadicDynCastAllOfMatcher</div><div> : public llvm::VariadicFunction<</div><div> BindableMatcher<SourceT>, Matcher<TargetT>,</div><div> makeDynCastAllOfComposite<SourceT, TargetT> > {</div><div>public:</div><div> VariadicDynCastAllOfMatcher() {}</div><div>};</div></div><div><br></div><div>llvm::VariadicFunction has many templated overloads of "operator()"</div><div>I haven’t written template code to automatically wrap variadic functions (as in functions that take … ellipses).</div><div><br></div><div>I can wrap functions that take ArrayRef’s though - is there a function like namedDecl(ArrayRef<ASTMatcher>) for ASTMatchers?</div><div><br></div><div>I’ve only been getting deep into C++ template programming for about two months so I’m still struggling with reading complex template code.</div><div><br></div><div><br></div><div><br></div><div><br><blockquote type="cite"><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><br></div><div>Otherwise I think going the dynamic matcher route is a good approach.</div><div><br></div><div>Cheers,</div><div>/Manuel</div></div></div></div></div></blockquote></div><br></body></html>