[PATCH] Expose AST Record layout attributes to libclang
Dmitri Gribenko
gribozavr at gmail.com
Sat Feb 9 04:52:04 PST 2013
On Sat, Feb 9, 2013 at 3:55 AM, Loïc Jaquemet <loic.jaquemet at gmail.com> wrote:
> This patch is 3 functions in libclang to get more Record Layout
> information from the AST when using libclang.
Hi Loïc,
This patch should add functions with documentation to
include/clang-c/Index.h, and also update CINDEX_VERSION_MINOR there.
Instead of using CharUnits::QuantityType as a return type, please use
uint64_t directly, because libclang is a C API, independent of
internal Clang APIs and headers.
This also needs tests (tools/c-index-test/ utility should be improved
to use these new APIs, tests themselves should be in test/Index).
+ const Decl *D = static_cast<const Decl*>(C.data[0]);
Use getCursorDecl().
+ ASTUnit *AU = cxcursor::getCursorASTUnit(C);
+ ASTContext &Ctx = AU->getASTContext();
This should be replaced by a single call to getCursorContext().
+ const RecordDecl *RD = static_cast<const RecordDecl*>(D);
Space before "*" inside the cast.
+ const ASTRecordLayout &layout = Ctx.getASTRecordLayout(RD);
+ CharUnits size = layout.getSize();
Variable names should start with an uppercase letter.
+ if ( ((C.kind != CXCursor_StructDecl) &&
+ (C.kind != CXCursor_UnionDecl) &&
+ (C.kind != CXCursor_ClassDecl)) ||
+ !clang_isDeclaration(C.kind) )
Drop spaces after '(' and before ')'.
+ // get the layout for a record
Comments should start with a capital letter and end with a period.
+ const RecordDecl *RD = static_cast<const RecordDecl*>(D);
Use dyn_cast and you can drop C.kind checks from the conditional above.
+ const FieldDecl *F = static_cast<const FieldDecl*>(D);
Same as above.
Dmitri
--
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr at gmail.com>*/
More information about the cfe-commits
mailing list