[cfe-dev] Deep const experiment - how to retrieve SourceLocation of "const"?

Douglas Gregor dgregor at apple.com
Wed Aug 3 08:16:22 PDT 2011


On Aug 2, 2011, at 2:08 PM, george moudry wrote:

> 
> Dear Clang developers, I am experimenting with “poor man’s deep const” in C++.
> I have the following C++ code:
>  
>     #define immutable const
>     struct CC { immutable int myInt; };
>  
> I would like to use Clang to check if the type qualifier source code reads “const” or “immutable”.
> I am able to retrieve the clang::FieldDecl and it’s QualType.
> Is it possible, given my fieldDecl, to retrieve it’s DeclSpec?
> If I had a DeclSpec, I would then call DeclSpec::getConstSpecLoc() and retrieve the source code at that location.
> 
> Here are two of the approaches I already tried:
> 1) called fieldDecl->getSourceRange(); but that returns range only for "int myInt"
> 2) retrieved my field's TypeLoc and cast it to a QualifiedTypeLoc.
> But, as the header file warns, the QualifiedTypeLoc does not have valid SourceRange data.

That's correct. Clang does not retain the source location of every qualifier.

George R.'s suggesting of adding your own 'immutable' attribute is a good one.

	- Doug

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20110803/3ca2d97a/attachment.html>


More information about the cfe-dev mailing list