From nobody Thu Dec 18 00:53:45 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1678293584; cv=none; d=zohomail.com; s=zohoarc; b=A+uudAjZ84YqE9qpSL/BWMaf+OIxRDNM6YLhl/H7dz9u3sEX2t/krXJloZEogTQXX4qYzBQBK0TJhZQQZf0O+1KjmYUFtsgFRrp4DHs9BJUJJXFu/jGOcAHjdyYUbZQW+q8mJDf9sUEAPqOuQYr2C3EfMnB+M+UpkjOujO4Debw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1678293584; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=sc6P6GtwXp+dFpZqOGm8C5ffdQFsDwJ2RgyqHDJgWgQ=; b=jWbhsnNZpoYxv8TvZ02HszuH2wG9svc6RWz/PPgyAyC+Wotq+jvGEo9dn9eokozkcZECtZSECPwEci+rj7mok8M8kchwgcKdhjy1X0wSUX7oEzA/pUUbYX73nvy9Rr40NOBOg726DTni0PN+s9kk8frbHBMllkIfaBSJvYPzIRo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1678293584398990.6498105439778; Wed, 8 Mar 2023 08:39:44 -0800 (PST) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-417-vNT2S634NQyX0-2VDcQxGQ-1; Wed, 08 Mar 2023 11:39:40 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D642F3806652; Wed, 8 Mar 2023 16:39:26 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id BF1BE1120AC4; Wed, 8 Mar 2023 16:39:26 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 62E8519472D0; Wed, 8 Mar 2023 16:39:23 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id DD34B1946A5E for ; Wed, 8 Mar 2023 16:39:18 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id C199B112132D; Wed, 8 Mar 2023 16:39:18 +0000 (UTC) Received: from virtlab420.virt.lab.eng.bos.redhat.com (virtlab420.virt.lab.eng.bos.redhat.com [10.19.152.148]) by smtp.corp.redhat.com (Postfix) with ESMTP id A79001121314; Wed, 8 Mar 2023 16:39:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678293583; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=sc6P6GtwXp+dFpZqOGm8C5ffdQFsDwJ2RgyqHDJgWgQ=; b=dGs4sv77BoLalrlsBjbiohvlQb0XR80MSmPebBAT7Dq7+EjkwuTs/T+pXb6Re4cUsw9Beo qdAJS92QqwjVZ3D/RAZe7EqWLDnH9Xu1ejbYKgg8MUk6H5mifN08v/U8lEs34q6tsFWMgA tMRPdjadSAQPlOliq+UPcInAPSHCttU= X-MC-Unique: vNT2S634NQyX0-2VDcQxGQ-1 X-Original-To: libvir-list@listman.corp.redhat.com From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Subject: [PATCH 07/16] rpcgen: define a visitor API for XDR protocol specs Date: Wed, 8 Mar 2023 11:39:04 -0500 Message-Id: <20230308163913.338952-8-berrange@redhat.com> In-Reply-To: <20230308163913.338952-1-berrange@redhat.com> References: <20230308163913.338952-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1678293584783100001 The visitor API defines an interface for visiting each element in the XDR protocol spec abstract syntax tree. Signed-off-by: Daniel P. Berrang=C3=A9 --- scripts/rpcgen/rpcgen/visitor.py | 156 +++++++++++++++++++++++++++++++ 1 file changed, 156 insertions(+) create mode 100644 scripts/rpcgen/rpcgen/visitor.py diff --git a/scripts/rpcgen/rpcgen/visitor.py b/scripts/rpcgen/rpcgen/visit= or.py new file mode 100644 index 0000000000..e1b2d907c1 --- /dev/null +++ b/scripts/rpcgen/rpcgen/visitor.py @@ -0,0 +1,156 @@ +# SPDX-License-Identifier: LGPL-2.1-or-later + +import abc + +from .ast import ( + XDRSpecification, + XDRDefinition, + XDRDeclaration, + XDRType, + XDREnumValue, + XDREnumBody, + XDRStructBody, + XDRUnionCase, + XDRUnionBody, +) + + +class XDRVisitor(abc.ABC): + def __init__(self, spec): + self.spec =3D spec + + def visit(self, indent=3D"", context=3D""): + return self.visit_object(self.spec, indent=3D"", context=3Dcontext) + + def visit_object(self, obj, indent=3D"", context=3D""): + if isinstance(obj, XDRSpecification): + funcname =3D "visit_specification" + elif isinstance(obj, XDRDefinition): + funcname =3D "visit_definition_" + type(obj).__name__[13:].low= er() + elif isinstance(obj, XDRDeclaration): + funcname =3D "visit_declaration_" + type(obj).__name__[14:].lo= wer() + elif isinstance(obj, XDRType): + funcname =3D "visit_type_" + type(obj).__name__[7:].lower() + elif isinstance(obj, XDREnumValue): + funcname =3D "visit_enum_value" + elif isinstance(obj, XDREnumBody): + funcname =3D "visit_enum_body" + elif isinstance(obj, XDRStructBody): + funcname =3D "visit_struct_body" + elif isinstance(obj, XDRUnionCase): + funcname =3D "visit_union_case" + elif isinstance(obj, XDRUnionBody): + funcname =3D "visit_union_body" + else: + raise Exception("Unhandled %s" % obj.__class__.__name__) + + func =3D getattr(self, funcname) + assert func is not None + return func(obj, indent, context) + + def visit_specification(self, obj, indent, context): + code =3D [] + for definition in self.spec.definitions: + defcode =3D self.visit_object(definition, indent, context) + if defcode is not None: + code.append(defcode) + return "\n".join(code) + + def visit_definition_cescape(self, obj, indent, context): + pass + + def visit_definition_constant(self, obj, indent, context): + pass + + def visit_definition_enum(self, obj, indent, context): + pass + + def visit_definition_struct(self, obj, indent, context): + pass + + def visit_definition_union(self, obj, indent, context): + pass + + def visit_definition_typedef(self, obj, indent, context): + pass + + def visit_declaration_scalar(self, obj, indent, context): + pass + + def visit_declaration_pointer(self, obj, indent, context): + pass + + def visit_declaration_fixedarray(self, obj, indent, context): + pass + + def visit_declaration_variablearray(self, obj, indent, context): + pass + + def visit_type_custom(self, obj, indent, context): + pass + + def visit_type_opaque(self, obj, indent, context): + pass + + def visit_type_string(self, obj, indent, context): + pass + + def visit_type_void(self, obj, indent, context): + pass + + def visit_type_char(self, obj, indent, context): + pass + + def visit_type_unsignedchar(self, obj, indent, context): + pass + + def visit_type_short(self, obj, indent, context): + pass + + def visit_type_unsignedshort(self, obj, indent, context): + pass + + def visit_type_int(self, obj, indent, context): + pass + + def visit_type_unsignedint(self, obj, indent, context): + pass + + def visit_type_hyper(self, obj, indent, context): + pass + + def visit_type_unsignedhyper(self, obj, indent, context): + pass + + def visit_type_bool(self, obj, indent, context): + pass + + def visit_type_float(self, obj, indent, context): + pass + + def visit_type_double(self, obj, indent, context): + pass + + def visit_type_enum(self, obj, indent, context): + pass + + def visit_type_struct(self, obj, indent, context): + pass + + def visit_type_union(self, obj, indent, context): + pass + + def visit_enum_value(self, obj, indent, context): + pass + + def visit_enum_body(self, obj, indent, context): + pass + + def visit_struct_body(self, obj, indent, context): + pass + + def visit_union_case(self, obj, indent, context): + pass + + def visit_union_body(self, obj, indent, context): + pass --=20 2.39.1