Refactor: Generate all struct bindings within the codegen.

PiperOrigin-RevId: 828973537
Change-Id: I3f371d2f88e1cd9b1bb5c0a9c6a5ace7a21673fb
This commit is contained in:
Matias Manevi
2025-11-06 08:48:52 -08:00
committed by Copybara-Service
parent 2c2773e36d
commit 06ecdd6ba1
5 changed files with 1517 additions and 1590 deletions
+9 -5
View File
@@ -47,13 +47,15 @@ class CodeBuilder:
class IndentBlock:
"""Helper class to manage indentation within a `with` statement."""
def __init__(self, builder: "CodeBuilder", header_line=""):
def __init__(self, builder: "CodeBuilder", header_line="", braces=True):
self._builder = builder
self._header_line = header_line
self._braces = braces
def __enter__(self):
line = self._header_line
line += " {" if line else "{"
if self._braces:
line += " {" if line else "{"
self._builder.line(line)
self._builder._indent_level += 1
self._line_count_enter = len(self._builder._lines)
@@ -65,20 +67,22 @@ class CodeBuilder:
if self._line_count_enter == len(self._builder._lines):
self._builder._lines[-1] += "}"
else:
self._builder.line("}")
if self._braces:
self._builder.line("}")
def block(self, header_line="") -> IndentBlock:
def block(self, header_line="", braces=True) -> IndentBlock:
"""Creates a block including braces and an optional header before the opening brace.
Use via a `with` statement.
Args:
header_line: Optional header line to add before the opening brace.
braces: Whether to include opening and closing braces.
Returns:
An IndentBlock instance that manages the indentation.
"""
return self.IndentBlock(self, header_line)
return self.IndentBlock(self, header_line, braces)
def function(self, signature="") -> IndentBlock:
"""Creates a function."""