[cfe-dev] libclang, initializers and constant folding

Vinay Sajip vinay_sajip at yahoo.co.uk
Thu Sep 8 05:14:48 PDT 2011


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?

Regards,

Vinay Sajip




More information about the cfe-dev mailing list