Re: [Cocci] [v4 3/3] tests: Add test case to match const pointer variants

2020-02-09 Thread Markus Elfring
> > Do you mean that the C file/res file should conform to the Linux style?
>
> I think it would be nicer if it did.

Is the interest for the clarification of a topic like “Make change influence
configurable for coding style rules” growing?
https://github.com/coccinelle/coccinelle/issues/37

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


Re: [Cocci] [PATCH v4 3/3] tests: Add test case to match const pointer variants

2020-02-09 Thread Julia Lawall



On Sun, 9 Feb 2020, Jaskaran Singh wrote:

> On Sun, 2020-02-09 at 17:48 +0100, Julia Lawall wrote:
> > On Sun, 9 Feb 2020, Jaskaran Singh wrote:
> >
> > > Pointer to const pointer and its variants would not match
> > > previously.
> > > Add a test case for matching these types.
> > >
> > > Signed-off-by: Jaskaran Singh 
> > > ---
> > >  tests/constptr.c |  7 +++
> > >  tests/constptr.cocci | 19 +++
> > >  tests/constptr.res   |  7 +++
> > >  3 files changed, 33 insertions(+)
> > >  create mode 100644 tests/constptr.c
> > >  create mode 100644 tests/constptr.cocci
> > >  create mode 100644 tests/constptr.res
> > >
> > > diff --git a/tests/constptr.c b/tests/constptr.c
> > > new file mode 100644
> > > index ..13fe064c
> > > --- /dev/null
> > > +++ b/tests/constptr.c
> > > @@ -0,0 +1,7 @@
> > > +int main()
> > > +{
> > > + const char * const * id;
> > > + const char * * const * id;
> > > + const char * const * * id;
> > > + const char * const id;
> >
> > As far as I can see in the Linux kernel, there is no space between
> > two *s,
> > and there is no space before an identifier.
> >
>
> Well, the test isn't replacing the type here. It's just replacing the
> ident as per the matches. So I guess the spaces are preserved as in the
> C file.
> When replacing the type like say
> -t x;
> +t y;
> Spaces are not added between the stars or the ident.

Yes, I agree.

>
> Sorry if I'm missing something. Do you mean that the C file/res file
> should conform to the Linux style?

I think it would be nicer if it did.

julia

> Cheers,
> Jaskaran.
>
> > julia
> >
> > > +}
> > > diff --git a/tests/constptr.cocci b/tests/constptr.cocci
> > > new file mode 100644
> > > index ..29f0aa96
> > > --- /dev/null
> > > +++ b/tests/constptr.cocci
> > > @@ -0,0 +1,19 @@
> > > +@ r0 @
> > > +identifier id;
> > > +@@
> > > +const char * const *
> > > +- id
> > > ++ id1
> > > +;
> > > +const char * * const *
> > > +- id
> > > ++ id2
> > > +;
> > > +const char * const * *
> > > +- id
> > > ++ id3
> > > +;
> > > +const char * const
> > > +- id
> > > ++ id4
> > > +;
> > > diff --git a/tests/constptr.res b/tests/constptr.res
> > > new file mode 100644
> > > index ..0af4de9a
> > > --- /dev/null
> > > +++ b/tests/constptr.res
> > > @@ -0,0 +1,7 @@
> > > +int main()
> > > +{
> > > + const char * const * id1;
> > > + const char * * const * id2;
> > > + const char * const * * id3;
> > > + const char * const id4;
> > > +}
> > > --
> > > 2.21.1
> > >
> > >
>
>
___
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci


Re: [Cocci] [PATCH v4 3/3] tests: Add test case to match const pointer variants

2020-02-09 Thread Jaskaran Singh
On Sun, 2020-02-09 at 17:48 +0100, Julia Lawall wrote:
> On Sun, 9 Feb 2020, Jaskaran Singh wrote:
> 
> > Pointer to const pointer and its variants would not match
> > previously.
> > Add a test case for matching these types.
> > 
> > Signed-off-by: Jaskaran Singh 
> > ---
> >  tests/constptr.c |  7 +++
> >  tests/constptr.cocci | 19 +++
> >  tests/constptr.res   |  7 +++
> >  3 files changed, 33 insertions(+)
> >  create mode 100644 tests/constptr.c
> >  create mode 100644 tests/constptr.cocci
> >  create mode 100644 tests/constptr.res
> > 
> > diff --git a/tests/constptr.c b/tests/constptr.c
> > new file mode 100644
> > index ..13fe064c
> > --- /dev/null
> > +++ b/tests/constptr.c
> > @@ -0,0 +1,7 @@
> > +int main()
> > +{
> > +   const char * const * id;
> > +   const char * * const * id;
> > +   const char * const * * id;
> > +   const char * const id;
> 
> As far as I can see in the Linux kernel, there is no space between
> two *s,
> and there is no space before an identifier.
> 

Well, the test isn't replacing the type here. It's just replacing the
ident as per the matches. So I guess the spaces are preserved as in the
C file.
When replacing the type like say
-t x;
+t y;
Spaces are not added between the stars or the ident.

Sorry if I'm missing something. Do you mean that the C file/res file
should conform to the Linux style?

Cheers,
Jaskaran.

> julia
> 
> > +}
> > diff --git a/tests/constptr.cocci b/tests/constptr.cocci
> > new file mode 100644
> > index ..29f0aa96
> > --- /dev/null
> > +++ b/tests/constptr.cocci
> > @@ -0,0 +1,19 @@
> > +@ r0 @
> > +identifier id;
> > +@@
> > +const char * const *
> > +- id
> > ++ id1
> > +;
> > +const char * * const *
> > +- id
> > ++ id2
> > +;
> > +const char * const * *
> > +- id
> > ++ id3
> > +;
> > +const char * const
> > +- id
> > ++ id4
> > +;
> > diff --git a/tests/constptr.res b/tests/constptr.res
> > new file mode 100644
> > index ..0af4de9a
> > --- /dev/null
> > +++ b/tests/constptr.res
> > @@ -0,0 +1,7 @@
> > +int main()
> > +{
> > +   const char * const * id1;
> > +   const char * * const * id2;
> > +   const char * const * * id3;
> > +   const char * const id4;
> > +}
> > --
> > 2.21.1
> > 
> > 

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


