<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>
<br><div><div>On Jan 13, 2014, at 5:19 PM, Samuel Benzaquen <<a href="mailto:sbenza@google.com">sbenza@google.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Jan 13, 2014 at 3:18 PM, Christian Schafmeister <span dir="ltr"><<a href="mailto:meister@temple.edu" target="_blank" class="cremed">meister@temple.edu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div>So, I managed to hack/rewrite parts of Registry.cpp, Registry.h, Marshaller.h and Diagnostics.h so that they work with Common Lisp Symbols and Conses.</div>
<div class="im">I can now assemble ASTMatchers from s-expressions. </div><div>I exposed the entire ASTMatcher interface in one go - so I can write any ASTMatcher using S-expressions that can be written with the C++ DSL.</div>
<div><br></div><div>Using the C++ DSL you would use:</div><div>fieldDecl(hasType(recordDecl(isDerivedFrom(recordDecl(hasName(“GCObject”)))))).bind(“all”)</div><div><br></div><div>In Common Lisp I would use:</div><div>(:bind :all (:field-decl (:has-type (:record-decl (:is-derived-from (:record-decl (:has-name "GCObject"))))))))</div>
<div><br></div><div><br></div><div>Question:</div><div><br></div><div>How do you get proficient at writing these matchers? I still struggle with it. </div></div></blockquote><div><br></div><div>In theory, they should read as english (with some bad grammar =P).</div>
<div>In your example, it reads as:</div><div>"A <fieldDecl> that a <hasType> that is a <recordDecl> which <isDerivedFrom> ..."</div><div>In my experience, the hardest part is figuring out which matchers to use (which basically requires knowing about them), not how to assemble them. <br></div></div></div></div></blockquote><div><br></div>Thanks - that helps. </div><div><br><blockquote type="cite"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div>
</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div>Do you have some way of looking at the AST dumps and then inverting them in your head into queries?</div>
</div></blockquote><div><br></div><div>I don't see what you mean by inverting.</div></div></div></div></blockquote><div><br></div>I got that from the first talk that I saw Chandler Carruth present on the ASTMatcher library:</div><div><a href="http://www.youtube.com/watch?v=mVbDzTM21BQ">http://www.youtube.com/watch?v=mVbDzTM21BQ</a> at 14:40</div><div><br></div><div>It sounded fascinating and planted this idea of exposing the ASTMatcher library in the Common Lisp system/compiler that I was just starting to write.</div><div><br></div><div>I still have no clear idea what he was talking about “...invert the AST and turn it into a set of matchers…” but it sounded compelling - hilarious huh?</div><div><br></div><div><br></div><div><br><blockquote type="cite"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div>There are two types of matchers: filters and traversal.</div><div>The filters check properties on the nodes, like "hasName()".</div>
<div>The traversal matchers help you reach other nodes in the AST, like "hasType()”.</div></div></div></div></blockquote><div><br></div>Two types of matchers - filter & traversal - that part I get - what about Narrowing matchers?</div><div>The traversal matchers somewhat correspond to methods of the node classes that they traverse from - right?</div><div>Like Expr nodes have a Expr::getType() method and an "expr()" matcher can have a “hasType()” matcher as an argument - as in “expr(hasType(…))”?</div><div><br></div><div>Can you help me understand the docs on <a href="http://clang.llvm.org/docs/LibASTMatchersReference.html?">http://clang.llvm.org/docs/LibASTMatchersReference.html?</a></div><div>There are the rows with three columns “Return Type” “Name” “Parameters”.</div><div>I understand the type of the parameters. What does the “Return type” tell us? Does it mean that you can only use that matcher X as a parameter of matcher Y if matcher Y accepts matcher Xs “Return Type” (or a more derived type) as a “Parameters” type?</div><div><br></div><div><blockquote type="cite"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><br></div><div>There are various trees that are interconnected; expressions, declarations and types. Matchers allow you to go from one to the other.</div>
<div>Eg. you can go from an expression (like &a->foo) to its type, from a type to some expression (like getting the initializer for a member field), etc.</div><div>In each tree you can also go up and down the hierarchies. Eg. you can go from Foo[] type to Foo, or from "1+foo->bar()" to "1" and "foo->bar()”.</div></div></div></div></blockquote><div><br></div>Ok, that is very helpful - thank you.</div><div><br></div><div>Best,</div><div><br></div><div>.Chris.</div><div><br></div><div><br></div><br></body></html>