<div dir="ltr">Manuel asked me for more info.<div><br></div><div>Given a checker like this:</div><div><br></div><div><div>class MyChecker : </div><div>    public Checker< check::PreStmt<ReturnStmt> > {</div></div><div>public:</div><div><div>  void checkPreStmt(const ReturnStmt *RS, CheckerContext &C) const;</div></div><div>};</div><div><br></div><div><div>void MyChecker::checkPreStmt(const ReturnStmt *RS,</div><div><span class="" style="white-space:pre">                          </span>     CheckerContext &C) const {</div><div>  RS->dump();</div><div><br></div><div>  const Stmt *s = RS;</div><div><br></div><div>  ParentMap &PM = C.getLocationContext()->getParentMap();</div><div><br></div><div>  while ((s = PM.getParent(s)) != NULL) {</div><div>    std::cerr << "------\n";</div><div>    s->dump();</div><div>  }</div><div>}</div></div><div><br></div><div>And this as input:</div><div><br></div><div><div>int f(void)</div><div>    {</div><div>    return 1;</div><div>    }</div></div><div><br></div><div><br></div><div>This is the output:</div><div><br></div><div><div>ReturnStmt 0x807cbdda8</div><div>`-IntegerLiteral 0x807cbdd88 'int' 1</div><div>------</div><div>CompoundStmt 0x807cbddc0</div><div>`-ReturnStmt 0x807cbdda8</div><div>  `-IntegerLiteral 0x807cbdd88 'int' 1</div></div><div><br></div><div>As you can see, it terminates at the function body, not the declaration.</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On 14 May 2015 at 07:03, Ben Laurie <span dir="ltr"><<a href="mailto:benl@google.com" target="_blank">benl@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote"><span class="">On 11 May 2015 at 11:20, Manuel Klimek <span dir="ltr"><<a href="mailto:klimek@google.com" target="_blank">klimek@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><span>On Sun, May 10, 2015 at 11:54 PM Nikola Smiljanic <<a href="mailto:popizdeh@gmail.com" target="_blank">popizdeh@gmail.com</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">I think you'll need to use ParentMap from ASTContext.</div></blockquote><div><br></div></span><div>Note that the parent-map is lazy-built (that is, the first time you get a parent, you build the parent-map for the whole TU), and thus has a pretty high cost. Usually we first try to get away with not using it.</div><div><br></div><div>Can you give a bit more context on what you're trying to do?</div></div></div></blockquote><div><br></div></span><div>Sorry for delay ... I am trying to label functions to have certain checks done on their return values if an attribute is set on the function.</div><div><br></div><div>ParentMap appears not to work for this case (it stops finding parents once you have the function body).</div><div><br></div><div>Currently, the only way I could make this work was to construct a map of function bodies that have the attribute set in an AST observer, and then using ParentMap to get back to the body, which is looked up in the map.</div><div><br></div><div>Doesn't seem optimal!</div><span class=""><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><span><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="gmail_extra"><br><div class="gmail_quote">On Mon, May 11, 2015 at 4:18 AM, Ben Laurie <span dir="ltr"><<a href="mailto:benl@google.com" target="_blank">benl@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">If I have a checker for check::PreStmt<ReturnStmt>, how do I get from<br>
the ReturnStmt to the function it is part of (I want to check<br>
attributes on that function)?<br>
_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu" target="_blank">cfe-dev@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
</blockquote></div><br></div>
_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu" target="_blank">cfe-dev@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
</blockquote></span></div></div>
</blockquote></span></div><br></div></div>
</blockquote></div><br></div>