Received: from eggs.gnu.org ([2001:4830:134:3::10]:44557) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XEpoV-0003pl-Ic for qemu-devel@nongnu.org; Tue, 05 Aug 2014 21:14:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XEpoP-0004do-Iq for qemu-devel@nongnu.org; Tue, 05 Aug 2014 21:14:47 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60118) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XEpoP-0004dP-CF for qemu-devel@nongnu.org; Tue, 05 Aug 2014 21:14:41 -0400 From: Eric Blake Date: Tue, 5 Aug 2014 19:14:27 -0600 Message-Id: <1407287673-20308-9-git-send-email-eblake@redhat.com> In-Reply-To: <1407287673-20308-1-git-send-email-eblake@redhat.com> References: <1407287673-20308-1-git-send-email-eblake@redhat.com> Subject: [Qemu-devel] [PATCH v3 08/14] qapi: add expr_name() helper List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Fam Zheng , Markus Armbruster , wenchaoqemu@gmail.com, Luiz Capitulino 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: -- 1.9.3