Coccinelle archive on lore.kernel.org
 help / color / Atom feed
* Re: [Cocci] [PATCH] parsing_c: Handle case of macro before typedef
@ 2020-01-21  9:35 Markus Elfring
  0 siblings, 0 replies; 5+ messages in thread
From: Markus Elfring @ 2020-01-21  9:35 UTC (permalink / raw)
  To: Jaskaran Singh, cocci; +Cc: linux-kernel-mentees

> A case in parsing_hacks.ml sometimes mislabels <macro> as a
> typedef ident.

Can a wording like “as a type definition identifier” be nicer
for this description of a software situation?

Regards,
Markus
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Cocci] [PATCH] parsing_c: Handle case of macro before typedef
  2020-01-19 13:46 Jaskaran Singh
@ 2020-01-21  6:28 ` Julia Lawall
  0 siblings, 0 replies; 5+ messages in thread
From: Julia Lawall @ 2020-01-21  6:28 UTC (permalink / raw)
  To: Jaskaran Singh; +Cc: linux-kernel-mentees, cocci



On Sun, 19 Jan 2020, Jaskaran Singh wrote:

> 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.

OK, I see that you are now using is_known_typdef in a more interesting
way.  Could you add a test case that shows what has improved?  I would
still know to know why the number of passed tokens increases.

julia


>
> 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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Cocci] [PATCH] parsing_c: Handle case of macro before typedef
@ 2020-01-19 13:46 Jaskaran Singh
  2020-01-21  6:28 ` Julia Lawall
  0 siblings, 1 reply; 5+ messages in thread
From: Jaskaran Singh @ 2020-01-19 13:46 UTC (permalink / raw)
  To: cocci; +Cc: linux-kernel-mentees

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Cocci] [PATCH] parsing_c: Handle case of macro before typedef
  2020-01-19 13:18 Jaskaran Singh
@ 2020-01-19 13:25 ` Jaskaran Singh
  0 siblings, 0 replies; 5+ messages in thread
From: Jaskaran Singh @ 2020-01-19 13:25 UTC (permalink / raw)
  To: Jaskaran Singh; +Cc: linux-kernel-mentees-request, cocci

On Sun, 2020-01-19 at 18:48 +0530, Jaskaran Singh wrote:
> 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 is a diff of --parse-c on the Linux Kernel v5.5-rc4:
> Before
> ---
> After
> 
> nb good = 18956150,  nb passed = 134061 =========> 0.70% passed
> ---
> nb good = 18956150,  nb passed = 134062 =========> 0.70% passed
> 
> Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com>


Whoops, ignore this. The commit message comes out badly.

Thanks,
Jaskaran.

_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Cocci] [PATCH] parsing_c: Handle case of macro before typedef
@ 2020-01-19 13:18 Jaskaran Singh
  2020-01-19 13:25 ` Jaskaran Singh
  0 siblings, 1 reply; 5+ messages in thread
From: Jaskaran Singh @ 2020-01-19 13:18 UTC (permalink / raw)
  To: cocci; +Cc: linux-kernel-mentees

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 is a diff of --parse-c on the Linux Kernel v5.5-rc4:
Before
---
After

nb good = 18956150,  nb passed = 134061 =========> 0.70% passed
---
nb good = 18956150,  nb passed = 134062 =========> 0.70% passed

Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com>
---
 parsing_c/parsing_hacks.ml | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/parsing_c/parsing_hacks.ml b/parsing_c/parsing_hacks.ml
index 8374731b..685a4908 100644
--- a/parsing_c/parsing_hacks.ml
+++ b/parsing_c/parsing_hacks.ml
@@ -2184,6 +2184,39 @@ 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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, back to index

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-21  9:35 [Cocci] [PATCH] parsing_c: Handle case of macro before typedef Markus Elfring
  -- strict thread matches above, loose matches on Subject: below --
2020-01-19 13:46 Jaskaran Singh
2020-01-21  6:28 ` Julia Lawall
2020-01-19 13:18 Jaskaran Singh
2020-01-19 13:25 ` Jaskaran Singh

Coccinelle archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/cocci/0 cocci/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 cocci cocci/ https://lore.kernel.org/cocci \
		cocci@systeme.lip6.fr
	public-inbox-index cocci

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/fr.lip6.systeme.cocci


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git