Hi!<div><br></div><div><div class="gmail_quote">On Thu, Mar 28, 2013 at 5:29 AM, Abir Basak <span dir="ltr"><<a href="mailto:abirbasak@gmail.com" target="_blank">abirbasak@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 dir="ltr"><div>I am new to clang ast, and trying to parse some c++ code with it.</div><div><br></div>When I am using TypedefDecl->getSourceRange() for say<div>typedef long double LDBL it returns the whole thing </div>

<div>However when I am using TypeAliasDecl->getSourceRange() for say</div><div>using LDBL = long double</div><div>it only returns the range using LDBL = long. (i.e removes the double part)</div><div>
<br></div><div>I used the code below to extract text from SourceRange</div><div><div>char const* first = sm.getCharacterData(r.getBegin()); </div><div> char const* last = sm.getCharacterData(pp.getLocForEndOfToken(r.getEnd()));</div>

<div> return std::string(first,last);</div></div></div></blockquote><div><br></div><div>The problem here is that BuiltinTypeLoc doesn't store the source locations for every keyword in the type, just for (apparently) the first one. Consequently, BuiltinTypeLoc::getLocalSourceRange() always returns a one-keyword range, and TypeAliasDecl::getSourceRange() picks the end of that range as the end of the declaration.<br>
 </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div>Am I doing something wrong? How can I get the whole source range, and esp the type part of it i.e. long double part, so that I can rearrange it as typedef long double LDBL</div>

</div><div>I am using clang 3.2 with RAV</div></div></blockquote><div><br></div><div>We should fix BuiltinTypeLoc to track the end location in the needsExtraLocalData() case. If you want a workaround for this, you could re-lex tokens from the end location until you hit a semicolon (this is imperfect in the presence of macros, but your code isn't robust against macro expansions within the alias declaration anyway, so this may be enough for your purposes) -- or even just scan through the character data until you hit a semicolon if you're not concerned about comments at the end of the declaration.</div>
</div></div>