Linux Kernel Mentees Archive on lore.kernel.org
 help / color / Atom feed
* [Linux-kernel-mentees] [PATCH] parsing_c: Handle case of annotation in function proto/def
@ 2020-01-08 15:05 Jaskaran Singh
  2020-01-09 10:47 ` Julia Lawall
  0 siblings, 1 reply; 2+ messages in thread
From: Jaskaran Singh @ 2020-01-08 15:05 UTC (permalink / raw)
  To: cocci; +Cc: julia.lawall, jaskaransingh7654321, linux-kernel-mentees

For the following case:

[const_vol] <type> [ptr] <annotation> <identifier> <open_par>

The lookahead function in Parsing_hacks would mislabel <annotation> as a
CppDirective, causing pretty printing errors.

Add a case in the lookahead function for handling this case.

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

diff --git a/parsing_c/parsing_hacks.ml b/parsing_c/parsing_hacks.ml
index 43421647..3f031f21 100644
--- a/parsing_c/parsing_hacks.ml
+++ b/parsing_c/parsing_hacks.ml
@@ -2066,6 +2066,20 @@ let lookahead2 ~pass next before =
 	&& is_type type_ ->
 	  TCommentCpp (Token_c.CppDirective, i1)
 
+        (* tt xx yy ( : xx is an annot *)
+  | (TIdent (s, i1)::TIdent (s2, i2)::TOPar _::_, seen::_)
+    when LP.current_context () = LP.InTopLevel
+	&& (is_struct_enum before || is_type seen)
+	&& s ==~ regexp_annot ->
+	  TCommentCpp (Token_c.CppMacro, i1)
+
+        (* tt * xx yy ( : xx is an annot *)
+  | (TIdent (s, i1)::TIdent (s2, i2)::TOPar _::_, ptr)
+    when LP.current_context () = LP.InTopLevel
+	&& pointer ptr
+	&& s ==~ regexp_annot ->
+	  TCommentCpp (Token_c.CppMacro, i1)
+
 	(* tt xx yy; : yy is an annot *)
   | (TIdent (s, i1)::(TPtVirg _|TEq _)::_, TIdent (s2, i2)::type_::rest)
     when (is_struct_enum (type_::rest)
-- 
2.21.1

_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

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

* Re: [Linux-kernel-mentees] [PATCH] parsing_c: Handle case of annotation in function proto/def
  2020-01-08 15:05 [Linux-kernel-mentees] [PATCH] parsing_c: Handle case of annotation in function proto/def Jaskaran Singh
@ 2020-01-09 10:47 ` Julia Lawall
  0 siblings, 0 replies; 2+ messages in thread
From: Julia Lawall @ 2020-01-09 10:47 UTC (permalink / raw)
  To: Jaskaran Singh; +Cc: linux-kernel-mentees, cocci



On Wed, 8 Jan 2020, Jaskaran Singh wrote:

> For the following case:
>
> [const_vol] <type> [ptr] <annotation> <identifier> <open_par>
>
> The lookahead function in Parsing_hacks would mislabel <annotation> as a
> CppDirective, causing pretty printing errors.
>
> Add a case in the lookahead function for handling this case.

Applied.  Thanks!

julia

>
> Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com>
> ---
>  parsing_c/parsing_hacks.ml | 14 ++++++++++++++
>  1 file changed, 14 insertions(+)
>
> diff --git a/parsing_c/parsing_hacks.ml b/parsing_c/parsing_hacks.ml
> index 43421647..3f031f21 100644
> --- a/parsing_c/parsing_hacks.ml
> +++ b/parsing_c/parsing_hacks.ml
> @@ -2066,6 +2066,20 @@ let lookahead2 ~pass next before =
>  	&& is_type type_ ->
>  	  TCommentCpp (Token_c.CppDirective, i1)
>
> +        (* tt xx yy ( : xx is an annot *)
> +  | (TIdent (s, i1)::TIdent (s2, i2)::TOPar _::_, seen::_)
> +    when LP.current_context () = LP.InTopLevel
> +	&& (is_struct_enum before || is_type seen)
> +	&& s ==~ regexp_annot ->
> +	  TCommentCpp (Token_c.CppMacro, i1)
> +
> +        (* tt * xx yy ( : xx is an annot *)
> +  | (TIdent (s, i1)::TIdent (s2, i2)::TOPar _::_, ptr)
> +    when LP.current_context () = LP.InTopLevel
> +	&& pointer ptr
> +	&& s ==~ regexp_annot ->
> +	  TCommentCpp (Token_c.CppMacro, i1)
> +
>  	(* tt xx yy; : yy is an annot *)
>    | (TIdent (s, i1)::(TPtVirg _|TEq _)::_, TIdent (s2, i2)::type_::rest)
>      when (is_struct_enum (type_::rest)
> --
> 2.21.1
>
>
_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

^ 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 15:05 [Linux-kernel-mentees] [PATCH] parsing_c: Handle case of annotation in function proto/def Jaskaran Singh
2020-01-09 10:47 ` Julia Lawall

Linux Kernel Mentees Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-kernel-mentees/0 linux-kernel-mentees/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 linux-kernel-mentees linux-kernel-mentees/ https://lore.kernel.org/linux-kernel-mentees \
		linux-kernel-mentees@lists.linuxfoundation.org
	public-inbox-index linux-kernel-mentees

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.linuxfoundation.lists.linux-kernel-mentees


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