diff options
author | Luke T. Shumaker <lukeshu@lukeshu.com> | 2025-03-29 18:19:37 -0600 |
---|---|---|
committer | Luke T. Shumaker <lukeshu@lukeshu.com> | 2025-03-29 18:20:53 -0600 |
commit | 0b31e9fa29699bbf140e168a17ead1c993d42e3e (patch) | |
tree | 4f37310b794895f131569455ddb2899f639b8c0a | |
parent | a492c4a31f1c8b2a0d58e24ab957ef3c8f9edfd2 (diff) |
lib9p: protogen: h.py: Tidy gen_struct()
-rw-r--r-- | lib9p/protogen/h.py | 20 |
1 files changed, 9 insertions, 11 deletions
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 |