Re: [Cocci] [PATCH v4 3/3] tests: Add test case to match const pointer variants

2020-02-09 Thread Julia Lawall
On Sun, 9 Feb 2020, Jaskaran Singh wrote:

> Pointer to const pointer and its variants would not match previously.
> Add a test case for matching these types.
>
> Signed-off-by: Jaskaran Singh 
> ---
>  tests/constptr.c |  7 +++
>  tests/constptr.cocci | 19 +++
>  tests/constptr.res   |  7 +++
>  3 files changed, 33 insertions(+)
>  create mode 100644 tests/constptr.c
>  create mode 100644 tests/constptr.cocci
>  create mode 100644 tests/constptr.res
>
> diff --git a/tests/constptr.c b/tests/constptr.c
> new file mode 100644
> index ..13fe064c
> --- /dev/null
> +++ b/tests/constptr.c
> @@ -0,0 +1,7 @@
> +int main()
> +{
> + const char * const * id;
> + const char * * const * id;
> + const char * const * * id;
> + const char * const id;

As far as I can see in the Linux kernel, there is no space between two *s,
and there is no space before an identifier.

julia

> +}
> diff --git a/tests/constptr.cocci b/tests/constptr.cocci
> new file mode 100644
> index ..29f0aa96
> --- /dev/null
> +++ b/tests/constptr.cocci
> @@ -0,0 +1,19 @@
> +@ r0 @
> +identifier id;
> +@@
> +const char * const *
> +- id
> ++ id1
> +;
> +const char * * const *
> +- id
> ++ id2
> +;
> +const char * const * *
> +- id
> ++ id3
> +;
> +const char * const
> +- id
> ++ id4
> +;
> diff --git a/tests/constptr.res b/tests/constptr.res
> new file mode 100644
> index ..0af4de9a
> --- /dev/null
> +++ b/tests/constptr.res
> @@ -0,0 +1,7 @@
> +int main()
> +{
> + const char * const * id1;
> + const char * * const * id2;
> + const char * const * * id3;
> + const char * const id4;
> +}
> --
> 2.21.1
>
>
___
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci


Re: [Cocci] [PATCH v4 1/3] parsing_c: Align C AST and Cocci AST for pointer

2020-02-09 Thread Julia Lawall
On Sun, 9 Feb 2020, Jaskaran Singh wrote:

