From 53a581fe0a8dfea4e7126eb8b2a01b8eddfb8cb0 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Thu, 16 Sep 2021 20:03:31 +0200 Subject: [PATCH] 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 --- scripts/field_report.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/scripts/field_report.py b/scripts/field_report.py index 1dc4db248f..a6fe932b6d 100755 --- a/scripts/field_report.py +++ b/scripts/field_report.py @@ -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)