From patchwork Wed Apr 29 13:06:27 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Blake X-Patchwork-Id: 465999 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id B576C14032C for ; Wed, 29 Apr 2015 23:08:02 +1000 (AEST) Received: from localhost ([::1]:38786 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YnRia-0000U4-RN for incoming@patchwork.ozlabs.org; Wed, 29 Apr 2015 09:08:00 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58403) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YnRhj-0007cu-BR for qemu-devel@nongnu.org; Wed, 29 Apr 2015 09:07:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YnRhh-0000y9-Vj for qemu-devel@nongnu.org; Wed, 29 Apr 2015 09:07:07 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47278) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YnRhh-0000y1-QY for qemu-devel@nongnu.org; Wed, 29 Apr 2015 09:07:05 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id 8C7788E3CC; Wed, 29 Apr 2015 13:07:05 +0000 (UTC) Received: from red.redhat.com (ovpn-113-25.phx2.redhat.com [10.3.113.25]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t3TD6wvp012100; Wed, 29 Apr 2015 09:07:05 -0400 From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 29 Apr 2015 07:06:27 -0600 Message-Id: <1430312814-19706-13-git-send-email-eblake@redhat.com> In-Reply-To: <1430312814-19706-1-git-send-email-eblake@redhat.com> References: <1430312814-19706-1-git-send-email-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, berto@igalia.com, armbru@redhat.com Subject: [Qemu-devel] [PATCH v7 12/39] qapi: Prepare for catching more semantic parse errors X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This patch widens the scope of a try block (with the attending reindentation required by Python) in preparation for a future patch adding more instances of QAPIExprError inside the block. It's easier to separate indentation from semantic changes, so this patch has no real behavior change. Signed-off-by: Eric Blake Reviewed-by: Markus Armbruster --- scripts/qapi.py | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/scripts/qapi.py b/scripts/qapi.py index 5f0f699..0c3459b 100644 --- a/scripts/qapi.py +++ b/scripts/qapi.py @@ -399,6 +399,7 @@ def check_exprs(schema): check_event(expr, info) def parse_schema(input_file): + # First pass: read entire file into memory try: schema = QAPISchema(open(input_file, "r")) except (QAPISchemaError, QAPIExprError), e: @@ -407,24 +408,26 @@ def parse_schema(input_file): exprs = [] - for expr_elem in schema.exprs: - expr = expr_elem['expr'] - if expr.has_key('enum'): - add_enum(expr['enum'], expr.get('data')) - elif expr.has_key('union'): - add_union(expr) - elif expr.has_key('type'): - add_struct(expr) - exprs.append(expr) - - # Try again for hidden UnionKind enum - for expr_elem in schema.exprs: - expr = expr_elem['expr'] - if expr.has_key('union'): - if not discriminator_find_enum_define(expr): - add_enum('%sKind' % expr['union']) - try: + # Next pass: learn the types. + for expr_elem in schema.exprs: + expr = expr_elem['expr'] + if expr.has_key('enum'): + add_enum(expr['enum'], expr.get('data')) + elif expr.has_key('union'): + add_union(expr) + elif expr.has_key('type'): + add_struct(expr) + exprs.append(expr) + + # Try again for hidden UnionKind enum + for expr_elem in schema.exprs: + expr = expr_elem['expr'] + if expr.has_key('union'): + if not discriminator_find_enum_define(expr): + add_enum('%sKind' % expr['union']) + + # Final pass - validate that exprs make sense check_exprs(schema) except QAPIExprError, e: print >>sys.stderr, e