> For a pointer, the C parser constructed an AST dissimilar from that
> of the Cocci AST. This caused failures in matching with certain
> pointer types. For example, for the following case:
>
> char *1 const *2 id;
>
> The C AST constructed would be:
> const Pointer1 -> Pointer2 -> char
>
> The Cocci AST constructed would be:
> Pointer2 -> const Pointer1 -> char
>
> Change the pointer rule in the C parser so that an AST similar to the
> Cocci AST is constructed.
>
> Make necessary changes in the C pretty printer so that the pointer type
> is printed correctly.
>
> Signed-off-by: Jaskaran Singh 
> ---
>  parsing_c/parser_c.mly  |  4 ++--
>  parsing_c/pretty_print_c.ml | 14 ++
>  2 files changed, 12 insertions(+), 6 deletions(-)
>
> diff --git a/parsing_c/parser_c.mly b/parsing_c/parser_c.mly
> index 8d7b761e..4c74f15a 100644
> --- a/parsing_c/parser_c.mly
> +++ b/parsing_c/parser_c.mly
> @@ -1333,14 +1333,14 @@ pointer:
>   | tmul   { (Ast_c.noattr,fun x -> mk_ty (Pointer x) [$1]) }
>   | tmul pointer
>   { let (attr,ptr) = $2 in
> -   (attr,fun x -> mk_ty (Pointer (ptr x)) [$1]) }
> +   (attr,fun x -> ptr (mk_ty (Pointer x) [$1])) }
>   | tmul type_qualif_list
>   { let (attr,tq) = $2 in
> (attr,fun x -> (tq.qualifD, mk_tybis (Pointer x) [$1]))}
>   | tmul type_qualif_list pointer
>   { let (attr1,tq) = $2 in
> let (attr2,ptr) = $3 in
> -   (attr1@attr2,fun x -> (tq.qualifD, mk_tybis (Pointer (ptr x)) [$1])) }
> +   (attr1@attr2,fun x -> ptr (tq.qualifD, mk_tybis (Pointer x) [$1])) }
>
>  tmul:
> TMul { $1 }
> diff --git a/parsing_c/pretty_print_c.ml b/parsing_c/pretty_print_c.ml
> index a2e35588..3aaa97ca 100644
> --- a/parsing_c/pretty_print_c.ml
> +++ b/parsing_c/pretty_print_c.ml
> @@ -804,11 +804,14 @@ and pp_string_format (e,ii) =
>   (FunctionType (return=void, params=int i) *)
>(*WRONG I THINK, use left & right function *)
>(* bug: pp_type_with_ident_rest None t;  print_ident ident *)
> +  pp_type_left t;
>pr_elem i;
> -  iiqu +> List.iter pr_elem; (* le const est forcement apres le '*' 
> *)
> +  iiqu +>
> +  List.iter (* le const est forcement apres le '*' *)
> +(function x -> (pr_space(); pr_elem x));

There is no need for the parentheses around the pr_space and pr_elem
calls.

>if iiqu <> [] || get_comments_after i <> []
>then pr_space();
> -  pp_type_with_ident_rest ident t attrs Ast_c.noattr;
> +  print_ident ident
>
>(* ugly special case ... todo? maybe sufficient in practice *)
>| (ParenType ttop, [i1;i2]) ->
> @@ -885,11 +888,14 @@ and pp_string_format (e,ii) =
>match ty, iity with
>   (NoType,_) -> failwith "pp_type_left: unexpected NoType"
>| (Pointer t, [i]) ->
> +  pp_type_left t;
>pr_elem i;
> -  iiqu +> List.iter pr_elem; (* le const est forcement apres le '*' 
> *)
> +  iiqu +>
> +  List.iter (* le const est forcement apres le '*' *)
> +(function x -> (pr_space(); pr_elem x));
>if iiqu <> [] || get_comments_after i <> []
>then pr_space();
> -  pp_type_left t
> +  ()

This is not needed.  YOu can just drop the ; after the pr_space() and the
whole call to pp_type_left.

julia

>
>| (Array (eopt, t), [i1;i2]) -> pp_type_left t
>| (FunctionType (returnt, paramst), [i1;i2]) -> pp_type_left returnt
> --
> 2.21.1
>
>
___
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci


[Cocci] [PATCH v4 2/3] tests: Add space between * and const in ptrconstptr.res

2020-02-09 Thread Jaskaran Singh
A space is now added between the * and qualifier. Reflect this
change in the ptrconstptr test case.

Signed-off-by: Jaskaran Singh 
---
 tests/ptrconstptr.res | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/ptrconstptr.res b/tests/ptrconstptr.res
index f5b2210c..1d0c3c1d 100644
--- a/tests/ptrconstptr.res
+++ b/tests/ptrconstptr.res
@@ -1,3 +1,3 @@
 void main() {
-   const char *const *y;
+   const char * const *y;
 }
-- 
2.21.1

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


[Cocci] [PATCH v4 3/3] tests: Add test case to match const pointer variants

2020-02-09 Thread Jaskaran Singh
Pointer to const pointer and its variants would not match previously.
Add a test case for matching these types.

Signed-off-by: Jaskaran Singh 
---
 tests/constptr.c |  7 +++
 tests/constptr.cocci | 19 +++
 tests/constptr.res   |  7 +++
 3 files changed, 33 insertions(+)
 create mode 100644 tests/constptr.c
 create mode 100644 tests/constptr.cocci
 create mode 100644 tests/constptr.res

diff --git a/tests/constptr.c b/tests/constptr.c
new file mode 100644
index ..13fe064c
--- /dev/null
+++ b/tests/constptr.c
@@ -0,0 +1,7 @@
+int main()
+{
+   const char * const * id;
+   const char * * const * id;
+   const char * const * * id;
+   const char * const id;
+}
diff --git a/tests/constptr.cocci b/tests/constptr.cocci
new file mode 100644
index ..29f0aa96
--- /dev/null
+++ b/tests/constptr.cocci
@@ -0,0 +1,19 @@
+@ r0 @
+identifier id;
+@@
+const char * const *
+- id
++ id1
+;
+const char * * const *
+- id
++ id2
+;
+const char * const * *
+- id
++ id3
+;
+const char * const
+- id
++ id4
+;
diff --git a/tests/constptr.res b/tests/constptr.res
new file mode 100644
index ..0af4de9a
--- /dev/null
+++ b/tests/constptr.res
@@ -0,0 +1,7 @@
+int main()
+{
+   const char * const * id1;
+   const char * * const * id2;
+   const char * const * * id3;
+   const char * const id4;
+}
-- 
2.21.1

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


