[PATCH] libclang: functions to deal with anonymous fields

Loïc Jaquemet loic.jaquemet at gmail.com
Mon Feb 10 17:13:05 PST 2014


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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: libclang-visit-fields.201116
Type: application/octet-stream
Size: 20152 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140210/17630f8b/attachment.obj>


More information about the cfe-commits mailing list