]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
xdrgen: Track constant values
authorChuck Lever <chuck.lever@oracle.com>
Thu, 3 Oct 2024 18:54:32 +0000 (14:54 -0400)
committerChuck Lever <chuck.lever@oracle.com>
Mon, 11 Nov 2024 18:42:01 +0000 (13:42 -0500)
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>
tools/net/sunrpc/xdrgen/xdr_ast.py

index 68f09945f2c40ea9d5ed5a071daf1683f850b81e..b7df45f47707b7f774dcb67b65ac6f9f2765e113 100644 (file)
@@ -19,6 +19,8 @@ public_apis = []
 structs = set()
 pass_by_reference = set()
 
+constants = {}
+
 
 @dataclass
 class _XdrAst(ast_utils.Ast):
@@ -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):
@@ -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):