Skip to content

Commit

Permalink
xdrgen: Track constant values
Browse files Browse the repository at this point in the history
In order to compute the numeric on-the-wire width of XDR types,
xdrgen needs to keep track of the numeric value of constants that
are defined in the input specification so it can perform
calculations with those values.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
  • Loading branch information
chucklever committed Nov 11, 2024
1 parent 1acd13c commit 189f55d
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions tools/net/sunrpc/xdrgen/xdr_ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
structs = set()
pass_by_reference = set()

constants = {}


@dataclass
class _XdrAst(ast_utils.Ast):
Expand Down Expand Up @@ -156,6 +158,10 @@ class _XdrConstant(_XdrAst):
name: str
value: str

def __post_init__(self):
if self.value not in constants:
constants[self.name] = int(self.value, 0)


@dataclass
class _XdrEnumerator(_XdrAst):
Expand All @@ -164,6 +170,10 @@ class _XdrEnumerator(_XdrAst):
name: str
value: str

def __post_init__(self):
if self.value not in constants:
constants[self.name] = int(self.value, 0)


@dataclass
class _XdrEnum(_XdrAst):
Expand Down

0 comments on commit 189f55d

Please sign in to comment.