[PATCH] xdrgen: Handle typedef void types
From: Khushal Chitturi
Date: Tue Nov 11 2025 - 15:59:57 EST
This patch Handle typedef void in XDR Generator. Previously, such
declarations triggered a NotImplementedError in typedef.py.
This change adds handling for _XdrVoid AST nodes within the
typedef generator. When an XDR includes a typedef void,
the generator now recognizes _XdrVoid nodes and emits the
respective C typedefs and associated functions. New Jinja2
templates were introduced for encoder, decoder, declaration,
definition, and maxsize generation. The XDR grammar was
updated so that void typedefs can be parsed properly
Tested by running xdrgen on tests/test.x containing a typedef void
declaration. The tool now runs and produces the encoder, decoder,
and typedef outputs across source, definitions, and declarations.
Signed-off-by: Khushal Chitturi <kc9282016@xxxxxxxxx>
---
tools/net/sunrpc/xdrgen/generators/typedef.py | 12 ++++++++----
tools/net/sunrpc/xdrgen/grammars/xdr.lark | 2 +-
.../xdrgen/templates/C/typedef/declaration/void.j2 | 2 ++
.../xdrgen/templates/C/typedef/decoder/void.j2 | 6 ++++++
.../xdrgen/templates/C/typedef/definition/void.j2 | 2 ++
.../xdrgen/templates/C/typedef/encoder/void.j2 | 6 ++++++
.../xdrgen/templates/C/typedef/maxsize/void.j2 | 2 ++
7 files changed, 27 insertions(+), 5 deletions(-)
create mode 100644 tools/net/sunrpc/xdrgen/templates/C/typedef/declaration/void.j2
create mode 100644 tools/net/sunrpc/xdrgen/templates/C/typedef/decoder/void.j2
create mode 100644 tools/net/sunrpc/xdrgen/templates/C/typedef/definition/void.j2
create mode 100644 tools/net/sunrpc/xdrgen/templates/C/typedef/encoder/void.j2
create mode 100644 tools/net/sunrpc/xdrgen/templates/C/typedef/maxsize/void.j2
diff --git a/tools/net/sunrpc/xdrgen/generators/typedef.py b/tools/net/sunrpc/xdrgen/generators/typedef.py
index fab72e9d6915..f49ae26c4830 100644
--- a/tools/net/sunrpc/xdrgen/generators/typedef.py
+++ b/tools/net/sunrpc/xdrgen/generators/typedef.py
@@ -58,7 +58,8 @@ def emit_typedef_declaration(environment: Environment, node: _XdrDeclaration) ->
elif isinstance(node, _XdrOptionalData):
raise NotImplementedError("<optional_data> typedef not yet implemented")
elif isinstance(node, _XdrVoid):
- raise NotImplementedError("<void> typedef not yet implemented")
+ template = get_jinja2_template(environment, "declaration", node.template)
+ print(template.render(name=node.name))
else:
raise NotImplementedError("typedef: type not recognized")
@@ -104,7 +105,8 @@ def emit_type_definition(environment: Environment, node: _XdrDeclaration) -> Non
elif isinstance(node, _XdrOptionalData):
raise NotImplementedError("<optional_data> typedef not yet implemented")
elif isinstance(node, _XdrVoid):
- raise NotImplementedError("<void> typedef not yet implemented")
+ template = get_jinja2_template(environment, "definition", node.template)
+ print(template.render(name=node.name))
else:
raise NotImplementedError("typedef: type not recognized")
@@ -165,7 +167,8 @@ def emit_typedef_decoder(environment: Environment, node: _XdrDeclaration) -> Non
elif isinstance(node, _XdrOptionalData):
raise NotImplementedError("<optional_data> typedef not yet implemented")
elif isinstance(node, _XdrVoid):
- raise NotImplementedError("<void> typedef not yet implemented")
+ template = get_jinja2_template(environment, "decoder", node.template)
+ print(template.render(name=node.name))
else:
raise NotImplementedError("typedef: type not recognized")
@@ -225,7 +228,8 @@ def emit_typedef_encoder(environment: Environment, node: _XdrDeclaration) -> Non
elif isinstance(node, _XdrOptionalData):
raise NotImplementedError("<optional_data> typedef not yet implemented")
elif isinstance(node, _XdrVoid):
- raise NotImplementedError("<void> typedef not yet implemented")
+ template = get_jinja2_template(environment, "encoder", node.template)
+ print(template.render(name=node.name))
else:
raise NotImplementedError("typedef: type not recognized")
diff --git a/tools/net/sunrpc/xdrgen/grammars/xdr.lark b/tools/net/sunrpc/xdrgen/grammars/xdr.lark
index 7c2c1b8c86d1..d8c5f7130d83 100644
--- a/tools/net/sunrpc/xdrgen/grammars/xdr.lark
+++ b/tools/net/sunrpc/xdrgen/grammars/xdr.lark
@@ -8,7 +8,7 @@ declaration : "opaque" identifier "[" value "]" -> fixed_
| type_specifier identifier "<" [ value ] ">" -> variable_length_array
| type_specifier "*" identifier -> optional_data
| type_specifier identifier -> basic
- | "void" -> void
+ | "void" [identifier] -> void
value : decimal_constant
| hexadecimal_constant
diff --git a/tools/net/sunrpc/xdrgen/templates/C/typedef/declaration/void.j2 b/tools/net/sunrpc/xdrgen/templates/C/typedef/declaration/void.j2
new file mode 100644
index 000000000000..22c5226ee526
--- /dev/null
+++ b/tools/net/sunrpc/xdrgen/templates/C/typedef/declaration/void.j2
@@ -0,0 +1,2 @@
+{# SPDX-License-Identifier: GPL-2.0 #}
+typedef void {{ name }};
diff --git a/tools/net/sunrpc/xdrgen/templates/C/typedef/decoder/void.j2 b/tools/net/sunrpc/xdrgen/templates/C/typedef/decoder/void.j2
new file mode 100644
index 000000000000..ed9e2455b36f
--- /dev/null
+++ b/tools/net/sunrpc/xdrgen/templates/C/typedef/decoder/void.j2
@@ -0,0 +1,6 @@
+{# SPDX-License-Identifier: GPL-2.0 #}
+static inline bool
+xdrgen_decode_{{ name }}(struct xdr_stream *xdr, void *ptr)
+{
+ return true;
+}
diff --git a/tools/net/sunrpc/xdrgen/templates/C/typedef/definition/void.j2 b/tools/net/sunrpc/xdrgen/templates/C/typedef/definition/void.j2
new file mode 100644
index 000000000000..22c5226ee526
--- /dev/null
+++ b/tools/net/sunrpc/xdrgen/templates/C/typedef/definition/void.j2
@@ -0,0 +1,2 @@
+{# SPDX-License-Identifier: GPL-2.0 #}
+typedef void {{ name }};
diff --git a/tools/net/sunrpc/xdrgen/templates/C/typedef/encoder/void.j2 b/tools/net/sunrpc/xdrgen/templates/C/typedef/encoder/void.j2
new file mode 100644
index 000000000000..47d48af81546
--- /dev/null
+++ b/tools/net/sunrpc/xdrgen/templates/C/typedef/encoder/void.j2
@@ -0,0 +1,6 @@
+{# SPDX-License-Identifier: GPL-2.0 #}
+static inline bool
+xdrgen_encode_{{ name }}(struct xdr_stream *xdr, const void *ptr)
+{
+ return true;
+}
diff --git a/tools/net/sunrpc/xdrgen/templates/C/typedef/maxsize/void.j2 b/tools/net/sunrpc/xdrgen/templates/C/typedef/maxsize/void.j2
new file mode 100644
index 000000000000..129374200ad0
--- /dev/null
+++ b/tools/net/sunrpc/xdrgen/templates/C/typedef/maxsize/void.j2
@@ -0,0 +1,2 @@
+{# SPDX-License-Identifier: GPL-2.0 #}
+#define {{ macro }} 0
--
2.51.2