From: Jaskaran Singh <jaskaransingh7654321@gmail.com> To: cocci@systeme.lip6.fr Cc: linux-kernel-mentees@lists.linuxfoundation.org Subject: [Cocci] [PATCH] parsing_c: Handle case of macro before typedef Date: Sun, 19 Jan 2020 19:16:10 +0530 [thread overview] Message-ID: <20200119134610.31961-1-jaskaransingh7654321@gmail.com> (raw) For the following case: <macro> <typedef> <identifier> A case in parsing_hacks.ml sometimes mislabels <macro> as a typedef ident. If typedef is a known typedef (such as u8 or *_t), then label <macro> as a CppMacro. Subsequent cases will then label <typedef> correctly. Following are results of --parse-c on the Linux Kernel v5.5-rc4: Before: nb good = 18956150, nb passed = 134061 =========> 0.70% passed After: nb good = 18956150, nb passed = 134062 =========> 0.70% passed Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com> --- parsing_c/parsing_hacks.ml | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/parsing_c/parsing_hacks.ml b/parsing_c/parsing_hacks.ml index 8374731b..23d675cf 100644 --- a/parsing_c/parsing_hacks.ml +++ b/parsing_c/parsing_hacks.ml @@ -2184,6 +2184,41 @@ let lookahead2 ~pass next before = && ok_typedef s && is_macro s2 && is_type type_ -> TIdent (s, i1) + + (* xx yy zz : xx is a macro *) + | (TIdent (s, i1)::TIdent (s2, i2)::TIdent(_,_)::_ , _) + when not_struct_enum before + && ok_typedef s2 + && is_known_typdef s2 + -> + TCommentCpp(Token_c.CppMacro, i1) + + (* xx yy zz : xx is a typedef ident *) + | (TIdent (s, i1)::TIdent (s2, i2)::TIdent(_,_)::_ , _) + when not_struct_enum before + && ok_typedef s + -> + msg_typedef s i1 2; LP.add_typedef_root s i1; + TypedefIdent (s, i1) + + (* xx yy * zz : xx is a macro *) + | (TIdent (s, i1)::TIdent (s2, i2)::ptr , _) + when pointer ~followed_by:(function TIdent _ -> true | _ -> false) ptr + && not_struct_enum before + && ok_typedef s2 + && is_known_typdef s2 + -> + TCommentCpp(Token_c.CppMacro, i1) + + (* xx yy * zz : xx is a typedef ident *) + | (TIdent (s, i1)::TIdent (s2, i2)::ptr , _) + when pointer ~followed_by:(function TIdent _ -> true | _ -> false) ptr + && not_struct_enum before + && ok_typedef s + -> + msg_typedef s i1 2; LP.add_typedef_root s i1; + TypedefIdent (s, i1) + (* xx yy *) | (TIdent (s, i1)::TIdent (s2, i2)::rest , _) when not_struct_enum before && ok_typedef s && not (is_macro_paren s2 rest) -- 2.21.1 _______________________________________________ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
WARNING: multiple messages have this Message-ID (diff)
From: Jaskaran Singh <jaskaransingh7654321@gmail.com> To: cocci@systeme.lip6.fr Cc: julia.lawall@inria.fr, Jaskaran Singh <jaskaransingh7654321@gmail.com>, linux-kernel-mentees@lists.linuxfoundation.org Subject: [Linux-kernel-mentees] [PATCH] parsing_c: Handle case of macro before typedef Date: Sun, 19 Jan 2020 19:16:10 +0530 [thread overview] Message-ID: <20200119134610.31961-1-jaskaransingh7654321@gmail.com> (raw) For the following case: <macro> <typedef> <identifier> A case in parsing_hacks.ml sometimes mislabels <macro> as a typedef ident. If typedef is a known typedef (such as u8 or *_t), then label <macro> as a CppMacro. Subsequent cases will then label <typedef> correctly. Following are results of --parse-c on the Linux Kernel v5.5-rc4: Before: nb good = 18956150, nb passed = 134061 =========> 0.70% passed After: nb good = 18956150, nb passed = 134062 =========> 0.70% passed Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com> --- parsing_c/parsing_hacks.ml | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/parsing_c/parsing_hacks.ml b/parsing_c/parsing_hacks.ml index 8374731b..23d675cf 100644 --- a/parsing_c/parsing_hacks.ml +++ b/parsing_c/parsing_hacks.ml @@ -2184,6 +2184,41 @@ let lookahead2 ~pass next before = && ok_typedef s && is_macro s2 && is_type type_ -> TIdent (s, i1) + + (* xx yy zz : xx is a macro *) + | (TIdent (s, i1)::TIdent (s2, i2)::TIdent(_,_)::_ , _) + when not_struct_enum before + && ok_typedef s2 + && is_known_typdef s2 + -> + TCommentCpp(Token_c.CppMacro, i1) + + (* xx yy zz : xx is a typedef ident *) + | (TIdent (s, i1)::TIdent (s2, i2)::TIdent(_,_)::_ , _) + when not_struct_enum before + && ok_typedef s + -> + msg_typedef s i1 2; LP.add_typedef_root s i1; + TypedefIdent (s, i1) + + (* xx yy * zz : xx is a macro *) + | (TIdent (s, i1)::TIdent (s2, i2)::ptr , _) + when pointer ~followed_by:(function TIdent _ -> true | _ -> false) ptr + && not_struct_enum before + && ok_typedef s2 + && is_known_typdef s2 + -> + TCommentCpp(Token_c.CppMacro, i1) + + (* xx yy * zz : xx is a typedef ident *) + | (TIdent (s, i1)::TIdent (s2, i2)::ptr , _) + when pointer ~followed_by:(function TIdent _ -> true | _ -> false) ptr + && not_struct_enum before + && ok_typedef s + -> + msg_typedef s i1 2; LP.add_typedef_root s i1; + TypedefIdent (s, i1) + (* xx yy *) | (TIdent (s, i1)::TIdent (s2, i2)::rest , _) when not_struct_enum before && ok_typedef s && not (is_macro_paren s2 rest) -- 2.21.1 _______________________________________________ Linux-kernel-mentees mailing list Linux-kernel-mentees@lists.linuxfoundation.org https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
next reply other threads:[~2020-01-19 13:46 UTC|newest] Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-01-19 13:46 Jaskaran Singh [this message] 2020-01-19 13:46 ` [Linux-kernel-mentees] [PATCH] parsing_c: Handle case of macro before typedef Jaskaran Singh 2020-01-21 6:28 ` [Cocci] " Julia Lawall 2020-01-21 6:28 ` [Linux-kernel-mentees] " Julia Lawall -- strict thread matches above, loose matches on Subject: below -- 2020-01-21 9:35 [Cocci] " Markus Elfring 2020-01-19 13:18 Jaskaran Singh 2020-01-19 13:25 ` Jaskaran Singh
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=20200119134610.31961-1-jaskaransingh7654321@gmail.com \ --to=jaskaransingh7654321@gmail.com \ --cc=cocci@systeme.lip6.fr \ --cc=linux-kernel-mentees@lists.linuxfoundation.org \ /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: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.