[PATCH] Expose AST Record layout attributes to libclang

Dmitri Gribenko gribozavr at gmail.com
Tue Feb 12 05:07:47 PST 2013


On Tue, Feb 12, 2013 at 2:57 PM, Dmitri Gribenko <gribozavr at gmail.com> wrote:
> On Tue, Feb 12, 2013 at 7:51 AM, Loïc Jaquemet <loic.jaquemet at gmail.com> wrote:
>> Hello,
>>
>> This patch is 3 functions in libclang to get more Record Layout
>> information from the AST when using libclang.
>>
>> I am trying to implement the python ctypeslib record generator by
>> replacing gccxml with libclang.
>>
>> Files:
>> 001:
>>  include/clang-c/Index.h
>>  tools/libclang/libclang.exports
>>  tools/libclang/CXType.cpp
>> 002:
>>  test/Index/record-layout.cpp
>>  test/Index/record-layout.c
>>  test/Index/record-layout-virtual.cpp
>>  tools/c-index-test/c-index-test.c
>> 003:
>>  bindings/python/clang/cindex.py
>> 004:
>>  bindings/python/tests/cindex/util.py
>>  bindings/python/tests/cindex/test_type.py
>>
>>
>> Here is the latest version following your comments.
>> Given that I'm pretty sure the -m32/-m64 flag is not sufficient. lets
>> say this is a draft for you to comment on.
>
> After thinking a little more about it, I have a general question about
> the approach here: wouldn't it be better to implement
> clang_getTypeSize/clang_getTypeAlignment that work for all types?
> These functions should work just like sizeof/alignof.  This should be
> easy enough to implement: ASTContext::getTypeSize()/getTypeAlign() + a
> few special cases, which are:
>
> * sizeof(void), __alignof__(void), sizeof(function) = 1 as a gcc
> extension (lib/AST/ExprConstant.cpp:1372)
>
> * C++ [expr.sizeof]p2: "When applied to a reference or a reference
> type, the result is the size of the referenced type."
> (lib/AST/ExprConstant.cpp:5228).
>
> * incomplete types -- just return an error for these.

Or if we can complete the type, we should do it.
Sema::RequireCompleteType().  There's ASTUnit::getSema() to get a Sema
object.

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