[Cocci] [PATCH v4 1/3] parsing_c: Align C AST and Cocci AST for pointer

2020-02-09 Thread Jaskaran Singh
For a pointer, the C parser constructed an AST dissimilar from that
of the Cocci AST. This caused failures in matching with certain
pointer types. For example, for the following case:

char *1 const *2 id;

The C AST constructed would be:
const Pointer1 -> Pointer2 -> char

The Cocci AST constructed would be:
Pointer2 -> const Pointer1 -> char

Change the pointer rule in the C parser so that an AST similar to the
Cocci AST is constructed.

Make necessary changes in the C pretty printer so that the pointer type
is printed correctly.

Signed-off-by: Jaskaran Singh 
---
 parsing_c/parser_c.mly  |  4 ++--
 parsing_c/pretty_print_c.ml | 14 ++
 2 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/parsing_c/parser_c.mly b/parsing_c/parser_c.mly
index 8d7b761e..4c74f15a 100644
--- a/parsing_c/parser_c.mly
+++ b/parsing_c/parser_c.mly
@@ -1333,14 +1333,14 @@ pointer:
  | tmul   { (Ast_c.noattr,fun x -> mk_ty (Pointer x) [$1]) }
  | tmul pointer
  { let (attr,ptr) = $2 in
-   (attr,fun x -> mk_ty (Pointer (ptr x)) [$1]) }
+   (attr,fun x -> ptr (mk_ty (Pointer x) [$1])) }
  | tmul type_qualif_list
  { let (attr,tq) = $2 in
(attr,fun x -> (tq.qualifD, mk_tybis (Pointer x) [$1]))}
  | tmul type_qualif_list pointer
  { let (attr1,tq) = $2 in
let (attr2,ptr) = $3 in
-   (attr1@attr2,fun x -> (tq.qualifD, mk_tybis (Pointer (ptr x)) [$1])) }
+   (attr1@attr2,fun x -> ptr (tq.qualifD, mk_tybis (Pointer x) [$1])) }
 
 tmul:
TMul { $1 }
diff --git a/parsing_c/pretty_print_c.ml b/parsing_c/pretty_print_c.ml
index a2e35588..3aaa97ca 100644
--- a/parsing_c/pretty_print_c.ml
+++ b/parsing_c/pretty_print_c.ml
@@ -804,11 +804,14 @@ and pp_string_format (e,ii) =
  (FunctionType (return=void, params=int i) *)
   (*WRONG I THINK, use left & right function *)
   (* bug: pp_type_with_ident_rest None t;  print_ident ident *)
+  pp_type_left t;
   pr_elem i;
-  iiqu +> List.iter pr_elem; (* le const est forcement apres le '*' *)
+  iiqu +>
+  List.iter (* le const est forcement apres le '*' *)
+(function x -> (pr_space(); pr_elem x));
   if iiqu <> [] || get_comments_after i <> []
   then pr_space();
-  pp_type_with_ident_rest ident t attrs Ast_c.noattr;
+  print_ident ident
 
   (* ugly special case ... todo? maybe sufficient in practice *)
   | (ParenType ttop, [i1;i2]) ->
@@ -885,11 +888,14 @@ and pp_string_format (e,ii) =
   match ty, iity with
(NoType,_) -> failwith "pp_type_left: unexpected NoType"
   | (Pointer t, [i]) ->
+  pp_type_left t;
   pr_elem i;
-  iiqu +> List.iter pr_elem; (* le const est forcement apres le '*' *)
+  iiqu +>
+  List.iter (* le const est forcement apres le '*' *)
+(function x -> (pr_space(); pr_elem x));
   if iiqu <> [] || get_comments_after i <> []
   then pr_space();
-  pp_type_left t
+  ()
 
   | (Array (eopt, t), [i1;i2]) -> pp_type_left t
   | (FunctionType (returnt, paramst), [i1;i2]) -> pp_type_left returnt
-- 
2.21.1

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


[Cocci] [PATCH v4 0/3] cocci: Align the C AST and Cocci AST for pointer

2020-02-09 Thread Jaskaran Singh
This series is to address the type matching problem in Coccinelle.

Patch 1/3 is for aligning the C and Cocci AST so that
pointer to const pointer and its variants can be matched.

Patch 2/3 reflects the pretty printing changes made in 
1/3 in the ptrconstptr test case. A space is added between
the * and const.

Patch 3/3 consists of a test case for matching a pointer to
const pointer and its variants.

Changes in v4:
--
- Change coding style w/r/t placement of comment with List.iter and
  the qualifier printing function.

Changes in v3:
--
- Add a space between the * and qualifier in Patch 1/3.
- Add Patch 2/3 to add a space between * and const in the test
  case ptrconstptr.

