<div class="gmail_quote">On Tue, May 15, 2012 at 8:05 PM, Lukhnos Liu <span dir="ltr"><<a href="mailto:lukhnos@lukhnos.org" target="_blank">lukhnos@lukhnos.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi,<br>
<br>
In what circumstances would one get the same location by calling the getBeginLoc() and getEndLoc() of a TypeLoc instance?<br></blockquote><div><br></div>An 'end' SourceLocation points to the start of the last token in the range. Therefore, you will see the same begin and end locations on all entities which are exactly one token long.<br>
<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">My setup is like this: I have a SemaConsumer, and from the HandleTranslationUnit method, I descend (via the passed ASTContext's getTranslationUnitDecl()) to the Decl I'm interested in:<br>
<br>
// I is an iterator from a DeclContext's decls_begin()<br>
if (const DeclaratorDecl *DD = dyn_cast<DeclaratorDecl>(*I)) {<br>
TypeSourceInfo *TSI = DD->getTypeSourceInfo();<br>
TypeLoc TL = TSI->getTypeLoc();<br>
SourceLocation B = TL.getBeginLoc();<br>
SourceLocation E = TL.getEndLoc();<br>
<br>
// want to do something with B and E, e.g. get the characterData from the source manager<br></blockquote></div><br><div>See Lexer::getLocForEndOfToken and Lexer::getSpelling.</div>