Coccinelle archive on lore.kernel.org
 help / color / Atom feed
* [Cocci] [PATCH] parsing_c: Handle case of annotation and ; or = after ident
@ 2020-01-08 11:31 Jaskaran Singh
  2020-01-08 13:00 ` Julia Lawall
  0 siblings, 1 reply; 2+ messages in thread
From: Jaskaran Singh @ 2020-01-08 11:31 UTC (permalink / raw)
  To: cocci; +Cc: linux-kernel-mentees, skhan

For the following case:

[const_vol] <type> [ptr] <identifier> <annotation> <semicolon|eq>

The lookahead function in Parsing_hacks would mislabel <identifier> as a
CppDirective.

Add cases in the lookahead function for handling this case.

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

diff --git a/parsing_c/parsing_hacks.ml b/parsing_c/parsing_hacks.ml
index 56857f3c..43421647 100644
--- a/parsing_c/parsing_hacks.ml
+++ b/parsing_c/parsing_hacks.ml
@@ -1887,6 +1887,11 @@ let not_struct_enum = function
     (Parser_c.Tstruct _ | Parser_c.Tunion _ | Parser_c.Tenum _)::_ -> false
   | _ -> true
 
+let is_struct_enum = function
+  | (Parser_c.TIdent _)::
+    (Parser_c.Tstruct _ | Parser_c.Tunion _ | Parser_c.Tenum _)::_ -> true
+  | _ -> false
+
 let not_opar = function
     TOPar _ -> false
   | _ -> true
@@ -2061,6 +2066,32 @@ let lookahead2 ~pass next before =
 	&& is_type type_ ->
 	  TCommentCpp (Token_c.CppDirective, i1)
 
+	(* tt xx yy; : yy is an annot *)
+  | (TIdent (s, i1)::(TPtVirg _|TEq _)::_, TIdent (s2, i2)::type_::rest)
+    when (is_struct_enum (type_::rest)
+	|| is_type type_)
+	&& s ==~ regexp_annot ->
+	  TCommentCpp (Token_c.CppMacro, i1)
+
+	(* tt * xx yy; : yy is an annot *)
+  | (TIdent (s, i1)::(TPtVirg _|TEq _)::_, TIdent (s2, i2)::ptr)
+    when pointer ptr
+	&& s ==~ regexp_annot ->
+	  TCommentCpp (Token_c.CppMacro, i1)
+
+	(* tt xx yy; : yy is an annot, so xx is an ident *)
+  | (TIdent (s, i1)::TIdent (s2, i2)::(TPtVirg _|TEq _)::_, seen::_)
+    when (is_struct_enum before
+	|| is_type seen)
+	&& s2 ==~ regexp_annot ->
+	  TIdent (s, i1)
+
+	(* tt * xx yy; : yy is an annot, so xx is an ident *)
+  | (TIdent (s, i1)::TIdent (s2, i2)::(TPtVirg _|TEq _)::_, ptr)
+    when pointer ptr
+	&& s2 ==~ regexp_annot ->
+	  TIdent (s, i1)
+
 	(* tt xx yy *)
   | (TIdent (s, i1)::TIdent (s2, i2)::_  , seen::_)
     when not_struct_enum before
-- 
2.21.1

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

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

* Re: [Cocci] [PATCH] parsing_c: Handle case of annotation and ; or = after ident
  2020-01-08 11:31 [Cocci] [PATCH] parsing_c: Handle case of annotation and ; or = after ident Jaskaran Singh
@ 2020-01-08 13:00 ` Julia Lawall
  0 siblings, 0 replies; 2+ messages in thread
From: Julia Lawall @ 2020-01-08 13:00 UTC (permalink / raw)
  To: Jaskaran Singh; +Cc: linux-kernel-mentees, cocci, skhan



On Wed, 8 Jan 2020, Jaskaran Singh wrote:

> For the following case:
>
> [const_vol] <type> [ptr] <identifier> <annotation> <semicolon|eq>
>
> The lookahead function in Parsing_hacks would mislabel <identifier> as a
> CppDirective.
>
> Add cases in the lookahead function for handling this case.
>
> Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com>

Looks good.  There are a lot of __ro_after_inits that now get properly
recognized as attributes.  The patch is applied.

julia

> ---
>  parsing_c/parsing_hacks.ml | 31 +++++++++++++++++++++++++++++++
>  1 file changed, 31 insertions(+)
>
> diff --git a/parsing_c/parsing_hacks.ml b/parsing_c/parsing_hacks.ml
> index 56857f3c..43421647 100644
> --- a/parsing_c/parsing_hacks.ml
> +++ b/parsing_c/parsing_hacks.ml
> @@ -1887,6 +1887,11 @@ let not_struct_enum = function
>      (Parser_c.Tstruct _ | Parser_c.Tunion _ | Parser_c.Tenum _)::_ -> false
>    | _ -> true
>
> +let is_struct_enum = function
> +  | (Parser_c.TIdent _)::
> +    (Parser_c.Tstruct _ | Parser_c.Tunion _ | Parser_c.Tenum _)::_ -> true
> +  | _ -> false
> +
>  let not_opar = function
>      TOPar _ -> false
>    | _ -> true
> @@ -2061,6 +2066,32 @@ let lookahead2 ~pass next before =
>  	&& is_type type_ ->
>  	  TCommentCpp (Token_c.CppDirective, i1)
>
> +	(* tt xx yy; : yy is an annot *)
> +  | (TIdent (s, i1)::(TPtVirg _|TEq _)::_, TIdent (s2, i2)::type_::rest)
> +    when (is_struct_enum (type_::rest)
> +	|| is_type type_)
> +	&& s ==~ regexp_annot ->
> +	  TCommentCpp (Token_c.CppMacro, i1)
> +
> +	(* tt * xx yy; : yy is an annot *)
> +  | (TIdent (s, i1)::(TPtVirg _|TEq _)::_, TIdent (s2, i2)::ptr)
> +    when pointer ptr
> +	&& s ==~ regexp_annot ->
> +	  TCommentCpp (Token_c.CppMacro, i1)
> +
> +	(* tt xx yy; : yy is an annot, so xx is an ident *)
> +  | (TIdent (s, i1)::TIdent (s2, i2)::(TPtVirg _|TEq _)::_, seen::_)
> +    when (is_struct_enum before
> +	|| is_type seen)
> +	&& s2 ==~ regexp_annot ->
> +	  TIdent (s, i1)
> +
> +	(* tt * xx yy; : yy is an annot, so xx is an ident *)
> +  | (TIdent (s, i1)::TIdent (s2, i2)::(TPtVirg _|TEq _)::_, ptr)
> +    when pointer ptr
> +	&& s2 ==~ regexp_annot ->
> +	  TIdent (s, i1)
> +
>  	(* tt xx yy *)
>    | (TIdent (s, i1)::TIdent (s2, i2)::_  , seen::_)
>      when not_struct_enum before
> --
> 2.21.1
>
>
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

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

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-08 11:31 [Cocci] [PATCH] parsing_c: Handle case of annotation and ; or = after ident Jaskaran Singh
2020-01-08 13:00 ` Julia Lawall

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