Changes in v2:
--
- Change body and subject of Patch 2/2 as per suggestion of Markus
  Elfring.

[PATCH v4 1/3] parsing_c: Align C AST and Cocci AST for pointer
[PATCH v4 2/3] tests: Add space between * and const in
[PATCH v4 3/3] tests: Add test case to match const pointer variants

 parsing_c/parser_c.mly  |4 ++--
 parsing_c/pretty_print_c.ml |   14 ++
 tests/constptr.c|7 +++
 tests/constptr.cocci|   19 +++
 tests/constptr.res  |7 +++
 tests/ptrconstptr.res   |2 +-
 6 files changed, 46 insertions(+), 7 deletions(-)

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


Re: [Cocci] [PATCH v3 1/3] parsing_c: Align C AST and Cocci AST for pointer

2020-02-09 Thread Julia Lawall
On Sun, 9 Feb 2020, Jaskaran Singh wrote:

> For a pointer, the C parser constructed an AST dissimilar from that
> of the Cocci AST. This caused failures in matching with certain
> pointer types. For example, for the following case:
>
> char *1 const *2 id;
>
> The C AST constructed would be:
> const Pointer1 -> Pointer2 -> char
>
> The Cocci AST constructed would be:
> Pointer2 -> const Pointer1 -> char
>
> Change the pointer rule in the C parser so that an AST similar to the
> Cocci AST is constructed.
>
> Make necessary changes in the C pretty printer so that the pointer type
> is printed correctly.
>
> Signed-off-by: Jaskaran Singh 
> ---
>  parsing_c/parser_c.mly  |  4 ++--
>  parsing_c/pretty_print_c.ml | 12 
>  2 files changed, 10 insertions(+), 6 deletions(-)
>
> diff --git a/parsing_c/parser_c.mly b/parsing_c/parser_c.mly
> index 8d7b761e..4c74f15a 100644
> --- a/parsing_c/parser_c.mly
> +++ b/parsing_c/parser_c.mly
> @@ -1333,14 +1333,14 @@ pointer:
>   | tmul   { (Ast_c.noattr,fun x -> mk_ty (Pointer x) [$1]) }
>   | tmul pointer
>   { let (attr,ptr) = $2 in
> -   (attr,fun x -> mk_ty (Pointer (ptr x)) [$1]) }
> +   (attr,fun x -> ptr (mk_ty (Pointer x) [$1])) }
>   | tmul type_qualif_list
>   { let (attr,tq) = $2 in
> (attr,fun x -> (tq.qualifD, mk_tybis (Pointer x) [$1]))}
>   | tmul type_qualif_list pointer
>   { let (attr1,tq) = $2 in
> let (attr2,ptr) = $3 in
> -   (attr1@attr2,fun x -> (tq.qualifD, mk_tybis (Pointer (ptr x)) [$1])) }
> +   (attr1@attr2,fun x -> ptr (tq.qualifD, mk_tybis (Pointer x) [$1])) }
>
>  tmul:
> TMul { $1 }
> diff --git a/parsing_c/pretty_print_c.ml b/parsing_c/pretty_print_c.ml
> index a2e35588..ae02b513 100644
> --- a/parsing_c/pretty_print_c.ml
> +++ b/parsing_c/pretty_print_c.ml
> @@ -804,11 +804,13 @@ and pp_string_format (e,ii) =
>   (FunctionType (return=void, params=int i) *)
>(*WRONG I THINK, use left & right function *)
>(* bug: pp_type_with_ident_rest None t;  print_ident ident *)
> +  pp_type_left t;
>pr_elem i;
> -  iiqu +> List.iter pr_elem; (* le const est forcement apres le '*' 
> *)
> +  iiqu +> List.iter (function x ->
> + (pr_space(); pr_elem x));(* le const est forcement apres le '*' 
> *)

I'm not very fond of this coding style.  I would prefer:

iiqu +>
List.iter (* the comment can go here *)
  (function x -> pr_space(); pr_elem x)

Likewise below.

julia

>if iiqu <> [] || get_comments_after i <> []
>then pr_space();
> -  pp_type_with_ident_rest ident t attrs Ast_c.noattr;
> +  print_ident ident
>
>(* ugly special case ... todo? maybe sufficient in practice *)
>| (ParenType ttop, [i1;i2]) ->
> @@ -885,11 +887,13 @@ and pp_string_format (e,ii) =
>match ty, iity with
>   (NoType,_) -> failwith "pp_type_left: unexpected NoType"
>| (Pointer t, [i]) ->
> +  pp_type_left t;
>pr_elem i;
> -  iiqu +> List.iter pr_elem; (* le const est forcement apres le '*' 
> *)
> +  iiqu +> List.iter (function x ->
> + (pr_space(); pr_elem x));(* le const est forcement apres le '*' 
> *)
>if iiqu <> [] || get_comments_after i <> []
>then pr_space();
> -  pp_type_left t
> +  ()
>
>| (Array (eopt, t), [i1;i2]) -> pp_type_left t
>| (FunctionType (returnt, paramst), [i1;i2]) -> pp_type_left returnt
> --
> 2.21.1
>
>
___
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci


