[cfe-dev] libclang, initializers and constant folding
Douglas Gregor
dgregor at apple.com
Thu Sep 8 07:39:24 PDT 2011
On Sep 8, 2011, at 5:14 AM, Vinay Sajip wrote:
> There appears to be no way one can get hold of compile-time constant
> initializers via the libclang API. For example, enumeration initializer values
> can't be accessed: the children of an enum declaration cursor have (for values
> with initializers) a cursor of type CXCursor_UnexposedExpr.
>
> ISTM the only way of getting beyond this is to use clang_tokenize on the extent
> of that cursor, but this does not help in the case where initializers are
> expressions. For example, say we process the source
>
> enum Enum1 {
> VAL1 = -1,
> VAL2,
> VAL3
> };
>
> enum Enum2 {
> VAL4 = VAL3,
> VAL5 = VAL2 + 7,
> VAL6 = VAL3 << 2
> };
>
> Is there any way using libclang to know that the values of VAL1 through VAL6
> would be -1, 0, 1, 1, 7 and 4?
There is currently no libclang API for this. One could be added, if needed.
- Doug
More information about the cfe-dev
mailing list