Skip to content

Commit

Permalink
xdrgen: XDR width for typedef
Browse files Browse the repository at this point in the history
The XDR width of a typedef is the same as the width of the base type.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
  • Loading branch information
Chuck Lever committed Nov 11, 2024
1 parent dc6fa83 commit 2852c92
Showing 1 changed file with 27 additions and 7 deletions.
34 changes: 27 additions & 7 deletions tools/net/sunrpc/xdrgen/xdr_ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,18 @@ class _XdrBasic(_XdrDeclaration):
spec: _XdrTypeSpecifier
template: str = "basic"

def max_width(self) -> int:
"""Return width of type in XDR_UNITS"""
return max_widths[self.spec.type_name]

def symbolic_width(self) -> List:
"""Return list containing XDR width of type's components"""
return symbolic_widths[self.spec.type_name]

def __post_init__(self):
max_widths[self.name] = self.max_width()
symbolic_widths[self.name] = self.symbolic_width()


@dataclass
class _XdrVoid(_XdrDeclaration):
Expand Down Expand Up @@ -361,14 +373,22 @@ class _XdrTypedef(_XdrAst):

declaration: _XdrDeclaration

def __post_init__(self):
if not isinstance(self.declaration, _XdrBasic):
return
def max_width(self) -> int:
"""Return width of type in XDR_UNITS"""
return self.declaration.max_width()

new_type = self.declaration
if isinstance(new_type.spec, _XdrDefinedType):
if new_type.spec.type_name in pass_by_reference:
pass_by_reference.add(new_type.name)
def symbolic_width(self) -> List:
"""Return list containing XDR width of type's components"""
return self.declaration.symbolic_width()

def __post_init__(self):
if isinstance(self.declaration, _XdrBasic):
new_type = self.declaration
if isinstance(new_type.spec, _XdrDefinedType):
if new_type.spec.type_name in pass_by_reference:
pass_by_reference.add(new_type.name)
max_widths[new_type.name] = self.max_width()
symbolic_widths[new_type.name] = self.symbolic_width()


@dataclass
Expand Down

0 comments on commit 2852c92

Please sign in to comment.