[Cocci] [PATCH v3 2/3] tests: Add space between * and const in ptrconstptr.res

2020-02-09 Thread Jaskaran Singh
A space is now added between the * and qualifier. Reflect this
change in the ptrconstptr test case.

Signed-off-by: Jaskaran Singh 
---
 tests/ptrconstptr.res | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/ptrconstptr.res b/tests/ptrconstptr.res
index f5b2210c..1d0c3c1d 100644
--- a/tests/ptrconstptr.res
+++ b/tests/ptrconstptr.res
@@ -1,3 +1,3 @@
 void main() {
-   const char *const *y;
+   const char * const *y;
 }
-- 
2.21.1

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


[Cocci] [PATCH v3 3/3] tests: Add test case to match const pointer variants

2020-02-09 Thread Jaskaran Singh
Pointer to const pointer and its variants would not match previously.
Add a test case for matching these types.

Signed-off-by: Jaskaran Singh 
---
 tests/constptr.c |  7 +++
 tests/constptr.cocci | 19 +++
 tests/constptr.res   |  7 +++
 3 files changed, 33 insertions(+)
 create mode 100644 tests/constptr.c
 create mode 100644 tests/constptr.cocci
 create mode 100644 tests/constptr.res

diff --git a/tests/constptr.c b/tests/constptr.c
new file mode 100644
index ..13fe064c
--- /dev/null
+++ b/tests/constptr.c
@@ -0,0 +1,7 @@
+int main()
+{
+   const char * const * id;
+   const char * * const * id;
+   const char * const * * id;
+   const char * const id;
+}
diff --git a/tests/constptr.cocci b/tests/constptr.cocci
new file mode 100644
index ..29f0aa96
--- /dev/null
+++ b/tests/constptr.cocci
@@ -0,0 +1,19 @@
+@ r0 @
+identifier id;
+@@
+const char * const *
+- id
++ id1
+;
+const char * * const *
+- id
++ id2
+;
+const char * const * *
+- id
++ id3
+;
+const char * const
+- id
++ id4
+;
diff --git a/tests/constptr.res b/tests/constptr.res
new file mode 100644
index ..0af4de9a
--- /dev/null
+++ b/tests/constptr.res
@@ -0,0 +1,7 @@
+int main()
+{
+   const char * const * id1;
+   const char * * const * id2;
+   const char * const * * id3;
+   const char * const id4;
+}
-- 
2.21.1

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


[Cocci] [PATCH v3 1/3] parsing_c: Align C AST and Cocci AST for pointer

2020-02-09 Thread Jaskaran Singh
For a pointer, the C parser constructed an AST dissimilar from that
of the Cocci AST. This caused failures in matching with certain
pointer types. For example, for the following case:

char *1 const *2 id;

The C AST constructed would be:
const Pointer1 -> Pointer2 -> char

The Cocci AST constructed would be:
Pointer2 -> const Pointer1 -> char

Change the pointer rule in the C parser so that an AST similar to the
Cocci AST is constructed.

Make necessary changes in the C pretty printer so that the pointer type
is printed correctly.

Signed-off-by: Jaskaran Singh 
---
 parsing_c/parser_c.mly  |  4 ++--
 parsing_c/pretty_print_c.ml | 12 
 2 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/parsing_c/parser_c.mly b/parsing_c/parser_c.mly
index 8d7b761e..4c74f15a 100644
--- a/parsing_c/parser_c.mly
+++ b/parsing_c/parser_c.mly
@@ -1333,14 +1333,14 @@ pointer:
  | tmul   { (Ast_c.noattr,fun x -> mk_ty (Pointer x) [$1]) }
  | tmul pointer
  { let (attr,ptr) = $2 in
-   (attr,fun x -> mk_ty (Pointer (ptr x)) [$1]) }
+   (attr,fun x -> ptr (mk_ty (Pointer x) [$1])) }
  | tmul type_qualif_list
  { let (attr,tq) = $2 in
(attr,fun x -> (tq.qualifD, mk_tybis (Pointer x) [$1]))}
  | tmul type_qualif_list pointer
  { let (attr1,tq) = $2 in
let (attr2,ptr) = $3 in
-   (attr1@attr2,fun x -> (tq.qualifD, mk_tybis (Pointer (ptr x)) [$1])) }
+   (attr1@attr2,fun x -> ptr (tq.qualifD, mk_tybis (Pointer x) [$1])) }
 
 tmul:
TMul { $1 }
diff --git a/parsing_c/pretty_print_c.ml b/parsing_c/pretty_print_c.ml
index a2e35588..ae02b513 100644
--- a/parsing_c/pretty_print_c.ml
+++ b/parsing_c/pretty_print_c.ml
@@ -804,11 +804,13 @@ and pp_string_format (e,ii) =
  (FunctionType (return=void, params=int i) *)
   (*WRONG I THINK, use left & right function *)
   (* bug: pp_type_with_ident_rest None t;  print_ident ident *)
