From: cel@kernel.org
To: Neil Brown <neilb@suse.de>, Jeff Layton <jlayton@kernel.org>,
Olga Kornievskaia <okorniev@redhat.com>,
Dai Ngo <dai.ngo@oracle.com>, Tom Talpey <tom@talpey.com>
Cc: <linux-nfs@vger.kernel.org>, Chuck Lever <chuck.lever@oracle.com>
Subject: [PATCH 01/16] xdrgen: Refactor transformer arms
Date: Thu, 3 Oct 2024 11:01:43 -0400 [thread overview]
Message-ID: <20241003150151.81951-2-cel@kernel.org> (raw)
In-Reply-To: <20241003150151.81951-1-cel@kernel.org>
From: Chuck Lever <chuck.lever@oracle.com>
Clean up: Add a __post_init__ function to the data classes that
need to update the "structs" and "pass_by_reference" sets.
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
tools/net/sunrpc/xdrgen/xdr_ast.py | 57 +++++++++++++++++-------------
1 file changed, 33 insertions(+), 24 deletions(-)
diff --git a/tools/net/sunrpc/xdrgen/xdr_ast.py b/tools/net/sunrpc/xdrgen/xdr_ast.py
index d5f0535ec84c..68f09945f2c4 100644
--- a/tools/net/sunrpc/xdrgen/xdr_ast.py
+++ b/tools/net/sunrpc/xdrgen/xdr_ast.py
@@ -51,13 +51,17 @@ class _XdrTypeSpecifier(_XdrAst):
"""Corresponds to 'type_specifier' in the XDR language grammar"""
type_name: str
- c_classifier: str
+ c_classifier: str = ""
@dataclass
class _XdrDefinedType(_XdrTypeSpecifier):
"""Corresponds to a type defined by the input specification"""
+ def __post_init__(self):
+ if self.type_name in structs:
+ self.c_classifier = "struct "
+
@dataclass
class _XdrBuiltInType(_XdrTypeSpecifier):
@@ -124,6 +128,10 @@ class _XdrOptionalData(_XdrDeclaration):
spec: _XdrTypeSpecifier
template: str = "optional_data"
+ def __post_init__(self):
+ structs.add(self.name)
+ pass_by_reference.add(self.name)
+
@dataclass
class _XdrBasic(_XdrDeclaration):
@@ -174,6 +182,10 @@ class _XdrStruct(_XdrAst):
name: str
fields: List[_XdrDeclaration]
+ def __post_init__(self):
+ structs.add(self.name)
+ pass_by_reference.add(self.name)
+
@dataclass
class _XdrPointer(_XdrAst):
@@ -182,6 +194,10 @@ class _XdrPointer(_XdrAst):
name: str
fields: List[_XdrDeclaration]
+ def __post_init__(self):
+ structs.add(self.name)
+ pass_by_reference.add(self.name)
+
@dataclass
class _XdrTypedef(_XdrAst):
@@ -189,6 +205,15 @@ class _XdrTypedef(_XdrAst):
declaration: _XdrDeclaration
+ def __post_init__(self):
+ if not isinstance(self.declaration, _XdrBasic):
+ return
+
+ 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)
+
@dataclass
class _XdrCaseSpec(_XdrAst):
@@ -216,6 +241,10 @@ class _XdrUnion(_XdrAst):
cases: List[_XdrCaseSpec]
default: _XdrDeclaration
+ def __post_init__(self):
+ structs.add(self.name)
+ pass_by_reference.add(self.name)
+
@dataclass
class _RpcProcedure(_XdrAst):
@@ -290,22 +319,13 @@ class ParseToAst(Transformer):
return _XdrConstantValue(value)
def type_specifier(self, children):
- """Instantiate one type_specifier object"""
- c_classifier = ""
+ """Instantiate one _XdrTypeSpecifier object"""
if isinstance(children[0], _XdrIdentifier):
name = children[0].symbol
- if name in structs:
- c_classifier = "struct "
- return _XdrDefinedType(
- type_name=name,
- c_classifier=c_classifier,
- )
+ return _XdrDefinedType(type_name=name)
name = children[0].data.value
- return _XdrBuiltInType(
- type_name=name,
- c_classifier=c_classifier,
- )
+ return _XdrBuiltInType(type_name=name)
def constant_def(self, children):
"""Instantiate one _XdrConstant object"""
@@ -380,8 +400,6 @@ class ParseToAst(Transformer):
"""Instantiate one _XdrOptionalData declaration object"""
spec = children[0]
name = children[1].symbol
- structs.add(name)
- pass_by_reference.add(name)
return _XdrOptionalData(name, spec)
@@ -400,8 +418,6 @@ class ParseToAst(Transformer):
def struct(self, children):
"""Instantiate one _XdrStruct object"""
name = children[0].symbol
- structs.add(name)
- pass_by_reference.add(name)
fields = children[1].children
last_field = fields[-1]
@@ -416,11 +432,6 @@ class ParseToAst(Transformer):
def typedef(self, children):
"""Instantiate one _XdrTypedef object"""
new_type = children[0]
- if isinstance(new_type, _XdrBasic) and isinstance(
- new_type.spec, _XdrDefinedType
- ):
- if new_type.spec.type_name in pass_by_reference:
- pass_by_reference.add(new_type.name)
return _XdrTypedef(new_type)
@@ -442,8 +453,6 @@ class ParseToAst(Transformer):
def union(self, children):
"""Instantiate one _XdrUnion object"""
name = children[0].symbol
- structs.add(name)
- pass_by_reference.add(name)
body = children[1]
discriminant = body.children[0].children[0]
--
2.46.2
next prev parent reply other threads:[~2024-10-03 15:01 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-03 15:01 [PATCH 00/16] xdrgen: Emit maxsize macros cel
2024-10-03 15:01 ` cel [this message]
2024-10-03 15:01 ` [PATCH 02/16] xdrgen: Track constant values cel
2024-10-03 15:01 ` [PATCH 03/16] xdrgen: Keep track of on-the-wire data type widths cel
2024-10-03 15:01 ` [PATCH 04/16] xdrgen: XDR widths for enum types cel
2024-10-03 15:01 ` [PATCH 05/16] xdrgen: XDR width for fixed-length opaque cel
2024-10-03 15:01 ` [PATCH 06/16] xdrgen: XDR width for variable-length opaque cel
2024-10-03 15:01 ` [PATCH 07/16] xdrgen: XDR width for a string cel
2024-10-03 15:01 ` [PATCH 08/16] xdrgen: XDR width for fixed-length array cel
2024-10-03 15:01 ` [PATCH 09/16] xdrgen: XDR width for variable-length array cel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241003150151.81951-2-cel@kernel.org \
--to=cel@kernel.org \
--cc=chuck.lever@oracle.com \
--cc=dai.ngo@oracle.com \
--cc=jlayton@kernel.org \
--cc=linux-nfs@vger.kernel.org \
--cc=neilb@suse.de \
--cc=okorniev@redhat.com \
--cc=tom@talpey.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.