diff options
Diffstat (limited to 'lib9p/protogen/c_unmarshal.py')
-rw-r--r-- | lib9p/protogen/c_unmarshal.py | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/lib9p/protogen/c_unmarshal.py b/lib9p/protogen/c_unmarshal.py index d076352..ea484b0 100644 --- a/lib9p/protogen/c_unmarshal.py +++ b/lib9p/protogen/c_unmarshal.py @@ -72,6 +72,8 @@ def gen_c_unmarshal(versions: set[str], typs: list[idl.UserType]) -> str: nonlocal indent_stack nonlocal indent_stack_len while len(indent_stack) > indent_stack_len: + if len(indent_stack) == indent_stack_len + 1 and indent_stack[-1].ifdef: + break ret += f"{'\t'*(indent_lvl()-1)}}}\n" if indent_stack.pop().ifdef: ret += cutil.ifdef_pop(ifdef_lvl()) @@ -82,11 +84,14 @@ def gen_c_unmarshal(versions: set[str], typs: list[idl.UserType]) -> str: child = path.elems[-1] parent = path.elems[-2].typ if len(path.elems) > 1 else path.root if child.in_versions < parent.in_versions: - ret += cutil.ifdef_push( + if line := cutil.ifdef_push( ifdef_lvl() + 1, c9util.ver_ifdef(child.in_versions) - ) - ret += f"{'\t'*indent_lvl()}if ({c9util.ver_cond(child.in_versions)}) {{\n" - indent_stack.append(IndentLevel(ifdef=True)) + ): + ret += line + ret += ( + f"{'\t'*indent_lvl()}if ({c9util.ver_cond(child.in_versions)}) {{\n" + ) + indent_stack.append(IndentLevel(ifdef=True)) if child.cnt: cnt_path = path.parent().add(child.cnt) if child.typ.static_size == 1: # SPECIAL (zerocopy) @@ -119,7 +124,9 @@ def gen_c_unmarshal(versions: set[str], typs: list[idl.UserType]) -> str: indent_stack = [IndentLevel(ifdef=True)] idlutil.walk(typ, handle) - - ret += "}\n" + while len(indent_stack) > 0: + ret += f"{'\t'*(indent_lvl()-1)}}}\n" + if indent_stack.pop().ifdef and indent_stack: + ret += cutil.ifdef_pop(ifdef_lvl()) ret += cutil.ifdef_pop(0) return ret |