[cfe-dev] Evaluating bitfield width with libclang

Richard Smith richard at metafoo.co.uk
Thu Sep 6 11:45:47 PDT 2012

On Thu, Sep 6, 2012 at 10:47 AM, Sergiy Migdalskiy
<migdalskiy at hotmail.com>wrote:

> Ok, does everyone agree on this variant?
> Also, is the check "isValueDependent()" essentially for the cases when
> bitwidth is templatized? Or is there some other reason?

Yes, exactly, it's for the case where the bitwidth involves a template
argument in a way which means we can't evaluate it.

> // Return bitfield bit width. Cursor must be a value-independent bit field
> declaration
> int clang_Cursor_getBitfieldWidth(**CXCursor C) {
>  if (clang_isDeclaration(C.kind)) {
>    Decl *D = cxcursor::getCursorDecl(C);
>    if( const FieldDecl *FD = dyn_cast_or_null< FieldDecl >(D) ){
>      Expr *pBitWidth = FD->getBitWidth();
>      if( pBitWidth && !pBitWidth->isValueDependent() )
>        return FD->getBitWidthValue( getCursorASTUnit(C)->**getASTContext()
> );
>    }
>  }
>  return -1;
> }

Yes, this looks fine to me, functionally. There are some coding style
violations here (variable names, whitespace). See:


The next thing to do is to get a complete patch together and mail it to
cfe-commits@ for a proper review. This patch should include test cases
(maybe extend c-index-test.c's PrintCursor to print out the bit width for
bitfields, and extend one of the test/Index/* tests to make sure the
correct value is produced).

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

More information about the cfe-dev mailing list