]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
xdrgen: XDR width for struct types
authorChuck Lever <chuck.lever@oracle.com>
Thu, 3 Oct 2024 18:54:42 +0000 (14:54 -0400)
committerChuck Lever <chuck.lever@oracle.com>
Mon, 11 Nov 2024 18:42:04 +0000 (13:42 -0500)
The XDR width of a struct type is the sum of the widths of each of
the struct's fields.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
tools/net/sunrpc/xdrgen/xdr_ast.py

index 8996f26cbd55777c411d955b54765d02ab0c5488..f34b147c8dfdf8ab1d813359b4489d7a24c9cb14 100644 (file)
@@ -350,9 +350,25 @@ class _XdrStruct(_XdrAst):
     name: str
     fields: List[_XdrDeclaration]
 
+    def max_width(self) -> int:
+        """Return width of type in XDR_UNITS"""
+        width = 0
+        for field in self.fields:
+            width += field.max_width()
+        return width
+
+    def symbolic_width(self) -> List:
+        """Return list containing XDR width of type's components"""
+        widths = []
+        for field in self.fields:
+            widths += field.symbolic_width()
+        return widths
+
     def __post_init__(self):
         structs.add(self.name)
         pass_by_reference.add(self.name)
+        max_widths[self.name] = self.max_width()
+        symbolic_widths[self.name] = self.symbolic_width()
 
 
 @dataclass