[cfe-dev] libclang, initializers and constant folding
Vinay Sajip
vinay_sajip at yahoo.co.uk
Thu Sep 8 09:24:57 PDT 2011
Douglas Gregor <dgregor at ...> writes:
> There is currently no libclang API for this. One could be added, if needed.
Well, I need such an API :-) There was also a question about this (from someone
else) on the mailing list, earlier this year.
I'm very new to the clang code base, so I tried implementing the functionality
using an experimental function like this:
int clang_getCursorValue(CXCursor C)
{
int result = 0;
Decl * D = getCursorDecl(C);
if (isa<EnumConstantDecl>(D)) {
llvm::APSInt Value = static_cast<EnumConstantDecl *>(D)->getInitVal();
result = (int) Value.getSExtValue();
}
return result;
}
This works as far as it goes, giving the correct values for my earlier example,
but it's obviously incomplete.
Possibly there should be a set of functions such as
int clang_getCursorIntegerValue(CXCursor);
double clang_getCursorDoubleValue(CXCursor);
CXString clang_getCursorStringValue(CXCursor);
However, I have no idea if this gels with whoever designed the existing API.
What's the best way to move this forward?
Regards,
Vinay Sajip
More information about the cfe-dev
mailing list