[PATCH] libclang: functions to deal with anonymous fields
Argyrios Kyrtzidis
kyrtzidis at apple.com
Mon Apr 13 09:58:30 PDT 2015
Committed in r234762, thanks!
> On Apr 1, 2015, at 3:38 PM, Loïc Jaquemet <loic.jaquemet at gmail.com> wrote:
>
> Hi,
> this is still the same patch as in 2013,
>
> Updated for r233836
>
> Would someone be able to commit it at last ?
>
>
> $ nosetests .
> .LIBCLANG TOOLING ERROR: json-compilation-database: Error while
> opening JSON database: No such file or directory
>
> .................................................................................................
> ----------------------------------------------------------------------
> Ran 98 tests in 1.554s
>
> OK
>
> llvm[0]: ***** Completed Release+Asserts Build
> $ make check-all
> llvm[0]: Running test suite
> Testing Time: 136.64s
> Expected Passes : 21027
> Expected Failures : 122
> Unsupported Tests : 99
>
>
>
>
>
>
> 2015-02-11 18:34 GMT-07:00 Loïc Jaquemet <loic.jaquemet at gmail.com <mailto:loic.jaquemet at gmail.com>>:
>> Updated for r228880
>>
>> 2015-01-30 19:13 GMT-07:00 Loïc Jaquemet <loic.jaquemet at gmail.com>:
>>> + Removed the useless default that creates a warning.
>>> + cleaned some whitespaces
>>>
>>> Testing Time: 127.86s
>>> Expected Passes : 20169
>>> Expected Failures : 103
>>> Unsupported Tests : 88
>>>
>>> 2015-01-29 19:08 GMT-07:00 Loïc Jaquemet <loic.jaquemet at gmail.com>:
>>>> my bad,
>>>>
>>>> I was using make check instead of make check-all
>>>>
>>>> the TU is fixed in the patch attached (2 modifs in print-type.cpp )
>>>>
>>>> $ ./Release+Asserts/bin/llvm-lit ~/llvm/tools/clang/test/Index/
>>>> [..]
>>>> Testing Time: 5.49s
>>>> Expected Passes : 239
>>>> $
>>>>
>>>>
>>>> $ make check-all
>>>> llvm[0]: Running test suite
>>>> [..]
>>>> Testing Time: 127.90s
>>>> Expected Passes : 20158
>>>> Expected Failures : 101
>>>> Unsupported Tests : 88
>>>>
>>>>
>>>>
>>>> 2015-01-29 18:22 GMT-07:00 Loïc Jaquemet <loic.jaquemet at gmail.com>:
>>>>> Apparently it was reverted in r227472
>>>>>
>>>>> 2015-01-29 5:49 GMT-07:00 Francois Pichet <pichet2000 at gmail.com>:
>>>>>> I committed in r227432, thanks.
>>>>>>
>>>>>> On Wed, Jan 28, 2015 at 5:18 PM, Argyrios Kyrtzidis <kyrtzidis at apple.com>
>>>>>> wrote:
>>>>>>>
>>>>>>> Yes, I think it’s good to go, thanks Loïc!
>>>>>>>
>>>>>>>
>>>>>>> On Jan 28, 2015, at 1:06 PM, Francois Pichet <pichet2000 at gmail.com> wrote:
>>>>>>>
>>>>>>> Hi, since your patch is just a rebasing of something that was already
>>>>>>> reviewed, I think you can go ahead and commit..
>>>>>>> any objection?
>>>>>>>
>>>>>>> On Tue, Jan 27, 2015 at 7:36 PM, Loïc Jaquemet <loic.jaquemet at gmail.com>
>>>>>>> wrote:
>>>>>>>>
>>>>>>>> Hi,
>>>>>>>>
>>>>>>>> would it be possible to get a review for this patch (libclang/python
>>>>>>>> bindings) ?
>>>>>>>>
>>>>>>>> Thanks
>>>>>>>>
>>>>>>>> 2015-01-21 19:00 GMT-07:00 Loïc Jaquemet <loic.jaquemet at gmail.com>:
>>>>>>>>> Please find this patches updated for .226743.
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> * libclang: Add three functions useful for dealing with anonymous
>>>>>>>>> fields.
>>>>>>>>> +clang_Cursor_getOffsetOfField
>>>>>>>>> +clang_Cursor_isAnonymous
>>>>>>>>> +clang_Type_visitFields
>>>>>>>>> Fixed: reuse CXVisitorResult instead of introducing a new enum
>>>>>>>>>
>>>>>>>>> * Python; Add corresponding methods for dealing with anonymous fields.
>>>>>>>>>
>>>>>>>>> * TU in print-type
>>>>>>>>> adds [nbFields] in c-index-test for records
>>>>>>>>> for anonymous record, shows offset of field in anonymous and parent
>>>>>>>>> record. ( clang_Type_getOffsetOf/clang_Cursor_getOffsetOfField)
>>>>>>>>>
>>>>>>>>> LLVM tests passes
>>>>>>>>> python tests passees
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> * Reference from 2013/2014
>>>>>>>>>
>>>>>>>>> http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20140217/099453.html
>>>>>>>>>
>>>>>>>>> 2015-01-21 12:28 GMT-07:00 Francois Pichet <pichet2000 at gmail.com>:
>>>>>>>>>> Hi Loic,
>>>>>>>>>>
>>>>>>>>>> Seems like this was never committed in trunk? Any reason why?
>>>>>>>>>> I have a project with a lot of anonymous struct and this patch would
>>>>>>>>>> be
>>>>>>>>>> useful.
>>>>>>>>>>
>>>>>>>>>> On Thu, Feb 20, 2014 at 2:40 AM, Argyrios Kyrtzidis
>>>>>>>>>> <kyrtzidis at apple.com>
>>>>>>>>>> wrote:
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> On Feb 16, 2014, at 11:49 AM, Loïc Jaquemet <loic.jaquemet at gmail.com>
>>>>>>>>>>> wrote:
>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>> +/**
>>>>>>>>>>>>> + * \brief Visitor invoked for each field found by a traversal.
>>>>>>>>>>>>> + *
>>>>>>>>>>>>> + * This visitor function will be invoked for each field found by
>>>>>>>>>>>>> + * clang_visitCursorFields(). Its first argument is the cursor
>>>>>>>>>>>>> being
>>>>>>>>>>>>> + * visited, its second argument is the client data provided to
>>>>>>>>>>>>> + * clang_visitCursorFields().
>>>>>>>>>>>>> + *
>>>>>>>>>>>>> + * The visitor should return one of the \c CXFieldVisitResult
>>>>>>>>>>>>> values
>>>>>>>>>>>>> + * to direct clang_visitCursorFields().
>>>>>>>>>>>>> + */
>>>>>>>>>>>>> +typedef enum CXFieldVisitResult (*CXFieldVisitor)(CXCursor C,
>>>>>>>>>>>>> + CXClientData
>>>>>>>>>>>>> client_data);
>>>>>>>>>>>>>
>>>>>>>>>>>>> +CINDEX_LINKAGE unsigned clang_Type_visitFields(CXType T,
>>>>>>>>>>>>> + CXFieldVisitor
>>>>>>>>>>>>> visitor,
>>>>>>>>>>>>> + CXClientData
>>>>>>>>>>>>> client_data);
>>>>>>>>>>>>>
>>>>>>>>>>>>> In general, the visitor is not recursing, right ? In that case why
>>>>>>>>>>>>> not
>>>>>>>>>>>>> use a simpler "getNumFields / getField" pair of functions ?
>>>>>>>>>>>>
>>>>>>>>>>>> Well, the source code (AST.Decl.h ) exposes a iterator on its
>>>>>>>>>>>> fields.
>>>>>>>>>>>> Given that in other similar cases a visitor is used, I did the
>>>>>>>>>>>> same.
>>>>>>>>>>>>
>>>>>>>>>>>> I did not want to introduce new code/new logic.
>>>>>>>>>>>> I just want to expose the iterator.
>>>>>>>>>>>>
>>>>>>>>>>>> Do you want me to change it to a "getNumFields / getField" pair of
>>>>>>>>>>>> functions ?
>>>>>>>>>>>
>>>>>>>>>>> I see, the visitor interface is fine.
>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>> +enum CXFieldVisitResult {
>>>>>>>>>>>>>
>>>>>>>>>>>>> Could you reuse CXVisitorResult instead of introducing a new enum
>>>>>>>>>>>>> ?
>>>>>>>>>>>>
>>>>>>>>>>>> Yes. I did not see that one.
>>>>>>>>>>>> Will change that.
>>>>>>>>>>>
>>>>>>>>>>> After that, LGTM!
>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>> On Feb 10, 2014, at 5:13 PM, Loïc Jaquemet
>>>>>>>>>>>>> <loic.jaquemet at gmail.com>
>>>>>>>>>>>>> wrote:
>>>>>>>>>>>>>
>>>>>>>>>>>>>> Hi,
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> I'm pinging back about this patch :
>>>>>>>>>>>>>> * libclang: Add three functions useful for dealing with anonymous
>>>>>>>>>>>>>> fields.
>>>>>>>>>>>>>> +clang_Cursor_getOffsetOfField
>>>>>>>>>>>>>> +clang_Cursor_isAnonymous
>>>>>>>>>>>>>> +clang_Type_visitFields
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Currently, there is no function in libclang to access clang logic
>>>>>>>>>>>>>> that
>>>>>>>>>>>>>> handles anonymous members in a record.
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Given the current API , there is no direct method to :
>>>>>>>>>>>>>> a) recover the offset of an anonymous field.
>>>>>>>>>>>>>> - displayname == spelling == '', clang_Type_getOffset does not
>>>>>>>>>>>>>> work
>>>>>>>>>>>>>> + new clang_Cursor_getOffsetOfField will expose that information
>>>>>>>>>>>>>> b) clearly identify that DECL as an anonymous record.
>>>>>>>>>>>>>> + new clang_Cursor_isAnonymous will expose that information
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> When using clang_visitChildren, an anonymous member will be
>>>>>>>>>>>>>> returned
>>>>>>>>>>>>>> as a STRUCT_DECL/UNION_DECL.
>>>>>>>>>>>>>> Currently the libclang user has to re-implement the logic to
>>>>>>>>>>>>>> differentiate FIELD_DECL in the list of children nodes
>>>>>>>>>>>>>> For example,
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> struct A {
>>>>>>>>>>>>>> struct {int a;} typeanon;
>>>>>>>>>>>>>> struct {
>>>>>>>>>>>>>> int bariton;
>>>>>>>>>>>>>> union {
>>>>>>>>>>>>>> int foo;
>>>>>>>>>>>>>> int foo2;
>>>>>>>>>>>>>> };
>>>>>>>>>>>>>> };
>>>>>>>>>>>>>> int c;
>>>>>>>>>>>>>> } ;
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Some children are STRUCT_DECL, some are FIELD_DECL, some are
>>>>>>>>>>>>>> attributes.
>>>>>>>>>>>>>> Worse,
>>>>>>>>>>>>>> children[0] == STRUCT_DECL (struct {int a;})
>>>>>>>>>>>>>> children[1] == FIELD_DECL (typeanon)
>>>>>>>>>>>>>> children[2] == STRUCT_DECL (anonymous structure)
>>>>>>>>>>>>>> children[3] == FIELD_DECL (int c)
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Sometime a STRUCT_DECL is a field (children[2]) sometimes it is
>>>>>>>>>>>>>> just a
>>>>>>>>>>>>>> STRUCT_DECL.
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> The new function clang_Type_visitFields will expose the existing
>>>>>>>>>>>>>> libclang capabilities to list only fields, and not all children
>>>>>>>>>>>>>> node,
>>>>>>>>>>>>>> as does clang_visitChildren.
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> fields[0] == FIELD_DECL (first structure - typeanon)
>>>>>>>>>>>>>> fields[1] == FIELD_DECL (second anonymous structure)
>>>>>>>>>>>>>> fields[2] == FIELD_DECL (int c)
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> --
>>>>>>>>>>>>>> Loïc Jaquemet
>>>>>>>>>>>>>> <libclang-visit-fields.201116>
>>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>> --
>>>>>>>>>>>> Loïc Jaquemet
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> _______________________________________________
>>>>>>>>>>> cfe-commits mailing list
>>>>>>>>>>> cfe-commits at cs.uiuc.edu
>>>>>>>>>>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> --
>>>>>>>>> Loïc Jaquemet
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> --
>>>>>>>> Loïc Jaquemet
>>>>>>>
>>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> Loïc Jaquemet
>>>>
>>>>
>>>>
>>>> --
>>>> Loïc Jaquemet
>>>
>>>
>>>
>>> --
>>> Loïc Jaquemet
>>
>>
>>
>> --
>> Loïc Jaquemet
>
>
>
> --
> Loïc Jaquemet
> <201501-visit-fields.r233836>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150413/baba2427/attachment.html>
More information about the cfe-commits
mailing list