[cfe-dev] How to get location of variable name in clang::VarDecl?

Алексей Кутумов alexey.kutumov at gmail.com
Tue Jan 31 10:05:21 PST 2012


Thank you for answering! getLocation() is what I need

31.01.2012, в 0:58, John McCall <rjmccall at apple.com> написал(а):

> On Jan 30, 2012, at 7:11 AM, Алексей Кутумов wrote:
>> I'm using clang 3.0 library for some analysis of C/C++ code, and I
>> need to get location of variable declaration, I tried this code:
>> 
>> clang::VarDecl * vd = ...;
>> clang::SourceManager & srcMgr = ...;
>> 
>> clang::SourceRange loc = vd->getSourceRange();
>> clang::PresumedLoc locStart = srcMgr.getPresumedLoc(loc.getBegin());
>> clang::PresumedLoc locEnd = srcMgr.getPresumedLoc(loc.getEnd());
>> 
>> But locStart and locEnd points to the beginning (and ending) of
>> declaration variable (with type, and, possibly initialiser). For
>> example:
>> 
>> const char * ptr = 0;
>> ^                 ^  ^   ^
>> 
>> locStart will point at the first pointer(^) , and locEnd will point at
>> the last pointer. How can I get the location of the second and third
>> pointers (only name, without type and initialiser)?
> 
> The location of the start of the name is the caret location for the entire
> Decl, i.e. getLocation().  The end location can be derived from that.
> 
> John.




More information about the cfe-dev mailing list