+  pp_type_left t;
   pr_elem i;
-  iiqu +> List.iter pr_elem; (* le const est forcement apres le '*' *)
+  iiqu +> List.iter (function x ->
+ (pr_space(); pr_elem x));(* le const est forcement apres le '*' *)
   if iiqu <> [] || get_comments_after i <> []
   then pr_space();
-  pp_type_with_ident_rest ident t attrs Ast_c.noattr;
+  print_ident ident
 
   (* ugly special case ... todo? maybe sufficient in practice *)
   | (ParenType ttop, [i1;i2]) ->
@@ -885,11 +887,13 @@ and pp_string_format (e,ii) =
   match ty, iity with
(NoType,_) -> failwith "pp_type_left: unexpected NoType"
   | (Pointer t, [i]) ->
+  pp_type_left t;
   pr_elem i;
-  iiqu +> List.iter pr_elem; (* le const est forcement apres le '*' *)
+  iiqu +> List.iter (function x ->
+ (pr_space(); pr_elem x));(* le const est forcement apres le '*' *)
   if iiqu <> [] || get_comments_after i <> []
   then pr_space();
-  pp_type_left t
+  ()
 
   | (Array (eopt, t), [i1;i2]) -> pp_type_left t
   | (FunctionType (returnt, paramst), [i1;i2]) -> pp_type_left returnt
-- 
2.21.1

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


[Cocci] [PATCH v3 0/3] cocci: Align the C AST and Cocci AST for pointer

2020-02-09 Thread Jaskaran Singh
This series is to address the type matching problem in Coccinelle.

Patch 1/3 is for aligning the C and Cocci AST so that
pointer to const pointer and its variants can be matched.

Patch 2/3 reflects the pretty printing changes made in 
1/3 in the ptrconstptr test case. A space is added between
the * and const.

Patch 3/3 consists of a test case for matching a pointer to
const pointer and its variants.

Changes in v3:
--
- Add a space between the * and qualifier in Patch 1/3.
- Add Patch 2/3 to add a space between * and const in the test
  case ptrconstptr.

Changes in v2:
--
- Change body and subject of Patch 2/2 as per suggestion of Markus
  Elfring.

[PATCH v3 1/3] parsing_c: Align C AST and Cocci AST for pointer
[PATCH v3 2/3] tests: Add space between * and const in
[PATCH v3 3/3] tests: Add test case to match const pointer variants

 parsing_c/parser_c.mly  |4 ++--
 parsing_c/pretty_print_c.ml |   12 
 tests/constptr.c|7 +++
 tests/constptr.cocci|   19 +++
 tests/constptr.res  |7 +++
 tests/ptrconstptr.res   |2 +-
 6 files changed, 44 insertions(+), 7 deletions(-)

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


Re: [Cocci] [v2 1/2] parsing_c: Align C AST and Coccinelle AST for pointers

2020-02-09 Thread Markus Elfring
>> https://en.wikipedia.org/wiki/AST
>
> Not necessary.  Anyone who is looking at the Coccinelle commits should
> know what an AST is.

I would appreciate to reduce the potential for confusion around
the application of parsing technologies.

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


Re: [Cocci] [PATCH v2 1/2] parsing_c: Align C AST and Coccinelle AST for pointers

2020-02-09 Thread Julia Lawall
On Sun, 9 Feb 2020, Markus Elfring wrote:

> > For a pointer, the C parser constructed an AST dissimilar from that
>
> I find it helpful to mention the meaning of the term “AST” without 
> abbreviation
> for a nicer patch description.
> https://en.wikipedia.org/wiki/AST

Not necessary.  Anyone who is looking at the Coccinelle commits should
know what an AST is.

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


Re: [Cocci] [PATCH v2 1/2] parsing_c: Align C AST and Coccinelle AST for pointers

2020-02-09 Thread Markus Elfring
> For a pointer, the C parser constructed an AST dissimilar from that

I find it helpful to mention the meaning of the term “AST” without abbreviation
for a nicer patch description.
https://en.wikipedia.org/wiki/AST

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


Re: [Cocci] [v2 1/2] parsing_c: Align C AST and Coccinelle AST for pointers

2020-02-09 Thread Markus Elfring
> + const char *const *y;
>  }
>
> There should be a space between * and const on the + line.

Will such a detail become more interesting for the clarification
around coding styles?
https://github.com/coccinelle/coccinelle/issues/37

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


Re: [Cocci] [v2 0/2] Align the C AST and Coccinelle AST for pointers

2020-02-09 Thread Julia Lawall
On Sun, 9 Feb 2020, Markus Elfring wrote:

> > Like what?
>
> Do find my corresponding previous suggestion reasonable?
> https://lore.kernel.org/cocci/702596c2-84bf-13ca-b014-8784bbb98...@web.de/
> https://systeme.lip6.fr/pipermail/cocci/2020-February/006842.html

