From 0b31e9fa29699bbf140e168a17ead1c993d42e3e Mon Sep 17 00:00:00 2001 From: "Luke T. Shumaker" Date: Sat, 29 Mar 2025 18:19:37 -0600 Subject: lib9p: protogen: h.py: Tidy gen_struct() --- lib9p/protogen/h.py | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) (limited to 'lib9p/protogen/h.py') diff --git a/lib9p/protogen/h.py b/lib9p/protogen/h.py index a9f0b39..b0d38bf 100644 --- a/lib9p/protogen/h.py +++ b/lib9p/protogen/h.py @@ -442,18 +442,16 @@ def gen_bitfield(typ: idl.Bitfield) -> str: def gen_struct(typ: idl.Struct) -> str: # and idl.Message ret = c9util.typename(typ) + " {" - if not typ.members: - ret += "};\n" - return ret - ret += "\n" + if typ.members: + ret += "\n" - typewidth = max(len(c9util.typename(m.typ, m)) for m in typ.members) + typewidth = max(len(c9util.typename(m.typ, m)) for m in typ.members) - for member in typ.members: - if member.val: - continue - ret += cutil.ifdef_push(2, c9util.ver_ifdef(member.in_versions)) - ret += f"\t{c9util.typename(member.typ, member):<{typewidth}} {'*' if member.cnt else ' '}{member.membname};\n" - ret += cutil.ifdef_pop(1) + for member in typ.members: + if member.val: + continue + ret += cutil.ifdef_push(2, c9util.ver_ifdef(member.in_versions)) + ret += f"\t{c9util.typename(member.typ, member):<{typewidth}} {'*' if member.cnt else ' '}{member.membname};\n" + ret += cutil.ifdef_pop(1) ret += "};\n" return ret -- cgit v1.2.3-2-g168b