From: Jaskaran Singh <jaskaran.singh@collabora.com>
To: cocci@systeme.lip6.fr
Subject: [Cocci] [PATCH v2 2/3] parsing_c: parse_c: Build name cache and includes dependency graph
Date: Thu, 10 Sep 2020 11:47:02 +0530 [thread overview]
Message-ID: <20200910061703.2397-3-jaskaran.singh@collabora.com> (raw)
In-Reply-To: <20200910061703.2397-1-jaskaran.singh@collabora.com>
Build the includes dependency graph and name cache while parsing header
files. Every header file is parsed only once for name caching and, while
parsing these files, an includes dependency graph is built to determine
reachability of one header file from another file.
Signed-off-by: Jaskaran Singh <jaskaran.singh@collabora.com>
---
parsing_c/parse_c.ml | 28 ++++++++++++++++++++++------
1 file changed, 22 insertions(+), 6 deletions(-)
diff --git a/parsing_c/parse_c.ml b/parsing_c/parse_c.ml
index 5574cb11b..ef5870123 100644
--- a/parsing_c/parse_c.ml
+++ b/parsing_c/parse_c.ml
@@ -17,6 +17,7 @@ open Common
module TH = Token_helpers
module LP = Lexer_parser
+module IC = Includes_cache
module Stat = Parsing_stat
@@ -995,15 +996,30 @@ let rec _parse_print_error_heuristic2 saved_typedefs saved_macros
and handle_include file wrapped_incl k =
let incl = Ast_c.unwrap wrapped_incl.Ast_c.i_include in
let parsing_style = Includes.get_parsing_style () in
+ let f = Includes.resolve file parsing_style incl in
if Includes.should_parse parsing_style file incl
then
- match Includes.resolve file parsing_style incl with
+ match f with
| Some header_filename when Common.lfile_exists header_filename ->
- (if !Flag_parsing_c.verbose_includes
- then pr2 ("including "^header_filename));
- let nonlocal =
- match incl with Ast_c.NonLocal _ -> true | _ -> false in
- ignore (k nonlocal header_filename)
+ if not (IC.has_been_parsed header_filename)
+ then
+ begin
+ IC.add_to_parsed_files header_filename;
+ (if !Flag_parsing_c.verbose_includes
+ then pr2 ("including "^header_filename));
+ let nonlocal =
+ match incl with Ast_c.NonLocal _ -> true | _ -> false in
+ let res = k nonlocal header_filename in
+ match res with
+ None -> ()
+ | Some x ->
+ let pt = x.parse_trees in
+ let (p, _, _) = pt in
+ with_program2_unit
+ (IC.extract_names header_filename)
+ p
+ end;
+ IC.add_to_dependency_graph file header_filename;
| _ -> ()
and _parse_print_error_heuristic2bis saved_typedefs saved_macros
--
2.21.3
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci
next prev parent reply other threads:[~2020-09-10 6:18 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-10 6:17 [Cocci] [PATCH v2 0/3] parsing_c: Optimize recursive header file parsing Jaskaran Singh
2020-09-10 6:17 ` [Cocci] [PATCH v2 1/3] parsing_c: includes_cache: Implement a name cache Jaskaran Singh
2020-09-10 6:17 ` Jaskaran Singh [this message]
2020-09-10 6:17 ` [Cocci] [PATCH v2 3/3] parsing_c: type_annoter_c: Use name cache for type annotation Jaskaran Singh
2020-09-10 6:19 ` [Cocci] [PATCH v2 0/3] parsing_c: Optimize recursive header file parsing Jaskaran Singh
2020-09-15 19:23 ` Julia Lawall
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200910061703.2397-3-jaskaran.singh@collabora.com \
--to=jaskaran.singh@collabora.com \
--cc=cocci@systeme.lip6.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox