From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50359) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WGMbY-00057v-Uc for qemu-devel@nongnu.org; Thu, 20 Feb 2014 00:55:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WGMbK-00015c-Kw for qemu-devel@nongnu.org; Thu, 20 Feb 2014 00:55:28 -0500 Received: from e28smtp01.in.ibm.com ([122.248.162.1]:46324) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WGMbJ-00014W-Uj for qemu-devel@nongnu.org; Thu, 20 Feb 2014 00:55:14 -0500 Received: from /spool/local by e28smtp01.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 20 Feb 2014 11:25:11 +0530 Received: from d28relay05.in.ibm.com (d28relay05.in.ibm.com [9.184.220.62]) by d28dlp03.in.ibm.com (Postfix) with ESMTP id 6A9521258059 for ; Thu, 20 Feb 2014 11:27:08 +0530 (IST) Received: from d28av02.in.ibm.com (d28av02.in.ibm.com [9.184.220.64]) by d28relay05.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id s1K5tB6I1769940 for ; Thu, 20 Feb 2014 11:25:11 +0530 Received: from d28av02.in.ibm.com (localhost [127.0.0.1]) by d28av02.in.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id s1K5t7vP001936 for ; Thu, 20 Feb 2014 11:25:07 +0530 From: Wenchao Xia Date: Thu, 20 Feb 2014 00:54:47 -0500 Message-Id: <1392875695-15627-4-git-send-email-xiawenc@linux.vnet.ibm.com> In-Reply-To: <1392875695-15627-1-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1392875695-15627-1-git-send-email-xiawenc@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH V7 03/11] qapi-script: remember line number in schema parsing List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, mdroth@linux.vnet.ibm.com, armbru@redhat.com, lcapitulino@redhat.com, Wenchao Xia Before this patch, 'QAPISchemaError' scans whole input until 'pos' to get error line number. After this patch, the scan is avoided since line number is remembered in schema parsing. This patch also benefits other error report functions, which would be introduced later. Signed-off-by: Wenchao Xia --- scripts/qapi.py | 14 ++++++++------ 1 files changed, 8 insertions(+), 6 deletions(-) diff --git a/scripts/qapi.py b/scripts/qapi.py index 3732fe1..c504eb4 100644 --- a/scripts/qapi.py +++ b/scripts/qapi.py @@ -39,12 +39,10 @@ class QAPISchemaError(Exception): def __init__(self, schema, msg): self.fp = schema.fp self.msg = msg - self.line = self.col = 1 - for ch in schema.src[0:schema.pos]: - if ch == '\n': - self.line += 1 - self.col = 1 - elif ch == '\t': + self.col = 1 + self.line = schema.line + for ch in schema.src[schema.line_pos:schema.pos]: + if ch == '\t': self.col = (self.col + 7) % 8 + 1 else: self.col += 1 @@ -60,6 +58,8 @@ class QAPISchema: if self.src == '' or self.src[-1] != '\n': self.src += '\n' self.cursor = 0 + self.line = 1 + self.line_pos = 0 self.exprs = [] self.accept() @@ -100,6 +100,8 @@ class QAPISchema: if self.cursor == len(self.src): self.tok = None return + self.line += 1 + self.line_pos = self.cursor elif not self.tok.isspace(): raise QAPISchemaError(self, 'Stray "%s"' % self.tok) -- 1.7.1