From patchwork Fri Feb 2 15:58:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 195925 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp526835dyc; Fri, 2 Feb 2024 08:05:15 -0800 (PST) X-Google-Smtp-Source: AGHT+IHjFJoOIRVz4lVXR2Sk+b1nAF4zjVnFs8wpSJH//VCF1wXtvms0opb/6Ns01wGIDvzwkZvR X-Received: by 2002:a17:902:d58c:b0:1d8:ee41:a825 with SMTP id k12-20020a170902d58c00b001d8ee41a825mr3307800plh.37.1706889915046; Fri, 02 Feb 2024 08:05:15 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706889915; cv=pass; d=google.com; s=arc-20160816; b=AGY4lVdcv2mJsVTpPl7nApVAx72m5th1iCZeMCR1trHenv4QHSuHY02InfTxG8vOj7 Yc2zjpmGjAHQfsDXPxeO0QpsfianPx55ZNSBq9wtvzUL57DFMgeN5QrE+HHDo8tbAmLi yGKfJg6oR2Jf6jSNsGtFzPRL0Iw4xzRjJHwlK4l7Lo/eTMqUvf3qOw01RtZkqQ3+uNL9 e1FUZYq8FlgNKNqCyrQRTzcDflk3Vy6xxx7oYyAakTlYqxMFMNoRdwAxcDnNV1SsHL7G 3mbwwZVuj4vuLrQdmjMxQH9KY/XWI4s2wZvb3WVhWCa8JQwsXRpY9UFbq0bsrgfInAF2 8WOw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=1TI7xBYL3AWKUo2RVm157M/whRDFy0+OCYXNeMoY93I=; fh=qbu7gs4z9Z4rG2EegggUdLH1KsGJOYFf79J3RQJ6r0U=; b=odoP8yjlxEOrAvJBPkCMwWnLFaQ6AS4CbCaSIIsjgYpYlvDOoLQg4LJGxF09JpikOr PZ6iwoFiZNiv44rt/lQRdlj8x53qLeDvB9rKX5ApQGdShEOwZDvoP+8OiKFkCfj36UE7 wGbFRsxS/B2Hb2MQ6wLdY/LZanwmSAVa5QoM0eNGEui8HUuhtRascdeoSsL3vVffhuq5 XXo1QNwItLrh+R+taMJN6UwTnFiWWEJDRcCdqcYgyZIZVA2ATHpSfVwbxNO9sc6vm/iL smcHewnqSGfUzW4/qhA3gDpKnsT+W3pUxPpW+k3WkZLEpTkOjmTE0vZgHP149m49aai/ UmwQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=dzabgXpC; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-50076-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50076-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=1; AJvYcCXJnACIy58HFGg507MSfXPZu6SydRYADf4poMqF+n8eOJ6KXPd4q8CfLehPdsaT3e3On8kj0Dq3jcQvgLAQJ1VZrMWgFw== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id q9-20020a63d609000000b005cdffe116d0si1700793pgg.532.2024.02.02.08.05.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Feb 2024 08:05:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-50076-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=dzabgXpC; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-50076-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50076-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id CAB2828B4C6 for ; Fri, 2 Feb 2024 16:03:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A6102150985; Fri, 2 Feb 2024 15:58:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="dzabgXpC" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C060D14D44A; Fri, 2 Feb 2024 15:58:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706889528; cv=none; b=vGlH9TsSE/tRJ+ywiiaT5NYZj8a4j0EykBecXIyKxZKtutsXWJJjJGLglRVN1MoHuDuuaTGVU+tv5U4xDgCsPnCxG9rN0TEPS4727OX6iBeulwELS/IjTpjl+w4w0rjK5CBzlpecCfqOol/EKCfYPKtfEiPHYAQ8ubkkRa1HMjA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706889528; c=relaxed/simple; bh=XGcvVEbpwvjpyVs7c6B8hKp1bvuUZzxnFMzXDLqk/JQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=VPNiRrLPU/jPSnV/SCOyBZ6g22DKKGTKBYabJ/orl5DZJAVcuTGTZMV9ilqb/G3JzoMIwumxTYCI+iJHs77HK5p4CvHLlHR3Uje0HfHKTYpGTOec67tQsS+ECwYwkwJhlovnTd3ZeaZO3hJhEf3ToRRdpozwpp4W0j/L1CgWWHw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=dzabgXpC; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9AD2EC433F1; Fri, 2 Feb 2024 15:58:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706889528; bh=XGcvVEbpwvjpyVs7c6B8hKp1bvuUZzxnFMzXDLqk/JQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dzabgXpCqPZGOOmY2HjYfoRaQDHhH7gXNlUAfg2P6hpRiGf6F3shxQfVIzl6C6H8V H629bnB/SwuPIYgpAW4laXhFoErIRoCJPjwTxtVtFuyk/mgAtUpgucIM5BRtFg5ihl R3bhViG2PdiimUVEWaF5M/Alv8ybNbdikVc7M2dh0dxaGtMZgRbrRlF3KTXnF2EIdn L392q5NJZ8paAoI1TBlbTXvE+uFQ93YTVTdEmxTGWUBKtP2pUhfXjBGyV0E1HNe3tG tJ/A4brR7IGKyHS7OII9DgpSZlCXigSn0aZ80ULa8jqLimKyMY7jtqLi14Y0Kch4uu owQfRWCOAHwEw== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Masahiro Yamada Subject: [PATCH 16/27] kconfig: move the file and lineno in struct file to struct buffer Date: Sat, 3 Feb 2024 00:58:14 +0900 Message-Id: <20240202155825.314567-17-masahiroy@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240202155825.314567-1-masahiroy@kernel.org> References: <20240202155825.314567-1-masahiroy@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789803799387475273 X-GMAIL-MSGID: 1789803799387475273 struct file has two link nodes, 'next' and 'parent'. The former is used to link files in the 'file_list' linked list, which manages the list of Kconfig files seen so far. The latter is used to link files in the 'current_file' linked list, which manages the inclusion ("source") tree. The latter should be tracked together with the lexer state. Signed-off-by: Masahiro Yamada --- scripts/kconfig/expr.h | 3 --- scripts/kconfig/lexer.l | 50 ++++++++++++++++++----------------------- scripts/kconfig/menu.c | 1 - 3 files changed, 22 insertions(+), 32 deletions(-) diff --git a/scripts/kconfig/expr.h b/scripts/kconfig/expr.h index 037db39c5bf0..85e0d1ab3c8a 100644 --- a/scripts/kconfig/expr.h +++ b/scripts/kconfig/expr.h @@ -19,9 +19,7 @@ extern "C" { struct file { struct file *next; - struct file *parent; const char *name; - int lineno; }; typedef enum tristate { @@ -278,7 +276,6 @@ struct jump_key { }; extern struct file *file_list; -extern struct file *current_file; extern struct symbol symbol_yes, symbol_no, symbol_mod; extern struct symbol *modules_sym; diff --git a/scripts/kconfig/lexer.l b/scripts/kconfig/lexer.l index db2397c4e343..71f651bb82ba 100644 --- a/scripts/kconfig/lexer.l +++ b/scripts/kconfig/lexer.l @@ -40,6 +40,8 @@ struct buffer { struct buffer *parent; YY_BUFFER_STATE state; int yylineno; + const char *filename; + int source_lineno; }; static struct buffer *current_buf; @@ -255,7 +257,7 @@ n [A-Za-z0-9_-] fprintf(stderr, "%s:%d:warning: no new line at end of file\n", cur_filename, yylineno); - if (current_file) { + if (current_buf) { zconf_endfile(); return T_EOL; } @@ -399,19 +401,20 @@ void zconf_initscan(const char *name) exit(1); } - current_file = file_lookup(name); - cur_filename = current_file->name; + cur_filename = file_lookup(name)->name; yylineno = 1; } void zconf_nextfile(const char *name) { - struct file *iter; struct file *file = file_lookup(name); struct buffer *buf = xmalloc(sizeof(*buf)); + bool recur_include = false; buf->state = YY_CURRENT_BUFFER; buf->yylineno = yylineno; + buf->filename = cur_filename; + buf->source_lineno = cur_lineno; buf->parent = current_buf; current_buf = buf; yyin = zconf_fopen(name); @@ -422,45 +425,36 @@ void zconf_nextfile(const char *name) } yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE)); - current_file->lineno = cur_lineno; - file->parent = current_file; + for (buf = current_buf; buf; buf = buf->parent) { + if (!strcmp(buf->filename, name)) + recur_include = true; + } - for (iter = current_file; iter; iter = iter->parent) { - if (!strcmp(iter->name, name)) { - fprintf(stderr, - "Recursive inclusion detected.\n" - "Inclusion path:\n" - " current file : %s\n", name); - iter = file; - do { - iter = iter->parent; - fprintf(stderr, " included from: %s:%d\n", - iter->name, iter->lineno); - } while (strcmp(iter->name, name)); - exit(1); - } + if (recur_include) { + fprintf(stderr, + "Recursive inclusion detected.\n" + "Inclusion path:\n" + " current file : %s\n", name); + + for (buf = current_buf; buf; buf = buf->parent) + fprintf(stderr, " included from: %s:%d\n", + buf->filename, buf->source_lineno); + exit(1); } yylineno = 1; cur_filename = file->name; - current_file = file; } static void zconf_endfile(void) { struct buffer *tmp; - current_file = current_file->parent; - if (current_file) - cur_filename = current_file->name; - - if (!current_buf) - return; - fclose(yyin); yy_delete_buffer(YY_CURRENT_BUFFER); yy_switch_to_buffer(current_buf->state); yylineno = current_buf->yylineno; + cur_filename = current_buf->filename; tmp = current_buf; current_buf = current_buf->parent; free(tmp); diff --git a/scripts/kconfig/menu.c b/scripts/kconfig/menu.c index 0ded0b1830d0..b879576d1ab4 100644 --- a/scripts/kconfig/menu.c +++ b/scripts/kconfig/menu.c @@ -17,7 +17,6 @@ struct menu rootmenu; static struct menu **last_entry_ptr; struct file *file_list; -struct file *current_file; void menu_warn(struct menu *menu, const char *fmt, ...) {