From nobody Wed Oct 1 21:27:55 2025 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 5A5352773F3; Wed, 1 Oct 2025 14:49:59 +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=1759330199; cv=none; b=RzND6hli3JHnP4JKAVo9yVnj/KoOsBRwe6IOqqZrHEj++3CXJ6rBjj6wDiQViAnsHwt2cN2+e/5rAHWxsnlWOlOsNWYfvvg8K+qbDqEOhyqDQYOEYWjF4CBem89BVhk5XUOfzarizAZHNgGTMG1ZX11cNfWKuGl4urrmi7tVbPc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759330199; c=relaxed/simple; bh=zSEgAo72B96PVvkyzVvVvzPA6asz0cr2DairSiNfMhM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GzUiVUf0CY6r/iZ1TsnbfHkCuOpFYf+FS1R7dvL65xR4hxwKx7hUUaOYUq8IOkNhPhxWkpwS6o32nTYqhNg15jeT3Sjr7E4LaTvASf8j2/OHBT1DuMbJdIRcV9l4Ax/RhsMrLbe+SWz1xVugqFnP/nIpUAmwdXHDITDTM7uQvv4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=UBg0h8Rt; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="UBg0h8Rt" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 01A3AC4CEF5; Wed, 1 Oct 2025 14:49:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1759330199; bh=zSEgAo72B96PVvkyzVvVvzPA6asz0cr2DairSiNfMhM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UBg0h8Rt7Yclm3TFlJ9JQ2RK5h5GTA8U4a4pB6ZrcuECEqjTOV9h4Ze+LDMlDH/Hs 0JY9d7a3B7AEXUvw3MEG01hDcC19xViNeusALoWlyI7ZQz9NEvcsMUMPicRlWj/N08 y/CxhwN5/LacDrzhbo9McqPY3OsuS2doq59/TgRaLaE1c9AA83QU0XWJPoohJp/8aO 1P7OS6thz+gA+qYtYS6YkG+1lDfbibSqeCC4qHTA7KqYJlzZ/Mg5AJwj6HCfk5/IxO r9PjaU5VLVZ/ungdJQ63Uqvex6jaUn0QV88EXPiu2ptYsXjh/Tfvk488O+99nPFeHo EyGzGOki8HrKQ== Received: from mchehab by mail.kernel.org with local (Exim 4.98.2) (envelope-from ) id 1v3y9V-0000000BLIN-1CHp; Wed, 01 Oct 2025 16:49:57 +0200 From: Mauro Carvalho Chehab To: "Jonathan Corbet" , Linux Doc Mailing List Cc: Mauro Carvalho Chehab , "Mauro Carvalho Chehab" , linux-kernel@vger.kernel.org, linux-media@vger.kernel.org Subject: [PATCH 06/23] tools: docs: parse_data_structs.py: get rid of process_exceptions() Date: Wed, 1 Oct 2025 16:49:29 +0200 Message-ID: <8575bbc94ff706aa7e7cc3a188399ca17a3169e6.1759329363.git.mchehab+huawei@kernel.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: Mauro Carvalho Chehab Content-Type: text/plain; charset="utf-8" Add an extra parameter to parse_file to make it handle exceptions internally, cleaning up the API. Signed-off-by: Mauro Carvalho Chehab --- Documentation/sphinx/kernel_include.py | 6 +- tools/docs/lib/parse_data_structs.py | 105 ++++++++++++------------- tools/docs/parse-headers.py | 5 +- 3 files changed, 56 insertions(+), 60 deletions(-) diff --git a/Documentation/sphinx/kernel_include.py b/Documentation/sphinx/= kernel_include.py index e8f7e7a49758..895646da7495 100755 --- a/Documentation/sphinx/kernel_include.py +++ b/Documentation/sphinx/kernel_include.py @@ -214,14 +214,16 @@ class KernelInclude(Directive): - a TOC table containing cross references. """ parser =3D ParseDataStructs() - parser.parse_file(path) =20 if 'exception-file' in self.options: source_dir =3D os.path.dirname(os.path.abspath( self.state_machine.input_lines.source( self.lineno - self.state_machine.input_offset - 1))) exceptions_file =3D os.path.join(source_dir, self.options['exc= eption-file']) - parser.process_exceptions(exceptions_file) + else: + exceptions_file =3D None + + parser.parse_file(path, exceptions_file) =20 # Store references on a symbol dict to be used at check time if 'warn-broken' in self.options: diff --git a/tools/docs/lib/parse_data_structs.py b/tools/docs/lib/parse_da= ta_structs.py index 46535a05ea4a..cbdbf7dfe785 100755 --- a/tools/docs/lib/parse_data_structs.py +++ b/tools/docs/lib/parse_data_structs.py @@ -175,6 +175,54 @@ class ParseDataStructs: =20 sys.exit(f"{name}:{ln}: invalid line: {line}") =20 + def apply_exceptions(self): + """ + Process exceptions file with rules to ignore or replace references. + """ + + # Handle ignore rules + for ln, c_type, symbol in self.ignore: + if c_type not in self.DEF_SYMBOL_TYPES: + sys.exit(f"{name}:{ln}: {c_type} is invalid") + + d =3D self.symbols[c_type] + if symbol in d: + del d[symbol] + + # Handle replace rules + for ln, c_type, old, new in self.replace: + if c_type not in self.DEF_SYMBOL_TYPES: + sys.exit(f"{name}:{ln}: {c_type} is invalid") + + reftype =3D None + + # Parse reference type when the type is specified + + match =3D re.match(r"^\:c\:(data|func|macro|type)\:\`(.+)\`", = new) + if match: + reftype =3D f":c:{match.group(1)}" + new =3D match.group(2) + else: + match =3D re.search(r"(\:ref)\:\`(.+)\`", new) + if match: + reftype =3D match.group(1) + new =3D match.group(2) + + # If the replacement rule doesn't have a type, get default + if not reftype: + reftype =3D self.DEF_SYMBOL_TYPES[c_type].get("ref_type") + if not reftype: + reftype =3D self.DEF_SYMBOL_TYPES[c_type].get("real_ty= pe") + + new_ref =3D f"{reftype}:`{old} <{new}>`" + + # Change self.symbols to use the replacement rule + if old in self.symbols[c_type]: + (_, ln) =3D self.symbols[c_type][old] + self.symbols[c_type][old] =3D (new_ref, ln) + else: + print(f"{name}:{ln}: Warning: can't find {old} {c_type}") + def store_type(self, ln, symbol_type: str, symbol: str, ref_name: str =3D None, replace_underscores: bool =3D T= rue): """ @@ -211,13 +259,15 @@ class ParseDataStructs: line =3D " " + line.expandtabs() self.data +=3D line.rstrip(" ") =20 - def parse_file(self, file_in: str): + def parse_file(self, file_in: str, exceptions: str =3D None): """Reads a C source file and get identifiers""" self.data =3D "" is_enum =3D False is_comment =3D False multiline =3D "" =20 + self.read_exceptions(exceptions) + with open(file_in, "r", encoding=3D"utf-8", errors=3D"backslashreplace") as f: for line_no, line in enumerate(f): @@ -309,59 +359,6 @@ class ParseDataStructs: self.store_type(line_no, "struct", match.group(1)) break =20 - def apply_exceptions(self): - """ - Process exceptions file with rules to ignore or replace references. - """ - - # Handle ignore rules - for ln, c_type, symbol in self.ignore: - if c_type not in self.DEF_SYMBOL_TYPES: - sys.exit(f"{name}:{ln}: {c_type} is invalid") - - d =3D self.symbols[c_type] - if symbol in d: - del d[symbol] - - # Handle replace rules - for ln, c_type, old, new in self.replace: - if c_type not in self.DEF_SYMBOL_TYPES: - sys.exit(f"{name}:{ln}: {c_type} is invalid") - - reftype =3D None - - # Parse reference type when the type is specified - - match =3D re.match(r"^\:c\:(data|func|macro|type)\:\`(.+)\`", = new) - if match: - reftype =3D f":c:{match.group(1)}" - new =3D match.group(2) - else: - match =3D re.search(r"(\:ref)\:\`(.+)\`", new) - if match: - reftype =3D match.group(1) - new =3D match.group(2) - - # If the replacement rule doesn't have a type, get default - if not reftype: - reftype =3D self.DEF_SYMBOL_TYPES[c_type].get("ref_type") - if not reftype: - reftype =3D self.DEF_SYMBOL_TYPES[c_type].get("real_ty= pe") - - new_ref =3D f"{reftype}:`{old} <{new}>`" - - # Change self.symbols to use the replacement rule - if old in self.symbols[c_type]: - (_, ln) =3D self.symbols[c_type][old] - self.symbols[c_type][old] =3D (new_ref, ln) - else: - print(f"{name}:{ln}: Warning: can't find {old} {c_type}") - - def process_exceptions(self, fname: str): - """ - Process exceptions file with rules to ignore or replace references. - """ - self.read_exceptions(fname) self.apply_exceptions() =20 def debug_print(self): diff --git a/tools/docs/parse-headers.py b/tools/docs/parse-headers.py index bfa4e46a53e3..6716c7300258 100755 --- a/tools/docs/parse-headers.py +++ b/tools/docs/parse-headers.py @@ -47,10 +47,7 @@ def main(): args =3D parser.parse_args() =20 parser =3D ParseDataStructs(debug=3Dargs.debug) - parser.parse_file(args.file_in) - - if args.file_rules: - parser.process_exceptions(args.file_rules) + parser.parse_file(args.file_in, args.file_rules) =20 parser.debug_print() parser.write_output(args.file_in, args.file_out, args.toc) --=20 2.51.0