@@ -2125,12 +2125,26 @@ def get_field_offsetof(self):
2125
2125
2126
2126
def is_anonymous (self ):
2127
2127
"""
2128
- Check if the record is anonymous.
2128
+ Check whether this is a record type without a name, or a field where
2129
+ the type is a record type without a name.
2130
+
2131
+ Use is_anonymous_record_decl to check whether a record is an
2132
+ "anonymous union" as defined in the C/C++ standard.
2129
2133
"""
2130
2134
if self .kind == CursorKind .FIELD_DECL :
2131
2135
return self .type .get_declaration ().is_anonymous ()
2132
2136
return conf .lib .clang_Cursor_isAnonymous (self ) # type: ignore [no-any-return]
2133
2137
2138
+ def is_anonymous_record_decl (self ):
2139
+ """
2140
+ Check if the record is an anonymous union as defined in the C/C++ standard
2141
+ (or an "anonymous struct", the corresponding non-standard extension for
2142
+ structs).
2143
+ """
2144
+ if self .kind == CursorKind .FIELD_DECL :
2145
+ return self .type .get_declaration ().is_anonymous_record_decl ()
2146
+ return conf .lib .clang_Cursor_isAnonymousRecordDecl (self ) # type: ignore [no-any-return]
2147
+
2134
2148
def is_bitfield (self ):
2135
2149
"""
2136
2150
Check if the field is a bitfield.
@@ -3902,12 +3916,13 @@ def write_main_file_to_stdout(self):
3902
3916
("clang_Cursor_getTemplateArgumentType" , [Cursor , c_uint ], Type ),
3903
3917
("clang_Cursor_getTemplateArgumentValue" , [Cursor , c_uint ], c_longlong ),
3904
3918
("clang_Cursor_getTemplateArgumentUnsignedValue" , [Cursor , c_uint ], c_ulonglong ),
3905
- ("clang_Cursor_isAnonymous" , [Cursor ], bool ),
3906
- ("clang_Cursor_isBitField" , [Cursor ], bool ),
3907
3919
("clang_Cursor_getBinaryOpcode" , [Cursor ], c_int ),
3908
3920
("clang_Cursor_getBriefCommentText" , [Cursor ], _CXString ),
3909
3921
("clang_Cursor_getRawCommentText" , [Cursor ], _CXString ),
3910
3922
("clang_Cursor_getOffsetOfField" , [Cursor ], c_longlong ),
3923
+ ("clang_Cursor_isAnonymous" , [Cursor ], bool ),
3924
+ ("clang_Cursor_isAnonymousRecordDecl" , [Cursor ], bool ),
3925
+ ("clang_Cursor_isBitField" , [Cursor ], bool ),
3911
3926
("clang_Location_isInSystemHeader" , [SourceLocation ], bool ),
3912
3927
("clang_Type_getAlignOf" , [Type ], c_longlong ),
3913
3928
("clang_Type_getClassType" , [Type ], Type ),
0 commit comments