[prev in list] [next in list] [prev in thread] [next in thread] 

List:       cfe-dev
Subject:    Re: [cfe-dev] Pinpointing VarDecl Location
From:       Nikola Smiljanic <popizdeh () gmail ! com>
Date:       2014-07-26 1:26:58
Message-ID: CAGq7tnOf-zPSPeZ8w811qZY-bBZzCYWFGcfmoiPqBLD=MKvzJQ () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


Hi Uri, start locations should be the same but as Hans said ranges aren't.
Doublecheck using -cc1 -ast-dump, and tell us what version of clang are you
using.


On Sat, Jul 26, 2014 at 2:10 AM, Hans Wennborg <hans@chromium.org> wrote:

> On Fri, Jul 25, 2014 at 9:04 AM, Uri Mann <umann@symantec.com> wrote:
> > Given:
> >
> > void f() {
> >   int a, b, c;
> > }
> >
> > I'm wondering if there's a way to find the SourceLocation and/or
> SourceRange
> > of a, b and c?
> >
> > Using VarDecl::getSourceRange(), VarDecl::getStartLoc(), etc I get the
> same
> > values for all instance between the type (int) and the ;.
>
> Looking at the ast dump, it seems like a, b and c have the same start
> loc, but different end locations. Maybe you can use that?
>
> $ echo 'void f() { int a, b, c; }' | clang -cc1 -ast-dump -
> TranslationUnitDecl 0x5fa3fe0 <<invalid sloc>> <invalid sloc>
> |-TypedefDecl 0x5fa44e0 <<invalid sloc>> <invalid sloc> implicit
> __int128_t '__int128'
> |-TypedefDecl 0x5fa4540 <<invalid sloc>> <invalid sloc> implicit
> __uint128_t 'unsigned __int128'
> |-TypedefDecl 0x5fa4890 <<invalid sloc>> <invalid sloc> implicit
> __builtin_va_list '__va_list_tag [1]'
> `-FunctionDecl 0x5fa4930 <<stdin>:1:1, col:25> col:6 f 'void ()'
>   `-CompoundStmt 0x5fa4b50 <col:10, col:25>
>     `-DeclStmt 0x5fa4b38 <col:12, col:23>
>       |-VarDecl 0x5fa49e0 <col:12, col:16> col:16 a 'int'
>       |-VarDecl 0x5fa4a50 <col:12, col:19> col:19 b 'int'
>       `-VarDecl 0x5fa4ac0 <col:12, col:22> col:22 c 'int'
>
>  - Hans
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev@cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>

[Attachment #5 (text/html)]

<div dir="ltr">Hi Uri, start locations should be the same but as Hans said ranges \
aren&#39;t. Doublecheck using -cc1 -ast-dump, and tell us what version of clang are \
you using.</div><div class="gmail_extra"><br><br><div class="gmail_quote">

On Sat, Jul 26, 2014 at 2:10 AM, Hans Wennborg <span dir="ltr">&lt;<a \
href="mailto:hans@chromium.org" target="_blank">hans@chromium.org</a>&gt;</span> \
wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px \
#ccc solid;padding-left:1ex">

<div class="">On Fri, Jul 25, 2014 at 9:04 AM, Uri Mann &lt;<a \
href="mailto:umann@symantec.com">umann@symantec.com</a>&gt; wrote:<br> &gt; \
Given:<br> &gt;<br>
&gt; void f() {<br>
&gt;    int a, b, c;<br>
&gt; }<br>
&gt;<br>
&gt; I'm wondering if there's a way to find the SourceLocation and/or SourceRange<br>
&gt; of a, b and c?<br>
&gt;<br>
&gt; Using VarDecl::getSourceRange(), VarDecl::getStartLoc(), etc I get the same<br>
&gt; values for all instance between the type (int) and the ;.<br>
<br>
</div>Looking at the ast dump, it seems like a, b and c have the same start<br>
loc, but different end locations. Maybe you can use that?<br>
<br>
$ echo &#39;void f() { int a, b, c; }&#39; | clang -cc1 -ast-dump -<br>
TranslationUnitDecl 0x5fa3fe0 &lt;&lt;invalid sloc&gt;&gt; &lt;invalid sloc&gt;<br>
> -TypedefDecl 0x5fa44e0 &lt;&lt;invalid sloc&gt;&gt; &lt;invalid sloc&gt; \
> implicit<br>
__int128_t &#39;__int128&#39;<br>
> -TypedefDecl 0x5fa4540 &lt;&lt;invalid sloc&gt;&gt; &lt;invalid sloc&gt; \
> implicit<br>
__uint128_t &#39;unsigned __int128&#39;<br>
> -TypedefDecl 0x5fa4890 &lt;&lt;invalid sloc&gt;&gt; &lt;invalid sloc&gt; \
> implicit<br>
__builtin_va_list &#39;__va_list_tag [1]&#39;<br>
`-FunctionDecl 0x5fa4930 &lt;&lt;stdin&gt;:1:1, col:25&gt; col:6 f &#39;void \
()&#39;<br>  `-CompoundStmt 0x5fa4b50 &lt;col:10, col:25&gt;<br>
      `-DeclStmt 0x5fa4b38 &lt;col:12, col:23&gt;<br>
         |-VarDecl 0x5fa49e0 &lt;col:12, col:16&gt; col:16 a &#39;int&#39;<br>
         |-VarDecl 0x5fa4a50 &lt;col:12, col:19&gt; col:19 b &#39;int&#39;<br>
         `-VarDecl 0x5fa4ac0 &lt;col:12, col:22&gt; col:22 c &#39;int&#39;<br>
<br>
  - Hans<br>
<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> \
</blockquote></div><br></div>



_______________________________________________
cfe-dev mailing list
cfe-dev@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic