<br><br><div class="gmail_quote">On Sat, Sep 1, 2012 at 6:50 PM, Balou <span dir="ltr"><<a href="mailto:cleanconcept83@gmail.com" target="_blank">cleanconcept83@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Thank you James for your answer. <div><br></div><div>I already tried getDeclContext, getParentFunctionOrMethod and others, but I can not retrieve the correct scope in the following case:<div><br></div><div>int main (int argc, char ** argv)</div>

<div>{</div><div>  int foo1;</div><div>  {</div><div>    int foo2;</div><div>  }</div><div>}</div><div><br></div><div>At declaration, foo2 has a DeclContext whose kind is "Function", which is not the correct scope... </div>

<div><br></div><div>Moreover, I see that there is a BlockDecl data structure, but VisitBlockDecl don't work, as it seems to works only for objective C block (ie ^{...}). Why this don't work for classical c-like blocks ?</div>

<div><br></div></div></blockquote><div><br>Seeing as Objective-C blocks are in fact lambdas in disguise (or close enough), if VisitBlockDecl were to also visit regular blocks, it would be quite confusing => they are really totally different (and unrelated) concepts.<br>
<br>-- Matthieu<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div></div><div>Finally, I'd like to retrieve the scope of each declared variable in termes of SourceRange. How can I get the SourceRange from a DeclContext ?</div>
<div><br></div><div>I'm sorry, but I'm a clang beginner...</div>
<div>Thank you by advance!</div><div><br></div><div>Nicolas<div class="im"><br><br><div class="gmail_quote">2012/9/1 James Dennett <span dir="ltr"><<a href="mailto:james.dennett@gmail.com" target="_blank">james.dennett@gmail.com</a>></span><br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>On Sat, Sep 1, 2012 at 8:20 AM, Balou <<a href="mailto:cleanconcept83@gmail.com" target="_blank">cleanconcept83@gmail.com</a>> wrote:<br>


> Hello everyone,<br>
><br>
> I'm writting some code for visiting variable, struct, ... declarations (I'm<br>
> using C Language). For that, my class derives from DeclVisitor. My goal is<br>
> to determine the scope of each variable at its declaration (ie inside the<br>
> VisitVarDecl method). The method getSourceRangeonly of VarDecl only returns<br>
> the range of the declaration in terms of caracters, not the real scope.<br>
<br>
</div>Right, the notion of a source range is about a position in the source<br>
text, not in the AST structure.<br>
<div><br>
> Is<br>
> there method for getting the VarDecl scope ?<br>
<br>
</div>You might look at getParentFunctionOrMethod and/or getDeclContext (and<br>
if you use getDeclContext you might also want DeclContext::getParent).<br>
 I'm assuming here that you're writing C++ code that visits C code,<br>
given that you spoke of a class derived from DeclVisitor.<br>
<span><font color="#888888"><br>
-- James<br>
</font></span></blockquote></div><br></div></div></div>
<br>_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu">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>
<br></blockquote></div><br>