<HTML><HEAD></HEAD>
<BODY dir=ltr>
<DIV dir=ltr>
<DIV style="FONT-FAMILY: 'Calibri'; COLOR: #000000; FONT-SIZE: 12pt">
<DIV>Hello,</DIV>
<DIV> </DIV>
<DIV>I just implemented my first function in libclang – it gets a field cursor 
and returns the bitfield width, if that’s a bitfield. Otherwise it returns a 
negative value.</DIV>
<DIV> </DIV>
<DIV>I’d like to submit it as a patch (never did that before, I’ll read up on 
how to do that later), but first can someone review this routine? It seems to 
work, but having never written anything inside clang (and having played with 
clang for only a couple of weeks now), I suspect there may just be half a dozen 
bugs there. In any case, I hope it’ll be helpful at least for some people 
reading this list.</DIV>
<DIV> </DIV>
<DIV>And by the way, kudos to all Clang developers for the high quality product. 
The code (at least the bits I looked at when implementing this) is a delight to 
read.</DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV>// -1 : cursor is not a field declaration</DIV>
<DIV>// -2 : cursor is not a bitfield declaration</DIV>
<DIV>// -3 : could not evaluate the bitfield width</DIV>
<DIV>int clang_Cursor_getBitfieldWidth(CXCursor C) {</DIV>
<DIV>  if (clang_isDeclaration(C.kind)) {</DIV>
<DIV>    Decl *D = cxcursor::getCursorDecl(C);</DIV>
<DIV>    if( const FieldDecl *FD = dyn_cast_or_null< FieldDecl 
>(D) ){</DIV>
<DIV>      Expr *pBitWidth = 
FD->getBitWidth();</DIV>
<DIV>      if( pBitWidth ){</DIV>
<DIV>        llvm::APSInt width;</DIV>
<DIV>        if( 
pBitWidth->EvaluateAsInt(width, getCursorASTUnit(C)->getASTContext() ) 
){</DIV>
<DIV>          return 
*width.getRawData();</DIV>
<DIV>        }</DIV>
<DIV>        return -3;</DIV>
<DIV>      }</DIV>
<DIV>      return -2;</DIV>
<DIV>    }</DIV>
<DIV>  }</DIV>
<DIV>  return -1;</DIV>
<DIV>}</DIV>
<DIV> </DIV>
<DIV>Sincerely,</DIV>
<DIV>Sergiy Migdalskiy</DIV></DIV></DIV></BODY></HTML>