From patchwork Thu Mar 22 17:00:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 132309 Delivered-To: patch@linaro.org Received: by 10.46.84.29 with SMTP id i29csp1087824ljb; Thu, 22 Mar 2018 10:01:57 -0700 (PDT) X-Google-Smtp-Source: AG47ELuBK+NikEaMP0aMDyxRKQOGd5olG0p7svu11CvhYGVeohTHnaub+mPdV1GuTrZLzGA77LNP X-Received: by 10.99.100.132 with SMTP id y126mr18114189pgb.77.1521738117470; Thu, 22 Mar 2018 10:01:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521738117; cv=none; d=google.com; s=arc-20160816; b=sn88f6jo6lP4B8ffPKrQHknkcSkkY+ETBO8zhe8Xe/65g5ibVgKsp9Ssqkv3E2CaqW jw/453TT2gWV7pdoMg1z0RX0TYOVq09Hy8jIqmpSeRRg/5WF7VKfwSnS1/ot0WGlQ24m Ky988nvtadJO4x9bubUId0ec8WDY5jJE0CWzj0WdBSbMzaHWXa482lb0raJwHgqfcSKS L8ET95eeuRKv/lBraC2RYEDuGgFJXuIukRwXJa0DyNxX/1+1kaWb72XKxA5OlR7SL3dD 9TC/2rXea65H9S+IqGa4F1Zs08UFOyRwnfF5jiQ64+R3KiOV1J5DY+Tk/YDn7MgXQ8iF AGnw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:dkim-filter :arc-authentication-results; bh=TdM89TA/Crj305aRLV39gwF6+e1O4YlkyNvavNN2Z3c=; b=H6vxFUfp1pIFQgyrB+/jMxZcGTgzazGdEARNQDG95gBJqJXzZtak2d5mK+x9MDyXKR 88Ypn0VjSOKGPJmx1gXeI98EHGxKU+tcwnJZPf/Rq1YjUelDpqynHRttVap2rImoortM lJ0EiZOlFo7gXdtB66kK0dyObgDC7pZmnNskKx8I7adCX3Xh9ytGzL5ryozKH4+bCH49 PfxSvSBzQTtEQLwDOio2xPspxHqdA/1fxB1XbOsQEFsexqoYD17mYJnvKd6gz8aYVs4U +2pkWZ2yhtJGvPFUS9vZYe6AaeXxkAhnqXLCwzGG2JsyEP+585mA35GjbXyIFaKspB3M +5qw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=1kxetWus; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t13si4443387pgu.62.2018.03.22.10.01.53; Thu, 22 Mar 2018 10:01:57 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=1kxetWus; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752001AbeCVRBa (ORCPT + 28 others); Thu, 22 Mar 2018 13:01:30 -0400 Received: from conuserg-09.nifty.com ([210.131.2.76]:47944 "EHLO conuserg-09.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751758AbeCVRBZ (ORCPT ); Thu, 22 Mar 2018 13:01:25 -0400 Received: from grover.sesame (FL1-125-199-20-195.osk.mesh.ad.jp [125.199.20.195]) (authenticated) by conuserg-09.nifty.com with ESMTP id w2MH0Mr4012430; Fri, 23 Mar 2018 02:00:23 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-09.nifty.com w2MH0Mr4012430 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1521738024; bh=TdM89TA/Crj305aRLV39gwF6+e1O4YlkyNvavNN2Z3c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1kxetWuscPsDO0UOsJWs6vYow8Wv/oTBssrelKwDQ506XjV1c1gdVcslRnYD5WBPh T9Z74U2AuNfRoiBMfYIGmmzKFZPksKY/RKYVudtdBfu7YtvxnRRO4H9gvKPJ56jISX Vnz4vl1qd5ozF6Yuo32+qqR0zLM0L5YptOivBhv4y0z0o1pHkRMLpawfxHnOOA/lAk YGWhe/6/7D9R084V/+h+NLGCKe9vSXnygdLymeBvzpIRzfNeMqbCKAkxLug4w1ez9P giPy4x9Ga3OkBFjeF7ijJYfxYPXWIe92AI6J4Fx1YxLbKC7HWHYiQDU/8/CPxw6YZx POcVHsjK5ecAw== X-Nifty-SrcIP: [125.199.20.195] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Michal Marek , Sam Ravnborg , Ulf Magnusson , "Luis R . Rodriguez" , Masahiro Yamada , linux-kernel@vger.kernel.org Subject: [PATCH 3/3] kconfig: use yylineno option instead of manual lineno increments Date: Fri, 23 Mar 2018 02:00:14 +0900 Message-Id: <1521738014-18895-3-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1521738014-18895-1-git-send-email-yamada.masahiro@socionext.com> References: <1521738014-18895-1-git-send-email-yamada.masahiro@socionext.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Tracking the line number by hand is error-prone since we need to make sure to increment it in all the \n matching patterns. If '%option yylineno' is set, flex defines 'yylineno' to contain the current line number and automatically updates it each time it reads a \n character. This is much more convenient although the lexer does not initializes yylineno, so you need to set it to 1 each time you start reading a new file, and restore it you go back to the previous file. I tested this with DEBUG_PARSE, and confirmed the same dump message was produced. I removed the perf-report option. Otherwise, I see the following message: %option yylineno entails a performance penalty ONLY on rules that can match newline characters Signed-off-by: Masahiro Yamada --- scripts/kconfig/lkc.h | 1 + scripts/kconfig/zconf.l | 20 +++++++++----------- 2 files changed, 10 insertions(+), 11 deletions(-) -- 2.7.4 diff --git a/scripts/kconfig/lkc.h b/scripts/kconfig/lkc.h index 2d5ec2d..f4394af 100644 --- a/scripts/kconfig/lkc.h +++ b/scripts/kconfig/lkc.h @@ -68,6 +68,7 @@ struct kconf_id { enum symbol_type stype; }; +extern int yylineno; void zconfdump(FILE *out); void zconf_starthelp(void); FILE *zconf_fopen(const char *name); diff --git a/scripts/kconfig/zconf.l b/scripts/kconfig/zconf.l index 29b5d33..045093d 100644 --- a/scripts/kconfig/zconf.l +++ b/scripts/kconfig/zconf.l @@ -1,5 +1,5 @@ %option nostdinit noyywrap never-interactive full ecs -%option 8bit nodefault perf-report perf-report +%option 8bit nodefault yylineno %option noinput %x COMMAND HELP STRING PARAM %{ @@ -83,7 +83,6 @@ n [A-Za-z0-9_-] [ \t]*#.*\n | [ \t]*\n { - current_file->lineno++; return T_EOL; } [ \t]*#.* @@ -104,7 +103,7 @@ n [A-Za-z0-9_-] const struct kconf_id *id = kconf_id_lookup(yytext, yyleng); BEGIN(PARAM); current_pos.file = current_file; - current_pos.lineno = current_file->lineno; + current_pos.lineno = yylineno; if (id && id->flags & TF_COMMAND) { yylval.id = id; return id->token; @@ -116,7 +115,6 @@ n [A-Za-z0-9_-] . warn_ignored_character(*yytext); \n { BEGIN(INITIAL); - current_file->lineno++; return T_EOL; } } @@ -138,7 +136,7 @@ n [A-Za-z0-9_-] new_string(); BEGIN(STRING); } - \n BEGIN(INITIAL); current_file->lineno++; return T_EOL; + \n BEGIN(INITIAL); return T_EOL; ({n}|[/.])+ { const struct kconf_id *id = kconf_id_lookup(yytext, yyleng); if (id && id->flags & TF_PARAM) { @@ -150,7 +148,7 @@ n [A-Za-z0-9_-] return T_WORD; } #.* /* comment */ - \\\n current_file->lineno++; + \\\n ; [[:blank:]]+ . warn_ignored_character(*yytext); <> { @@ -187,7 +185,6 @@ n [A-Za-z0-9_-] fprintf(stderr, "%s:%d:warning: multi-line strings not supported\n", zconf_curname(), zconf_lineno()); - current_file->lineno++; BEGIN(INITIAL); return T_EOL; } @@ -220,12 +217,10 @@ n [A-Za-z0-9_-] } } [ \t]*\n/[^ \t\n] { - current_file->lineno++; zconf_endhelp(); return T_HELPTEXT; } [ \t]*\n { - current_file->lineno++; append_string("\n", 1); } [^ \t\n].* { @@ -304,7 +299,7 @@ void zconf_initscan(const char *name) memset(current_buf, 0, sizeof(*current_buf)); current_file = file_lookup(name); - current_file->lineno = 1; + yylineno = 1; } void zconf_nextfile(const char *name) @@ -325,6 +320,7 @@ void zconf_nextfile(const char *name) buf->parent = current_buf; current_buf = buf; + current_file->lineno = yylineno; file->parent = current_file; for (iter = current_file; iter; iter = iter->parent) { @@ -343,7 +339,7 @@ void zconf_nextfile(const char *name) } } - file->lineno = 1; + yylineno = 1; current_file = file; } @@ -352,6 +348,8 @@ static void zconf_endfile(void) struct buffer *parent; current_file = current_file->parent; + if (current_file) + yylineno = current_file->lineno; parent = current_buf->parent; if (parent) {