Commit 6bc85bab authored by Chuck Lever's avatar Chuck Lever
Browse files

xdrgen: Implement pass-through lines in specifications



XDR specification files can contain lines prefixed with '%' that
pass through unchanged to generated output. Traditional rpcgen
removes the '%' and emits the remainder verbatim, allowing direct
insertion of C includes, pragma directives, or other language-
specific content into the generated code.

Until now, xdrgen silently discarded these lines during parsing.
This prevented specifications from including necessary headers or
preprocessor directives that might be required for the generated
code to compile correctly.

The grammar now captures pass-through lines instead of ignoring
them. A new AST node type represents pass-through content, and
the AST transformer strips the leading '%' character. Definition
and source generators emit pass-through content in document order,
preserving the original placement within the specification.

This brings xdrgen closer to feature parity with traditional
rpcgen while maintaining the existing document-order processing
model.

Existing generated xdrgen source code has been regenerated.

Signed-off-by: default avatarChuck Lever <chuck.lever@oracle.com>
parent 3daab311
Loading
Loading
Loading
Loading
+10 −1
Original line number Diff line number Diff line
// SPDX-License-Identifier: GPL-2.0
// Generated by xdrgen. Manual edits will be lost.
// XDR specification file: ../../Documentation/sunrpc/xdr/nfs4_1.x
// XDR specification modification time: Thu Dec 25 13:44:43 2025
// XDR specification modification time: Thu Jan  8 23:11:48 2026

#include <linux/sunrpc/svc.h>

@@ -178,6 +178,10 @@ xdrgen_decode_fattr4_open_arguments(struct xdr_stream *xdr, fattr4_open_argument
	return xdrgen_decode_open_arguments4(xdr, ptr);
}

/*
 * Determine what OPEN supports.
 */

bool
xdrgen_decode_fattr4_time_deleg_access(struct xdr_stream *xdr, fattr4_time_deleg_access *ptr)
{
@@ -190,6 +194,11 @@ xdrgen_decode_fattr4_time_deleg_modify(struct xdr_stream *xdr, fattr4_time_deleg
	return xdrgen_decode_nfstime4(xdr, ptr);
}

/*
 * New RECOMMENDED Attribute for
 * delegation caching of times
 */

static bool __maybe_unused
xdrgen_decode_open_delegation_type4(struct xdr_stream *xdr, open_delegation_type4 *ptr)
{
+1 −1
Original line number Diff line number Diff line
/* SPDX-License-Identifier: GPL-2.0 */
/* Generated by xdrgen. Manual edits will be lost. */
/* XDR specification file: ../../Documentation/sunrpc/xdr/nfs4_1.x */
/* XDR specification modification time: Thu Dec 25 13:44:43 2025 */
/* XDR specification modification time: Thu Jan  8 23:11:48 2026 */

#ifndef _LINUX_XDRGEN_NFS4_1_DECL_H
#define _LINUX_XDRGEN_NFS4_1_DECL_H
+10 −1
Original line number Diff line number Diff line
/* SPDX-License-Identifier: GPL-2.0 */
/* Generated by xdrgen. Manual edits will be lost. */
/* XDR specification file: ../../Documentation/sunrpc/xdr/nfs4_1.x */
/* XDR specification modification time: Thu Dec 25 13:44:43 2025 */
/* XDR specification modification time: Thu Jan  8 23:11:48 2026 */

#ifndef _LINUX_XDRGEN_NFS4_1_DEF_H
#define _LINUX_XDRGEN_NFS4_1_DEF_H
@@ -87,6 +87,10 @@ typedef enum open_args_createmode4 open_args_createmode4;

typedef struct open_arguments4 fattr4_open_arguments;

/*
 * Determine what OPEN supports.
 */

enum { FATTR4_OPEN_ARGUMENTS = 86 };

enum { OPEN4_RESULT_NO_OPEN_STATEID = 0x00000010 };
@@ -95,6 +99,11 @@ typedef struct nfstime4 fattr4_time_deleg_access;

typedef struct nfstime4 fattr4_time_deleg_modify;

/*
 * New RECOMMENDED Attribute for
 * delegation caching of times
 */

enum { FATTR4_TIME_DELEG_ACCESS = 84 };

enum { FATTR4_TIME_DELEG_MODIFY = 85 };
+0 −2
Original line number Diff line number Diff line
@@ -250,8 +250,6 @@ Add more pragma directives:
Enable something like a #include to dynamically insert the content
of other specification files

Properly support line-by-line pass-through via the "%" decorator

Build a unit test suite for verifying translation of XDR language
into compilable code

+26 −0
Original line number Diff line number Diff line
#!/usr/bin/env python3
# ex: set filetype=python:

"""Generate code for XDR pass-through lines"""

from generators import SourceGenerator, create_jinja2_environment
from xdr_ast import _XdrPassthru


class XdrPassthruGenerator(SourceGenerator):
    """Generate source code for XDR pass-through content"""

    def __init__(self, language: str, peer: str):
        """Initialize an instance of this class"""
        self.environment = create_jinja2_environment(language, "passthru")
        self.peer = peer

    def emit_definition(self, node: _XdrPassthru) -> None:
        """Emit one pass-through line"""
        template = self.environment.get_template("definition.j2")
        print(template.render(content=node.content))

    def emit_decoder(self, node: _XdrPassthru) -> None:
        """Emit one pass-through line"""
        template = self.environment.get_template("source.j2")
        print(template.render(content=node.content))
Loading