Skip to content

Commit

Permalink
xdrgen: XDR width for struct types
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Chuck Lever committed Nov 11, 2024
1 parent 2852c92 commit f4bc1e9
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions tools/net/sunrpc/xdrgen/xdr_ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f4bc1e9

Please sign in to comment.