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

George Russell george at codeplay.com
Wed Aug 3 02:43:13 PDT 2011


Hi,

Just noting that I have something quite similar hacked into Clang + LLVM 2.9
(https://bitbucket.org/grrussel/constcpp/wiki/Home)

Regarding you example, perhaps you could use an attribute in the define 
to allow distinguishing immutable from const?

Cheers,
George

On 02/08/2011 23:08, 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.
>
>
> Any ideas?
>
>
> Thanks for your advice,
>
> Jiri
>
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev

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


More information about the cfe-dev mailing list