Don't skip typedef struct {...}

Don't skip structure definitions that have no name, but for which there is a
named typedef. Do skip unions and anonymous structs that don't have a type
name (which is common for structs embedded in another struct or union).

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
This commit is contained in:
Gilles Peskine 2021-09-16 20:03:31 +02:00
parent 5336375090
commit 53a581fe0a

View File

@ -94,11 +94,17 @@ class Ast:
if not self.in_interesting_file(node.location):
continue
if node.kind == CursorKind.FIELD_DECL:
# If node.lexical_parent.spelling is an empty string,
# the field is inside an anonymous structure nested in
# another structure.
type_name = node.lexical_parent.spelling
# Skip unions
if node.lexical_parent.kind != CursorKind.STRUCT_DECL:
continue
# type_name is the struct name. If there's no struct
# name, see if there's a typedef name, to cope with
# "typedef struct { ... } foo;"
if not type_name:
type_name = node.lexical_parent.type.spelling
# Skip anonymous structs for now.
if '(anonymous ' in type_name:
continue
self.fields.setdefault(type_name, collections.OrderedDict())
self.fields[type_name][node.spelling] = FieldInfo(node)