Received: from eggs.gnu.org ([2001:4830:134:3::10]:37932) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XHrfD-0004XT-6B for qemu-devel@nongnu.org; Thu, 14 Aug 2014 05:49:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XHrf7-0003HJ-JE for qemu-devel@nongnu.org; Thu, 14 Aug 2014 05:49:43 -0400 Received: from mx1.redhat.com ([209.132.183.28]:32700) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XHrf7-0003HE-CQ for qemu-devel@nongnu.org; Thu, 14 Aug 2014 05:49:37 -0400 From: Markus Armbruster References: <1407287673-20308-1-git-send-email-eblake@redhat.com> <1407287673-20308-9-git-send-email-eblake@redhat.com> Date: Thu, 14 Aug 2014 11:49:33 +0200 In-Reply-To: <1407287673-20308-9-git-send-email-eblake@redhat.com> (Eric Blake's message of "Tue, 5 Aug 2014 19:14:27 -0600") Message-ID: <87a977jt8y.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Qemu-devel] [PATCH v3 08/14] qapi: add expr_name() helper List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eric Blake Cc: Luiz Capitulino , Fam Zheng , qemu-devel@nongnu.org, wenchaoqemu@gmail.com Eric Blake writes: > Now that we know every expression has a known meta-type, we > can add a helper function that retrieves the name of an > arbitrary expression, for use in future error messages. > > * scripts/qapi.py (expr_name): New function. > > Signed-off-by: Eric Blake > --- > scripts/qapi.py | 13 +++++++++++++ > 1 file changed, 13 insertions(+) > > diff --git a/scripts/qapi.py b/scripts/qapi.py > index 910e422..e02fa0b 100644 > --- a/scripts/qapi.py > +++ b/scripts/qapi.py > @@ -248,6 +248,19 @@ def discriminator_find_enum_define(expr): > > return find_enum(discriminator_type) > > +def expr_name(expr): > + if expr.has_key('union'): > + return expr['union'] > + if expr.has_key('type'): > + return expr['type'] > + if expr.has_key('enum'): > + return expr['enum'] > + if expr.has_key('command'): > + return expr['command'] > + if expr.has_key('event'): > + return expr['event'] > + return None > + > def check_event(expr, expr_info): > params = expr.get('data') > if params: Squash into the next commit?