I have absolutely no preference either way.

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


Re: [Cocci] [v2 0/2] Align the C AST and Coccinelle AST for pointers

2020-02-09 Thread Markus Elfring
> Like what?

Do find my corresponding previous suggestion reasonable?
https://lore.kernel.org/cocci/702596c2-84bf-13ca-b014-8784bbb98...@web.de/
https://systeme.lip6.fr/pipermail/cocci/2020-February/006842.html

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


Re: [Cocci] [PATCH v2 0/2] Align the C AST and Coccinelle AST for pointers

2020-02-09 Thread Julia Lawall
On Sun, 9 Feb 2020, Markus Elfring wrote:

> > This series is to address …
>
> Under which circumstances would you choose an adjusted wording for the message
> in the cover letter?

Like what?

If you are referring to something that occurs 5 lines below what you have
quoted, please include the specific part that poses a problem.

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


Re: [Cocci] [PATCH v2 0/2] Align the C AST and Coccinelle AST for pointers

2020-02-09 Thread Markus Elfring
> This series is to address …

Under which circumstances would you choose an adjusted wording for the message
in the cover letter?

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


Re: [Cocci] [PATCH v2 2/2] tests: Add test case to match const pointer variants

2020-02-09 Thread Julia Lawall
On Sun, 9 Feb 2020, Jaskaran Singh wrote:

> On Sun, 2020-02-09 at 08:20 +0100, Julia Lawall wrote:
> > On Fri, 7 Feb 2020, Jaskaran Singh wrote:
> >
> > > Pointer to const pointer and its variants would not match
> > > previously.
> > > Add a test case for matching these types.
> >
> > I don't get any matches for this test.  If I split the semantic patch
> > into
> > four separate rules, then I get the change for id2 and id4, but not
> > for
> > the other two.
> >
>
> That's weird, it works fine for me. I get this on both bytecode and
> native builds.

OK, you're right, it's OK.

Can you fix the *const problem?  I still see that one.

thanks,
julia

>
> --- tests/constptr.c
> +++ /tmp/cocci-output-31326-084eed-constptr.c
> @@ -1,7 +1,7 @@
>  int main()
>  {
> - const char * const * id;
> - const char * * const * id;
> - const char * const * * id;
> - const char * const id;
> + const char * const * id1;
> + const char * * const * id2;
> + const char * const * * id3;
> + const char * const id4;
>  }
>
>
> On the other hand, I get the id2 and id4 result with upstream.
>
> --- tests/constptr.c
> +++ /tmp/cocci-output-5387-a9b63b-constptr.c
> @@ -1,7 +1,7 @@
>  int main()
>  {
>   const char * const * id;
> - const char * * const * id;
> + const char * * const * id2;
>   const char * const * * id;
> - const char * const id;
> + const char * const id4;
>  }
>
> Could you check if you've applied 1/2 first?
>
> Cheers,
> Jaskaran.
>
> > julia
> >
> > > Signed-off-by: Jaskaran Singh 
> > > ---
> > >  tests/constptr.c |  7 +++
> > >  tests/constptr.cocci | 19 +++
> > >  tests/constptr.res   |  7 +++
> > >  3 files changed, 33 insertions(+)
> > >  create mode 100644 tests/constptr.c
> > >  create mode 100644 tests/constptr.cocci
> > >  create mode 100644 tests/constptr.res
> > >
> > > diff --git a/tests/constptr.c b/tests/constptr.c
> > > new file mode 100644
> > > index ..13fe064c
> > > --- /dev/null
> > > +++ b/tests/constptr.c
> > > @@ -0,0 +1,7 @@
> > > +int main()
> > > +{
> > > + const char * const * id;
> > > + const char * * const * id;
> > > + const char * const * * id;
> > > + const char * const id;
> > > +}
> > > diff --git a/tests/constptr.cocci b/tests/constptr.cocci
> > > new file mode 100644
> > > index ..29f0aa96
> > > --- /dev/null
> > > +++ b/tests/constptr.cocci
> > > @@ -0,0 +1,19 @@
> > > +@ r0 @
> > > +identifier id;
> > > +@@
> > > +const char * const *
> > > +- id
> > > ++ id1
> > > +;
> > > +const char * * const *
> > > +- id
> > > ++ id2
> > > +;
> > > +const char * const * *
> > > +- id
> > > ++ id3
> > > +;
> > > +const char * const
> > > +- id
> > > ++ id4
> > > +;
> > > diff --git a/tests/constptr.res b/tests/constptr.res
> > > new file mode 100644
> > > index ..0af4de9a
> > > --- /dev/null
> > > +++ b/tests/constptr.res
> > > @@ -0,0 +1,7 @@
> > > +int main()
> > > +{
> > > + const char * const * id1;
> > > + const char * * const * id2;
> > > + const char * const * * id3;
> > > + const char * const id4;
> > > +}
> > > --
> > > 2.21.1
> > >
> > >
>
>
___
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci