<html><head><meta http-equiv="Content-Type" content="text/html charset=iso-8859-1"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>You have to have gotten the DeclRefExpr from somewhere. A quick search for "ParentMap" shows that you can get one from an AnalysisDeclContext, which you can build trivially from the FunctionDecl (or whatever) containing your statement. Moreover, though, you can make your own ParentMap, constructing it with the top-level Stmt in your function.</div><div><br></div><div>Jordan</div><div><br></div><br><div><div>On Nov 15, 2012, at 17:30 , Mohammad Adil <<a href="mailto:madil90@gmail.com">madil90@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">Hi,<div>   There doesn't seem to be any way to extract a ParentMap from DeclRefExpr, Expr or Stmt. How do I build a ParentMap for a DeclRefExpr to find it's parent. I know that ParentMap can be extracted from LocationContext but there doesn't seem to be any way to find the LocationContext either. There must be some way to do this because the static analyzer in clang does this. Please at least tell me if this is possible or not.</div>
<div><br></div><div>Regards,</div><div>Adil</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Nov 16, 2012 at 3:07 AM, Mohammad Adil <span dir="ltr"><<a href="mailto:madil90@gmail.com" target="_blank">madil90@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Can you please give an example of how ParentMap can be used in this situation?<div class="HOEnZb"><div class="h5"><div class="gmail_extra">
<br><br><div class="gmail_quote">On Fri, Nov 16, 2012 at 3:00 AM, Eli Friedman <span dir="ltr"><<a href="mailto:eli.friedman@gmail.com" target="_blank">eli.friedman@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>On Thu, Nov 15, 2012 at 1:23 PM, Mohammad Adil <<a href="mailto:madil90@gmail.com" target="_blank">madil90@gmail.com</a>> wrote:<br>


> How can I get the CompundStmt or the Stmt for this expression?<br>
<br>
</div>ParentMap (or some equivalent).<br>
<div><br>
> Is there any<br>
> way to move token by token forward from a SourceLocation?<br>
<br>
</div>No.<br>
<span><font color="#888888"><br>
-Eli<br>
</font></span><div><br>
> On Fri, Nov 16, 2012 at 1:30 AM, Eli Friedman <<a href="mailto:eli.friedman@gmail.com" target="_blank">eli.friedman@gmail.com</a>><br>
> wrote:<br>
>><br>
>> On Thu, Nov 15, 2012 at 12:00 PM, madil90 <<a href="mailto:madil90@gmail.com" target="_blank">madil90@gmail.com</a>> wrote:<br>
>> > Hi,<br>
>> >   I have a DeclRefExpr which tells me wherever a variable is used. I<br>
>> > want to<br>
>> > find out the previous or the next ";" so that I can go to the start of<br>
>> > the<br>
>> > command in which this variable was used e.g.<br>
>> ><br>
>> > int a,b;<br>
>> ><br>
>> > a = b + 3;<br>
>> >      | |<br>
>> ><br>
>> >    In this case the DeclRefExpr for b will start and end at the<br>
>> > locations<br>
>> > shown. How can I find the previous ";" (in this case at the end of the<br>
>> > line<br>
>> > int a,b;))<br>
>><br>
>> There isn't any existing code to handle this, but it isn't too hard:<br>
>> find the CompoundStmt which contains the given expression, then get<br>
>> the end location of previous statement in that CompoundStmt.  (This is<br>
>> ignoring various edge cases, but that's the fundamental algorithm.)<br>
>> The ParentMap class might be useful for implementing this.<br>
>><br>
>> -Eli<br>
><br>
><br>
><br>
><br>
> --<br>
> Mohammad Adil<br>
> LUMS SSE<br>
><br>
</div></blockquote></div><br><br clear="all"><div><br></div>-- <br>Mohammad Adil<div>LUMS SSE</div><br>
</div>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br>Mohammad Adil<div>LUMS SSE</div><br>
</div>
_______________________________________________<br>cfe-dev mailing list<br><a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a><br>http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev<br></blockquote></div><br></body></html>