From: Jaskaran Singh <jaskaransingh7654321@gmail.com> To: cocci@systeme.lip6.fr Cc: linux-kernel-mentees@lists.linuxfoundation.org Subject: [Cocci] [PATCH v4 08/14] parsing_c: parser: Add init_declarator_attrs rule Date: Fri, 5 Jun 2020 19:13:16 +0530 [thread overview] Message-ID: <20200605134322.15307-9-jaskaransingh7654321@gmail.com> (raw) In-Reply-To: <20200605134322.15307-1-jaskaransingh7654321@gmail.com> As per GCC's C grammar, the init-declarator rule has the following production: init-declarator: declarator simple-asm-expr[opt] gnu-attributes[opt] declarator simple-asm-expr[opt] gnu-attributes[opt] = initializer Due to conflicts in Coccinelle's C grammar, adding productions with attributes to init_declarator is not possible. Create init_declarator_attrs and use this rule in init_declarator_list for handling attributes after commas. Following is an example of C code that is parsed successfully: struct mxser_mstatus ms, __user *msu = argp; Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com> --- parsing_c/parser_c.mly | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/parsing_c/parser_c.mly b/parsing_c/parser_c.mly index d24ab7b8..9afbd68c 100644 --- a/parsing_c/parser_c.mly +++ b/parsing_c/parser_c.mly @@ -1667,6 +1667,23 @@ init_declarator2: | declaratori TOParCplusplusInit argument_list TCPar { ($1, ConstrInit($3,[$2;$4])) } +/*(*-----------------------------------------------------------------------*)*/ +/*(* declarators (right part of type and variable). *)*/ +/*(* This is a workaround for the following case: *)*/ +/*(* <type> <declarator>, <attribute> <declarator> ...*)*/ +/*(* The normal init_declarator rule does not handle this, and adding *)*/ +/*(* attributes to it causes conflicts, thus the need for this rule. *)*/ +/*(*-----------------------------------------------------------------------*)*/ +init_declarator_attrs2: + | declaratori { ($1, NoInit) } + | attributes declaratori { ($2, NoInit) } + | declaratori teq initialize { ($1, ValInit($2, $3)) } + | attributes declaratori teq initialize { ($2, ValInit($3, $4)) } + /* C++ only */ + | declaratori TOParCplusplusInit argument_list TCPar + { ($1, ConstrInit($3,[$2;$4])) } + | attributes declaratori TOParCplusplusInit argument_list TCPar + { ($2, ConstrInit($4,[$3;$5])) } /*(*----------------------------*)*/ /*(* workarounds *)*/ @@ -1675,6 +1692,8 @@ teq: TEq { et "teq" (); $1 } init_declarator: init_declarator2 { dt "init" (); $1 } +init_declarator_attrs: init_declarator_attrs2 { dt "init_attrs" (); $1 } + /*(*----------------------------*)*/ /*(* gccext: *)*/ @@ -2372,9 +2391,9 @@ enumerator_list: init_declarator_list: | init_declarator { [$1, []] } - | init_declarator_list TComma cpp_directive_list init_declarator + | init_declarator_list TComma cpp_directive_list init_declarator_attrs { $1 @ [$4, [$2]] } - | init_declarator_list TComma init_declarator { $1 @ [$3, [$2]] } + | init_declarator_list TComma init_declarator_attrs { $1 @ [$3, [$2]] } parameter_list: -- 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, jaskaransingh7654321@gmail.com, linux-kernel-mentees@lists.linuxfoundation.org Subject: [Linux-kernel-mentees] [PATCH v4 08/14] parsing_c: parser: Add init_declarator_attrs rule Date: Fri, 5 Jun 2020 19:13:16 +0530 [thread overview] Message-ID: <20200605134322.15307-9-jaskaransingh7654321@gmail.com> (raw) In-Reply-To: <20200605134322.15307-1-jaskaransingh7654321@gmail.com> As per GCC's C grammar, the init-declarator rule has the following production: init-declarator: declarator simple-asm-expr[opt] gnu-attributes[opt] declarator simple-asm-expr[opt] gnu-attributes[opt] = initializer Due to conflicts in Coccinelle's C grammar, adding productions with attributes to init_declarator is not possible. Create init_declarator_attrs and use this rule in init_declarator_list for handling attributes after commas. Following is an example of C code that is parsed successfully: struct mxser_mstatus ms, __user *msu = argp; Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com> --- parsing_c/parser_c.mly | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/parsing_c/parser_c.mly b/parsing_c/parser_c.mly index d24ab7b8..9afbd68c 100644 --- a/parsing_c/parser_c.mly +++ b/parsing_c/parser_c.mly @@ -1667,6 +1667,23 @@ init_declarator2: | declaratori TOParCplusplusInit argument_list TCPar { ($1, ConstrInit($3,[$2;$4])) } +/*(*-----------------------------------------------------------------------*)*/ +/*(* declarators (right part of type and variable). *)*/ +/*(* This is a workaround for the following case: *)*/ +/*(* <type> <declarator>, <attribute> <declarator> ...*)*/ +/*(* The normal init_declarator rule does not handle this, and adding *)*/ +/*(* attributes to it causes conflicts, thus the need for this rule. *)*/ +/*(*-----------------------------------------------------------------------*)*/ +init_declarator_attrs2: + | declaratori { ($1, NoInit) } + | attributes declaratori { ($2, NoInit) } + | declaratori teq initialize { ($1, ValInit($2, $3)) } + | attributes declaratori teq initialize { ($2, ValInit($3, $4)) } + /* C++ only */ + | declaratori TOParCplusplusInit argument_list TCPar + { ($1, ConstrInit($3,[$2;$4])) } + | attributes declaratori TOParCplusplusInit argument_list TCPar + { ($2, ConstrInit($4,[$3;$5])) } /*(*----------------------------*)*/ /*(* workarounds *)*/ @@ -1675,6 +1692,8 @@ teq: TEq { et "teq" (); $1 } init_declarator: init_declarator2 { dt "init" (); $1 } +init_declarator_attrs: init_declarator_attrs2 { dt "init_attrs" (); $1 } + /*(*----------------------------*)*/ /*(* gccext: *)*/ @@ -2372,9 +2391,9 @@ enumerator_list: init_declarator_list: | init_declarator { [$1, []] } - | init_declarator_list TComma cpp_directive_list init_declarator + | init_declarator_list TComma cpp_directive_list init_declarator_attrs { $1 @ [$4, [$2]] } - | init_declarator_list TComma init_declarator { $1 @ [$3, [$2]] } + | init_declarator_list TComma init_declarator_attrs { $1 @ [$3, [$2]] } parameter_list: -- 2.21.1 _______________________________________________ Linux-kernel-mentees mailing list Linux-kernel-mentees@lists.linuxfoundation.org https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
next prev parent reply other threads:[~2020-06-05 13:44 UTC|newest] Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-06-05 13:43 [Cocci] [PATCH v4 00/14] cocci: Improve C parsing of attributes Jaskaran Singh 2020-06-05 13:43 ` [Linux-kernel-mentees] " Jaskaran Singh 2020-06-05 13:43 ` [Cocci] [PATCH v4 01/14] parsing_c: parse_c: Ignore TMacroAttr and TMacroEndAttr in passed tokens Jaskaran Singh 2020-06-05 13:43 ` [Linux-kernel-mentees] " Jaskaran Singh 2020-06-05 13:43 ` [Cocci] [PATCH v4 02/14] parsing_c: parsing_hacks: Label end attributes correctly Jaskaran Singh 2020-06-05 13:43 ` [Linux-kernel-mentees] " Jaskaran Singh 2020-06-05 13:43 ` [Cocci] [PATCH v4 03/14] parsing_c: parsing_hacks: Commentize attributes before qualif/type Jaskaran Singh 2020-06-05 13:43 ` [Linux-kernel-mentees] " Jaskaran Singh 2020-06-05 13:43 ` [Cocci] [PATCH v4 04/14] parsing_c: parser: Add rule for multiple end attributes Jaskaran Singh 2020-06-05 13:43 ` [Linux-kernel-mentees] " Jaskaran Singh 2020-06-05 13:43 ` [Cocci] [PATCH v4 05/14] parsing_c: parser: Add expression statement attributes Jaskaran Singh 2020-06-05 13:43 ` [Linux-kernel-mentees] " Jaskaran Singh 2020-06-05 13:43 ` [Cocci] [PATCH v4 06/14] parsing_c: parser: Add rule for optional end attributes Jaskaran Singh 2020-06-05 13:43 ` [Linux-kernel-mentees] " Jaskaran Singh 2020-06-05 13:43 ` [Cocci] [PATCH v4 07/14] parsing_c: parser: Add attribute production in spec_qualif_list Jaskaran Singh 2020-06-05 13:43 ` [Linux-kernel-mentees] " Jaskaran Singh 2020-06-05 13:43 ` Jaskaran Singh [this message] 2020-06-05 13:43 ` [Linux-kernel-mentees] [PATCH v4 08/14] parsing_c: parser: Add init_declarator_attrs rule Jaskaran Singh 2020-06-05 13:43 ` [Cocci] [PATCH v4 09/14] parsing_c: parser: Add field declaration end attributes production Jaskaran Singh 2020-06-05 13:43 ` [Linux-kernel-mentees] " Jaskaran Singh 2020-06-05 13:43 ` [Cocci] [PATCH v4 10/14] parsing_c: parser: Handle struct/union/enum end attributes Jaskaran Singh 2020-06-05 13:43 ` [Linux-kernel-mentees] " Jaskaran Singh 2020-06-05 13:43 ` [Cocci] [PATCH v4 11/14] parsing_c: parser: Add MacroDecl end attributes production Jaskaran Singh 2020-06-05 13:43 ` [Linux-kernel-mentees] " Jaskaran Singh 2020-06-05 13:43 ` [Cocci] [PATCH v4 12/14] parsing_c: parser: cpp_other " Jaskaran Singh 2020-06-05 13:43 ` [Linux-kernel-mentees] " Jaskaran Singh 2020-06-05 13:43 ` [Cocci] [PATCH v4 13/14] parsing_c: cpp_token_c: Introduce MACROANNOTATION hint Jaskaran Singh 2020-06-05 13:43 ` [Linux-kernel-mentees] " Jaskaran Singh 2020-06-05 13:43 ` [Cocci] [PATCH v4 14/14] cocci: standard.h: Annotate attributes with MACROANNOTATION Jaskaran Singh 2020-06-05 13:43 ` [Linux-kernel-mentees] " Jaskaran Singh 2020-06-05 13:48 ` [Cocci] [PATCH v4 00/14] cocci: Improve C parsing of attributes Jaskaran Singh 2020-06-05 13:48 ` [Linux-kernel-mentees] " 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=20200605134322.15307-9-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.