Re: [Cocci] [PATCH v2 0/3] parsing_c: Optimize recursive header file parsing

2020-09-10 Thread Jaskaran Singh
On Thu, 2020-09-10 at 11:47 +0530, Jaskaran Singh wrote:
> This patch series aims to optimize performance for recursively
> parsing
> header files in Coccinelle.
> 
> Coccinelle's C parsing subsystem has an option called --recursive-
> includes
> to recursively parse header files. This is used for type
> inference/annotation.
> 
> Previously, using --recursive-includes on the entire Linux kernel
> source
> code would take far too long. On my computer with the following
> specs,
>   - Processor: AMD Ryzen 5 3550H
>   - RAM: 8 GB
> it would take close to 7 hours to complete.  The optimization that
> this
> patch series implements reduces that time to 1 hour.
> 
> The following is a high-level description of what has been
> implemented:
> - As header files are recursively parsed, they are scanned for the
>   following:
>   - fields of structs/unions/enums
>   - typedefs
>   - function prototypes
>   - global variables
>   The names of the above are stored in a "name cache", i.e. a
> hashtable to
>   map the name to the files it is declared in.
> - A dependency graph is built to determine dependencies between all
> the
>   files in the codebase.
> - In the type annotation phase of the C subsystem, if a function
> call,
>   struct/union field or identifier is encountered, the type of which
> is
>   not known to the annoter, the name cache is checked for the name.
> - The name cache gives a list of files that the name is
> declared/defined
>   in.  These files are cross checked with the dependency graph to
>   determine if any of these are reachable by the file that the
> annoter is
>   working on.
> - If a reachable header file is found, that file is parsed and the
> type
>   associated to the name is returned.
> 
> Different approaches that were attempted to alleviate this issue, and
> the
> problems with each are as follows:
> - Caching the most recently used files: A LRU cache to store ASTs of
> the
>   most recently encountered header files. The problem with this
> approach
>   is the amount of memory it takes to cache the header file ASTs.
> - Caching the most troublesome files: A pseudo-LFU cache to store
> files
>   that cumulatively take the longest to parse, and thus bloat the
> time
>   taken. The problem with this approach is the amount of memory it
> takes
>   to cache the header file ASTs.
> - Skipping unparsable locations in header files: Skipping top-level
> items
>   in a header file that cannot be parsed. This approach does not
> produce
>   even close to the amount of optimization needed.
> 
> The next step from here would be:
> - Maintain a small but persistent cache of header files in groups of
>   directories. Leverage multiprocessing for parsing these header
> files.
> - Leverage multiprocessing to parse header files initially for name
>   extraction.
> - Performing some initial matching with the semantic patch to
> determine if
>   a C file matches. If matches are found, call the annoter and
> recursively
>   parse header files for type annotation.
> - Recursively parse all header files only once and build a large type
>   environment. Use the dependency graph to determine reachability.
> This
>   has potential memory usage issues though.
> 
> 
> Changes in v2:
> --
> - Change occurences of 'begin' and 'match' on the same line with
> something else
>   to the next line for better readability.
> 
> 
>  Makefile |2 
>  parsing_c/includes_cache.ml  |  286
> +++
>  parsing_c/includes_cache.mli |   47 +++
>  parsing_c/parse_c.ml |   27 +++-
>  parsing_c/type_annoter_c.ml  |  130 ---
>  5 files changed, 466 insertions(+), 26 deletions(-)
> 

Yikes, the diffstat is the old one. Here's the latest (not very
different)

 Makefile |2 
 parsing_c/includes_cache.ml  |  290
+++
 parsing_c/includes_cache.mli |   47 ++
 parsing_c/parse_c.ml |   28 +++-
 parsing_c/type_annoter_c.ml  |  134 +--
 5 files changed, 475 insertions(+), 26 deletions(-)


> 

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


[Cocci] [PATCH v2 0/3] parsing_c: Optimize recursive header file parsing

2020-09-10 Thread Jaskaran Singh
This patch series aims to optimize performance for recursively parsing
header files in Coccinelle.

Coccinelle's C parsing subsystem has an option called --recursive-includes
to recursively parse header files. This is used for type
inference/annotation.

Previously, using --recursive-includes on the entire Linux kernel source
code would take far too long. On my computer with the following specs,
- Processor: AMD Ryzen 5 3550H
- RAM: 8 GB
it would take close to 7 hours to complete.  The optimization that this
patch series implements reduces that time to 1 hour.

The following is a high-level description of what has been implemented:
- As header files are recursively parsed, they are scanned for the
  following:
- fields of structs/unions/enums
- typedefs
- function prototypes
- global variables
  The names of the above are stored in a "name cache", i.e. a hashtable to
  map the name to the files it is declared in.
- A dependency graph is built to determine dependencies between all the
  files in the codebase.
- In the type annotation phase of the C subsystem, if a function call,
  struct/union field or identifier is encountered, the type of which is
  not known to the annoter, the name cache is checked for the name.
- The name cache gives a list of files that the name is declared/defined
  in.  These files are cross checked with the dependency graph to
  determine if any of these are reachable by the file that the annoter is
  working on.
- If a reachable header file is found, that file is parsed and the type
  associated to the name is returned.

Different approaches that were attempted to alleviate this issue, and the
problems with each are as follows:
- Caching the most recently used files: A LRU cache to store ASTs of the
  most recently encountered header files. The problem with this approach
  is the amount of memory it takes to cache the header file ASTs.
- Caching the most troublesome files: A pseudo-LFU cache to store files
  that cumulatively take the longest to parse, and thus bloat the time
  taken. The problem with this approach is the amount of memory it takes
  to cache the header file ASTs.
- Skipping unparsable locations in header files: Skipping top-level items
  in a header file that cannot be parsed. This approach does not produce
  even close to the amount of optimization needed.

The next step from here would be:
- Maintain a small but persistent cache of header files in groups of
  directories. Leverage multiprocessing for parsing these header files.
- Leverage multiprocessing to parse header files initially for name
  extraction.
- Performing some initial matching with the semantic patch to determine if
  a C file matches. If matches are found, call the annoter and recursively
  parse header files for type annotation.
- Recursively parse all header files only once and build a large type
  environment. Use the dependency graph to determine reachability. This
  has potential memory usage issues though.


Changes in v2:
--
- Change occurences of 'begin' and 'match' on the same line with something else
  to the next line for better readability.


 Makefile |2 
 parsing_c/includes_cache.ml  |  286 +++
 parsing_c/includes_cache.mli |   47 +++
 parsing_c/parse_c.ml |   27 +++-
 parsing_c/type_annoter_c.ml  |  130 ---
 5 files changed, 466 insertions(+), 26 deletions(-)


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


[Cocci] [PATCH v2 2/3] parsing_c: parse_c: Build name cache and includes dependency graph

2020-09-10 Thread Jaskaran Singh
Build the includes dependency graph and name cache while parsing header
files. Every header file is parsed only once for name caching and, while
parsing these files, an includes dependency graph is built to determine
reachability of one header file from another file.

Signed-off-by: Jaskaran Singh 
---
 parsing_c/parse_c.ml | 28 ++--
 1 file changed, 22 insertions(+), 6 deletions(-)

diff --git a/parsing_c/parse_c.ml b/parsing_c/parse_c.ml
index 5574cb11b..ef5870123 100644
--- a/parsing_c/parse_c.ml
+++ b/parsing_c/parse_c.ml
@@ -17,6 +17,7 @@ open Common
 
 module TH = Token_helpers
 module LP = Lexer_parser
+module IC = Includes_cache
 
 module Stat = Parsing_stat
 
@@ -995,15 +996,30 @@ let rec _parse_print_error_heuristic2 saved_typedefs 
saved_macros
 and handle_include file wrapped_incl k =
 let incl = Ast_c.unwrap wrapped_incl.Ast_c.i_include in
 let parsing_style = Includes.get_parsing_style () in
+let f = Includes.resolve file parsing_style incl in
 if Includes.should_parse parsing_style file incl
 then
-  match Includes.resolve file parsing_style incl with
+  match f with
   | Some header_filename when Common.lfile_exists header_filename ->
- (if !Flag_parsing_c.verbose_includes
- then pr2 ("including "^header_filename));
- let nonlocal =
-   match incl with Ast_c.NonLocal _ -> true | _ -> false in
-  ignore (k nonlocal header_filename)
+  if not (IC.has_been_parsed header_filename)
+  then
+begin
+  IC.add_to_parsed_files header_filename;
+  (if !Flag_parsing_c.verbose_includes
+  then pr2 ("including "^header_filename));
+  let nonlocal =
+match incl with Ast_c.NonLocal _ -> true | _ -> false in
+  let res = k nonlocal header_filename in
+  match res with
+None -> ()
+  | Some x ->
+  let pt = x.parse_trees in
+  let (p, _, _) = pt in
+  with_program2_unit
+(IC.extract_names header_filename)
+p
+end;
+  IC.add_to_dependency_graph file header_filename;
   | _ -> ()
 
 and _parse_print_error_heuristic2bis saved_typedefs saved_macros
-- 
2.21.3

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


[Cocci] [PATCH v2 1/3] parsing_c: includes_cache: Implement a name cache

2020-09-10 Thread Jaskaran Singh
Implement a name cache and includes dependency graph to optimize
performance for recursive parsing of header files.

The following is a high-level description of what has been implemented:
- As header files are recursively parsed, they are scanned for the
  following:
- fields of structs/unions/enums
- typedefs
- function prototypes
- global variables
  The names of the above are stored in a "name cache", i.e. a hashtable
  to map the name to the files it is declared in.
- A dependency graph is built to determine dependencies between all the
  files in the codebase.
- In the type annotation phase of the C subsystem, if a function call,
  struct/union field or identifier is encountered, the type of which is
  not known to the annoter, the name cache is checked for the name.
- The name cache gives a list of files that the name is declared/defined
  in.  These files are cross checked with the dependency graph to
  determine if any of these are reachable by the file that the annoter is
  working on.
- If a reachable header file is found, that file is parsed and all of
  the above listed constructs are extracted from it.

Suggested-by: Julia Lawall 
Signed-off-by: Jaskaran Singh 
---
 Makefile |   2 +-
 parsing_c/includes_cache.ml  | 290 +++
 parsing_c/includes_cache.mli |  47 ++
 3 files changed, 338 insertions(+), 1 deletion(-)
 create mode 100644 parsing_c/includes_cache.ml
 create mode 100644 parsing_c/includes_cache.mli

diff --git a/Makefile b/Makefile
index e25174413..f8d3424c0 100644
--- a/Makefile
+++ b/Makefile
@@ -50,7 +50,7 @@ SOURCES_parsing_cocci := \
 SOURCES_parsing_c := \
token_annot.ml flag_parsing_c.ml parsing_stat.ml \
token_c.ml ast_c.ml includes.ml control_flow_c.ml \
-   visitor_c.ml lib_parsing_c.ml control_flow_c_build.ml \
+   visitor_c.ml lib_parsing_c.ml includes_cache.ml control_flow_c_build.ml 
\
pretty_print_c.ml semantic_c.ml lexer_parser.ml parser_c.mly \
lexer_c.mll parse_string_c.ml token_helpers.ml token_views_c.ml \
cpp_token_c.ml parsing_hacks.ml cpp_analysis_c.ml \
diff --git a/parsing_c/includes_cache.ml b/parsing_c/includes_cache.ml
new file mode 100644
index 0..ca5c91822
--- /dev/null
+++ b/parsing_c/includes_cache.ml
@@ -0,0 +1,290 @@
+(*
+ * This file is part of Coccinelle, licensed under the terms of the GPL v2.
+ * See copyright.txt in the Coccinelle source code for more information.
+ * The Coccinelle source code can be obtained at http://coccinelle.lip6.fr
+ *)
+
+open Common
+module Lib = Lib_parsing_c
+
+(*)
+(* Wrappers *)
+(*)
+let pr_inc s =
+  if !Flag_parsing_c.verbose_includes
+  then Common.pr2 s
+
+(*)
+(* Graph types/modules *)
+(*)
+
+(* Filenames as keys to check paths from file A to file B. *)
+module Key : Set.OrderedType with type t = Common.filename = struct
+  type t = Common.filename
+  let compare = String.compare
+end
+
+module KeySet = Set.Make (Key)
+
+module KeyMap = Map.Make (Key)
+
+module Node : Set.OrderedType with type t = unit = struct
+  type t = unit
+  let compare = compare
+end
+
+module Edge : Set.OrderedType with type t = unit = struct
+  type t = unit
+  let compare = compare
+end
+
+module KeyEdgePair : Set.OrderedType with type t = Key.t * Edge.t =
+struct
+  type t = Key.t * Edge.t
+  let compare = compare
+end
+
+module KeyEdgeSet = Set.Make (KeyEdgePair)
+
+module G = Ograph_simple.Make
+  (Key) (KeySet) (KeyMap) (Node) (Edge) (KeyEdgePair) (KeyEdgeSet)
+
+
+(*)
+(* Includes dependency graph *)
+(*)
+
+(* Header file includes dependency graph *)
+let dependency_graph = ref (new G.ograph_mutable)
+
+(* Check if a path exists between one node to another.
+ * Almost a copy of dfs_iter in commons/ograph_extended.ml with minor changes.
+ * Return true if g satisfies predicate f else false
+ *)
+let dfs_exists xi f g =
+  let already = Hashtbl.create 101 in
+  let rec aux_dfs xs =
+let h xi =
+  if Hashtbl.mem already xi
+  then false
+  else
+begin
+  Hashtbl.add already xi true;
+  if f xi
+  then true
+  else
+begin
+  let f' (key, _) keyset = KeySet.add key keyset in
+  let newset =
+try KeyEdgeSet.fold f' (g#successors xi) KeySet.empty
+with Not_found -> KeySet.empty in
+  aux_dfs newset
+end
+end in
+KeySet.exists h xs in
+  aux_dfs (KeySet.singlet

[Cocci] [PATCH v2 3/3] parsing_c: type_annoter_c: Use name cache for type annotation

2020-09-10 Thread Jaskaran Singh
Use the name cache for type annotation. On encountering the following
which are not stored in the environment, the name cache is looked up and
the relevant header file is parsed for type information:
- struct field use
- typedef
- function call
- identifier
- enumeration constant

Signed-off-by: Jaskaran Singh 
---
 parsing_c/type_annoter_c.ml | 134 +++-
 1 file changed, 115 insertions(+), 19 deletions(-)

diff --git a/parsing_c/type_annoter_c.ml b/parsing_c/type_annoter_c.ml
index 25cb6c0ee..49fd060be 100644
--- a/parsing_c/type_annoter_c.ml
+++ b/parsing_c/type_annoter_c.ml
@@ -19,6 +19,7 @@ open Common
 open Ast_c
 
 module Lib = Lib_parsing_c
+module IC = Includes_cache
 
 (*)
 (* Prelude *)
@@ -186,6 +187,13 @@ type nameenv = {
 
 type environment = nameenv list
 
+let includes_parse_fn file =
+  let choose_includes = Includes.get_parsing_style () in
+  Includes.set_parsing_style Includes.Parse_no_includes;
+  let ret = Parse_c.parse_c_and_cpp false false file in
+  Includes.set_parsing_style choose_includes;
+  List.map fst (fst ret)
+
 (*  *)
 (* can be modified by the init_env function below, by
  * the file environment_unix.h
@@ -294,6 +302,39 @@ let member_env_lookup_enum s env =
   | [] -> false
   | env :: _ -> StringMap.mem s env.enum_constant
 
+(*  *)
+
+let add_cache_binding_in_scope namedef =
+  let (current, older) = Common.uncons !_scoped_env in
+  let new_frame fr =
+match namedef with
+  | IC.RetVarOrFunc (s, typ) ->
+ {fr with
+  var_or_func = StringMap.add s typ fr.var_or_func}
+  | IC.RetTypeDef   (s, typ) ->
+ let cv = typ, fr.typedef, fr.level in
+ let new_typedef_c : typedefs = { defs = StringMap.add s cv 
fr.typedef.defs } in
+ {fr with typedef = new_typedef_c}
+  | IC.RetStructUnionNameDef (s, (su, typ)) ->
+ {fr with
+  struct_union_name_def = StringMap.add s (su, typ) 
fr.struct_union_name_def}
+  | IC.RetEnumConstant (s, body) ->
+ {fr with
+  enum_constant = StringMap.add s body fr.enum_constant} in
+  (* These are global, so have to reflect them in all the frames. *)
+  _scoped_env := (new_frame current)::(List.map new_frame older)
+
+(* Has side-effects on the environment.
+ * TODO: profile? *)
+let get_type_from_includes_cache file name exp_types on_success on_failure =
+  let file_bindings =
+IC.get_types_from_name_cache
+  file name exp_types includes_parse_fn in
+  List.iter add_cache_binding_in_scope file_bindings;
+  match file_bindings with
+[] -> on_failure ()
+  | _ -> on_success ()
+
 
 (*)
 (* "type-lookup"  *)
@@ -394,7 +435,14 @@ let rec type_unfold_one_step ty env =
  then type_unfold_one_step t' env'
   else loop (s::seen) t' env
with Not_found ->
-  ty
+  let f = Ast_c.file_of_info (Ast_c.info_of_name name) in
+  get_type_from_includes_cache
+f s [IC.CacheTypedef]
+(fun () ->
+  let (t', env') = lookup_typedef s !_scoped_env in
+  TypeName (name, Some t') +>
+  Ast_c.rewrap_typeC ty)
+(fun () -> ty)
   )
 
   | FieldType (t, _, _) -> type_unfold_one_step t env
@@ -474,7 +522,15 @@ let rec typedef_fix ty env =
  TypeName (name, Some fixed) +>
  Ast_c.rewrap_typeC ty
 with Not_found ->
-  ty))
+  let f = Ast_c.file_of_info (Ast_c.info_of_name name) in
+  get_type_from_includes_cache
+f s [IC.CacheTypedef]
+(fun () ->
+   let (t', env') = lookup_typedef s !_scoped_env in
+   TypeName (name, Some t') +>
+   Ast_c.rewrap_typeC ty)
+(fun () -> ty)
+  ))
 
 | FieldType (t, a, b) ->
FieldType (typedef_fix t env, a, b) +> Ast_c.rewrap_typeC ty
@@ -797,8 +853,16 @@ let annotater_expr_visitor_subpart = (fun (k,bigf) expr ->
 Type_c.noTypeHere
 )
 | None ->
-pr2_once ("type_annotater: no type for function ident: " ^ s);
-Type_c.noTypeHere
+let f =
+  Ast_c.file_of_info
+(Ast_c.info_of_name ident) in
+get_type_from_includes_cache
+  f s [IC.CacheVarFunc]
+  (fun () ->
+ match lookup_opt_env lookup_var s with
+   Some (typ, local) -> make_info_fix (typ, local)
+ | None -> Type_c.noTypeHere)

Re: [Cocci] [RFC PATCH 1/3] parsing_c: includes_cache: Implement a name cache

2020-09-09 Thread Jaskaran Singh
On Wed, 2020-09-09 at 22:05 +0200, Markus Elfring wrote:
> > Implement a name cache and includes dependency graph to optimize
> > performance for recursive parsing of header files.
> 
> Can such information trigger any more evolution besides the
> contributed
> OCaml source code?
> 
> 
> >   The names of the above are stored in a "name cache", i.e. a
> > hashtable
> >   to map the name to the files it is declared in.
> 
> How much does hashing matter here?
> 

It's a hash table. I don't know how OCaml's Hashtbl works under the
hood.

> 
> > - A dependency graph is built to determine dependencies between all
> > the
> >  files in the codebase.
> 
> Can such information indicate a need for its own programming
> interface?
> 

If you mean graphs, there are entire modules for them in Coccinelle.
(commons/ograph_*.ml).

> 
> > - In the type annotation phase of the C subsystem, if a function
> > call,
> >   struct/union field or identifier is encountered, the type of
> > which is
> >   not known to the annoter, the name cache is checked for the name.
> 
> Is there anything in common with symbol tables?
> 

Kind of.

Cheers,
Jaskaran.

> Regards,
> Markus

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


Re: [Cocci] [RFC PATCH 2/3] parsing_c: parse_c: Build name cache and includes dependency graph

2020-09-09 Thread Jaskaran Singh
On Wed, 2020-09-09 at 21:41 +0200, Julia Lawall wrote:
> 
> On Wed, 9 Sep 2020, Jaskaran Singh wrote:
> 
> > Build the includes dependency graph and name cache while parsing
> > header
> > files. Every header file is parsed only once for name caching and,
> > while
> > parsing these files, an includes dependency graph is built to
> > determine
> > reachability of one header file from another file.
> 
> So you really parse the whole file here?  

Yes.

> Could you avoid that? 

Well, we need the AST for name caching. I guess we could lazily parse
these on demand and do the name caching in the type annoter. But I'm
not sure how much of a difference that would make, it'd probably end up
parsing about 80% of those branches anyway.

>  Is it
> that you need to parse something to find the end of it?
> 

We need everything from it, i.e. struct fields, enumeration constants,
function prototypes, etc. as well as the #includes in it.

Cheers,
Jaskaran.

> julia
> 
> > Signed-off-by: Jaskaran Singh 
> > ---
> >  parsing_c/parse_c.ml | 27 +--
> >  1 file changed, 21 insertions(+), 6 deletions(-)
> > 
> > diff --git a/parsing_c/parse_c.ml b/parsing_c/parse_c.ml
> > index 5574cb11b..3b250720f 100644
> > --- a/parsing_c/parse_c.ml
> > +++ b/parsing_c/parse_c.ml
> > @@ -17,6 +17,7 @@ open Common
> > 
> >  module TH = Token_helpers
> >  module LP = Lexer_parser
> > +module IC = Includes_cache
> > 
> >  module Stat = Parsing_stat
> > 
> > @@ -995,15 +996,29 @@ let rec _parse_print_error_heuristic2
> > saved_typedefs saved_macros
> >  and handle_include file wrapped_incl k =
> >  let incl = Ast_c.unwrap wrapped_incl.Ast_c.i_include in
> >  let parsing_style = Includes.get_parsing_style () in
> > +let f = Includes.resolve file parsing_style incl in
> >  if Includes.should_parse parsing_style file incl
> >  then
> > -  match Includes.resolve file parsing_style incl with
> > +  match f with
> >| Some header_filename when Common.lfile_exists
> > header_filename ->
> > - (if !Flag_parsing_c.verbose_includes
> > - then pr2 ("including "^header_filename));
> > - let nonlocal =
> > -   match incl with Ast_c.NonLocal _ -> true | _ -> false in
> > -  ignore (k nonlocal header_filename)
> > +  if not (IC.has_been_parsed header_filename)
> > +  then begin
> > +IC.add_to_parsed_files header_filename;
> > +   (if !Flag_parsing_c.verbose_includes
> > +   then pr2 ("including "^header_filename));
> > +   let nonlocal =
> > + match incl with Ast_c.NonLocal _ -> true | _ -> false in
> > +let res = k nonlocal header_filename in
> > +match res with
> > +  None -> ()
> > +| Some x ->
> > +let pt = x.parse_trees in
> > +let (p, _, _) = pt in
> > +with_program2_unit
> > +  (IC.extract_names header_filename)
> > +  p
> > +  end;
> > +  IC.add_to_dependency_graph file header_filename;
> >| _ -> ()
> > 
> >  and _parse_print_error_heuristic2bis saved_typedefs saved_macros
> > --
> > 2.21.3
> > 
> > 

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


[Cocci] [RFC PATCH 0/3] parsing_c: Optimize recursive header file parsing

2020-09-09 Thread Jaskaran Singh
This patch series aims to optimize performance for recursively parsing
header files in Coccinelle.

Coccinelle's C parsing subsystem has an option called --recursive-includes
to recursively parse header files. This is used for type
inference/annotation.

Previously, using --recursive-includes on the entire Linux kernel source
code would take far too long. On my computer with the following specs,
- Processor: AMD Ryzen 5 3550H
- RAM: 8 GB
it would take close to 7 hours to complete.  The optimization that this
patch series implements reduces that time to 1 hour.

The following is a high-level description of what has been implemented:
- As header files are recursively parsed, they are scanned for the
  following:
- fields of structs/unions/enums
- typedefs
- function prototypes
- global variables
  The names of the above are stored in a "name cache", i.e. a hashtable to
  map the name to the files it is declared in.
- A dependency graph is built to determine dependencies between all the
  files in the codebase.
- In the type annotation phase of the C subsystem, if a function call,
  struct/union field or identifier is encountered, the type of which is
  not known to the annoter, the name cache is checked for the name.
- The name cache gives a list of files that the name is declared/defined
  in.  These files are cross checked with the dependency graph to
  determine if any of these are reachable by the file that the annoter is
  working on.
- If a reachable header file is found, that file is parsed and the type
  associated to the name is returned.

Different approaches that were attempted to alleviate this issue, and the
problems with each are as follows:
- Caching the most recently used files: A LRU cache to store ASTs of the
  most recently encountered header files. The problem with this approach
  is the amount of memory it takes to cache the header file ASTs.
- Caching the most troublesome files: A pseudo-LFU cache to store files
  that cumulatively take the longest to parse, and thus bloat the time
  taken. The problem with this approach is the amount of memory it takes
  to cache the header file ASTs.
- Skipping unparsable locations in header files: Skipping top-level items
  in a header file that cannot be parsed. This approach does not produce
  even close to the amount of optimization needed.

The next step from here would be:
- Maintain a small but persistent cache of header files in groups of
  directories. Leverage multiprocessing for parsing these header files.
- Leverage multiprocessing to parse header files initially for name
  extraction.
- Performing some initial matching with the semantic patch to determine if
  a C file matches. If matches are found, call the annoter and recursively
  parse header files for type annotation.
- Recursively parse all header files only once and build a large type
  environment. Use the dependency graph to determine reachability. This
  has potential memory usage issues though.


 Makefile |2 
 parsing_c/includes_cache.ml  |  286 +++
 parsing_c/includes_cache.mli |   47 +++
 parsing_c/parse_c.ml |   27 +++-
 parsing_c/type_annoter_c.ml  |  130 ---
 5 files changed, 466 insertions(+), 26 deletions(-)


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


[Cocci] [RFC PATCH 3/3] parsing_c: type_annoter_c: Use name cache for type annotation

2020-09-09 Thread Jaskaran Singh
Use the name cache for type annotation. On encountering the following
which are not stored in the environment, the name cache is looked up and
the relevant header file is parsed for type information:
- struct field use
- typedef
- function call
- identifier
- enumeration constant

Signed-off-by: Jaskaran Singh 
---
 parsing_c/type_annoter_c.ml | 130 ++--
 1 file changed, 111 insertions(+), 19 deletions(-)

diff --git a/parsing_c/type_annoter_c.ml b/parsing_c/type_annoter_c.ml
index 25cb6c0ee..497332544 100644
--- a/parsing_c/type_annoter_c.ml
+++ b/parsing_c/type_annoter_c.ml
@@ -19,6 +19,7 @@ open Common
 open Ast_c
 
 module Lib = Lib_parsing_c
+module IC = Includes_cache
 
 (*)
 (* Prelude *)
@@ -186,6 +187,13 @@ type nameenv = {
 
 type environment = nameenv list
 
+let includes_parse_fn file =
+  let choose_includes = Includes.get_parsing_style () in
+  Includes.set_parsing_style Includes.Parse_no_includes;
+  let ret = Parse_c.parse_c_and_cpp false false file in
+  Includes.set_parsing_style choose_includes;
+  List.map fst (fst ret)
+
 (*  *)
 (* can be modified by the init_env function below, by
  * the file environment_unix.h
@@ -294,6 +302,39 @@ let member_env_lookup_enum s env =
   | [] -> false
   | env :: _ -> StringMap.mem s env.enum_constant
 
+(*  *)
+
+let add_cache_binding_in_scope namedef =
+  let (current, older) = Common.uncons !_scoped_env in
+  let new_frame fr =
+match namedef with
+  | IC.RetVarOrFunc (s, typ) ->
+ {fr with
+  var_or_func = StringMap.add s typ fr.var_or_func}
+  | IC.RetTypeDef   (s, typ) ->
+ let cv = typ, fr.typedef, fr.level in
+ let new_typedef_c : typedefs = { defs = StringMap.add s cv 
fr.typedef.defs } in
+ {fr with typedef = new_typedef_c}
+  | IC.RetStructUnionNameDef (s, (su, typ)) ->
+ {fr with
+  struct_union_name_def = StringMap.add s (su, typ) 
fr.struct_union_name_def}
+  | IC.RetEnumConstant (s, body) ->
+ {fr with
+  enum_constant = StringMap.add s body fr.enum_constant} in
+  (* These are global, so have to reflect them in all the frames. *)
+  _scoped_env := (new_frame current)::(List.map new_frame older)
+
+(* Has side-effects on the environment.
+ * TODO: profile? *)
+let get_type_from_includes_cache file name exp_types on_success on_failure =
+  let file_bindings =
+IC.get_types_from_name_cache
+  file name exp_types includes_parse_fn in
+  List.iter add_cache_binding_in_scope file_bindings;
+  match file_bindings with
+[] -> on_failure ()
+  | _ -> on_success ()
+
 
 (*)
 (* "type-lookup"  *)
@@ -394,7 +435,14 @@ let rec type_unfold_one_step ty env =
  then type_unfold_one_step t' env'
   else loop (s::seen) t' env
with Not_found ->
-  ty
+  let f = Ast_c.file_of_info (Ast_c.info_of_name name) in
+  get_type_from_includes_cache
+f s [IC.CacheTypedef]
+(fun () ->
+  let (t', env') = lookup_typedef s !_scoped_env in
+  TypeName (name, Some t') +>
+  Ast_c.rewrap_typeC ty)
+(fun () -> ty)
   )
 
   | FieldType (t, _, _) -> type_unfold_one_step t env
@@ -474,7 +522,15 @@ let rec typedef_fix ty env =
  TypeName (name, Some fixed) +>
  Ast_c.rewrap_typeC ty
 with Not_found ->
-  ty))
+  let f = Ast_c.file_of_info (Ast_c.info_of_name name) in
+  get_type_from_includes_cache
+f s [IC.CacheTypedef]
+(fun () ->
+  let (t', env') = lookup_typedef s !_scoped_env in
+  TypeName (name, Some t') +>
+  Ast_c.rewrap_typeC ty)
+(fun () -> ty)
+  ))
 
 | FieldType (t, a, b) ->
FieldType (typedef_fix t env, a, b) +> Ast_c.rewrap_typeC ty
@@ -797,8 +853,15 @@ let annotater_expr_visitor_subpart = (fun (k,bigf) expr ->
 Type_c.noTypeHere
 )
 | None ->
-pr2_once ("type_annotater: no type for function ident: " ^ s);
-Type_c.noTypeHere
+let f =
+  Ast_c.file_of_info
+(Ast_c.info_of_name ident) in
+get_type_from_includes_cache
+  f s [IC.CacheVarFunc]
+  (fun () -> match lookup_opt_env lookup_var s with
+Some (typ, local) -> make_info_fix (typ, local)
+  | None -> Type_c.noTypeHere)
+  

[Cocci] [RFC PATCH 1/3] parsing_c: includes_cache: Implement a name cache

2020-09-09 Thread Jaskaran Singh
Implement a name cache and includes dependency graph to optimize
performance for recursive parsing of header files.

The following is a high-level description of what has been implemented:
- As header files are recursively parsed, they are scanned for the
  following:
- fields of structs/unions/enums
- typedefs
- function prototypes
- global variables
  The names of the above are stored in a "name cache", i.e. a hashtable
  to map the name to the files it is declared in.
- A dependency graph is built to determine dependencies between all the
  files in the codebase.
- In the type annotation phase of the C subsystem, if a function call,
  struct/union field or identifier is encountered, the type of which is
  not known to the annoter, the name cache is checked for the name.
- The name cache gives a list of files that the name is declared/defined
  in.  These files are cross checked with the dependency graph to
  determine if any of these are reachable by the file that the annoter is
  working on.
- If a reachable header file is found, that file is parsed and all of
  the above listed constructs are extracted from it.

Suggested-by: Julia Lawall 
Signed-off-by: Jaskaran Singh 
---
 Makefile |   2 +-
 parsing_c/includes_cache.ml  | 286 +++
 parsing_c/includes_cache.mli |  47 ++
 3 files changed, 334 insertions(+), 1 deletion(-)
 create mode 100644 parsing_c/includes_cache.ml
 create mode 100644 parsing_c/includes_cache.mli

diff --git a/Makefile b/Makefile
index e25174413..f8d3424c0 100644
--- a/Makefile
+++ b/Makefile
@@ -50,7 +50,7 @@ SOURCES_parsing_cocci := \
 SOURCES_parsing_c := \
token_annot.ml flag_parsing_c.ml parsing_stat.ml \
token_c.ml ast_c.ml includes.ml control_flow_c.ml \
-   visitor_c.ml lib_parsing_c.ml control_flow_c_build.ml \
+   visitor_c.ml lib_parsing_c.ml includes_cache.ml control_flow_c_build.ml 
\
pretty_print_c.ml semantic_c.ml lexer_parser.ml parser_c.mly \
lexer_c.mll parse_string_c.ml token_helpers.ml token_views_c.ml \
cpp_token_c.ml parsing_hacks.ml cpp_analysis_c.ml \
diff --git a/parsing_c/includes_cache.ml b/parsing_c/includes_cache.ml
new file mode 100644
index 0..2c2cb0235
--- /dev/null
+++ b/parsing_c/includes_cache.ml
@@ -0,0 +1,286 @@
+(*
+ * This file is part of Coccinelle, licensed under the terms of the GPL v2.
+ * See copyright.txt in the Coccinelle source code for more information.
+ * The Coccinelle source code can be obtained at http://coccinelle.lip6.fr
+ *)
+
+open Common
+module Lib = Lib_parsing_c
+
+(*)
+(* Wrappers *)
+(*)
+let pr_inc s =
+  if !Flag_parsing_c.verbose_includes
+  then Common.pr2 s
+
+(*)
+(* Graph types/modules *)
+(*)
+
+(* Filenames as keys to check paths from file A to file B. *)
+module Key : Set.OrderedType with type t = Common.filename = struct
+  type t = Common.filename
+  let compare = String.compare
+end
+
+module KeySet = Set.Make (Key)
+
+module KeyMap = Map.Make (Key)
+
+module Node : Set.OrderedType with type t = unit = struct
+  type t = unit
+  let compare = compare
+end
+
+module Edge : Set.OrderedType with type t = unit = struct
+  type t = unit
+  let compare = compare
+end
+
+module KeyEdgePair : Set.OrderedType with type t = Key.t * Edge.t =
+struct
+  type t = Key.t * Edge.t
+  let compare = compare
+end
+
+module KeyEdgeSet = Set.Make (KeyEdgePair)
+
+module G = Ograph_simple.Make
+  (Key) (KeySet) (KeyMap) (Node) (Edge) (KeyEdgePair) (KeyEdgeSet)
+
+
+(*)
+(* Includes dependency graph *)
+(*)
+
+(* Header file includes dependency graph *)
+let dependency_graph = ref (new G.ograph_mutable)
+
+(* Check if a path exists between one node to another.
+ * Almost a copy of dfs_iter in commons/ograph_extended.ml with minor changes.
+ * Return true if g satisfies predicate f else false
+ *)
+let dfs_exists xi f g =
+  let already = Hashtbl.create 101 in
+  let rec aux_dfs xs =
+let h xi =
+  if Hashtbl.mem already xi
+  then false
+  else begin
+Hashtbl.add already xi true;
+if f xi
+then true
+else begin
+  let f' (key, _) keyset = KeySet.add key keyset in
+  let newset =
+try KeyEdgeSet.fold f' (g#successors xi) KeySet.empty
+with Not_found -> KeySet.empty in
+  aux_dfs newset
+end
+  end in
+KeySet.exists h xs in
+  aux_dfs (KeySet.singleton xi)
+
+let add_to_dependency_graph parent file =
+ 

[Cocci] [RFC PATCH 2/3] parsing_c: parse_c: Build name cache and includes dependency graph

2020-09-09 Thread Jaskaran Singh
Build the includes dependency graph and name cache while parsing header
files. Every header file is parsed only once for name caching and, while
parsing these files, an includes dependency graph is built to determine
reachability of one header file from another file.

Signed-off-by: Jaskaran Singh 
---
 parsing_c/parse_c.ml | 27 +--
 1 file changed, 21 insertions(+), 6 deletions(-)

diff --git a/parsing_c/parse_c.ml b/parsing_c/parse_c.ml
index 5574cb11b..3b250720f 100644
--- a/parsing_c/parse_c.ml
+++ b/parsing_c/parse_c.ml
@@ -17,6 +17,7 @@ open Common
 
 module TH = Token_helpers
 module LP = Lexer_parser
+module IC = Includes_cache
 
 module Stat = Parsing_stat
 
@@ -995,15 +996,29 @@ let rec _parse_print_error_heuristic2 saved_typedefs 
saved_macros
 and handle_include file wrapped_incl k =
 let incl = Ast_c.unwrap wrapped_incl.Ast_c.i_include in
 let parsing_style = Includes.get_parsing_style () in
+let f = Includes.resolve file parsing_style incl in
 if Includes.should_parse parsing_style file incl
 then
-  match Includes.resolve file parsing_style incl with
+  match f with
   | Some header_filename when Common.lfile_exists header_filename ->
- (if !Flag_parsing_c.verbose_includes
- then pr2 ("including "^header_filename));
- let nonlocal =
-   match incl with Ast_c.NonLocal _ -> true | _ -> false in
-  ignore (k nonlocal header_filename)
+  if not (IC.has_been_parsed header_filename)
+  then begin
+IC.add_to_parsed_files header_filename;
+   (if !Flag_parsing_c.verbose_includes
+   then pr2 ("including "^header_filename));
+   let nonlocal =
+ match incl with Ast_c.NonLocal _ -> true | _ -> false in
+let res = k nonlocal header_filename in
+match res with
+  None -> ()
+| Some x ->
+let pt = x.parse_trees in
+let (p, _, _) = pt in
+with_program2_unit
+  (IC.extract_names header_filename)
+  p
+  end;
+  IC.add_to_dependency_graph file header_filename;
   | _ -> ()
 
 and _parse_print_error_heuristic2bis saved_typedefs saved_macros
-- 
2.21.3

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


Re: [Cocci] [00/43] cocci: Add support for meta attributes to SmPL

2020-08-08 Thread Jaskaran Singh
On Sat, 2020-08-08 at 13:33 +0200, Markus Elfring wrote:
> > Probably a pretty printing mistake. I'll fix this.
> 
> How do you think about to clarify any related software dependencies?
> 

What do you mean?

> Regards,
> Markus

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


Re: [Cocci] [00/43] cocci: Add support for meta attributes to SmPL

2020-08-03 Thread Jaskaran Singh
On Mon, 2020-08-03 at 07:37 +0200, Markus Elfring wrote:
> > > Do you care if a SmPL name variable would accidentally not be
> > > used
> > > (like in the script “
> > > https://github.com/coccinelle/coccinelle/blob/04f36d537b9f6c0c127d05184cccd21f1a46b952/tests/metaattr.cocci#L2”
> > > )?
> > 
> > It actually is used, to help parsing the .c file.  This information
> > will
> > be added to the documentation shortly.
> 
> I would expect that the following SmPL script variant will generate
> also a patch.
> (Why would extra “help” be needed for parsing source files?)
> 
> @replacement@
> attribute a;
> identifier b;
> @@
> -int
> +char
>  b a = 1;
> 
> 
> By the way:
> I have noticed another detail which I find questionable at the
> moment.
> 
> elfring@Sonne:~/Projekte/Coccinelle/20160205> spatch --parse-cocci
> tests/metaattr-2.cocci
> …
> (
> -int
>   >>> char
>  b a = 1;
> -signed
>   >>> char
> -int b a = 1;
> )
> …
> 

Probably a pretty printing mistake. I'll fix this.

Thanks,
Jaskaran.

> I would interpret the display for the second part of such a SmPL
> disjunction
> in the way that a variable definition will be deleted (instead of
> taking only
> the key word “signed” also into account according to the isomorphism
> “add_signed”).
> 
> Regards,
> Markus

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


Re: [Cocci] [PATCH 00/43] cocci: Add support for meta attributes to SmPL

2020-08-02 Thread Jaskaran Singh
On Sat, 2020-08-01 at 22:36 +0200, Julia Lawall wrote:
> 
> On Sun, 26 Jul 2020, Jaskaran Singh wrote:
> 
> > This patch series aims to add support for meta attributes in SmPL.
> > Currently, only meta attributes in context and minus code are
> > supported.
> > 
> > Changes include adding the MetaAttribute and MetaAttributeDecl
> > constructors to
> > the SmPL ASTs and the MetaAttributeVal constructor to the C AST.
> > 
> > Two test cases are included for detecting and removing meta
> > attributes.
> 
> Applied.
> 
> Is this the end of atributes?
> 

There are a few more patches, but not as wide as this.

Cheers,
Jaskaran.

> julia
> 
> > Jaskaran Singh (43):
> >   parsing_cocci: ast0_cocci: Add MetaAttribute &
> > MetaAttributeDecl
> >   parsing_cocci: parser: Parse meta attributes and metaattr
> > decls
> >   parsing_cocci: parse_cocci: Reflect MetaAttribute &
> > MetaAttributeDecl
> >   parsing_cocci: ast_cocci: Add MetaAttribute &
> > MetaAttributeDecl
> >   parsing_cocci: iso_pattern: Reflect MetaAttribute &
> > MetaAttributeDecl
> >   parsing_c: unparse_hrule: Reflect MetaAttribute &
> > MetaAttributeDecl
> >   parsing_cocci: pretty_print_cocci: Reflect MetaAttribute &
> > MetaAttributeDecl
> >   ocaml: coccilib: Reflect MetaAttribute & MetaAttributeDecl
> >   ocaml: yes_prepare_ocamlcocci: Reflect MetaAttribute &
> > MetaAttributeDecl
> >   parsing_c: ast_c: Add MetaAttributeVal
> >   parsing_c: unparse_hrule: Reflect MetaAttributeVal
> >   engine: cocci_vs_c: Reflect MetaAttributeVal
> >   engine: pattern_c: Reflect MetaAttributeVal
> >   engine: pretty_print_engine: Add MetaAttributeVal
> >   ocaml: coccilib: Reflect MetaAttributeVal
> >   ocaml: ocamlcocci_aux: Reflect MetaAttributeVal
> >   ocaml: run_ocamlcocci: Reflect MetaAttributeVal
> >   python: pycocci_aux: Reflect MetaAttributeVal
> >   parsing_cocci: visitor_ast0: Reflect MetaAttribute
> >   parsing_cocci: check_meta: Reflect MetaAttribute
> >   parsing_cocci: adjust_pragmas: Reflect MetaAttribute
> >   parsing_cocci: context_neg: Reflect MetaAttribute
> >   parsing_cocci: compute_lines: Reflect MetaAttribute
> >   parsing_cocci: iso_pattern: Reflect MetaAttribute
> >   parsing_cocci: function_prototypes: Reflect MetaAttribute
> >   parsing_cocci: arity: Reflect MetaAttribute
> >   parsing_cocci: unitary_ast0: Reflect MetaAttribute
> >   parsing_cocci: unparse_ast0: Reflect MetaAttribute
> >   parsing_cocci: ast0toast: Reflect MetaAttribute
> >   parsing_cocci: visitor_ast: Reflect MetaAttribute
> >   parsing_cocci: cleanup_rules: Reflect MetaAttribute
> >   parsing_cocci: free_vars: Reflect MetaAttribute
> >   parsing_cocci: get_constants: Reflect MetaAttribute
> >   parsing_cocci: get_constants2: Reflect MetaAttribute
> >   parsing_cocci: index: Reflect MetaAttribute
> >   parsing_cocci: pretty_print_cocci: Reflect MetaAttribute
> >   parsing_cocci: safe_for_multi_decls: Reflect MetaAttribute
> >   parsing_cocci: unify_ast: Reflect MetaAttribute
> >   parsing_c: unparse_cocci: Reflect MetaAttribute
> >   engine: cocci_vs_c: Reflect MetaAttribute
> >   tools: spgen: Reflect MetaAttribute
> >   tests: Add test case to match meta attribute
> >   tests: Add test case to remove a meta attribute
> > 
> >  engine/cocci_vs_c.ml  |   23 ++---
> >  engine/pattern_c.ml   |6 
> >  engine/pretty_print_engine.ml |1
> >  ocaml/coccilib.ml |1
> >  ocaml/coccilib.mli|7 +
> >  ocaml/ocamlcocci_aux.ml   |2 +
> >  ocaml/run_ocamlcocci.ml   |1
> >  ocaml/yes_prepare_ocamlcocci.ml   |1
> >  parsing_c/ast_c.ml|1
> >  parsing_c/ast_c.mli   |1
> >  parsing_c/lib_parsing_c.ml|3 ++
> >  parsing_c/lib_parsing_c.mli   |3 ++
> >  parsing_c/pretty_print_c.ml   |   12 
> >  parsing_c/pretty_print_c.mli  |5 +++
> >  parsing_c/unparse_cocci.ml|6 
> >  parsing_c/unparse_hrule.ml|5 +++
> >  parsing_cocci/adjust_pragmas.ml   |3 ++
> >  parsing_cocci/arity.ml|   29 ++---
> >  parsing_cocci/ast0_cocci.ml   |1
> &

[Cocci] [PATCH 30/43] parsing_cocci: visitor_ast: Reflect MetaAttribute

2020-07-26 Thread Jaskaran Singh
MetaAttribute is added to the SmPL AST. Visit it in the SmPL AST
visitor.

Signed-off-by: Jaskaran Singh 
---
 parsing_cocci/visitor_ast.ml | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/parsing_cocci/visitor_ast.ml b/parsing_cocci/visitor_ast.ml
index 17afc5183..315b94243 100644
--- a/parsing_cocci/visitor_ast.ml
+++ b/parsing_cocci/visitor_ast.ml
@@ -921,7 +921,8 @@ let combiner bind option_default
   and attribute a =
 let k a =
   match Ast.unwrap a with
-Ast.Attribute(attr) -> string_mcode attr in
+Ast.Attribute(attr) -> string_mcode attr
+  | Ast.MetaAttribute(name,_,_,_) -> meta_mcode name in
 attributefn all_functions k a
 
 
@@ -1919,7 +1920,9 @@ let rebuilder
 let k a =
   Ast.rewrap a
 (match Ast.unwrap a with
-  Ast.Attribute(attr) -> Ast.Attribute(string_mcode attr)) in
+  Ast.Attribute(attr) -> Ast.Attribute(string_mcode attr)
+   | Ast.MetaAttribute(name,constraints,keep,inherited) ->
+   Ast.MetaAttribute(meta_mcode name,constraints,keep,inherited)) in
 attributefn all_functions k a
 
   and whencode notfn alwaysfn = function
-- 
2.21.3

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


[Cocci] [PATCH 23/43] parsing_cocci: compute_lines: Reflect MetaAttribute

2020-07-26 Thread Jaskaran Singh
MetaAttribute is added to the SmPL AST. Reflect these changes in
compute_lines.ml.

Signed-off-by: Jaskaran Singh 
---
 parsing_cocci/compute_lines.ml | 14 +-
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/parsing_cocci/compute_lines.ml b/parsing_cocci/compute_lines.ml
index 4420e9524..4042b1025 100644
--- a/parsing_cocci/compute_lines.ml
+++ b/parsing_cocci/compute_lines.ml
@@ -907,11 +907,15 @@ and initialiser_list prev = dots is_init_dots prev 
initialiser
 (* for export *)
 and initialiser_dots x = dots is_init_dots None initialiser x
 
-and attribute a =
-  match Ast0.unwrap a with
-Ast0.Attribute(attr) ->
-  let ln = promote_mcode attr in
-  mkres a (Ast0.Attribute(attr)) ln ln
+and attribute attr =
+  match Ast0.unwrap attr with
+Ast0.Attribute(a) ->
+  let ln = promote_mcode a in
+  mkres attr (Ast0.Attribute(a)) ln ln
+  | Ast0.MetaAttribute(name,a,b) ->
+  let name = normal_mcode name in
+  let ln = promote_mcode name in
+  mkres attr (Ast0.MetaAttribute(name,a,b)) ln ln
 
 
 (* - *)
-- 
2.21.3

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


[Cocci] [PATCH 38/43] parsing_cocci: unify_ast: Reflect MetaAttribute

2020-07-26 Thread Jaskaran Singh
MetaAttribute is added to the SmPL AST. Reflect these changes in
unify_ast.ml.

Signed-off-by: Jaskaran Singh 
---
 parsing_cocci/unify_ast.ml | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/parsing_cocci/unify_ast.ml b/parsing_cocci/unify_ast.ml
index 98e2ab1dd..811c91f30 100644
--- a/parsing_cocci/unify_ast.ml
+++ b/parsing_cocci/unify_ast.ml
@@ -723,6 +723,8 @@ and unify_attribute attr1 attr2 =
   match (Ast.unwrap attr1,Ast.unwrap attr2) with
 (Ast.Attribute(attr1),Ast.Attribute(attr2)) ->
   unify_mcode attr1 attr2
+  | (Ast.MetaAttribute(_,_,_,_),_)
+  | (_,Ast.MetaAttribute(_,_,_,_)) -> true
 
 and unify_exec_code ec1 ec2 =
   match (Ast.unwrap ec1,Ast.unwrap ec2) with
-- 
2.21.3

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


[Cocci] [PATCH 36/43] parsing_cocci: pretty_print_cocci: Reflect MetaAttribute

2020-07-26 Thread Jaskaran Singh
MetaAttribute is added to the SmPL AST. Reflect these changes in
pretty_print_cocci.ml.

Signed-off-by: Jaskaran Singh 
---
 parsing_cocci/pretty_print_cocci.ml | 1 +
 1 file changed, 1 insertion(+)

diff --git a/parsing_cocci/pretty_print_cocci.ml 
b/parsing_cocci/pretty_print_cocci.ml
index fe54a8d61..c4de73f1f 100644
--- a/parsing_cocci/pretty_print_cocci.ml
+++ b/parsing_cocci/pretty_print_cocci.ml
@@ -458,6 +458,7 @@ and print_attribute_list attrs =
 and print_attribute attr =
   match Ast.unwrap attr with
 Ast.Attribute(a) -> mcode print_string a
+  | Ast.MetaAttribute(name,_,_,_) -> mcode print_meta name
 
 and typeC ty =
   match Ast.unwrap ty with
-- 
2.21.3

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


[Cocci] [PATCH 42/43] tests: Add test case to match meta attribute

2020-07-26 Thread Jaskaran Singh
Meta attributes are added to SmPL. Add test case to match and detect a
meta attribute in C code.

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

diff --git a/tests/metaattr.c b/tests/metaattr.c
new file mode 100644
index 0..d3b091cd9
--- /dev/null
+++ b/tests/metaattr.c
@@ -0,0 +1,5 @@
+int main() {
+   int b __attr__ = 1;
+   int b = 1;
+   return 0;
+}
diff --git a/tests/metaattr.cocci b/tests/metaattr.cocci
new file mode 100644
index 0..a325ad06f
--- /dev/null
+++ b/tests/metaattr.cocci
@@ -0,0 +1,9 @@
+@@
+attribute name __attr__;
+attribute a;
+identifier b;
+@@
+
+-  int
++  char
+  b a = 1;
diff --git a/tests/metaattr.res b/tests/metaattr.res
new file mode 100644
index 0..9cd2014f2
--- /dev/null
+++ b/tests/metaattr.res
@@ -0,0 +1,5 @@
+int main() {
+   char b __attr__ = 1;
+   int b = 1;
+   return 0;
+}
-- 
2.21.3

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


[Cocci] [PATCH 40/43] engine: cocci_vs_c: Reflect MetaAttribute

2020-07-26 Thread Jaskaran Singh
MetaAttribute is added to the SmPL AST. Reflect these changes in
cocci_vs_c.ml.

Signed-off-by: Jaskaran Singh 
---
 engine/cocci_vs_c.ml | 15 ++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/engine/cocci_vs_c.ml b/engine/cocci_vs_c.ml
index ed91a4785..0b698287d 100644
--- a/engine/cocci_vs_c.ml
+++ b/engine/cocci_vs_c.ml
@@ -1535,7 +1535,8 @@ let rec (expression: (A.expression, Ast_c.expression) 
matcher) =
   let attr_allminus =
 let attr_is_not_context a =
   match A.unwrap a with
-  | A.Attribute(_,_,A.CONTEXT(_,_),_) -> false
+  | A.Attribute(_,_,A.CONTEXT(_,_),_)
+  | A.MetaAttribute((_,_,A.CONTEXT(_,_),_),_,_,_) -> false
   | _ -> true in
 check_allminus.Visitor_ast.combiner_fullType typa &&
 List.for_all attr_is_not_context attrsa in
@@ -4282,6 +4283,18 @@ and attribute = fun allminus ea eb ->
  A.rewrap ea (A.Attribute(attra)),
   (B.Attribute attrb,ib1)
 )))
+  | A.MetaAttribute (ida,constraints,keep,inherited), _ ->
+  (* todo: use quaopt, hasreg ? *)
+  let max_min _ = Lib_parsing_c.ii_of_attr eb in
+  let mn = Ast_c.MetaAttributeVal eb in
+  check_constraints constraints ida mn
+   (fun () ->
+ X.envf keep inherited (ida,mn,max_min) (fun () ->
+X.distrf_attr ida eb)
+   >>= (fun ida eb ->
+ return
+   (A.MetaAttribute(ida,constraints,keep,inherited)+>
+A.rewrap ea,eb)))
   | _ -> fail
 
 (*---*)
-- 
2.21.3

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


[Cocci] [PATCH 43/43] tests: Add test case to remove a meta attribute

2020-07-26 Thread Jaskaran Singh
Meta attributes are added to SmPL. Add a test case to match and remove a
meta attribute from C code.

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

diff --git a/tests/remove_metaattr.c b/tests/remove_metaattr.c
new file mode 100644
index 0..d3b091cd9
--- /dev/null
+++ b/tests/remove_metaattr.c
@@ -0,0 +1,5 @@
+int main() {
+   int b __attr__ = 1;
+   int b = 1;
+   return 0;
+}
diff --git a/tests/remove_metaattr.cocci b/tests/remove_metaattr.cocci
new file mode 100644
index 0..e35bc7e3c
--- /dev/null
+++ b/tests/remove_metaattr.cocci
@@ -0,0 +1,9 @@
+@@
+attribute name __attr__;
+attribute a;
+identifier b;
+@@
+
+int b
+-  a
+   = 1;
diff --git a/tests/remove_metaattr.res b/tests/remove_metaattr.res
new file mode 100644
index 0..7d9292a55
--- /dev/null
+++ b/tests/remove_metaattr.res
@@ -0,0 +1,5 @@
+int main() {
+   int b = 1;
+   int b = 1;
+   return 0;
+}
-- 
2.21.3

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


[Cocci] [PATCH 39/43] parsing_c: unparse_cocci: Reflect MetaAttribute

2020-07-26 Thread Jaskaran Singh
MetaAttribute is added to the SmPL AST. Reflect these changes in
unparse_cocci.ml.

Signed-off-by: Jaskaran Singh 
---
 parsing_c/unparse_cocci.ml | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/parsing_c/unparse_cocci.ml b/parsing_c/unparse_cocci.ml
index e544336d0..7be18bf1c 100644
--- a/parsing_c/unparse_cocci.ml
+++ b/parsing_c/unparse_cocci.ml
@@ -714,6 +714,12 @@ and print_attribute_list attrs =
 and print_attribute attr =
   match Ast.unwrap attr with
 Ast.Attribute(a) -> mcode print_string a
+  | Ast.MetaAttribute(name,_,_,_) ->
+  handle_metavar name
+   (function
+   Ast_c.MetaAttributeVal a ->
+  pretty_print_c.Pretty_print_c.attribute a
+  | _ -> error name attr "attribute value expected")
 
 and typeC ty =
   match Ast.unwrap ty with
-- 
2.21.3

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


[Cocci] [PATCH 32/43] parsing_cocci: free_vars: Reflect MetaAttribute

2020-07-26 Thread Jaskaran Singh
MetaAttribute is added to the SmPL AST. Reflect these changes in
free_vars.ml.

Signed-off-by: Jaskaran Singh 
---
 parsing_cocci/free_vars.ml | 28 +---
 1 file changed, 25 insertions(+), 3 deletions(-)

diff --git a/parsing_cocci/free_vars.ml b/parsing_cocci/free_vars.ml
index 6958f48ee..404e2d549 100644
--- a/parsing_cocci/free_vars.ml
+++ b/parsing_cocci/free_vars.ml
@@ -137,6 +137,13 @@ let collect_refs include_constraints =
  bind (constraints cstr) [metaid name]
   | _ -> option_default) in
 
+  let astfvattribute recursor k a =
+bind (k a)
+  (match Ast.unwrap a with
+   Ast.MetaAttribute(name,cstr,_,_) ->
+ bind (constraints cstr) [metaid name]
+  | _ -> option_default) in
+
   let rec collect_assign_names aop =
 match Ast.unwrap aop with
   Ast.MetaAssign(name,cstr,_,_) ->
@@ -253,7 +260,8 @@ let collect_refs include_constraints =
 astfvident astfvexpr astfvfrag astfvfmt astfvassignop astfvbinaryop
 astfvfullType astfvtypeC astfvinit astfvparam astfvdefine_param
 astfvdecls donothing astfvfields astafvfields donothing
-astfvrule_elem astfvstatement donothing donothing donothing donothing_a
+astfvrule_elem astfvstatement donothing astfvattribute
+donothing donothing_a
 
 let collect_all_refs = collect_refs true
 let collect_non_constraint_refs = collect_refs false
@@ -369,6 +377,12 @@ let collect_saved =
Ast.MetaFormat(name,_,Ast.Saved,_) -> [metaid name]
   | _ -> option_default) in
 
+  let astfvattribute recursor k a =
+bind (k a)
+  (match Ast.unwrap a with
+   Ast.MetaAttribute(name,_,Ast.Saved,_) -> [metaid name]
+  | _ -> option_default) in
+
   let astfvassign recursor k aop =
 bind (k aop)
   (match Ast.unwrap aop with
@@ -479,7 +493,7 @@ let collect_saved =
 astfvident astfvexpr astfvfrag astfvfmt astfvassign astfvbinary donothing
 astfvtypeC astfvinit astfvparam astfvdefine_param astfvdecls donothing
 astfvfields donothing donothing astfvrule_elem donothing donothing
-donothing donothing donothing
+astfvattribute donothing donothing
 
 (*  *)
 
@@ -779,6 +793,14 @@ let classify_variables metavar_decls minirules used_after =
Ast.rewrap ft (Ast.MetaFormat(name,constraints,unitary,inherited))
 | _ -> ft in
 
+  let attribute r k a =
+let a = k a in
+match Ast.unwrap a with
+  Ast.MetaAttribute(name,constraints,_,_) ->
+   let (unitary,inherited) = classify name in
+   Ast.rewrap a (Ast.MetaAttribute(name,constraints,unitary,inherited))
+| _ -> a in
+
   let assignop r k ft =
 let ft = k ft in
 match Ast.unwrap ft with
@@ -905,7 +927,7 @@ let classify_variables metavar_decls minirules used_after =
   ident expression string_fragment string_format assignop binaryop
   donothing typeC
   init param define_param decl donothing field donothing donothing
-  rule_elem donothing donothing donothing donothing donothing in
+  rule_elem donothing donothing attribute donothing donothing in
 
   List.map fn.V.rebuilder_top_level minirules
 
-- 
2.21.3

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


[Cocci] [PATCH 34/43] parsing_cocci: get_constants2: Reflect MetaAttribute

2020-07-26 Thread Jaskaran Singh
MetaAttribute is added to the SmPL AST. Reflect these changes in
get_constants2.ml.

Signed-off-by: Jaskaran Singh 
---
 parsing_cocci/get_constants2.ml | 9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/parsing_cocci/get_constants2.ml b/parsing_cocci/get_constants2.ml
index 8fffe1955..33d8ccf5a 100644
--- a/parsing_cocci/get_constants2.ml
+++ b/parsing_cocci/get_constants2.ml
@@ -529,9 +529,10 @@ let do_get_constants constants keywords env (neg_pos,_) =
 | Ast.MetaType(name,_,_,_) -> bind (minherited name) (k ty)
 | _ -> k ty in
 
-  let attribute a =
+  let attribute r k a =
 match Ast.unwrap a with
-  Ast.Attribute(attr) -> Ast.unwrap_mcode attr in
+  Ast.MetaAttribute(name,_,_,_) -> bind (k a) (minherited name)
+| Ast.Attribute(attr) -> constants (Ast.unwrap_mcode attr) in
 
   let declaration r k d =
 match Ast.unwrap d with
@@ -543,7 +544,7 @@ let do_get_constants constants keywords env (neg_pos,_) =
 (* need things with explicit names too *)
 | Ast.Init(_,_,_,attr,_,_,_) | Ast.UnInit(_,_,_,attr,_) ->
List.fold_left bind (k d)
- (List.map (fun attr -> constants (attribute attr)) attr)
+ (List.map r.V.combiner_attribute attr)
 | _ -> k d in
 
   let field r k d =
@@ -645,7 +646,7 @@ let do_get_constants constants keywords env (neg_pos,_) =
 donothing donothing donothing donothing donothing donothing donothing
 ident expression string_fragment string_format donothing donothing
 fullType typeC initialiser parameter define_parameter declaration donothing
-field ann_field donothing rule_elem statement donothing donothing donothing
+field ann_field donothing rule_elem statement donothing attribute donothing
 donothing
 
 (*  *)
-- 
2.21.3

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


[Cocci] [PATCH 31/43] parsing_cocci: cleanup_rules: Reflect MetaAttribute

2020-07-26 Thread Jaskaran Singh
MetaAttribute is added to the SmPL AST. Reflect these changes in
cleanup_rules.ml.

Signed-off-by: Jaskaran Singh 
---
 parsing_cocci/cleanup_rules.ml | 10 +-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/parsing_cocci/cleanup_rules.ml b/parsing_cocci/cleanup_rules.ml
index 7f03f98fd..e11484539 100644
--- a/parsing_cocci/cleanup_rules.ml
+++ b/parsing_cocci/cleanup_rules.ml
@@ -244,6 +244,14 @@ let statement r k s =
   | Ast.OptStm(_) -> s
   | _ -> k s
 
+let attribute r k a =
+  match Ast.unwrap a with
+Ast.MetaAttribute(name,_,_,_) ->
+  (if List.mem (get_rule name) !dropped
+  then set_failed !drop_stack);
+  k a
+  | _ -> k a
+
 let do_cleanup =
   let donothing r k e = k e in
   V.rebuilder
@@ -254,7 +262,7 @@ let do_cleanup =
 ident expression string_fragment string_format assignOp
 binaryOp fullType typeC initialiser parameterTypeDef define_param
 declaration donothing field ann_field donothing
-rule_elem statement donothing donothing donothing donothing
+rule_elem statement donothing attribute donothing donothing
 
 let cleanup_rules rules d =
   dropped := d;
-- 
2.21.3

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


[Cocci] [PATCH 41/43] tools: spgen: Reflect MetaAttribute

2020-07-26 Thread Jaskaran Singh
MetaAttribute is added to the SmPL AST. Reflect these changes in spgen.

Signed-off-by: Jaskaran Singh 
---
 tools/spgen/source/meta_variable.ml | 8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/tools/spgen/source/meta_variable.ml 
b/tools/spgen/source/meta_variable.ml
index 40dcae9c2..70a9fe878 100644
--- a/tools/spgen/source/meta_variable.ml
+++ b/tools/spgen/source/meta_variable.ml
@@ -396,7 +396,6 @@ let metavar_combiner rn =
   let casefn = donothing in
   let topfn = donothing in
   let enumdeclfn = donothing in
-  let attributefn = donothing in
 
   (* --- These are shortened formatting functions that return MVSets --- *)
 
@@ -571,6 +570,13 @@ let metavar_combiner rn =
)
 | _ -> fn v in
 
+  let attributefn c fn v =
+match Ast0.unwrap v with
+| Ast0.MetaAttribute(mc, idconstr, pure) ->
+let constr = constraints ~rn idconstr in
+meta_mc_format ~mc ~typ:"parameter " ~constr
+| _ -> fn v in
+
   V0.flat_combiner bind option_default
 meta_mcode string_mcode const_mcode simpleAssign_mcode opAssign_mcode
 fix_mcode unary_mcode arithOp_mcode logicalOp_mcode cv_mcode sign_mcode
-- 
2.21.3

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


[Cocci] [PATCH 37/43] parsing_cocci: safe_for_multi_decls: Reflect MetaAttribute

2020-07-26 Thread Jaskaran Singh
MetaAttribute is added to the SmPL AST. Reflect these changes in
safe_for_multi_decls.ml.

Signed-off-by: Jaskaran Singh 
---
 parsing_cocci/safe_for_multi_decls.ml | 1 +
 1 file changed, 1 insertion(+)

diff --git a/parsing_cocci/safe_for_multi_decls.ml 
b/parsing_cocci/safe_for_multi_decls.ml
index ee3741b96..a4ad2f36c 100644
--- a/parsing_cocci/safe_for_multi_decls.ml
+++ b/parsing_cocci/safe_for_multi_decls.ml
@@ -106,6 +106,7 @@ let contains_modif =
 let attribute a =
   match Ast.unwrap a with
 Ast.Attribute(attr) -> mcode () attr
+  | Ast.MetaAttribute(name,b,c,d) -> mcode () name
 
 let decl r k e =
   let e = k e in
-- 
2.21.3

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


[Cocci] [PATCH 28/43] parsing_cocci: unparse_ast0: Reflect MetaAttribute

2020-07-26 Thread Jaskaran Singh
MetaAttribute is added to the SmPL AST. Reflect these changes in
unparse_ast0.ml.

Signed-off-by: Jaskaran Singh 
---
 parsing_cocci/unparse_ast0.ml | 1 +
 1 file changed, 1 insertion(+)

diff --git a/parsing_cocci/unparse_ast0.ml b/parsing_cocci/unparse_ast0.ml
index 875282fb0..e2556cb80 100644
--- a/parsing_cocci/unparse_ast0.ml
+++ b/parsing_cocci/unparse_ast0.ml
@@ -768,6 +768,7 @@ and print_attribute_list attrs =
 and print_attribute a =
   match Ast0.unwrap a with
 Ast0.Attribute(attr) -> mcode print_string attr
+  | Ast0.MetaAttribute(name,_,_) -> mcode print_meta name
 
 and whencode notfn alwaysfn = function
 Ast0.WhenNot (_,_,a) ->
-- 
2.21.3

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


[Cocci] [PATCH 33/43] parsing_cocci: get_constants: Reflect MetaAttribute

2020-07-26 Thread Jaskaran Singh
MetaAttribute is added to the SmPL AST. Reflect these changes in
get_constants.ml.

Signed-off-by: Jaskaran Singh 
---
 parsing_cocci/get_constants.ml | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/parsing_cocci/get_constants.ml b/parsing_cocci/get_constants.ml
index a23f2e4f8..ebab24871 100644
--- a/parsing_cocci/get_constants.ml
+++ b/parsing_cocci/get_constants.ml
@@ -235,6 +235,11 @@ let check_inherited nm =
 | Ast.MetaStmtList(name,_,_) -> bind (k re) (minherited name)
 | _ -> k re in
 
+  let strictattribute recursor k a =
+match Ast.unwrap a with
+  Ast.MetaAttribute(name,_,_) -> bind (k a) (minherited name)
+| _ -> k a in
+
   let strictstatement recursor k s =
 match Ast.unwrap s with
   Ast.Disj(stms) -> option_default
@@ -244,7 +249,7 @@ let check_inherited nm =
 mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode
 donothing donothing donothing donothing
 strictident strictexpr strictfullType stricttypeC donothing strictparam
-strictdecls strictrule_elem strictstatement donothing donothing donothing
+strictdecls strictrule_elem strictstatement attributefn donothing donothing
 
 (*  *)
 
-- 
2.21.3

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


[Cocci] [PATCH 16/43] ocaml: ocamlcocci_aux: Reflect MetaAttributeVal

2020-07-26 Thread Jaskaran Singh
MetaAttributeVal is added to the C AST. Reflect these changes in
ocamlcocci_aux.ml.

Signed-off-by: Jaskaran Singh 
---
 ocaml/ocamlcocci_aux.ml | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/ocaml/ocamlcocci_aux.ml b/ocaml/ocamlcocci_aux.ml
index 7ec3a964f..ccbf6858e 100644
--- a/ocaml/ocamlcocci_aux.ml
+++ b/ocaml/ocamlcocci_aux.ml
@@ -47,6 +47,8 @@ let stringrep = function
 call_pretty0 Pretty_print_c.pp_string_fragment_list_gen frags
 | Ast_c.MetaFmtVal fmt ->
 call_pretty0 Pretty_print_c.pp_string_format_gen fmt
+| Ast_c.MetaAttributeVal attr ->
+call_pretty0 Pretty_print_c.pp_attribute_gen attr
 | Ast_c.MetaListlenVal n -> string_of_int n
 | Ast_c.MetaPosVal (pos1, pos2) ->
 let print_pos = function
-- 
2.21.3

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


[Cocci] [PATCH 08/43] ocaml: coccilib: Reflect MetaAttribute & MetaAttributeDecl

2020-07-26 Thread Jaskaran Singh
MetaAttribute and MetaAttributeDecl are added to the SmPL AST. Reflect
these changes in coccilib.mli.

Signed-off-by: Jaskaran Singh 
---
 ocaml/coccilib.mli | 4 
 1 file changed, 4 insertions(+)

diff --git a/ocaml/coccilib.mli b/ocaml/coccilib.mli
index 19f1512cd..3960d1046 100644
--- a/ocaml/coccilib.mli
+++ b/ocaml/coccilib.mli
@@ -2520,6 +2520,7 @@ module Ast_cocci :
   | MetaPosDecl of arity * meta_name
   | MetaComDecl of arity * meta_name
   | MetaFmtDecl of arity * meta_name
+  | MetaAttributeDecl of arity * meta_name
   | MetaFragListDecl of arity * meta_name * list_len
   | MetaAnalysisDecl of string * meta_name
   | MetaDeclarerDecl of arity * meta_name
@@ -2928,6 +2929,8 @@ module Ast_cocci :
 and base_attr =
   Ast_cocci.base_attr =
 Attribute of string mcode
+  | MetaAttribute of meta_name mcode * constraints * keep_binding *
+  inherited
 and attr = base_attr wrap
 and metaStmtInfo =
   Ast_cocci.metaStmtInfo =
@@ -3560,6 +3563,7 @@ module Ast0_cocci :
 and base_attr =
   Ast0_cocci.base_attr =
 Attribute of string mcode
+  | MetaAttribute of Ast_cocci.meta_name mcode * constraints * pure
 and attr = base_attr wrap
 and ('a, 'b) whencode =
   ('a, 'b) Ast0_cocci.whencode =
-- 
2.21.3

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


[Cocci] [PATCH 29/43] parsing_cocci: ast0toast: Reflect MetaAttribute

2020-07-26 Thread Jaskaran Singh
MetaAttribute is added to the SmPL AST. Reflect these changes in
ast0toast.ml.

Signed-off-by: Jaskaran Singh 
---
 parsing_cocci/ast0toast.ml | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/parsing_cocci/ast0toast.ml b/parsing_cocci/ast0toast.ml
index b4b7600ed..16a2ffd30 100644
--- a/parsing_cocci/ast0toast.ml
+++ b/parsing_cocci/ast0toast.ml
@@ -1200,7 +1200,9 @@ and fninfo = function
 and attribute a =
   rewrap a no_isos
 (match Ast0.unwrap a with
-  Ast0.Attribute(attr) -> Ast.Attribute(mcode attr))
+  Ast0.Attribute(attr) -> Ast.Attribute(mcode attr)
+| Ast0.MetaAttribute(name,cstr,_) ->
+   Ast.MetaAttribute(mcode name,constraints cstr,unitary,false))
 
 and option_to_list = function
 Some x -> [x]
-- 
2.21.3

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


[Cocci] [PATCH 26/43] parsing_cocci: arity: Reflect MetaAttribute

2020-07-26 Thread Jaskaran Singh
MetaAttribute is added to the SmPL AST. Reflect these changes in
arity.ml.

Signed-off-by: Jaskaran Singh 
---
 parsing_cocci/arity.ml | 29 +++--
 1 file changed, 19 insertions(+), 10 deletions(-)

diff --git a/parsing_cocci/arity.ml b/parsing_cocci/arity.ml
index 23eb32f9a..28ab8410d 100644
--- a/parsing_cocci/arity.ml
+++ b/parsing_cocci/arity.ml
@@ -259,7 +259,7 @@ let rec top_expression opt_allowed tgt expr =
exp_same (mcode2line lp) (List.map mcode2arity ([lp;rp])) in
   let lp = mcode lp in
   let ty = typeC arity ty in
-  let attr = List.map attribute attr in
+  let attr = List.map (attribute arity) attr in
   let rp = mcode rp in
   let exp = expression arity exp in
   make_exp expr tgt arity (Ast0.Cast(lp,ty,attr,rp,exp))
@@ -564,7 +564,7 @@ and declaration tgt decl =
   let stg = get_option mcode stg in
   let ty = typeC arity ty in
   let id = ident false arity id in
-  let attr = List.map attribute attr in
+  let attr = List.map (attribute arity) attr in
   let eq = mcode eq in
   let exp = initialiser arity exp in
   let sem = mcode sem in
@@ -577,7 +577,7 @@ and declaration tgt decl =
   let stg = get_option mcode stg in
   let ty = typeC arity ty in
   let id = ident false arity id in
-  let attr = List.map attribute attr in
+  let attr = List.map (attribute arity) attr in
   let sem = mcode sem in
   make_decl decl tgt arity (Ast0.UnInit(stg,ty,id,attr,sem))
   | Ast0.FunProto(fi,name,lp1,params,va,rp1,sem) ->
@@ -607,7 +607,7 @@ and declaration tgt decl =
   let lp = mcode lp in
   let args = dots (expression arity) args in
   let rp = mcode rp in
-  let attr = List.map attribute attr in
+  let attr = List.map (attribute arity) attr in
   let sem = mcode sem in
   make_decl decl tgt arity (Ast0.MacroDecl(stg,name,lp,args,rp,attr,sem))
   | Ast0.MacroDeclInit(stg,name,lp,args,rp,eq,ini,sem) ->
@@ -629,7 +629,7 @@ and declaration tgt decl =
all_same true tgt
  (mcode2line sem) [mcode2arity sem] in
   let ty = typeC arity ty in
-  let attr = List.map attribute attr in
+  let attr = List.map (attribute arity) attr in
   let sem = mcode sem in
   make_decl decl tgt arity (Ast0.TyDecl(ty,attr,sem))
   | Ast0.Typedef(stg,ty,id,sem) ->
@@ -818,11 +818,12 @@ and parameterTypeDef tgt param =
   let param_same = all_same true tgt in
   match Ast0.unwrap param with
 Ast0.VoidParam(ty,attr) ->
-  Ast0.rewrap param (Ast0.VoidParam(typeC tgt ty,List.map attribute attr))
+  Ast0.rewrap param
+(Ast0.VoidParam(typeC tgt ty,List.map (attribute tgt) attr))
   | Ast0.Param(ty,Some id,attr) ->
   let ty = top_typeC tgt true ty in
   let id = ident true tgt id in
-  let attr = List.map attribute attr in
+  let attr = List.map (attribute tgt) attr in
   Ast0.rewrap param
(match (Ast0.unwrap ty,Ast0.unwrap id) with
  (Ast0.OptType(ty),Ast0.OptIdent(id)) ->
@@ -834,7 +835,7 @@ and parameterTypeDef tgt param =
| _ -> Ast0.Param(ty,Some id,attr))
   | Ast0.Param(ty,None,attr) ->
   let ty = top_typeC tgt true ty in
-  let attr = List.map attribute attr in
+  let attr = List.map (attribute tgt) attr in
   Ast0.rewrap param
(match Ast0.unwrap ty with
  Ast0.OptType(ty) ->
@@ -1262,7 +1263,7 @@ and fninfo arity = function
 Ast0.FStorage(stg) -> Ast0.FStorage(mcode stg)
   | Ast0.FType(ty) -> Ast0.FType(typeC arity ty)
   | Ast0.FInline(inline) -> Ast0.FInline(mcode inline)
-  | Ast0.FAttr(attr) -> Ast0.FAttr(attribute attr)
+  | Ast0.FAttr(attr) -> Ast0.FAttr(attribute arity attr)
 
 and fninfo2arity fninfo =
   List.concat
@@ -1274,10 +1275,18 @@ and fninfo2arity fninfo =
 | Ast0.FAttr(attr) -> [])
fninfo)
 
-and attribute attr =
+and make_attribute =
+  make_opt
+(function x -> failwith "opt not allowed for attributes")
+
+and attribute tgt attr =
   match Ast0.unwrap attr with
 Ast0.Attribute(a) ->
   Ast0.rewrap attr (Ast0.Attribute(mcode a))
+  | Ast0.MetaAttribute(name,cstr,pure) ->
+  let arity = all_same false tgt (mcode2line name) [mcode2arity name] in
+  let name = mcode name in
+  make_attribute attr tgt arity (Ast0.MetaAttribute(name,cstr,pure))
 
 and whencode notfn alwaysfn expression = function
 Ast0.WhenNot (w,e,a) -> Ast0.WhenNot (w,e,notfn a)
-- 
2.21.3

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


[Cocci] [PATCH 10/43] parsing_c: ast_c: Add MetaAttributeVal

2020-07-26 Thread Jaskaran Singh
Add the MetaAttributeVal constructor to the C AST.

Signed-off-by: Jaskaran Singh 
---
 parsing_c/ast_c.ml  | 1 +
 parsing_c/ast_c.mli | 1 +
 2 files changed, 2 insertions(+)

diff --git a/parsing_c/ast_c.ml b/parsing_c/ast_c.ml
index 645f9e183..2c682fe21 100644
--- a/parsing_c/ast_c.ml
+++ b/parsing_c/ast_c.ml
@@ -821,6 +821,7 @@ and metavars_binding = (Ast_cocci.meta_name, 
metavar_binding_kind) assoc
   | MetaStmtListVal  of statement_sequencable list * stripped
   | MetaDParamListVal of (string wrap) wrap2 list
   | MetaFmtVal   of string_format
+  | MetaAttributeVal of attribute
   | MetaFragListVal  of string_fragment list
   | MetaAssignOpVal  of assignOp
   | MetaBinaryOpVal  of binaryOp
diff --git a/parsing_c/ast_c.mli b/parsing_c/ast_c.mli
index a4d1f40d8..d03b5cf2b 100644
--- a/parsing_c/ast_c.mli
+++ b/parsing_c/ast_c.mli
@@ -326,6 +326,7 @@ and metavar_binding_kind =
   | MetaStmtListVal of statement_sequencable list * stripped
   | MetaDParamListVal of string wrap wrap2 list
   | MetaFmtVal of string_format
+  | MetaAttributeVal of attribute
   | MetaFragListVal of string_fragment list
   | MetaAssignOpVal of assignOp
   | MetaBinaryOpVal of binaryOp
-- 
2.21.3

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


[Cocci] [PATCH 05/43] parsing_cocci: iso_pattern: Reflect MetaAttribute & MetaAttributeDecl

2020-07-26 Thread Jaskaran Singh
MetaAttribute and MetaAttributeDecl are added to the SmPL AST. Reflect
these changes in iso_pattern.ml.

Signed-off-by: Jaskaran Singh 
---
 parsing_cocci/iso_pattern.ml | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/parsing_cocci/iso_pattern.ml b/parsing_cocci/iso_pattern.ml
index 24c2927c9..4a9a80b4f 100644
--- a/parsing_cocci/iso_pattern.ml
+++ b/parsing_cocci/iso_pattern.ml
@@ -2458,6 +2458,8 @@ let get_name bindings = function
   (nm,function nm -> Ast.MetaFragListDecl(ar,nm,nm1))
   | Ast.MetaFmtDecl(ar,nm) ->
   (nm,function nm -> Ast.MetaFmtDecl(ar,nm))
+  | Ast.MetaAttributeDecl(ar,nm) ->
+  (nm,function nm -> Ast.MetaAttributeDecl(ar,nm))
   | Ast.MetaAnalysisDecl(ar,nm) ->
   (nm,function nm -> Ast.MetaAnalysisDecl(ar,nm))
   | Ast.MetaDeclarerDecl(ar,nm) ->
-- 
2.21.3

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


[Cocci] [PATCH 06/43] parsing_c: unparse_hrule: Reflect MetaAttribute & MetaAttributeDecl

2020-07-26 Thread Jaskaran Singh
MetaAttribute and MetaAttributeDecl are added to the SmPL AST. Reflect
these changes in unparse_hrule.ml.

Signed-off-by: Jaskaran Singh 
---
 parsing_c/unparse_hrule.ml | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/parsing_c/unparse_hrule.ml b/parsing_c/unparse_hrule.ml
index 3078dde41..4d7ba93cc 100644
--- a/parsing_c/unparse_hrule.ml
+++ b/parsing_c/unparse_hrule.ml
@@ -432,6 +432,8 @@ let pp_meta_decl pr env decl =
   no_arity ar; pr "comments "; pp_name name; pr ";\n"
   | Ast.MetaFmtDecl(ar, name) ->
   no_arity ar; pr "format "; pp_name name; pr ";\n"
+  | Ast.MetaAttributeDecl(ar, name) ->
+  no_arity ar; pr "attribute "; pp_name name; pr ";\n"
   | Ast.MetaFragListDecl(ar, name, len) ->
   no_arity ar; pr "format list "; pp_len pr len; pp_name name; pr ";\n"
   | Ast.MetaAnalysisDecl(code, name) ->
-- 
2.21.3

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


[Cocci] [PATCH 22/43] parsing_cocci: context_neg: Reflect MetaAttribute

2020-07-26 Thread Jaskaran Singh
MetaAttribute is added to the SmPL AST. Reflect these changes in
context_neg.ml.

Signed-off-by: Jaskaran Singh 
---
 parsing_cocci/context_neg.ml | 18 --
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/parsing_cocci/context_neg.ml b/parsing_cocci/context_neg.ml
index ebb93806b..8b2512c9b 100644
--- a/parsing_cocci/context_neg.ml
+++ b/parsing_cocci/context_neg.ml
@@ -403,9 +403,6 @@ let classify is_minus all_marked table code =
  disj_cases e starter expr_list r.VT0.combiner_rec_expression ender
   |_ -> k e) in
 
-  let attribute a =
-match Ast0.unwrap a with
-  Ast0.Attribute(attr) -> mcode attr in
 
   (* not clear why we have the next cases, since DisjDecl and
   as it only comes from isos *)
@@ -430,7 +427,8 @@ let classify is_minus all_marked table code =
(bind (r.VT0.combiner_rec_typeC ty)
   (bind (r.VT0.combiner_rec_ident id)
   (bind
- (List.fold_right bind (List.map attribute attr)
+ (List.fold_right bind
+   (List.map r.VT0.combiner_rec_attribute attr)
option_default)
 (bind (mcode eq)
(bind (r.VT0.combiner_rec_initialiser ini)
@@ -440,7 +438,8 @@ let classify is_minus all_marked table code =
(bind (r.VT0.combiner_rec_typeC ty)
   (bind (r.VT0.combiner_rec_ident id)
   (bind
- (List.fold_right bind (List.map attribute attr)
+ (List.fold_right bind
+   (List.map r.VT0.combiner_rec_attribute attr)
option_default)
 (mcode sem
   |_ -> k e) in
@@ -477,7 +476,9 @@ let classify is_minus all_marked table code =
  (* needed for the same reason as in the Init and UnInit cases *)
  bind (r.VT0.combiner_rec_typeC ty)
(bind (r.VT0.combiner_rec_ident id)
-  (List.fold_right bind (List.map attribute attr) option_default))
+  (List.fold_right bind
+ (List.map r.VT0.combiner_rec_attribute attr)
+ option_default))
   |_ -> k e) in
 
   let typeC r k e =
@@ -596,6 +597,9 @@ let equal_attribute a1 a2 =
   match (Ast0.unwrap a1, Ast0.unwrap a2) with
 (Ast0.Attribute(attr1),Ast0.Attribute(attr2)) ->
   equal_mcode attr1 attr2
+  | (Ast0.MetaAttribute(name1,_,_),Ast0.MetaAttribute(name2,_,_)) ->
+  equal_mcode name1 name2
+  | _ -> false
 
 let equal_ident i1 i2 =
   match (Ast0.unwrap i1,Ast0.unwrap i2) with
@@ -865,8 +869,10 @@ let equal_initialiser i1 i2 =
 let equal_parameterTypeDef p1 p2 =
   match (Ast0.unwrap p1,Ast0.unwrap p2) with
 (Ast0.VoidParam(_,ar1),Ast0.VoidParam(_,ar2)) ->
+  (List.length ar1) = (List.length ar2) &&
   List.for_all2 equal_attribute ar1 ar2
   | (Ast0.Param(_,_,ar1),Ast0.Param(_,_,ar2)) ->
+  (List.length ar1) = (List.length ar2) &&
   List.for_all2 equal_attribute ar1 ar2
   | (Ast0.MetaParam(name1,_,_),Ast0.MetaParam(name2,_,_))
   | (Ast0.MetaParamList(name1,_,_,_),Ast0.MetaParamList(name2,_,_,_)) ->
-- 
2.21.3

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


[Cocci] [PATCH 09/43] ocaml: yes_prepare_ocamlcocci: Reflect MetaAttribute & MetaAttributeDecl

2020-07-26 Thread Jaskaran Singh
MetaAttribute and MetaAttributeDecl are added to the SmPL AST. Reflect
these changes in yes_prepare_ocamlcocci.ml.

Signed-off-by: Jaskaran Singh 
---
 ocaml/yes_prepare_ocamlcocci.ml | 1 +
 1 file changed, 1 insertion(+)

diff --git a/ocaml/yes_prepare_ocamlcocci.ml b/ocaml/yes_prepare_ocamlcocci.ml
index aa6a1b606..fef237189 100644
--- a/ocaml/yes_prepare_ocamlcocci.ml
+++ b/ocaml/yes_prepare_ocamlcocci.ml
@@ -114,6 +114,7 @@ let ast_rep_binding ctr = function
   | (Some nm,Ast.MetaStmDecl _) -> print_match ctr nm "Stmt"
   | (Some nm,Ast.MetaStmListDecl _) -> print_match ctr nm "StmtList"
   | (Some nm,Ast.MetaFmtDecl _) -> print_match ctr nm "Fmt"
+  | (Some nm,Ast.MetaAttributeDecl _) -> print_match ctr nm "Attribute"
   | (Some nm,Ast.MetaFragListDecl _) -> print_match ctr nm "FragList"
   | (Some nm,Ast.MetaFuncDecl _) -> print_match ctr nm "Str"
   | (Some nm,Ast.MetaLocalFuncDecl _) -> print_match ctr nm "Str"
-- 
2.21.3

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


[Cocci] [PATCH 13/43] engine: pattern_c: Reflect MetaAttributeVal

2020-07-26 Thread Jaskaran Singh
MetaAttributeVal is added to the C AST. Reflect these changes in
pattern_c.ml.

Signed-off-by: Jaskaran Singh 
---
 engine/pattern_c.ml | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/engine/pattern_c.ml b/engine/pattern_c.ml
index 821a5900e..7d9a2dcc1 100644
--- a/engine/pattern_c.ml
+++ b/engine/pattern_c.ml
@@ -538,6 +538,12 @@ module XMATCH = struct
   (if strip
   then Lib_parsing_c.al_string_format a
   else Lib_parsing_c.semi_al_string_format a))
+  | Ast_c.MetaAttributeVal a ->
+ success
+   (Ast_c.MetaAttributeVal
+  (if strip
+  then Lib_parsing_c.al_attribute a
+  else Lib_parsing_c.semi_al_attribute a))
 
   | Ast_c.MetaPosVal (pos1,pos2) ->
  success(Ast_c.MetaPosVal (pos1,pos2))
-- 
2.21.3

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


[Cocci] [PATCH 14/43] engine: pretty_print_engine: Add MetaAttributeVal

2020-07-26 Thread Jaskaran Singh
MetaAttributeVal is added to the C AST. Reflect these changes in
pretty_print_engine.ml.

Signed-off-by: Jaskaran Singh 
---
 engine/pretty_print_engine.ml |  1 +
 parsing_c/pretty_print_c.ml   | 12 
 parsing_c/pretty_print_c.mli  |  5 +
 3 files changed, 18 insertions(+)

diff --git a/engine/pretty_print_engine.ml b/engine/pretty_print_engine.ml
index 383016ce3..b825fac39 100644
--- a/engine/pretty_print_engine.ml
+++ b/engine/pretty_print_engine.ml
@@ -42,6 +42,7 @@ let rec pp_binding_kind = function
   | Ast_c.MetaStmtListVal  (statxs,_) ->
   Pretty_print_c.pp_statement_seq_list_simple statxs
   | Ast_c.MetaFmtVal fmt -> Pretty_print_c.pp_string_format_simple fmt
+  | Ast_c.MetaAttributeVal attr -> Pretty_print_c.pp_attribute_simple attr
   | Ast_c.MetaFragListVal frags ->
   frags +> (List.iter Pretty_print_c.pp_string_fragment_simple)
   | Ast_c.MetaParamVal params -> pp "<>"
diff --git a/parsing_c/pretty_print_c.ml b/parsing_c/pretty_print_c.ml
index 74b57344e..6ac3e4767 100644
--- a/parsing_c/pretty_print_c.ml
+++ b/parsing_c/pretty_print_c.ml
@@ -55,6 +55,7 @@ type pretty_printers = {
   fragment: Ast_c.string_fragment printer;
   fragment_list   : (Ast_c.string_fragment list) printer;
   format  : Ast_c.string_format printer;
+  attribute   : Ast_c.attribute printer;
   flow: Control_flow_c.node printer;
   name: Ast_c.name printer
 }
@@ -1145,6 +1146,12 @@ and pp_init (init, iinit) =
   ii +> List.iter pr_elem;
 );
 
+  and pp_attribute (e,ii) =
+match (e,ii) with
+  Attribute(a), ii  ->
+let (i) = Common.tuple_of_list1 ii in
+pr_elem i
+
 (* -- *)
   and pp_def_start defbis iifunc1 iifunc2 ifakestart isto =
 let {f_name = name;
@@ -1524,6 +1531,7 @@ and pp_init (init, iinit) =
 toplevel   = pp_toplevel;
 fragment   = pp_string_fragment;
 fragment_list = pp_string_fragment_list;
+attribute  = pp_attribute;
 format = pp_string_format;
 flow   = pp_flow;
 name   = pp_name;
@@ -1583,6 +1591,7 @@ let pp_init_simple   = ppc.init
 let pp_toplevel_simple   = ppc.toplevel
 let pp_string_fragment_simple = ppc.fragment
 let pp_string_format_simple = ppc.format
+let pp_attribute_simple  = ppc.attribute
 let pp_flow_simple   = ppc.flow
 let pp_name  = ppc.name
 
@@ -1649,6 +1658,9 @@ let pp_string_fragment_list_gen ~pr_elem ~pr_space =
 let pp_string_format_gen ~pr_elem ~pr_space =
   (pp_elem_sp pr_elem pr_space).format
 
+let pp_attribute_gen ~pr_elem ~pr_space =
+  (pp_elem_sp pr_elem pr_space).attribute
+
 let pp_program_gen ~pr_elem ~pr_space =
   (pp_elem_sp pr_elem pr_space).toplevel
 
diff --git a/parsing_c/pretty_print_c.mli b/parsing_c/pretty_print_c.mli
index 5cfcc779d..daaad2061 100644
--- a/parsing_c/pretty_print_c.mli
+++ b/parsing_c/pretty_print_c.mli
@@ -26,6 +26,7 @@ type pretty_printers = {
   fragment: Ast_c.string_fragment printer;
   fragment_list   : (Ast_c.string_fragment list) printer;
   format  : Ast_c.string_format printer;
+  attribute   : Ast_c.attribute printer;
   flow: Control_flow_c.node printer;
   name: Ast_c.name printer
 }
@@ -80,6 +81,9 @@ val pp_string_fragment_list_gen:
 val pp_string_format_gen:
 pr_elem:Ast_c.info printer -> pr_space:unit printer ->
   Ast_c.string_format printer
+val pp_attribute_gen:
+pr_elem:Ast_c.info printer -> pr_space:unit printer ->
+  Ast_c.attribute printer
 val pp_program_gen : pr_elem:Ast_c.info printer -> pr_space:unit printer ->
   Ast_c.toplevel printer
 
@@ -98,6 +102,7 @@ val pp_statement_seq_list_simple: 
Ast_c.statement_sequencable list printer
 val pp_toplevel_simple:   Ast_c.toplevel printer
 val pp_string_fragment_simple:   Ast_c.string_fragment printer
 val pp_string_format_simple: Ast_c.string_format printer
+val pp_attribute_simple: Ast_c.attribute printer
 
 val debug_info_of_node:
   Control_flow_c.G.key -> Control_flow_c.cflow -> string
-- 
2.21.3

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


[Cocci] [PATCH 35/43] parsing_cocci: index: Reflect MetaAttribute

2020-07-26 Thread Jaskaran Singh
MetaAttribute is added to the SmPL AST. Reflect these changes in
index.ml.

Signed-off-by: Jaskaran Singh 
---
 parsing_cocci/index.ml | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/parsing_cocci/index.ml b/parsing_cocci/index.ml
index cb3ac7ecd..ca54bc85d 100644
--- a/parsing_cocci/index.ml
+++ b/parsing_cocci/index.ml
@@ -5,7 +5,7 @@
  *)
 
 (* create an index for each constructor *)
-(* current max is 192, also unused: 8-9, 15, 40, 42, 46, 57, 65, 85-86,
+(* current max is 192, also unused: 8-9, 15, 42, 46, 57, 65, 85-86,
  113-115, 140, 162 *)
 
 (* doesn't really work - requires that identical terms with no token
@@ -232,6 +232,7 @@ let string_fragment f =
 let attribute a =
   match Ast0.unwrap a with
 Ast0.Attribute(attr) -> [39]
+  | Ast0.MetaAttribute(name,_,_) -> [40]
 
 let top_level t =
   match Ast0.unwrap t with
-- 
2.21.3

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


[Cocci] [PATCH 07/43] parsing_cocci: pretty_print_cocci: Reflect MetaAttribute & MetaAttributeDecl

2020-07-26 Thread Jaskaran Singh
MetaAttribute and MetaAttributeDecl are added to the SmPL AST. Reflect
these changes in pretty_print_cocci.ml.

Signed-off-by: Jaskaran Singh 
---
 parsing_cocci/pretty_print_cocci.ml | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/parsing_cocci/pretty_print_cocci.ml 
b/parsing_cocci/pretty_print_cocci.ml
index 095144b17..fe54a8d61 100644
--- a/parsing_cocci/pretty_print_cocci.ml
+++ b/parsing_cocci/pretty_print_cocci.ml
@@ -1110,6 +1110,8 @@ let unparse_cocci_mv rule = function
   print_string "comments "; print_name rule r n; print_string ";"
   | Ast.MetaFmtDecl(_,(r,n)) ->
   print_string "format "; print_name rule r n; print_string ";"
+  | Ast.MetaAttributeDecl(_,(r,n)) ->
+  print_string "attribute "; print_name rule r n; print_string ";"
   | Ast.MetaFragListDecl(_,(r,n),len) ->
   print_string "fragment list"; print_listlen rule len;
   print_name rule r n; print_string ";"
-- 
2.21.3

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


[Cocci] [PATCH 21/43] parsing_cocci: adjust_pragmas: Reflect MetaAttribute

2020-07-26 Thread Jaskaran Singh
MetaAttribute is added to the SmPL AST. Reflect these changes in
adjust_pragmas.ml.

Signed-off-by: Jaskaran Singh 
---
 parsing_cocci/adjust_pragmas.ml | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/parsing_cocci/adjust_pragmas.ml b/parsing_cocci/adjust_pragmas.ml
index 8f24fa718..6891d886f 100644
--- a/parsing_cocci/adjust_pragmas.ml
+++ b/parsing_cocci/adjust_pragmas.ml
@@ -225,6 +225,9 @@ let left_attribute attr =
   match Ast0.unwrap attr with
 Ast0.Attribute(a) ->
   call_right left_mcode a attr (function a -> Ast0.Attribute(a))
+  | Ast0.MetaAttribute(name,a,b) ->
+  call_right left_mcode name attr
+(function name -> Ast0.MetaAttribute(name,a,b))
 
 let left_fundecl name fninfo =
   let fncall_right processor data cont =
-- 
2.21.3

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


[Cocci] [PATCH 19/43] parsing_cocci: visitor_ast0: Reflect MetaAttribute

2020-07-26 Thread Jaskaran Singh
MetaAttribute is added to the SmPL AST. Visit meta attributes in the
SmPL AST0 visitor.

Signed-off-by: Jaskaran Singh 
---
 parsing_cocci/visitor_ast0.ml | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/parsing_cocci/visitor_ast0.ml b/parsing_cocci/visitor_ast0.ml
index e45f92415..0a5db947b 100644
--- a/parsing_cocci/visitor_ast0.ml
+++ b/parsing_cocci/visitor_ast0.ml
@@ -1154,7 +1154,10 @@ let visitor mode bind option_default
 (match Ast0.unwrap a with
   Ast0.Attribute(attr) ->
 let (attr_n,attr) = string_mcode attr in
-(attr_n,Ast0.Attribute(attr))) in
+(attr_n,Ast0.Attribute(attr))
+   | Ast0.MetaAttribute(name,constraints,pure) ->
+   let (n,name) = meta_mcode name in
+   (n,Ast0.MetaAttribute(name,constraints,pure))) in
 attributefn all_functions k a
 
   (* we only include the when string mcode w because the parameterised
-- 
2.21.3

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


[Cocci] [PATCH 27/43] parsing_cocci: unitary_ast0: Reflect MetaAttribute

2020-07-26 Thread Jaskaran Singh
MetaAttribute is added to the SmPL AST. Reflect these changes in
unitary_ast0.ml.

Signed-off-by: Jaskaran Singh 
---
 parsing_cocci/unitary_ast0.ml | 8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/parsing_cocci/unitary_ast0.ml b/parsing_cocci/unitary_ast0.ml
index fadfa4707..294dc91ff 100644
--- a/parsing_cocci/unitary_ast0.ml
+++ b/parsing_cocci/unitary_ast0.ml
@@ -174,6 +174,12 @@ let get_free checker t =
detect_unitary_frees(List.map r.VT0.combiner_rec_case_line case_lines)
 | _ -> k c in
 
+  let attribute r k a =
+match Ast0.unwrap a with
+  Ast0.MetaAttribute(name,_,_) ->
+   bind (k a) (checker name)
+| _ -> option_default in
+
   let statement r k s =
match Ast0.unwrap s with
  Ast0.MetaStmt(name,_,_) | Ast0.MetaStmtList(name,_,_,_) ->
@@ -207,7 +213,7 @@ let get_free checker t =
   donothing donothing
   ident expression donothing donothing typeC donothing parameter
   declaration field donothing statement donothing case_line donothing
-  donothing donothing in
+  attribute donothing in
 
   collect_unitary_nonunitary
 (List.concat (List.map res.VT0.combiner_rec_top_level t))
-- 
2.21.3

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


[Cocci] [PATCH 00/43] cocci: Add support for meta attributes to SmPL

2020-07-26 Thread Jaskaran Singh
This patch series aims to add support for meta attributes in SmPL.
Currently, only meta attributes in context and minus code are supported.

Changes include adding the MetaAttribute and MetaAttributeDecl constructors to
the SmPL ASTs and the MetaAttributeVal constructor to the C AST.

Two test cases are included for detecting and removing meta attributes.

Jaskaran Singh (43):
  parsing_cocci: ast0_cocci: Add MetaAttribute & MetaAttributeDecl
  parsing_cocci: parser: Parse meta attributes and metaattr decls
  parsing_cocci: parse_cocci: Reflect MetaAttribute & MetaAttributeDecl
  parsing_cocci: ast_cocci: Add MetaAttribute & MetaAttributeDecl
  parsing_cocci: iso_pattern: Reflect MetaAttribute & MetaAttributeDecl
  parsing_c: unparse_hrule: Reflect MetaAttribute & MetaAttributeDecl
  parsing_cocci: pretty_print_cocci: Reflect MetaAttribute & 
MetaAttributeDecl
  ocaml: coccilib: Reflect MetaAttribute & MetaAttributeDecl
  ocaml: yes_prepare_ocamlcocci: Reflect MetaAttribute & MetaAttributeDecl
  parsing_c: ast_c: Add MetaAttributeVal
  parsing_c: unparse_hrule: Reflect MetaAttributeVal
  engine: cocci_vs_c: Reflect MetaAttributeVal
  engine: pattern_c: Reflect MetaAttributeVal
  engine: pretty_print_engine: Add MetaAttributeVal
  ocaml: coccilib: Reflect MetaAttributeVal
  ocaml: ocamlcocci_aux: Reflect MetaAttributeVal
  ocaml: run_ocamlcocci: Reflect MetaAttributeVal
  python: pycocci_aux: Reflect MetaAttributeVal
  parsing_cocci: visitor_ast0: Reflect MetaAttribute
  parsing_cocci: check_meta: Reflect MetaAttribute
  parsing_cocci: adjust_pragmas: Reflect MetaAttribute
  parsing_cocci: context_neg: Reflect MetaAttribute
  parsing_cocci: compute_lines: Reflect MetaAttribute
  parsing_cocci: iso_pattern: Reflect MetaAttribute
  parsing_cocci: function_prototypes: Reflect MetaAttribute
  parsing_cocci: arity: Reflect MetaAttribute
  parsing_cocci: unitary_ast0: Reflect MetaAttribute
  parsing_cocci: unparse_ast0: Reflect MetaAttribute
  parsing_cocci: ast0toast: Reflect MetaAttribute
  parsing_cocci: visitor_ast: Reflect MetaAttribute
  parsing_cocci: cleanup_rules: Reflect MetaAttribute
  parsing_cocci: free_vars: Reflect MetaAttribute
  parsing_cocci: get_constants: Reflect MetaAttribute
  parsing_cocci: get_constants2: Reflect MetaAttribute
  parsing_cocci: index: Reflect MetaAttribute
  parsing_cocci: pretty_print_cocci: Reflect MetaAttribute
  parsing_cocci: safe_for_multi_decls: Reflect MetaAttribute
  parsing_cocci: unify_ast: Reflect MetaAttribute
  parsing_c: unparse_cocci: Reflect MetaAttribute
  engine: cocci_vs_c: Reflect MetaAttribute
  tools: spgen: Reflect MetaAttribute
  tests: Add test case to match meta attribute
  tests: Add test case to remove a meta attribute

 engine/cocci_vs_c.ml  |   23 ++---
 engine/pattern_c.ml   |6 
 engine/pretty_print_engine.ml |1 
 ocaml/coccilib.ml |1 
 ocaml/coccilib.mli|7 +
 ocaml/ocamlcocci_aux.ml   |2 +
 ocaml/run_ocamlcocci.ml   |1 
 ocaml/yes_prepare_ocamlcocci.ml   |1 
 parsing_c/ast_c.ml|1 
 parsing_c/ast_c.mli   |1 
 parsing_c/lib_parsing_c.ml|3 ++
 parsing_c/lib_parsing_c.mli   |3 ++
 parsing_c/pretty_print_c.ml   |   12 
 parsing_c/pretty_print_c.mli  |5 +++
 parsing_c/unparse_cocci.ml|6 
 parsing_c/unparse_hrule.ml|5 +++
 parsing_cocci/adjust_pragmas.ml   |3 ++
 parsing_cocci/arity.ml|   29 ++---
 parsing_cocci/ast0_cocci.ml   |1 
 parsing_cocci/ast0_cocci.mli  |1 
 parsing_cocci/ast0toast.ml|4 ++
 parsing_cocci/ast_cocci.ml|3 ++
 parsing_cocci/ast_cocci.mli   |2 +
 parsing_cocci/check_meta.ml   |   27 ++-
 parsing_cocci/cleanup_rules.ml|   10 ++-
 parsing_cocci/compute_lines.ml|   14 ++
 parsing_cocci/context_neg.ml  |   18 -
 parsing_cocci/data.ml |1 
 parsing_cocci/data.mli|1 
 parsing_cocci/free_vars.ml|   28 ++--
 parsing_cocci/function_prototypes.ml  |   10 ++-
 parsing_cocci/get_constants.ml|7 -
 parsing_cocci/get_constants2.ml   |9 +++---
 parsing_cocci/index.ml|3 +-
 parsing_cocci/iso_pattern.ml  |   46 +-
 parsing_cocci/lexer_cocci.mll |   12 
 parsing_cocci/parse_aux.ml|4 ++
 parsing_cocci/parse_cocci.ml  |   11 ++--
 parsing_cocci/parser_cocci_menhir.mly |   25 +

[Cocci] [PATCH 02/43] parsing_cocci: parser: Parse meta attributes and metaattr decls

2020-07-26 Thread Jaskaran Singh
Introduce changes to parse meta attributes and meta attribute
declarations in SmPL rules. Currently, meta attributes are only parsed
in context and minus code.

Signed-off-by: Jaskaran Singh 
---
 parsing_cocci/data.ml |  1 +
 parsing_cocci/data.mli|  1 +
 parsing_cocci/lexer_cocci.mll | 12 
 parsing_cocci/parse_aux.ml|  4 
 parsing_cocci/parser_cocci_menhir.mly | 25 +
 5 files changed, 35 insertions(+), 8 deletions(-)

diff --git a/parsing_cocci/data.ml b/parsing_cocci/data.ml
index d604fd636..3c5e6c941 100644
--- a/parsing_cocci/data.ml
+++ b/parsing_cocci/data.ml
@@ -132,6 +132,7 @@ let add_binaryOp_meta:
 
 let add_type_name: (string -> unit) ref = ref uninitialized_add_meta
 let add_attribute: (string -> unit) ref = ref uninitialized_add_meta
+let add_attribute_meta: cstr_meta_type ref = ref uninitialized_add_meta
 let add_declarer_name: (string -> unit) ref = ref uninitialized_add_meta
 let add_iterator_name: (string -> unit) ref = ref uninitialized_add_meta
 
diff --git a/parsing_cocci/data.mli b/parsing_cocci/data.mli
index 9fa4e45a2..88f29baa7 100644
--- a/parsing_cocci/data.mli
+++ b/parsing_cocci/data.mli
@@ -112,6 +112,7 @@ val add_binaryOp_meta:
 
 val add_type_name: (string -> unit) ref
 val add_attribute: (string -> unit) ref
+val add_attribute_meta: cstr_meta_type ref
 val add_declarer_name: (string -> unit) ref
 val add_iterator_name: (string -> unit) ref
 val init_rule: (unit -> unit) ref
diff --git a/parsing_cocci/lexer_cocci.mll b/parsing_cocci/lexer_cocci.mll
index f05c6de02..9e85efe48 100644
--- a/parsing_cocci/lexer_cocci.mll
+++ b/parsing_cocci/lexer_cocci.mll
@@ -533,6 +533,18 @@ let init _ = (* per file, first .cocci then iso *)
TDirective (Ast.Space name, clt)
| _ -> Tattr (name, clt) in
   Hashtbl.replace attr_names name fn);
+  Data.add_attribute_meta :=
+(fun name cstr pure ->
+  let fn ((d,ln,_,_,_,_,_,_,_,_) as clt) =
+if (match d with (Data.PLUS | Data.PLUSPLUS) -> true | _ -> false)
+then
+  (* TODO support meta attributes in plus code *)
+ failwith
+   (Printf.sprintf
+ "%d: meta attributes currently only allowed in context/minus code"
+ ln);
+TMetaAttribute(name,cstr,pure,clt) in
+  Hashtbl.replace metavariables (get_name name) fn);
   Data.add_declarer_name :=
 (function name ->
   let fn clt = TDeclarerId(name,clt) in
diff --git a/parsing_cocci/parse_aux.ml b/parsing_cocci/parse_aux.ml
index f2036bfc1..7ba7ce861 100644
--- a/parsing_cocci/parse_aux.ml
+++ b/parsing_cocci/parse_aux.ml
@@ -345,6 +345,10 @@ let check_meta_tyopt type_irrelevant v =
   (match meta_lookup rule name v with
Ast.MetaFragListDecl(_,_,_) -> ()
   | _ -> fail name)
+  | Ast.MetaAttributeDecl(Ast.NONE,(rule,name)) ->
+  (match meta_lookup rule name v with
+   Ast.MetaAttributeDecl(_,_) -> ()
+  | _ -> fail name)
   | Ast.MetaAnalysisDecl(analyzer,(rule,name)) ->
   (match meta_lookup rule name v with
Ast.MetaAnalysisDecl(analyzer1,_) ->
diff --git a/parsing_cocci/parser_cocci_menhir.mly 
b/parsing_cocci/parser_cocci_menhir.mly
index af9726e10..056ed0048 100644
--- a/parsing_cocci/parser_cocci_menhir.mly
+++ b/parsing_cocci/parser_cocci_menhir.mly
@@ -254,6 +254,7 @@ let inline_id aft = function
 %tokenTMetaErr
 %token   TMetaParam TMetaStm
 %token   TMetaInit TMetaDecl TMetaField TMeta
+%token   TMetaAttribute
 %token  TMetaParamList TMetaExpList TMetaInitList
 %token  TMetaFieldList TMetaStmList TMetaDParamList
 %token  TMetaExp
@@ -764,6 +765,10 @@ delimited_list_len:
 { (fun arity name pure check_meta constraints ->
   let tok = check_meta(Ast_cocci.MetaTypeDecl(arity,name)) in
   !Data.add_type_meta name constraints pure; tok) }
+| TAttribute
+{ (fun arity name pure check_meta constraints ->
+  let tok = check_meta(Ast.MetaAttributeDecl(arity,name)) in
+  !Data.add_attribute_meta name constraints pure; tok) }
 | TError
 { (fun arity name pure check_meta constraints ->
   let tok = check_meta(Ast_cocci.MetaErrDecl(arity,name)) in
@@ -1495,11 +1500,11 @@ fninfo:
let _ = List.find (function Ast0_cocci.FInline(_) -> true | _ -> false) 
$2 in
raise (Semantic_cocci.Semantic "duplicate inline")
   with Not_found -> (Ast0_cocci.FInline(Parse_aux.clt2mcode "inline" 
$1))::$2 }
-  | a=Tattrfninfo
+  | a=attrfninfo
   { try
let _ = List.find (function Ast0_cocci.FAttr(_) -> true | _ -> false) 
$2 in
raise (Semantic_cocci.Semantic "multiple attributes")
-  with Not_found -> (Ast0_cocci.FAttr(Parse_aux.make_attr a))::$2 }
+  with Not_found -> (Ast0_cocci.FAttr(a))::$2 }
 
 fninfo_nt:
 /* e

[Cocci] [PATCH 04/43] parsing_cocci: ast_cocci: Add MetaAttribute & MetaAttributeDecl

2020-07-26 Thread Jaskaran Singh
Add the MetaAttribute and MetaAttributeDecl consturctors the SmPL AST.

Signed-off-by: Jaskaran Singh 
---
 parsing_cocci/ast_cocci.ml  | 3 +++
 parsing_cocci/ast_cocci.mli | 2 ++
 2 files changed, 5 insertions(+)

diff --git a/parsing_cocci/ast_cocci.ml b/parsing_cocci/ast_cocci.ml
index 29c58..656c3d929 100644
--- a/parsing_cocci/ast_cocci.ml
+++ b/parsing_cocci/ast_cocci.ml
@@ -128,6 +128,7 @@ and metavar =
   | MetaPosDecl of arity * meta_name (* name *)
   | MetaComDecl of arity * meta_name (* name *)
   | MetaFmtDecl of arity * meta_name (* name *)
+  | MetaAttributeDecl of arity * meta_name (* name *)
   | MetaFragListDecl of arity * meta_name (* name *) * list_len (*len*)
   | MetaAnalysisDecl of string * meta_name (* name *)
   | MetaDeclarerDecl of arity * meta_name (* name *)
@@ -626,6 +627,7 @@ and fninfo =
 
 and base_attr =
 Attribute of string mcode
+  | MetaAttribute of meta_name mcode * constraints * keep_binding * inherited
 
 and attr = base_attr wrap
 
@@ -914,6 +916,7 @@ let get_meta_name = function
   | MetaPosDecl(_ar,nm) -> nm
   | MetaComDecl(_ar,nm) -> nm
   | MetaFmtDecl(_ar,nm) -> nm
+  | MetaAttributeDecl(_ar,nm) -> nm
   | MetaFragListDecl(_ar,nm,_nm1) -> nm
   | MetaAnalysisDecl(_code,nm) -> nm
   | MetaDeclarerDecl(_ar,nm) -> nm
diff --git a/parsing_cocci/ast_cocci.mli b/parsing_cocci/ast_cocci.mli
index 983449123..9495e83c8 100644
--- a/parsing_cocci/ast_cocci.mli
+++ b/parsing_cocci/ast_cocci.mli
@@ -113,6 +113,7 @@ and metavar =
   | MetaPosDecl of arity * meta_name (* name *)
   | MetaComDecl of arity * meta_name (* name *)
   | MetaFmtDecl of arity * meta_name (* name *)
+  | MetaAttributeDecl of arity * meta_name (* name *)
   | MetaFragListDecl of arity * meta_name (* name *) * list_len (*len*)
   | MetaAnalysisDecl of string * meta_name (* name *)
   | MetaDeclarerDecl of arity * meta_name (* name *)
@@ -606,6 +607,7 @@ and fninfo =
 
 and base_attr =
 Attribute of string mcode
+  | MetaAttribute of meta_name mcode * constraints * keep_binding * inherited
 
 and attr = base_attr wrap
 
-- 
2.21.3

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


[Cocci] [PATCH 11/43] parsing_c: unparse_hrule: Reflect MetaAttributeVal

2020-07-26 Thread Jaskaran Singh
MetaAttributeVal is added to the C AST. Reflect these changes in
unparse_hrule.ml.

Signed-off-by: Jaskaran Singh 
---
 parsing_c/unparse_hrule.ml | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/parsing_c/unparse_hrule.ml b/parsing_c/unparse_hrule.ml
index 4d7ba93cc..9d6421f31 100644
--- a/parsing_c/unparse_hrule.ml
+++ b/parsing_c/unparse_hrule.ml
@@ -251,6 +251,7 @@ let print_extra_typedefs pr env =
   | Ast_c.MetaFieldListVal(fields) ->
  Visitor_c.vk_struct_fields bigf fields
   | Ast_c.MetaFmtVal(fmt) -> Visitor_c.vk_string_format bigf fmt
+  | Ast_c.MetaAttributeVal(attr) -> Visitor_c.vk_attribute bigf attr
   | Ast_c.MetaFragListVal(frags) ->
  Visitor_c.vk_string_fragments bigf frags
   | Ast_c.MetaStmtVal(stm,_,_) -> Visitor_c.vk_statement bigf stm
@@ -313,6 +314,8 @@ let rename argids env =
   Ast_c.MetaFieldListVal(Visitor_c.vk_struct_fields_s bigf stm)
| Ast_c.MetaFmtVal(fmt) ->
   Ast_c.MetaFmtVal(Visitor_c.vk_string_format_s bigf fmt)
+   | Ast_c.MetaAttributeVal(attr) ->
+  Ast_c.MetaAttributeVal(Visitor_c.vk_attribute_s bigf attr)
| Ast_c.MetaFragListVal(frags) ->
   Ast_c.MetaFragListVal(Visitor_c.vk_string_fragments_s bigf frags)
| Ast_c.MetaStmtVal(stm,original,ty) ->
-- 
2.21.3

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


[Cocci] [PATCH 18/43] python: pycocci_aux: Reflect MetaAttributeVal

2020-07-26 Thread Jaskaran Singh
MetaAttributeVal is added to the C AST. Reflect these changes in
pycocci_aux.ml.

Signed-off-by: Jaskaran Singh 
---
 python/pycocci_aux.ml | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/python/pycocci_aux.ml b/python/pycocci_aux.ml
index d83059455..85a8eefe3 100644
--- a/python/pycocci_aux.ml
+++ b/python/pycocci_aux.ml
@@ -81,6 +81,8 @@ let stringrep = function
 call_pretty0 Pretty_print_c.pp_string_fragment_list_gen frags
 | Ast_c.MetaFmtVal fmt ->
 call_pretty0 Pretty_print_c.pp_string_format_gen fmt
+| Ast_c.MetaAttributeVal attr ->
+call_pretty0 Pretty_print_c.pp_attribute_gen attr
 | Ast_c.MetaListlenVal n -> string_of_int n
 | Ast_c.MetaPosVal (pos1, pos2) ->
 let print_pos = function
-- 
2.21.3

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


[Cocci] [PATCH 12/43] engine: cocci_vs_c: Reflect MetaAttributeVal

2020-07-26 Thread Jaskaran Singh
MetaAttributeVal is added to the C AST. Reflect these changes in
cocci_vs_c.ml.

Signed-off-by: Jaskaran Singh 
---
 engine/cocci_vs_c.ml| 8 ++--
 parsing_c/lib_parsing_c.ml  | 3 +++
 parsing_c/lib_parsing_c.mli | 3 +++
 3 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/engine/cocci_vs_c.ml b/engine/cocci_vs_c.ml
index cba6c8d01..ed91a4785 100644
--- a/engine/cocci_vs_c.ml
+++ b/engine/cocci_vs_c.ml
@@ -229,6 +229,8 @@ let equal_metavarval valu valu' =
 
   | Ast_c.MetaFmtVal a, Ast_c.MetaFmtVal b ->
   Lib_parsing_c.al_string_format a = Lib_parsing_c.al_string_format b
+  | Ast_c.MetaAttributeVal a, Ast_c.MetaAttributeVal b ->
+  Lib_parsing_c.al_attribute a = Lib_parsing_c.al_attribute b
   | Ast_c.MetaFragListVal a, Ast_c.MetaFragListVal b ->
   Lib_parsing_c.al_string_fragments a =
   Lib_parsing_c.al_string_fragments b
@@ -287,7 +289,7 @@ let equal_metavarval valu valu' =
   |B.MetaExprListVal _
   |B.MetaExprVal _|B.MetaLocalFuncVal _|B.MetaFuncVal _|B.MetaIdVal _
   |B.MetaAssignOpVal _ | B.MetaBinaryOpVal _
-  |B.MetaFmtVal _|B.MetaFragListVal _
+  |B.MetaFmtVal _|B.MetaFragListVal _|B.MetaAttributeVal _
 ), _
   -> raise (Impossible 16)
 
@@ -322,6 +324,8 @@ let equal_inh_metavarval valu valu'=
   | Ast_c.MetaFmtVal a, Ast_c.MetaFmtVal b ->
   Lib_parsing_c.al_inh_string_format a =
   Lib_parsing_c.al_inh_string_format b
+  | Ast_c.MetaAttributeVal a, Ast_c.MetaAttributeVal b ->
+  Lib_parsing_c.al_inh_attribute a = Lib_parsing_c.al_inh_attribute b
   | Ast_c.MetaFragListVal a, Ast_c.MetaFragListVal b ->
   Lib_parsing_c.al_inh_string_fragments a =
   Lib_parsing_c.al_inh_string_fragments b
@@ -388,7 +392,7 @@ let equal_inh_metavarval valu valu'=
   |B.MetaExprListVal _
   |B.MetaExprVal _|B.MetaLocalFuncVal _|B.MetaFuncVal _|B.MetaIdVal _
   |B.MetaAssignOpVal _ | B.MetaBinaryOpVal _
-  |B.MetaFmtVal _|B.MetaFragListVal _
+  |B.MetaFmtVal _|B.MetaFragListVal _|B.MetaAttributeVal _
 ), _
   -> raise (Impossible 17)
 
diff --git a/parsing_c/lib_parsing_c.ml b/parsing_c/lib_parsing_c.ml
index 99e43be3b..687833604 100644
--- a/parsing_c/lib_parsing_c.ml
+++ b/parsing_c/lib_parsing_c.ml
@@ -86,6 +86,7 @@ let al_name  x = Visitor_c.vk_name_s  
(strip_info_visitor()) x
 let al_string_format x = Visitor_c.vk_string_format_s (strip_info_visitor()) x
 let al_string_fragments x =
   Visitor_c.vk_string_fragments_s (strip_info_visitor()) x
+let al_attribute x = Visitor_c.vk_attribute_s (strip_info_visitor()) x
 
 let al_node  x = Visitor_c.vk_node_s  (strip_info_visitor()) x
 
@@ -147,6 +148,7 @@ let al_inh_string_format x =
   Visitor_c.vk_string_format_s (strip_inh_info_visitor()) x
 let al_inh_string_fragments x =
   Visitor_c.vk_string_fragments_s (strip_inh_info_visitor()) x
+let al_inh_attribute x = Visitor_c.vk_attribute_s (strip_inh_info_visitor()) x
 
 
 
@@ -184,6 +186,7 @@ let semi_al_string_format =
   Visitor_c.vk_string_format_s semi_strip_info_visitor
 let semi_al_string_fragments =
   Visitor_c.vk_string_fragments_s semi_strip_info_visitor
+let semi_al_attribute = Visitor_c.vk_attribute_s semi_strip_info_visitor
 
 let semi_al_program =
   List.map (Visitor_c.vk_toplevel_s semi_strip_info_visitor)
diff --git a/parsing_c/lib_parsing_c.mli b/parsing_c/lib_parsing_c.mli
index d9578f3ca..0e53f9060 100644
--- a/parsing_c/lib_parsing_c.mli
+++ b/parsing_c/lib_parsing_c.mli
@@ -22,6 +22,7 @@ val al_arguments :
 val al_fields : Ast_c.field list -> Ast_c.field list
 val al_name : Ast_c.name -> Ast_c.name
 val al_string_format : Ast_c.string_format -> Ast_c.string_format
+val al_attribute : Ast_c.attribute -> Ast_c.attribute
 val al_string_fragments :
   Ast_c.string_fragment list -> Ast_c.string_fragment list
 val al_node : Control_flow_c.node -> Control_flow_c.node
@@ -44,6 +45,7 @@ val al_inh_arguments :
 val al_inh_string_format : Ast_c.string_format -> Ast_c.string_format
 val al_inh_string_fragments :
   Ast_c.string_fragment list -> Ast_c.string_fragment list
+val al_inh_attribute : Ast_c.attribute -> Ast_c.attribute
 val semi_strip_info_visitor : Visitor_c.visitor_c_s
 val semi_al_expr : Ast_c.expression -> Ast_c.expression
 val semi_al_declaration : Ast_c.declaration -> Ast_c.declaration
@@ -67,6 +69,7 @@ val semi_al_arguments :
 val semi_al_string_format : Ast_c.string_format -> Ast_c.string_format
 val semi_al_string_fragments :
   Ast_c.string_fragment list -> Ast_c.string_fragment list
+val semi_al_attribute : Ast_c.attribute -> Ast_c.attribute
 val semi_al_program : Ast_c.toplevel list -> Ast_c.toplevel list
 val real_strip_info_visitor : 'a -> Visitor_c.visitor_c_s
 val real_al_expr : Ast_c.expression -> Ast_c.expression
-- 
2.21.3

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


[Cocci] [PATCH 20/43] parsing_cocci: check_meta: Reflect MetaAttribute

2020-07-26 Thread Jaskaran Singh
MetaAttribute is added to the SmPL AST. Reflect these changes in
check_meta.ml.

Signed-off-by: Jaskaran Singh 
---
 parsing_cocci/check_meta.ml | 27 +++
 1 file changed, 19 insertions(+), 8 deletions(-)

diff --git a/parsing_cocci/check_meta.ml b/parsing_cocci/check_meta.ml
index 342cbd87f..fb8d05ccc 100644
--- a/parsing_cocci/check_meta.ml
+++ b/parsing_cocci/check_meta.ml
@@ -173,8 +173,9 @@ let rec expression context old_metas table minus e =
   expression ID old_metas table minus exp;
   ident FIELD old_metas table minus field
   | Ast0.Cast(lp,ty,attr,rp,exp) ->
-  (* No meta attribute yet *)
-  typeC old_metas table minus ty; expression ID old_metas table minus exp
+  typeC old_metas table minus ty;
+  List.iter (attribute old_metas table minus) attr;
+  expression ID old_metas table minus exp
   | Ast0.SizeOfExpr(szf,exp) -> expression ID old_metas table minus exp
   | Ast0.SizeOfType(szf,lp,ty,rp) -> typeC old_metas table minus ty
   | Ast0.TypeExp(ty) -> typeC old_metas table minus ty
@@ -266,6 +267,7 @@ and declaration context old_metas table minus d =
   | Ast0.Init(stg,ty,id,attr,eq,ini,sem) ->
   typeC old_metas table minus ty;
   ident context old_metas table minus id;
+  List.iter (attribute old_metas table minus) attr;
   (match Ast0.unwrap ini with
Ast0.InitExpr exp ->
  expression ID old_metas table minus exp
@@ -277,14 +279,15 @@ and declaration context old_metas table minus d =
  else*)
initialiser old_metas table minus ini)
   | Ast0.UnInit(stg,ty,id,attr,sem) ->
-  typeC old_metas table minus ty; ident context old_metas table minus id
+  typeC old_metas table minus ty; ident context old_metas table minus id;
+  List.iter (attribute old_metas table minus) attr
   | Ast0.FunProto(fi,name,lp1,params,va,rp1,sem) ->
   ident FN old_metas table minus name;
   List.iter (fninfo old_metas table minus) fi;
   parameter_list old_metas table minus params
   | Ast0.MacroDecl(stg,name,lp,args,rp,attr,sem) ->
-  (* no meta attribute yet *)
   ident GLOBAL old_metas table minus name;
+  List.iter (attribute old_metas table minus) attr;
   dots (expression ID old_metas table minus) args
   | Ast0.MacroDeclInit(stg,name,lp,args,rp,eq,ini,sem) ->
   ident GLOBAL old_metas table minus name;
@@ -292,7 +295,9 @@ and declaration context old_metas table minus d =
   (match Ast0.unwrap ini with
Ast0.InitExpr exp -> expression ID old_metas table minus exp
   |_ -> initialiser old_metas table minus ini)
-  | Ast0.TyDecl(ty,attr,sem) -> typeC old_metas table minus ty
+  | Ast0.TyDecl(ty,attr,sem) ->
+  typeC old_metas table minus ty;
+  List.iter (attribute old_metas table minus) attr
   | Ast0.Typedef(stg,ty,id,sem) ->
   typeC old_metas table minus ty;
   typeC old_metas table minus id
@@ -377,9 +382,9 @@ and initialiser_list old_metas table minus =
 and parameterTypeDef old_metas table minus param =
   match Ast0.unwrap param with
 Ast0.Param(ty,id,attr) ->
-  (* No meta attribute yet *)
   get_opt (ident ID old_metas table minus) id;
-  typeC old_metas table minus ty
+  typeC old_metas table minus ty;
+  List.iter (attribute old_metas table minus) attr
   | Ast0.MetaParam(name,_,_) ->
   check_table table minus name
   | Ast0.MetaParamList(name,len,_,_) ->
@@ -519,7 +524,13 @@ and fninfo old_metas table minus = function
 Ast0.FStorage(stg) -> ()
   | Ast0.FType(ty) -> typeC old_metas table minus ty
   | Ast0.FInline(inline) -> ()
-  | Ast0.FAttr(attr) -> ()
+  | Ast0.FAttr(attr) -> attribute old_metas table minus attr
+
+and attribute old_metas table minus x =
+  match Ast0.unwrap x with
+Ast0.MetaAttribute(name,_,_) ->
+  check_table table minus name
+  | _ -> ()
 
 and whencode notfn alwaysfn expression = function
 Ast0.WhenNot (_,_,a) -> notfn a
-- 
2.21.3

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


[Cocci] [PATCH 17/43] ocaml: run_ocamlcocci: Reflect MetaAttributeVal

2020-07-26 Thread Jaskaran Singh
MetaAttributeVal is added to the C AST. Reflect these changes in
run_ocamlcocci.ml.

Signed-off-by: Jaskaran Singh 
---
 ocaml/run_ocamlcocci.ml | 1 +
 1 file changed, 1 insertion(+)

diff --git a/ocaml/run_ocamlcocci.ml b/ocaml/run_ocamlcocci.ml
index 065428391..14decf886 100644
--- a/ocaml/run_ocamlcocci.ml
+++ b/ocaml/run_ocamlcocci.ml
@@ -76,6 +76,7 @@ let ast_binding vl = function
   | Ast_c.MetaStmtListVal(stm,_) -> Coccilib.StmtList stm
   | Ast_c.MetaFragListVal frags -> Coccilib.FragList frags
   | Ast_c.MetaFmtVal fmt -> Coccilib.Fmt fmt
+  | Ast_c.MetaAttributeVal attr -> Coccilib.Attribute attr
   | Ast_c.MetaNoVal -> failwith "no value for script metavariable"
   | Ast_c.MetaComValList l -> Coccilib.AstCom l
 
-- 
2.21.3

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


[Cocci] [PATCH 15/43] ocaml: coccilib: Reflect MetaAttributeVal

2020-07-26 Thread Jaskaran Singh
MetaAttributeVal is added to the C AST. Reflect these changes in
coccilib.ml and coccilib.mli.

Signed-off-by: Jaskaran Singh 
---
 ocaml/coccilib.ml  | 1 +
 ocaml/coccilib.mli | 3 +++
 2 files changed, 4 insertions(+)

diff --git a/ocaml/coccilib.ml b/ocaml/coccilib.ml
index 0a7e0eb98..459f4c6be 100644
--- a/ocaml/coccilib.ml
+++ b/ocaml/coccilib.ml
@@ -70,6 +70,7 @@ type param_type =
   | FieldList of Ast_c.field list
   | FragList of Ast_c.string_fragment list
   | Fmt of Ast_c.string_format
+  | Attribute of Ast_c.attribute
   | Stmt of Ast_c.statement
   | StmtList of Ast_c.statement_sequencable list
 
diff --git a/ocaml/coccilib.mli b/ocaml/coccilib.mli
index 3960d1046..970229ee9 100644
--- a/ocaml/coccilib.mli
+++ b/ocaml/coccilib.mli
@@ -434,6 +434,7 @@ module Ast_c :
   | MetaStmtListVal of statement_sequencable list * stripped
   | MetaDParamListVal of string wrap wrap2 list
   | MetaFmtVal of string_format
+  | MetaAttributeVal of attribute
   | MetaFragListVal of string_fragment list
   | MetaAssignOpVal of assignOp
   | MetaBinaryOpVal of binaryOp
@@ -854,6 +855,7 @@ module Pretty_print_c :
   fragment : Ast_c.string_fragment printer;
   fragment_list : Ast_c.string_fragment list printer;
   format : Ast_c.string_format printer;
+  attribute : Ast_c.attribute printer;
   flow : Control_flow_c.node printer;
   name : Ast_c.name printer;
 }
@@ -3785,6 +3787,7 @@ type param_type =
   | FieldList of Ast_c.field list
   | FragList of Ast_c.string_fragment list
   | Fmt of Ast_c.string_format
+  | Attribute of Ast_c.attribute
   | Stmt of Ast_c.statement
   | StmtList of Ast_c.statement_sequencable list
 val fcts :
-- 
2.21.3

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


[Cocci] [PATCH 24/43] parsing_cocci: iso_pattern: Reflect MetaAttribute

2020-07-26 Thread Jaskaran Singh
MetaAttribute is added to the SmPL AST. Reflect these changes in
iso_pattern.ml.

Signed-off-by: Jaskaran Singh 
---
 parsing_cocci/iso_pattern.ml | 44 +++-
 1 file changed, 38 insertions(+), 6 deletions(-)

diff --git a/parsing_cocci/iso_pattern.ml b/parsing_cocci/iso_pattern.ml
index 4a9a80b4f..c800665fd 100644
--- a/parsing_cocci/iso_pattern.ml
+++ b/parsing_cocci/iso_pattern.ml
@@ -475,13 +475,19 @@ let match_maker checks_needed context_required 
whencode_allowed =
  Ast0.MetaStmt(name,_,pure) | Ast0.MetaStmtList(name,_,_,pure) -> pure
| _ -> Ast0.Impure) in
 
+let attribute r k a =
+  bind (bind (pure_mcodekind (Ast0.get_mcodekind a)) (k a))
+   (match Ast0.unwrap a with
+ Ast0.MetaAttribute(name,_,pure) -> pure
+   | _ -> Ast0.Impure) in
+
 V0.flat_combiner bind option_default
   mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode
   mcode mcode
   donothing donothing donothing donothing donothing donothing donothing
   donothing donothing
   ident expression assignOp binaryOp typeC init param decl field donothing
-  stmt donothing donothing donothing donothing donothing in
+  stmt donothing donothing donothing attribute donothing in
 
   let add_pure_list_binding name pure is_pure builder1 builder2 lst =
 match (checks_needed,pure) with
@@ -1417,10 +1423,22 @@ let match_maker checks_needed context_required 
whencode_allowed =
   |_ -> return false in
 loop (patterninfo,cinfo)
 
-  and match_attribute a1 a2 =
-match (Ast0.unwrap a1,Ast0.unwrap a2) with
-  (Ast0.Attribute(attr1),Ast0.Attribute(attr2)) ->
-check_mcode attr1 attr2
+  and match_attribute pattern a =
+match Ast0.unwrap pattern with
+  Ast0.MetaAttribute(name,_,pure) ->
+   add_pure_binding name pure pure_sp_code.VT0.combiner_rec_attribute
+ (function a -> Ast0.AttributeTag a)
+ a
+| up ->
+   if not(checks_needed) || not(context_required) || is_context a
+   then
+ match (up,Ast0.unwrap a) with
+   (Ast0.Attribute(attra),Ast0.Attribute(attrb)) ->
+  if mcode_equal attra attrb
+  then check_mcode attra attrb
+  else return false
+ | _ -> return false
+   else return_false (ContextRequired (Ast0.AttributeTag a))
 
   and match_attributes a1 a2 =
 match_list match_attribute
@@ -2169,13 +2187,27 @@ let instantiate bindings mv_bindings model =
(List.filter (function (x,v) -> x = (dot_term d)) bindings)))
 | _ -> e in
 
+  let attributefn r k e =
+let e = k e in
+match Ast0.unwrap e with
+  Ast0.MetaAttribute(name,cstr,pure) ->
+   (rebuild_mcode None).VT0.rebuilder_rec_attribute
+ (match lookup name bindings mv_bindings with
+   Common.Left(Ast0.AttributeTag(a)) -> a
+ | Common.Left(_) -> failwith "not possible 1"
+ | Common.Right(new_mv) ->
+ Ast0.rewrap e
+   (Ast0.MetaAttribute
+  (Ast0.set_mcode_data new_mv name,cstr,pure)))
+| _ -> e in
+
   V0.flat_rebuilder
 mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode
 mcode mcode
 (dots elist) donothing (dots plist) (dots slist) donothing donothing
 donothing donothing donothing
 identfn exprfn donothing donothing tyfn initfn paramfn declfn fieldfn
-enumdeclfn stmtfn donothing donothing donothing donothing donothing
+enumdeclfn stmtfn donothing donothing donothing attributefn donothing
 
 (* - *)
 
-- 
2.21.3

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


[Cocci] [PATCH 03/43] parsing_cocci: parse_cocci: Reflect MetaAttribute & MetaAttributeDecl

2020-07-26 Thread Jaskaran Singh
MetaAttribute and MetaAttributeDecl are added to the SmPL AST. Reflect
these changes in parse_cocci.ml.

Signed-off-by: Jaskaran Singh 
---
 parsing_cocci/parse_cocci.ml | 11 +--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/parsing_cocci/parse_cocci.ml b/parsing_cocci/parse_cocci.ml
index e455fce06..e8dca63a3 100644
--- a/parsing_cocci/parse_cocci.ml
+++ b/parsing_cocci/parse_cocci.ml
@@ -243,6 +243,7 @@ let token2c (tok,_) add_clt =
   | PC.TMetaDParamList(_,_,_,_,clt) -> add_clt "dparamlistmeta" clt
   | PC.TMetaFunc(_,_,_,clt)  -> add_clt "funcmeta" clt
   | PC.TMetaLocalFunc(_,_,_,clt) -> add_clt "funcmeta" clt
+  | PC.TMetaAttribute(_,_,_,clt) -> add_clt "attributemeta" clt
   | PC.TMetaPos(_,_,_,clt)   -> "posmeta"
   | PC.TMetaCom(_,_,clt)   -> "commeta"
   | PC.TMPtVirg -> ";"
@@ -404,6 +405,7 @@ let plus_attachable only_plus (tok,_) =
   | PC.TCPar0(s,clt) -> NOTPLUS
   | PC.TMetaPos(nm,_,_,_) -> NOTPLUS
   | PC.TMetaCom(nm,_,_) -> NOTPLUS
+  | PC.TMetaAttribute(nm,_,_,_) -> NOTPLUS
   | PC.TSub(clt) -> NOTPLUS
   | PC.TDirective(_,clt) -> NOTPLUS
   | PC.TAttr_(clt) -> NOTPLUS
@@ -466,6 +468,7 @@ let get_clt (tok,_) =
   | PC.TMetaFieldList(_,_,_,_,clt)
   | PC.TMetaFunc(_,_,_,clt) | PC.TMetaLocalFunc(_,_,_,clt)
   | PC.TMetaPos(_,_,_,clt) | PC.TMetaCom(_,_,clt)
+  | PC.TMetaAttribute(_,_,_,clt)
   | PC.TMetaDeclarer(_,_,_,clt) | PC.TMetaIterator(_,_,_,clt)
 
   | PC.TWhen(clt) | PC.TWhenTrue(clt) | PC.TWhenFalse(clt)
@@ -680,6 +683,7 @@ let update_clt (tok,x) clt =
   | PC.TMetaDParamList(a,b,c,d,_) -> (PC.TMetaDParamList(a,b,c,d,clt),x)
   | PC.TMetaFunc(a,b,c,_)  -> (PC.TMetaFunc(a,b,c,clt),x)
   | PC.TMetaLocalFunc(a,b,c,_) -> (PC.TMetaLocalFunc(a,b,c,clt),x)
+  | PC.TMetaAttribute(a,b,c,_) -> (PC.TMetaAttribute(a,b,c,clt),x)
 
   | PC.TMetaDeclarer(a,b,c,_) -> (PC.TMetaDeclarer(a,b,c,clt),x)
   | PC.TMetaIterator(a,b,c,_) -> (PC.TMetaIterator(a,b,c,clt),x)
@@ -929,7 +933,8 @@ let split_token ((tok,_) as t) =
   | PC.TMetaDeclarer(_,_,_,clt) | PC.TMetaIterator(_,_,_,clt) -> split t clt
   | PC.TMPtVirg | PC.TArob | PC.TArobArob | PC.TScript _
   | PC.TInitialize | PC.TFinalize -> ([t],[t])
-  | PC.TPArob clt | PC.TMetaPos(_,_,_,clt) | PC.TMetaCom(_,_,clt) -> split t 
clt
+  | PC.TPArob clt | PC.TMetaPos(_,_,_,clt) | PC.TMetaCom(_,_,clt)
+  | PC.TMetaAttribute (_,_,_,clt) -> split t clt
 
   | PC.TFunDecl(clt) | PC.TFunProto(clt)
   | PC.TWhen(clt) | PC.TWhenTrue(clt) | PC.TWhenFalse(clt)
@@ -1220,7 +1225,8 @@ let detect_types in_meta_decls l =
 | (PC.TMetaStmList(_,_,_,_,_),_)
 | (PC.TMetaDParamList(_,_,_,_,_),_)
 | (PC.TMetaPos(_,_,_,_),_)
-| (PC.TMetaCom(_,_,_),_) -> in_meta_decls
+| (PC.TMetaCom(_,_,_),_)
+| (PC.TMetaAttribute(_,_,_,_),_) -> in_meta_decls
 | _ -> false in
   let is_tyleft = function (* things that can start a var decl *)
   (PC.TMul(_),_)
@@ -1330,6 +1336,7 @@ let token2line (tok,_) =
   | PC.TMetaStm(_,_,_,clt) | PC.TMetaStmList(_,_,_,_,clt)
   | PC.TMetaDParamList(_,_,_,_,clt) | PC.TMetaFunc(_,_,_,clt)
   | PC.TMetaLocalFunc(_,_,_,clt) | PC.TMetaPos(_,_,_,clt) | 
PC.TMetaCom(_,_,clt)
+  | PC.TMetaAttribute(_,_,_,clt)
 
   | PC.TFunDecl(clt) | PC.TFunProto(clt)
   | PC.TWhen(clt) | PC.TWhenTrue(clt) | PC.TWhenFalse(clt)
-- 
2.21.3

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


[Cocci] [PATCH 25/43] parsing_cocci: function_prototypes: Reflect MetaAttribute

2020-07-26 Thread Jaskaran Singh
MetaAttribute is added to the SmPL AST. Reflect these changes in
function_prototypes.ml.

Signed-off-by: Jaskaran Singh 
---
 parsing_cocci/function_prototypes.ml | 10 +-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/parsing_cocci/function_prototypes.ml 
b/parsing_cocci/function_prototypes.ml
index 94dd2751a..8c6e559ac 100644
--- a/parsing_cocci/function_prototypes.ml
+++ b/parsing_cocci/function_prototypes.ml
@@ -167,6 +167,14 @@ and strip =
 Ast0.MetaParamList(nm,lenname,cstr,Ast0.Pure)
 | e -> e)) in
 
+  let attribute r k e =
+donothing r k
+  (Ast0.rewrap e
+(match Ast0.unwrap e with
+  Ast0.MetaAttribute(nm,cstr,pure) ->
+Ast0.MetaAttribute(nm,cstr,Ast0.Pure)
+| e -> e)) in
+
   V0.flat_rebuilder
 mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode
 mcode mcode
@@ -174,7 +182,7 @@ and strip =
 donothing donothing
 ident donothing donothing donothing typeC donothing param
 donothing donothing donothing donothing donothing donothing donothing
-donothing donothing
+attribute donothing
 
 and changed_proto = function
 (mname,mdef,mproto,None) -> true
-- 
2.21.3

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


[Cocci] [PATCH 01/43] parsing_cocci: ast0_cocci: Add MetaAttribute & MetaAttributeDecl

2020-07-26 Thread Jaskaran Singh
Add the MetaAttribute and MetaAttributeDecl variants to AST0 of SmPL.

Signed-off-by: Jaskaran Singh 
---
 parsing_cocci/ast0_cocci.ml  | 1 +
 parsing_cocci/ast0_cocci.mli | 1 +
 2 files changed, 2 insertions(+)

diff --git a/parsing_cocci/ast0_cocci.ml b/parsing_cocci/ast0_cocci.ml
index d7d810014..eac1d10c7 100644
--- a/parsing_cocci/ast0_cocci.ml
+++ b/parsing_cocci/ast0_cocci.ml
@@ -462,6 +462,7 @@ and fninfo =
 
 and base_attr =
 Attribute of string mcode
+  | MetaAttribute of Ast.meta_name mcode * constraints * pure
 
 and attr = base_attr wrap
 
diff --git a/parsing_cocci/ast0_cocci.mli b/parsing_cocci/ast0_cocci.mli
index 6097039fd..431a542f8 100644
--- a/parsing_cocci/ast0_cocci.mli
+++ b/parsing_cocci/ast0_cocci.mli
@@ -447,6 +447,7 @@ and fninfo =
 
 and base_attr =
 Attribute of string mcode
+  | MetaAttribute of Ast_cocci.meta_name mcode * constraints * pure
 
 and attr = base_attr wrap
 
-- 
2.21.3

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


[Cocci] [PATCH 13/17] engine: asttoctl2: Reflect attributefn in AST visitor

2020-07-16 Thread Jaskaran Singh
The SmPL AST visitor has a function for attributes. Reflect these
changes in asttoctl2.ml.

Signed-off-by: Jaskaran Singh 
---
 engine/asttoctl2.ml | 11 ++-
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/engine/asttoctl2.ml b/engine/asttoctl2.ml
index 51d574fa..6f415c1c 100644
--- a/engine/asttoctl2.ml
+++ b/engine/asttoctl2.ml
@@ -344,7 +344,7 @@ let elim_opt =
 donothing donothing donothing donothing donothing donothing
 donothing donothing donothing donothing donothing donothing donothing
 donothing donothing donothing donothing donothing donothing donothing
-donothing
+donothing donothing
 
 (* - *)
 (* after management *)
@@ -470,7 +470,7 @@ let contains_modif =
   do_nothing do_nothing do_nothing do_nothing init do_nothing do_nothing
   do_nothing do_nothing do_nothing
   do_nothing do_nothing rule_elem do_nothing do_nothing do_nothing
-  do_nothing in
+  do_nothing do_nothing in
   recursor.V.combiner_rule_elem
 
 let contains_pos =
@@ -499,7 +499,7 @@ let contains_pos =
   do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing
   do_nothing do_nothing do_nothing
   do_nothing do_nothing rule_elem do_nothing do_nothing do_nothing
-  do_nothing in
+  do_nothing do_nothing in
   recursor.V.combiner_rule_elem
 
 (* code is not a DisjRuleElem *)
@@ -598,7 +598,8 @@ let count_nested_braces s =
   donothing donothing donothing donothing donothing donothing donothing
   donothing donothing donothing donothing donothing donothing donothing
   donothing donothing donothing donothing donothing donothing donothing
-  donothing donothing donothing stmt_count donothing donothing donothing in
+  donothing donothing donothing stmt_count donothing donothing donothing
+  donothing in
   let res = string_of_int (recursor.V.combiner_statement s) in
   string2var ("p"^res)
 
@@ -2688,7 +2689,7 @@ and drop_minuses stmt_dots =
   donothing donothing donothing donothing donothing donothing donothing
   donothing donothing donothing donothing donothing donothing donothing
   donothing donothing donothing donothing donothing donothing donothing
-  donothing donothing donothing donothing donothing donothing donothing in
+  donothing donothing donothing donothing donothing donothing donothing 
donothing in
   v.V.rebuilder_statement_dots stmt_dots
 
 and find_xx = function
-- 
2.21.3

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


[Cocci] [PATCH 00/17] parsing_cocci: Add attributefn to the SmPL AST visitor

2020-07-16 Thread Jaskaran Singh
This patch series aims to add a public function for visiting attributes
to the SmPL AST visitor. This is needed to support meta attributes.

Jaskaran Singh (17):
  parsing_cocci: visitor_ast: Add attributefn to SmPL AST visitor
  parsing_cocci: parse_cocci: Reflect attributefn in AST visitor
  parsing_cocci: cleanup_rules: Reflect attributefn in AST visitor
  parsing_cocci: disjdistr: Reflect attributefn in AST visitor
  parsing_cocci: free_vars: Reflect attributefn in AST visitor
  parsing_cocci: get_constants2: Reflect attributefn in AST visitor
  parsing_cocci: re_constraints: Reflect attributefn in AST visitor
  parsing_cocci: safe_for_multi_decls: Reflect attributefn in AST visitor
  parsing_cocci: stmtlist: Reflect attributefn in AST visitor
  parsing_cocci: unify_ast: Reflect attributefn in AST visitor
  parsing_c: unparse_hrule: Reflect attributefn in AST visitor
  cocci: Reflect attributefn in AST visitor
  engine: asttoctl2: Reflect attributefn in AST visitor
  engine: asttomember: Reflect attributefn in AST visitor
  engine: cocci_vs_c: Reflect attributefn in AST visitor
  engine: transformation_c: Reflect attributefn in AST visitor
  popl09: popltoctl: Reflect attributefn in AST visitor

 cocci.ml  |2 +-
 engine/asttoctl2.ml   |   11 ++-
 engine/asttomember.ml |8 
 engine/cocci_vs_c.ml  |4 ++--
 engine/transformation_c.ml|2 +-
 parsing_c/unparse_hrule.ml|2 +-
 parsing_cocci/cleanup_rules.ml|2 +-
 parsing_cocci/disjdistr.ml|5 +++--
 parsing_cocci/free_vars.ml|   16 +---
 parsing_cocci/get_constants2.ml   |3 ++-
 parsing_cocci/parse_cocci.ml  |2 +-
 parsing_cocci/re_constraints.ml   |8 +---
 parsing_cocci/safe_for_multi_decls.ml |6 +++---
 parsing_cocci/stmtlist.ml |2 +-
 parsing_cocci/unify_ast.ml|   20 +---
 parsing_cocci/visitor_ast.ml  |   12 
 parsing_cocci/visitor_ast.mli |4 
 popl09/popltoctl.ml   |2 +-
 18 files changed, 66 insertions(+), 45 deletions(-)


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


[Cocci] [PATCH 05/17] parsing_cocci: free_vars: Reflect attributefn in AST visitor

2020-07-16 Thread Jaskaran Singh
The SmPL AST visitor has a function for attributes. Reflect these
changes in free_vars.ml.

Signed-off-by: Jaskaran Singh 
---
 parsing_cocci/free_vars.ml | 16 +---
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/parsing_cocci/free_vars.ml b/parsing_cocci/free_vars.ml
index 6ad35dcc..6958f48e 100644
--- a/parsing_cocci/free_vars.ml
+++ b/parsing_cocci/free_vars.ml
@@ -253,7 +253,7 @@ let collect_refs include_constraints =
 astfvident astfvexpr astfvfrag astfvfmt astfvassignop astfvbinaryop
 astfvfullType astfvtypeC astfvinit astfvparam astfvdefine_param
 astfvdecls donothing astfvfields astafvfields donothing
-astfvrule_elem astfvstatement donothing donothing donothing_a
+astfvrule_elem astfvstatement donothing donothing donothing donothing_a
 
 let collect_all_refs = collect_refs true
 let collect_non_constraint_refs = collect_refs false
@@ -303,7 +303,7 @@ let collect_pos_positions =
 donothing donothing donothing donothing donothing donothing donothing
 donothing donothing donothing donothing donothing donothing
 donothing donothing donothing donothing
-cprule_elem cpstmt donothing donothing donothing
+cprule_elem cpstmt donothing donothing donothing donothing
 
 (*  *)
 
@@ -479,7 +479,7 @@ let collect_saved =
 astfvident astfvexpr astfvfrag astfvfmt astfvassign astfvbinary donothing
 astfvtypeC astfvinit astfvparam astfvdefine_param astfvdecls donothing
 astfvfields donothing donothing astfvrule_elem donothing donothing
-donothing donothing
+donothing donothing donothing
 
 (*  *)
 
@@ -612,7 +612,7 @@ let collect_in_plus_term =
 donothing donothing donothing donothing donothing donothing donothing
 donothing donothing donothing donothing donothing donothing donothing
 donothing donothing donothing donothing donothing donothing astfvrule_elem
-astfvstatement donothing donothing donothing
+astfvstatement donothing donothing donothing donothing
 
 let collect_in_plus metavars minirules =
   nub
@@ -905,7 +905,7 @@ let classify_variables metavar_decls minirules used_after =
   ident expression string_fragment string_format assignop binaryop
   donothing typeC
   init param define_param decl donothing field donothing donothing
-  rule_elem donothing donothing donothing donothing in
+  rule_elem donothing donothing donothing donothing donothing in
 
   List.map fn.V.rebuilder_top_level minirules
 
@@ -1091,7 +1091,8 @@ let astfvs metavars bound =
 donothing donothing donothing donothing donothing donothing donothing
 donothing donothing donothing donothing donothing donothing donothing
 donothing donothing donothing
-astfvrule_elem astfvstatement astfvcase_line astfvtoplevel donothing
+astfvrule_elem astfvstatement astfvcase_line donothing astfvtoplevel
+donothing
 
 (*
 let collect_astfvs rules =
@@ -1175,7 +1176,8 @@ let get_neg_pos_list (_,rule) used_after_list =
 donothing donothing donothing donothing donothing donothing donothing
 donothing donothing donothing donothing donothing donothing donothing
 donothing donothing donothing donothing donothing donothing donothing
-donothing donothing donothing donothing donothing donothing donothing in
+donothing donothing donothing donothing donothing donothing donothing
+donothing in
   match rule with
 Ast.CocciRule(rule_name,_,minirules,_,_) ->
   List.map
-- 
2.21.3

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


[Cocci] [PATCH 02/17] parsing_cocci: parse_cocci: Reflect attributefn in AST visitor

2020-07-16 Thread Jaskaran Singh
The SmPL AST visitor has a function for attributes. Reflect these
changes in parse_cocci.ml.

Signed-off-by: Jaskaran Singh 
---
 parsing_cocci/parse_cocci.ml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/parsing_cocci/parse_cocci.ml b/parsing_cocci/parse_cocci.ml
index eb88c019..e455fce0 100644
--- a/parsing_cocci/parse_cocci.ml
+++ b/parsing_cocci/parse_cocci.ml
@@ -2620,7 +2620,7 @@ let contains_modifs ast =
   donothing donothing donothing donothing donothing donothing
   donothing donothing donothing donothing donothing donothing
   donothing donothing donothing donothing donothing donothing
-  donothing donothing donothing donothing in
+  donothing donothing donothing donothing donothing in
   List.exists
 (function
Ast.CocciRule(nm,infos,ast,_,_) ->
-- 
2.21.3

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


[Cocci] [PATCH 08/17] parsing_cocci: safe_for_multi_decls: Reflect attributefn in AST visitor

2020-07-16 Thread Jaskaran Singh
The SmPL AST visitor has a function for attributes. Reflect these
changes in safe_for_multi_decls.ml.

Signed-off-by: Jaskaran Singh 
---
 parsing_cocci/safe_for_multi_decls.ml | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/parsing_cocci/safe_for_multi_decls.ml 
b/parsing_cocci/safe_for_multi_decls.ml
index 70335abb..ee3741b9 100644
--- a/parsing_cocci/safe_for_multi_decls.ml
+++ b/parsing_cocci/safe_for_multi_decls.ml
@@ -43,7 +43,7 @@ let all_removed_recursor =
 do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing
 do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing
 do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing
-do_nothing do_nothing do_nothing do_nothing
+do_nothing do_nothing do_nothing do_nothing do_nothing
 
 let all_removed_decl =
   all_removed_recursor.V.combiner_declaration
@@ -100,7 +100,7 @@ let contains_modif =
   do_nothing do_nothing do_nothing init do_nothing
   do_nothing do_nothing do_nothing do_nothing
   do_nothing do_nothing rule_elem do_nothing do_nothing do_nothing
-  do_nothing in
+  do_nothing do_nothing in
   recursor.V.combiner_fullType
 
 let attribute a =
@@ -178,7 +178,7 @@ let process =
   donothing donothing donothing donothing donothing donothing donothing
   donothing donothing donothing donothing donothing donothing donothing
   donothing donothing donothing donothing decl anndecl field annfield
-  donothing donothing donothing donothing donothing donothing in
+  donothing donothing donothing donothing donothing donothing donothing in
   List.map fn.V.rebuilder_top_level
 
 let safe_for_multi_decls rules =
-- 
2.21.3

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


[Cocci] [PATCH 09/17] parsing_cocci: stmtlist: Reflect attributefn in AST visitor

2020-07-16 Thread Jaskaran Singh
The SmPL AST visitor has a function for attributes. Reflect these
changes in stmtlist.ml.

Signed-off-by: Jaskaran Singh 
---
 parsing_cocci/stmtlist.ml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/parsing_cocci/stmtlist.ml b/parsing_cocci/stmtlist.ml
index 4e7a0b5a..56e54d0a 100644
--- a/parsing_cocci/stmtlist.ml
+++ b/parsing_cocci/stmtlist.ml
@@ -56,7 +56,7 @@ let stmtlist_rebuilder =
 donothing donothing donothing donothing donothing donothing
 donothing donothing donothing donothing donothing donothing
 donothing donothing donothing donothing donothing donothing
-statement donothing donothing donothing
+statement donothing donothing donothing donothing
 
 let stmtlist rule =
   match rule with
-- 
2.21.3

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


[Cocci] [PATCH 12/17] cocci: Reflect attributefn in AST visitor

2020-07-16 Thread Jaskaran Singh
The SmPL AST visitor has a function for attributes. Reflect these
changes in cocci.ml.

Signed-off-by: Jaskaran Singh 
---
 cocci.ml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/cocci.ml b/cocci.ml
index 3f315d4c..858c6672 100644
--- a/cocci.ml
+++ b/cocci.ml
@@ -600,7 +600,7 @@ let sp_contain_typed_metavar_z toplevel_list_list =
   donothing expression donothing donothing donothing donothing donothing
   donothing donothing donothing donothing donothing donothing
   donothing donothing donothing donothing donothing donothing
-  donothing donothing
+  donothing donothing donothing
   in
   toplevel_list_list +>
 List.exists
-- 
2.21.3

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


[Cocci] [PATCH 16/17] engine: transformation_c: Reflect attributefn in AST visitor

2020-07-16 Thread Jaskaran Singh
The SmPL AST visitor has a function for attributes. Reflect these
changes in transformation_c.ml.

Signed-off-by: Jaskaran Singh 
---
 engine/transformation_c.ml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/engine/transformation_c.ml b/engine/transformation_c.ml
index eecd4858..cb121a12 100644
--- a/engine/transformation_c.ml
+++ b/engine/transformation_c.ml
@@ -291,7 +291,7 @@ module XTRANS = struct
ident expression donothing donothing donothing donothing
donothing donothing donothing donothing donothing donothing
donothing donothing donothing donothing donothing donothing
-   donothing donothing donothing in
+   donothing donothing donothing donothing in
 
   fn.Visitor_ast.rebuilder_anything anything
 
-- 
2.21.3

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


[Cocci] [PATCH 11/17] parsing_c: unparse_hrule: Reflect attributefn in AST visitor

2020-07-16 Thread Jaskaran Singh
The SmPL AST visitor has a function for attributes. Reflect these
changes in unparse_hrule.ml.

Signed-off-by: Jaskaran Singh 
---
 parsing_c/unparse_hrule.ml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/parsing_c/unparse_hrule.ml b/parsing_c/unparse_hrule.ml
index fca985ca..3078dde4 100644
--- a/parsing_c/unparse_hrule.ml
+++ b/parsing_c/unparse_hrule.ml
@@ -136,7 +136,7 @@ let get_function_name rule env =
   donothing donothing donothing donothing donothing donothing donothing
   donothing expression donothing donothing donothing donothing donothing
   donothing donothing donothing donothing donothing donothing donothing
-  donothing donothing
+  donothing donothing donothing
   donothing donothing donothing donothing donothing).V.combiner_top_level
   rule in
   match names with
-- 
2.21.3

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


[Cocci] [PATCH 10/17] parsing_cocci: unify_ast: Reflect attributefn in AST visitor

2020-07-16 Thread Jaskaran Singh
The SmPL AST visitor has a function for attributes. Reflect these
changes in unify_ast.ml. Also add a few fixes w/r/t the usage of
for_all2 for comparing attributes.

Signed-off-by: Jaskaran Singh 
---
 parsing_cocci/unify_ast.ml | 20 +---
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/parsing_cocci/unify_ast.ml b/parsing_cocci/unify_ast.ml
index 90cb70ee..98e2ab1d 100644
--- a/parsing_cocci/unify_ast.ml
+++ b/parsing_cocci/unify_ast.ml
@@ -221,7 +221,8 @@ and unify_expression e1 e2 =
   | (Ast.RecordPtAccess(e1,pt1,fld1),Ast.RecordPtAccess(e2,pt2,fld2)) ->
   unify_expression e1 e2 && unify_ident fld1 fld2
   | (Ast.Cast(lp1,ty1,attr1,rp1,e1),Ast.Cast(lp2,ty2,attr2,rp2,e2)) ->
-  if List.for_all2 unify_attribute attr1 attr2
+  if (List.length attr1 = List.length attr2) &&
+ List.for_all2 unify_attribute attr1 attr2
   then unify_fullType ty1 ty2 && unify_expression e1 e2
   else false
   | (Ast.SizeOfExpr(szf1,e1),Ast.SizeOfExpr(szf2,e2)) ->
@@ -386,6 +387,7 @@ and unify_declaration d1 d2 =
   | (Ast.Init(stg1,ft1,id1,attr1,eq1,i1,s1),
  Ast.Init(stg2,ft2,id2,attr2,eq2,i2,s2)) ->
   if bool_unify_option unify_mcode stg1 stg2 &&
+ (List.length attr1 = List.length attr2) &&
  List.for_all2 unify_attribute attr1 attr2
   then
unify_fullType ft1 ft2 &&
@@ -394,6 +396,7 @@ and unify_declaration d1 d2 =
   else false
   | (Ast.UnInit(stg1,ft1,id1,attr1,s1),Ast.UnInit(stg2,ft2,id2,attr2,s2)) ->
   if bool_unify_option unify_mcode stg1 stg2 &&
+ (List.length attr1 = List.length attr2) &&
  List.for_all2 unify_attribute attr1 attr2
   then unify_fullType ft1 ft2 && unify_ident id1 id2
   else false
@@ -414,6 +417,7 @@ and unify_declaration d1 d2 =
   | (Ast.MacroDecl(s1,n1,lp1,args1,rp1,attr1,sem1),
  Ast.MacroDecl(s2,n2,lp2,args2,rp2,attr2,sem2)) ->
if bool_unify_option unify_mcode s1 s2 &&
+ (List.length attr1 = List.length attr2) &&
  List.for_all2 unify_attribute attr1 attr2
then
 unify_ident n1 n2 &&
@@ -428,7 +432,8 @@ and unify_declaration d1 d2 =
 unify_initialiser ini1 ini2
else false
   | (Ast.TyDecl(ft1,attr1,s1),Ast.TyDecl(ft2,attr2,s2)) ->
-  if List.for_all2 unify_attribute attr1 attr2
+  if (List.length attr1 = List.length attr2) &&
+ List.for_all2 unify_attribute attr1 attr2
   then unify_fullType ft1 ft2
   else false
   | (Ast.Typedef(stg1,ft1,id1,s1),Ast.Typedef(stg2,ft2,id2,s2)) ->
@@ -549,12 +554,13 @@ and unify_designator d1 d2 =
 and unify_parameterTypeDef p1 p2 =
   match (Ast.unwrap p1,Ast.unwrap p2) with
 (Ast.VoidParam(ft1,attr1),Ast.VoidParam(ft2,attr2)) ->
-  if List.for_all2 unify_attribute attr1 attr2
+  if (List.length attr1 = List.length attr2) &&
+ List.for_all2 unify_attribute attr1 attr2
   then unify_fullType ft1 ft2
   else false
   | (Ast.Param(ft1,i1,attr1),Ast.Param(ft2,i2,attr2)) ->
-
-  if List.for_all2 unify_attribute attr1 attr2
+  if (List.length attr1 = List.length attr2) &&
+ List.for_all2 unify_attribute attr1 attr2
   then
 unify_fullType ft1 ft2 &&
 unify_option unify_ident i1 i2
@@ -740,7 +746,7 @@ and subexp f =
   donothing expr
   donothing donothing donothing donothing donothing donothing donothing
   donothing donothing donothing donothing donothing donothing donothing
-  donothing donothing donothing donothing donothing in
+  donothing donothing donothing donothing donothing donothing in
   recursor.V.combiner_rule_elem
 
 and subtype f =
@@ -756,7 +762,7 @@ and subtype f =
   donothing donothing donothing donothing donothing donothing fullType
   donothing donothing donothing donothing donothing donothing
   donothing donothing donothing donothing donothing donothing
-  donothing donothing in
+  donothing donothing donothing in
   recursor.V.combiner_rule_elem
 
 let rec unify_statement s1 s2 =
-- 
2.21.3

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


[Cocci] [PATCH 14/17] engine: asttomember: Reflect attributefn in AST visitor

2020-07-16 Thread Jaskaran Singh
The SmPL AST visitor has a function for attributes. Reflect these
changes in asttomember.ml.

Signed-off-by: Jaskaran Singh 
---
 engine/asttomember.ml | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/engine/asttomember.ml b/engine/asttomember.ml
index a893a833..05896443 100644
--- a/engine/asttomember.ml
+++ b/engine/asttomember.ml
@@ -48,7 +48,7 @@ let contains_modif used_after x =
do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing
do_nothing do_nothing do_nothing
do_nothing do_nothing rule_elem do_nothing do_nothing do_nothing
-   do_nothing in
+   do_nothing do_nothing in
 recursor.V.combiner_rule_elem x
 
 (* contains an inherited metavariable or contains a constant *)
@@ -76,7 +76,7 @@ let contains_constant x =
  ident expr do_nothing do_nothing do_nothing do_nothing do_nothing
  do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing
  do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing
- do_nothing do_nothing in
+ do_nothing do_nothing do_nothing in
   recursor.V.combiner_rule_elem x
   | _ -> true
 
@@ -138,7 +138,7 @@ let strip x =
   do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing
   decl_or_field do_absolutely_nothing decl_or_field do_absolutely_nothing
   do_nothing rule_elem
-  do_nothing do_nothing do_nothing do_absolutely_nothing in
+  do_nothing do_nothing do_nothing do_nothing do_absolutely_nothing in
   r.V.rebuilder_rule_elem x
 
 (* - *)
@@ -205,7 +205,7 @@ let find_commonalities res : Ast_cocci.rule_elem option =
do_nothing do_nothing
expression do_nothing do_nothing do_nothing do_nothing
do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing
-   do_nothing do_nothing do_nothing
+   do_nothing do_nothing do_nothing do_nothing
do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing in
 recursor.V.combiner_rule_elem x in
   match res with
-- 
2.21.3

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


[Cocci] [PATCH 01/17] parsing_cocci: visitor_ast: Add attributefn to SmPL AST visitor

2020-07-16 Thread Jaskaran Singh
Add a public function to visit attributes in the SmPL AST visitor.

Signed-off-by: Jaskaran Singh 
---
 parsing_cocci/visitor_ast.ml  | 12 
 parsing_cocci/visitor_ast.mli |  4 
 2 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/parsing_cocci/visitor_ast.ml b/parsing_cocci/visitor_ast.ml
index 5288c6f2..17afc518 100644
--- a/parsing_cocci/visitor_ast.ml
+++ b/parsing_cocci/visitor_ast.ml
@@ -34,6 +34,7 @@ type 'a combiner =
  combiner_rule_elem : Ast.rule_elem -> 'a;
  combiner_statement : Ast.statement -> 'a;
  combiner_case_line : Ast.case_line -> 'a;
+ combiner_attribute : Ast.attr -> 'a;
  combiner_top_level : Ast.top_level -> 'a;
  combiner_anything : Ast.anything  -> 'a;
  combiner_expression_dots : Ast.expression Ast.dots -> 'a;
@@ -57,7 +58,7 @@ let combiner bind option_default
 identfn exprfn fragfn fmtfn assignOpfn binaryOpfn ftfn tyfn initfn
 paramfn define_paramfn declfn
 annotated_declfn fieldfn annotated_fieldfn enum_declfn rulefn stmtfn
-casefn topfn anyfn =
+casefn attributefn topfn anyfn =
   let multibind l =
 let rec loop = function
[] -> option_default
@@ -921,7 +922,7 @@ let combiner bind option_default
 let k a =
   match Ast.unwrap a with
 Ast.Attribute(attr) -> string_mcode attr in
-k a
+attributefn all_functions k a
 
 
   and whencode notfn alwaysfn = function
@@ -1027,6 +1028,7 @@ let combiner bind option_default
   combiner_rule_elem = rule_elem;
   combiner_statement = statement;
   combiner_case_line = case_line;
+  combiner_attribute = attribute;
   combiner_top_level = top_level;
   combiner_anything = anything;
   combiner_expression_dots = expression_dots;
@@ -1059,6 +1061,7 @@ type rebuilder =
   rebuilder_parameter_list : Ast.parameter_list inout;
   rebuilder_statement : Ast.statement inout;
   rebuilder_case_line : Ast.case_line inout;
+  rebuilder_attribute : Ast.attr inout;
   rebuilder_rule_elem : Ast.rule_elem inout;
   rebuilder_top_level : Ast.top_level inout;
   rebuilder_expression_dots : Ast.expression Ast.dots inout;
@@ -1085,7 +1088,7 @@ let rebuilder
 enumdecldotsfn initdotsfn
 identfn exprfn fragfn fmtfn assignOpfn binaryOpfn ftfn tyfn initfn
 paramfn define_paramfn declfn annotated_declfn fieldfn annotated_fieldfn
-enum_declfn rulefn stmtfn casefn topfn anyfn =
+enum_declfn rulefn stmtfn casefn attributefn topfn anyfn =
   let get_option f = function
   Some x -> Some (f x)
 | None -> None in
@@ -1917,7 +1920,7 @@ let rebuilder
   Ast.rewrap a
 (match Ast.unwrap a with
   Ast.Attribute(attr) -> Ast.Attribute(string_mcode attr)) in
-k a
+attributefn all_functions k a
 
   and whencode notfn alwaysfn = function
   Ast.WhenNot a -> Ast.WhenNot (notfn a)
@@ -2026,6 +2029,7 @@ let rebuilder
   rebuilder_rule_elem = rule_elem;
   rebuilder_statement = statement;
   rebuilder_case_line = case_line;
+  rebuilder_attribute = attribute;
   rebuilder_top_level = top_level;
   rebuilder_expression_dots = expression_dots;
   rebuilder_statement_dots = statement_dots;
diff --git a/parsing_cocci/visitor_ast.mli b/parsing_cocci/visitor_ast.mli
index 0ed17774..55bfbf3f 100644
--- a/parsing_cocci/visitor_ast.mli
+++ b/parsing_cocci/visitor_ast.mli
@@ -23,6 +23,7 @@ type 'a combiner =
  combiner_rule_elem : Ast_cocci.rule_elem -> 'a;
  combiner_statement : Ast_cocci.statement -> 'a;
  combiner_case_line : Ast_cocci.case_line -> 'a;
+ combiner_attribute : Ast_cocci.attr -> 'a;
  combiner_top_level : Ast_cocci.top_level -> 'a;
  combiner_anything : Ast_cocci.anything  -> 'a;
  combiner_expression_dots : Ast_cocci.expression Ast_cocci.dots -> 'a;
@@ -77,6 +78,7 @@ val combiner :
   ((Ast_cocci.rule_elem,'a) ccode) ->
   ((Ast_cocci.statement,'a) ccode) ->
   ((Ast_cocci.case_line,'a) ccode) ->
+  ((Ast_cocci.attr,'a) ccode) ->
   ((Ast_cocci.top_level,'a) ccode) ->
   ((Ast_cocci.anything,'a) ccode) ->
   'a combiner
@@ -101,6 +103,7 @@ type rebuilder =
   rebuilder_parameter_list : Ast_cocci.parameter_list inout;
   rebuilder_statement : Ast_cocci.statement inout;
   rebuilder_case_line : Ast_cocci.case_line inout;
+  rebuilder_attribute : Ast_cocci.attr inout;
   rebuilder_rule_elem : Ast_cocci.rule_elem inout;
   rebuilder_top_level : Ast_cocci.top_level inout;
   rebuilder_expression_dots : Ast_cocci.expression Ast_cocci.dots inout;
@@ -158,6 +161,7 @@ val rebuilder :
 (Ast_cocci.rule_elem rcode) ->
 (Ast_cocci.statement rcode) ->
 (Ast_cocci.case_line rcode) ->
+(Ast_cocci.attr rcode) ->
 (Ast_cocci.top_level rcode) ->
 (Ast_cocci.anything rcode) ->
 rebuilder
-- 
2.21.3

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


[Cocci] [PATCH 07/17] parsing_cocci: re_constraints: Reflect attributefn in AST visitor

2020-07-16 Thread Jaskaran Singh
The SmPL AST visitor has a function for attributes. Reflect these
changes in re_constraints.ml.

Signed-off-by: Jaskaran Singh 
---
 parsing_cocci/re_constraints.ml | 8 +---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/parsing_cocci/re_constraints.ml b/parsing_cocci/re_constraints.ml
index 17011465..76ae85e6 100644
--- a/parsing_cocci/re_constraints.ml
+++ b/parsing_cocci/re_constraints.ml
@@ -44,7 +44,7 @@ let disj_free re =
 donothing donothing donothing donothing donothing donothing donothing ident
 expr donothing donothing donothing donothing ty donothing
 donothing donothing donothing decl donothing donothing ann_field donothing
-rule_elem statement donothing donothing donothing in
+rule_elem statement donothing donothing donothing donothing in
   try Hashtbl.find disj_free_table re
   with Not_found ->
 let res = v.V.combiner_rule_elem re in
@@ -90,7 +90,8 @@ let ok_for_all_rule_elems cstr minirules =
   donothing donothing donothing donothing donothing donothing donothing
   donothing donothing donothing donothing donothing donothing donothing
   donothing donothing donothing donothing donothing donothing donothing
-  donothing donothing rule_elem donothing donothing donothing donothing in
+  donothing donothing rule_elem donothing donothing donothing donothing
+  donothing in
   List.for_all v.V.combiner_top_level minirules
 
 let update_for_all_rule_elems cstr minirules =
@@ -113,7 +114,8 @@ let update_for_all_rule_elems cstr minirules =
   donothing donothing donothing donothing donothing donothing
   donothing donothing donothing donothing donothing
   donothing donothing donothing donothing donothing
-  donothing rule_elem donothing donothing donothing donothing in
+  donothing rule_elem donothing donothing donothing donothing
+  donothing in
   List.map v.V.rebuilder_top_level minirules
 
 let remove rule_name ((nm,_) as x) =
-- 
2.21.3

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


[Cocci] [PATCH 15/17] engine: cocci_vs_c: Reflect attributefn in AST visitor

2020-07-16 Thread Jaskaran Singh
The SmPL AST visitor has a function for attributes. Reflect these
changes in cocci_vs_c.ml.

Signed-off-by: Jaskaran Singh 
---
 engine/cocci_vs_c.ml | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/engine/cocci_vs_c.ml b/engine/cocci_vs_c.ml
index 9439cdb3..cba6c8d0 100644
--- a/engine/cocci_vs_c.ml
+++ b/engine/cocci_vs_c.ml
@@ -609,7 +609,7 @@ let check_allminus =
 donothing donothing donothing donothing donothing donothing
 donothing donothing donothing donothing donothing donothing
 donothing donothing donothing donothing donothing donothing
-donothing donothing donothing donothing
+donothing donothing donothing donothing donothing
 
 (*)
 (* Functor parameter combinators *)
@@ -2335,7 +2335,7 @@ and (declaration: (A.mcodekind * bool * 
A.declaration,B.declaration) matcher) =
donothing donothing donothing donothing donothing donothing
donothing donothing donothing donothing donothing donothing
donothing donothing donothing donothing donothing donothing
-   donothing donothing donothing donothing in
+   donothing donothing donothing donothing donothing in
v.Visitor_ast.rebuilder_declaration decla in
 
  xs +> List.fold_left (fun acc var ->
-- 
2.21.3

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


[Cocci] [PATCH 04/17] parsing_cocci: disjdistr: Reflect attributefn in AST visitor

2020-07-16 Thread Jaskaran Singh
The SmPL AST visitor has a function for attributes. Reflect these
changes in disjdistr.ml.

Signed-off-by: Jaskaran Singh 
---
 parsing_cocci/disjdistr.ml | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/parsing_cocci/disjdistr.ml b/parsing_cocci/disjdistr.ml
index ba2b8c02..93633e9c 100644
--- a/parsing_cocci/disjdistr.ml
+++ b/parsing_cocci/disjdistr.ml
@@ -483,6 +483,7 @@ let disj_all =
 donothing donothing donothing donothing donothing donothing donothing
 donothing donothing donothing donothing donothing donothing donothing
 donothing donothing disj_rule_elem donothing donothing donothing donothing
+donothing
 
 (* --- *)
 (* collect iso information at the rule_elem level *)
@@ -500,7 +501,7 @@ let collect_all_isos =
 donothing donothing donothing donothing donothing donothing donothing
 donothing donothing donothing donothing donothing
 doanything donothing doanything donothing donothing donothing donothing
-donothing doanything
+donothing donothing doanything
 
 let collect_iso_info =
   let mcode x = x in
@@ -518,7 +519,7 @@ let collect_iso_info =
 donothing donothing donothing donothing donothing donothing
 donothing donothing donothing donothing donothing
 donothing donothing donothing donothing donothing rule_elem donothing 
donothing
-donothing donothing
+donothing donothing donothing
 
 (* --- *)
 
-- 
2.21.3

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


[Cocci] [PATCH 06/17] parsing_cocci: get_constants2: Reflect attributefn in AST visitor

2020-07-16 Thread Jaskaran Singh
The SmPL AST visitor has a function for attributes. Reflect these
changes in get_constants2.ml.

Signed-off-by: Jaskaran Singh 
---
 parsing_cocci/get_constants2.ml | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/parsing_cocci/get_constants2.ml b/parsing_cocci/get_constants2.ml
index d1d77f65..8fffe195 100644
--- a/parsing_cocci/get_constants2.ml
+++ b/parsing_cocci/get_constants2.ml
@@ -646,6 +646,7 @@ let do_get_constants constants keywords env (neg_pos,_) =
 ident expression string_fragment string_format donothing donothing
 fullType typeC initialiser parameter define_parameter declaration donothing
 field ann_field donothing rule_elem statement donothing donothing donothing
+donothing
 
 (*  *)
 
@@ -714,7 +715,7 @@ let all_context =
 donothing donothing donothing donothing donothing donothing donothing
 donothing
 initialiser donothing donothing donothing donothing donothing donothing
-donothing rule_elem statement donothing donothing donothing
+donothing rule_elem statement donothing donothing donothing donothing
 
 (*  *)
 
-- 
2.21.3

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


[Cocci] [PATCH 03/17] parsing_cocci: cleanup_rules: Reflect attributefn in AST visitor

2020-07-16 Thread Jaskaran Singh
The SmPL AST visitor has a function for attributes. Reflect these
changes in cleanup_rules.ml.

Signed-off-by: Jaskaran Singh 
---
 parsing_cocci/cleanup_rules.ml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/parsing_cocci/cleanup_rules.ml b/parsing_cocci/cleanup_rules.ml
index 60452bec..7f03f98f 100644
--- a/parsing_cocci/cleanup_rules.ml
+++ b/parsing_cocci/cleanup_rules.ml
@@ -254,7 +254,7 @@ let do_cleanup =
 ident expression string_fragment string_format assignOp
 binaryOp fullType typeC initialiser parameterTypeDef define_param
 declaration donothing field ann_field donothing
-rule_elem statement donothing donothing donothing
+rule_elem statement donothing donothing donothing donothing
 
 let cleanup_rules rules d =
   dropped := d;
-- 
2.21.3

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


[Cocci] [PATCH 17/17] popl09: popltoctl: Reflect attributefn in AST visitor

2020-07-16 Thread Jaskaran Singh
The SmPL AST visitor has a function for attributes. Reflect these
changes in popltoctl.ml.

Signed-off-by: Jaskaran Singh 
---
 popl09/popltoctl.ml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/popl09/popltoctl.ml b/popl09/popltoctl.ml
index 1b05a762..da278168 100644
--- a/popl09/popltoctl.ml
+++ b/popl09/popltoctl.ml
@@ -48,7 +48,7 @@ let contains_modif =
   do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing
   do_nothing do_nothing do_nothing
   do_nothing do_nothing rule_elem do_nothing do_nothing do_nothing
-  do_nothing in
+  do_nothing do_nothing in
   recursor.V.combiner_rule_elem
 
 let ctl_exists keep_wit v x =
-- 
2.21.3

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


[Cocci] [PATCH 18/24] parsing_c: unparse_cocci: Reflect AttributeTag in SmPL AST

2020-07-16 Thread Jaskaran Singh
AttributeTag is added to the SmPL AST. Reflect these changes in
unparse_cocci.ml.

Signed-off-by: Jaskaran Singh 
---
 parsing_c/unparse_cocci.ml | 1 +
 1 file changed, 1 insertion(+)

diff --git a/parsing_c/unparse_cocci.ml b/parsing_c/unparse_cocci.ml
index 6d437971..e544336d 100644
--- a/parsing_c/unparse_cocci.ml
+++ b/parsing_c/unparse_cocci.ml
@@ -1512,6 +1512,7 @@ let pp_any = function
   | Ast.ForInfoTag(x) -> forinfo x; false
   | Ast.CaseLineTag(x) -> case_line "" x; false
   | Ast.StringFragmentTag(x) -> string_fragment x; false
+  | Ast.AttributeTag(x) -> print_attribute x; false
 
   | Ast.ConstVolTag(x) -> const_vol x unknown unknown; false
   | Ast.Directive(xs) ->
-- 
2.21.3

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


[Cocci] [PATCH 22/24] parsing_cocci: context_neg: Reflect attributefn in AST0 visitor

2020-07-16 Thread Jaskaran Singh
The SmPL AST0 visitor has a function for attributes. Reflect these
changes in context_neg.ml. Also add a few general fixes w/r/t the usage
of the for_all2 function for comparing attributes.

Signed-off-by: Jaskaran Singh 
---
 parsing_cocci/ast0_cocci.mli |  1 +
 parsing_cocci/context_neg.ml | 20 ++--
 2 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/parsing_cocci/ast0_cocci.mli b/parsing_cocci/ast0_cocci.mli
index c4b9260b..6097039f 100644
--- a/parsing_cocci/ast0_cocci.mli
+++ b/parsing_cocci/ast0_cocci.mli
@@ -599,6 +599,7 @@ val stmt : statement -> anything
 val forinfo : forinfo -> anything
 val case_line : case_line -> anything
 val string_fragment : string_fragment -> anything
+val attr : attr -> anything
 val top : top_level -> anything
 
 (* - *)
diff --git a/parsing_cocci/context_neg.ml b/parsing_cocci/context_neg.ml
index a0d52e9a..ebb93806 100644
--- a/parsing_cocci/context_neg.ml
+++ b/parsing_cocci/context_neg.ml
@@ -186,7 +186,7 @@ let collect_plus_lines top =
   donothing donothing
   donothing donothing donothing donothing donothing donothing donothing
   donothing donothing donothing statement donothing donothing donothing
-  donothing in
+  donothing donothing in
   fn.VT0.combiner_rec_top_level top
 
 (* - *)
@@ -557,7 +557,7 @@ let classify is_minus all_marked table code =
   ident expression (do_nothing Ast0.assignOp) (do_nothing Ast0.binaryOp)
   typeC initialiser param declaration field enum_decl
   statement (do_nothing Ast0.forinfo) case_line string_fragment
-  (do_top Ast0.top) in
+  (do_nothing Ast0.attr) (do_top Ast0.top) in
   combiner.VT0.combiner_rec_top_level code
 
 (* - *)
@@ -644,6 +644,7 @@ let rec equal_expression e1 e2 =
   equal_mcode ar1 ar2
   | (Ast0.Cast(lp1,_,ar1,rp1,_),Ast0.Cast(lp2,_,ar2,rp2,_)) ->
   equal_mcode lp1 lp2 &&
+  (List.length ar1) = (List.length ar2) &&
   List.for_all2 equal_attribute ar1 ar2 &&
   equal_mcode rp1 rp2
   | (Ast0.SizeOfExpr(szf1,_),Ast0.SizeOfExpr(szf2,_)) ->
@@ -752,10 +753,14 @@ let equal_declaration d1 d2 =
   equal_mcode name1 name2
   | (Ast0.Init(stg1,_,_,attr1,eq1,_,sem1),
  Ast0.Init(stg2,_,_,attr2,eq2,_,sem2)) ->
-  equal_option stg1 stg2 && List.for_all2 equal_attribute attr1 attr2 &&
+  equal_option stg1 stg2 &&
+  (List.length attr1) = (List.length attr2) &&
+  List.for_all2 equal_attribute attr1 attr2 &&
   equal_mcode eq1 eq2 && equal_mcode sem1 sem2
   | (Ast0.UnInit(stg1,_,_,attr1,sem1),Ast0.UnInit(stg2,_,_,attr2,sem2)) ->
-  equal_option stg1 stg2 && List.for_all2 equal_attribute attr1 attr2 &&
+  equal_option stg1 stg2 &&
+  (List.length attr1) = (List.length attr2) &&
+  List.for_all2 equal_attribute attr1 attr2 &&
   equal_mcode sem1 sem2
   | (Ast0.FunProto(fninfo1,name1,lp1,p1,va1,rp1,sem1),
  Ast0.FunProto(fninfo2,name2,lp2,p2,va2,rp2,sem2)) ->
@@ -770,7 +775,9 @@ let equal_declaration d1 d2 =
equal_mcode rp1 rp2 && equal_mcode sem1 sem2
   | (Ast0.MacroDecl(stg1,nm1,lp1,_,rp1,attr1,sem1),
  Ast0.MacroDecl(stg2,nm2,lp2,_,rp2,attr2,sem2)) ->
-  equal_option stg1 stg2 && List.for_all2 equal_attribute attr1 attr2 &&
+  equal_option stg1 stg2 &&
+  (List.length attr1) = (List.length attr2) &&
+  List.for_all2 equal_attribute attr1 attr2 &&
   equal_mcode lp1 lp2 && equal_mcode rp1 rp2 && equal_mcode sem1 sem2
   | (Ast0.MacroDeclInit(stg1,nm1,lp1,_,rp1,eq1,_,sem1),
  Ast0.MacroDeclInit(stg2,nm2,lp2,_,rp2,eq2,_,sem2)) ->
@@ -778,6 +785,7 @@ let equal_declaration d1 d2 =
equal_mcode lp1 lp2 && equal_mcode rp1 rp2 && equal_mcode eq1 eq2
 && equal_mcode sem1 sem2
   | (Ast0.TyDecl(_,attr1,sem1),Ast0.TyDecl(_,attr2,sem2)) ->
+   (List.length attr1) = (List.length attr2) &&
List.for_all2 equal_attribute attr1 attr2 && equal_mcode sem1 sem2
   | (Ast0.OptDecl(_),Ast0.OptDecl(_)) -> true
   | (Ast0.DisjDecl(starter1,_,mids1,ender1),
@@ -1055,7 +1063,7 @@ let contextify_all =
 donothing donothing donothing donothing donothing donothing donothing
 donothing donothing donothing donothing donothing donothing donothing
 donothing donothing donothing donothing donothing donothing donothing
-donothing donothing donothing
+donothing donothing donothing donothing
 
 let contextify_whencode =
   let bind x y = () in
-- 
2.21.3

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


[Cocci] [PATCH 08/24] parsing_cocci: single_statement: Reflect attributefn in AST0 visitor

2020-07-16 Thread Jaskaran Singh
The SmPL AST0 visitor has a function for attributes. Reflect these
changes in single_statement.ml.

Signed-off-by: Jaskaran Singh 
---
 parsing_cocci/single_statement.ml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/parsing_cocci/single_statement.ml 
b/parsing_cocci/single_statement.ml
index df50df6a..0b192a94 100644
--- a/parsing_cocci/single_statement.ml
+++ b/parsing_cocci/single_statement.ml
@@ -463,7 +463,7 @@ and contains_only_minus =
 dots dots dots dots dots dots dots dots dots
 identifier expression donothing donothing typeC donothing donothing
 declaration field donothing statement donothing case_line donothing
-donothing
+donothing donothing
 
 
 (* needs a special case when there is a Disj or an empty DOTS *)
-- 
2.21.3

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


[Cocci] [PATCH 16/24] parsing_cocci: ast_cocci: Add AttributeTag to the SmPL AST

2020-07-16 Thread Jaskaran Singh
Add the AttributeTag constructor to the SmPL AST.

Signed-off-by: Jaskaran Singh 
---
 parsing_cocci/ast_cocci.ml  | 2 ++
 parsing_cocci/ast_cocci.mli | 1 +
 2 files changed, 3 insertions(+)

diff --git a/parsing_cocci/ast_cocci.ml b/parsing_cocci/ast_cocci.ml
index be6731ab..29c5 100644
--- a/parsing_cocci/ast_cocci.ml
+++ b/parsing_cocci/ast_cocci.ml
@@ -804,6 +804,7 @@ and anything =
   | ForInfoTag  of forinfo
   | CaseLineTag of case_line
   | StringFragmentTag   of string_fragment
+  | AttributeTagof attr
   | ConstVolTag of const_vol
   | Token   of string * info option
   | Directive   of added_string list
@@ -948,6 +949,7 @@ and tag2c = function
   | ForInfoTag _   -> "ForInfoTag"
   | CaseLineTag _  -> "CaseLineTag"
   | StringFragmentTag _ -> "StringFragmentTag"
+  | AttributeTag _ -> "AttributeTag"
   | ConstVolTag _  -> "ConstVolTag"
   | Token _ -> "Token"
   | Directive _ -> "Directive"
diff --git a/parsing_cocci/ast_cocci.mli b/parsing_cocci/ast_cocci.mli
index 6fc961b7..98344912 100644
--- a/parsing_cocci/ast_cocci.mli
+++ b/parsing_cocci/ast_cocci.mli
@@ -773,6 +773,7 @@ and anything =
   | ForInfoTag  of forinfo
   | CaseLineTag of case_line
   | StringFragmentTag   of string_fragment
+  | AttributeTagof attr
   | ConstVolTag of const_vol
   | Token   of string * info option
   | Directive   of added_string list
-- 
2.21.3

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


[Cocci] [PATCH 07/24] parsing_cocci: parse_cocci: Reflect attributefn in AST0 visitor

2020-07-16 Thread Jaskaran Singh
The SmPL AST0 visitor has a function for attributes. Reflect these
changes in parse_cocci.ml.

Signed-off-by: Jaskaran Singh 
---
 parsing_cocci/parse_cocci.ml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/parsing_cocci/parse_cocci.ml b/parsing_cocci/parse_cocci.ml
index e30039dc..eb88c019 100644
--- a/parsing_cocci/parse_cocci.ml
+++ b/parsing_cocci/parse_cocci.ml
@@ -1966,7 +1966,7 @@ let any_modif rule =
   donothing donothing donothing donothing donothing donothing donothing
   donothing donothing donothing donothing donothing donothing donothing
   donothing donothing donothing donothing donothing donothing donothing
-  donothing donothing donothing in
+  donothing donothing donothing donothing in
   List.exists fn.VT0.combiner_rec_top_level rule
 
 let eval_virt virt =
-- 
2.21.3

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


[Cocci] [PATCH 00/24] parsing_cocci: Add attributefn to the SmPL AST0 visitor

2020-07-16 Thread Jaskaran Singh
This patch series aims to add a public function for visiting attributes
to the SmPL AST0 visitor. This is needed to support meta attributes. An
AttributeTag constructor is also added due to dependencies, as well as
to maintain consistency with the codebase.

Jaskaran Singh (24):
  parsing_cocci: visitor_ast0: Add attributefn to SmPL AST0 visitor
  parsing_cocci: ast0toast: Reflect attributefn in AST0 visitor
  parsing_cocci: check_meta: Reflect attributefn in AST0 visitor
  parsing_cocci: function_prototypes: Reflect attributefn in AST0 visitor
  parsing_cocci: iso_compile: Reflect attributefn in AST0 visitor
  parsing_cocci: iso_pattern: Reflect attributefn in AST0 visitor
  parsing_cocci: parse_cocci: Reflect attributefn in AST0 visitor
  parsing_cocci: single_statement: Reflect attributefn in AST0 visitor
  parsing_cocci: unitary_ast0: Reflect attributefn in AST0 visitor
  parsing_cocci: ast0_cocci: Add AttributeTag to SmPL AST0
  parsing_cocci: visitor_ast0: Reflect AttributeTag in SmPL AST0
  parsing_cocci: iso_pattern: Reflect AttributeTag in SmPL AST0
  parsing_cocci: unparse_ast0: Reflect AttributeTag in SmPL AST0
  parsing_cocci: context_neg: Reflect AttributeTag in SmPL AST0
  parsing_cocci: insert_plus: Reflect AttributeTag in SmPL AST0
  parsing_cocci: ast_cocci: Add AttributeTag to the SmPL AST
  parsing_cocci: pretty_print_cocci: Reflect AttributeTag in SmPL AST
  parsing_c: unparse_cocci: Reflect AttributeTag in SmPL AST
  parsing_cocci: visitor_ast: Reflect AttributeTag in SmPL AST
  parsing_cocci: ast0toast: Reflect AttributeTag in the SmPL ASTs
  ocaml: coccilib: Reflect AttributeTag in the SmPL ASTs
  parsing_cocci: context_neg: Reflect attributefn in AST0 visitor
  parsing_cocci: insert_plus: Reflect attributefn in AST0 visitor
  tools: spgen: Reflect attributefn in AST0 visitor

 ocaml/coccilib.mli   |2 ++
 parsing_c/unparse_cocci.ml   |1 +
 parsing_cocci/ast0_cocci.ml  |2 ++
 parsing_cocci/ast0_cocci.mli |2 ++
 parsing_cocci/ast0toast.ml   |5 +++--
 parsing_cocci/ast0toast.mli  |1 +
 parsing_cocci/ast_cocci.ml   |2 ++
 parsing_cocci/ast_cocci.mli  |1 +
 parsing_cocci/check_meta.ml  |4 ++--
 parsing_cocci/context_neg.ml |   23 +--
 parsing_cocci/function_prototypes.ml |6 +++---
 parsing_cocci/insert_plus.ml |   18 ++
 parsing_cocci/iso_compile.ml |2 +-
 parsing_cocci/iso_pattern.ml |   17 +++--
 parsing_cocci/parse_cocci.ml |2 +-
 parsing_cocci/pretty_print_cocci.ml  |1 +
 parsing_cocci/single_statement.ml|2 +-
 parsing_cocci/unitary_ast0.ml|2 +-
 parsing_cocci/unparse_ast0.ml|1 +
 parsing_cocci/visitor_ast.ml |2 ++
 parsing_cocci/visitor_ast0.ml|   24 
 parsing_cocci/visitor_ast0.mli   |2 ++
 parsing_cocci/visitor_ast0_types.ml  |6 ++
 parsing_cocci/visitor_ast0_types.mli |6 ++
 tools/spgen/source/detect_patch.ml   |3 ++-
 tools/spgen/source/meta_variable.ml  |3 ++-
 tools/spgen/source/rule_body.ml  |3 ++-
 27 files changed, 109 insertions(+), 34 deletions(-)


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


[Cocci] [PATCH 15/24] parsing_cocci: insert_plus: Reflect AttributeTag in SmPL AST0

2020-07-16 Thread Jaskaran Singh
AttributeTag is added to SmPL AST0. Reflect these changes in
insert_plus.ml.

Signed-off-by: Jaskaran Singh 
---
 parsing_cocci/ast0toast.mli  | 1 +
 parsing_cocci/insert_plus.ml | 8 
 2 files changed, 9 insertions(+)

diff --git a/parsing_cocci/ast0toast.mli b/parsing_cocci/ast0toast.mli
index f4d2bb19..302c2b7d 100644
--- a/parsing_cocci/ast0toast.mli
+++ b/parsing_cocci/ast0toast.mli
@@ -36,6 +36,7 @@ val define_param_dots :
   Ast_cocci.define_param Ast_cocci.dots
 val case_line : Ast0_cocci.case_line -> Ast_cocci.case_line
 val string_fragment : Ast0_cocci.string_fragment -> Ast_cocci.string_fragment
+val attribute : Ast0_cocci.attr -> Ast_cocci.attr
 val typeC : bool (*allminus*) -> Ast0_cocci.typeC -> Ast_cocci.fullType
 val declaration : Ast0_cocci.declaration -> Ast_cocci.declaration
 val field : Ast0_cocci.field -> Ast_cocci.field
diff --git a/parsing_cocci/insert_plus.ml b/parsing_cocci/insert_plus.ml
index 63635b43..6c11a339 100644
--- a/parsing_cocci/insert_plus.ml
+++ b/parsing_cocci/insert_plus.ml
@@ -133,6 +133,7 @@ let create_root_token_table minus =
  | Ast0.ForInfoTag(d) -> Ast0.get_index d
  | Ast0.CaseLineTag(d) -> Ast0.get_index d
  | Ast0.StringFragmentTag(d) -> Ast0.get_index d
+ | Ast0.AttributeTag(d) -> Ast0.get_index d
  | Ast0.TopTag(d) -> Ast0.get_index d
  | Ast0.IsoWhenTag(_) -> failwith "only within iso phase"
  | Ast0.IsoWhenTTag(_) -> failwith "only within iso phase"
@@ -461,6 +462,9 @@ let call_collect_minus context_nodes :
   | Ast0.StringFragmentTag(e) ->
  (Ast0.get_index e,
   (collect_minus_join_points e).VT0.combiner_rec_string_fragment e)
+  | Ast0.AttributeTag(e) ->
+  (Ast0.get_index e,
+   (collect_minus_join_points e).VT0.combiner_rec_attribute e)
   | Ast0.CaseLineTag(e) ->
  (Ast0.get_index e,
   (collect_minus_join_points e).VT0.combiner_rec_case_line e)
@@ -548,6 +552,7 @@ let mk_statement x= Ast.StatementTag 
(Ast0toast.statement x)
 let mk_forinfo x  = Ast.ForInfoTag (Ast0toast.forinfo x)
 let mk_case_line x= Ast.CaseLineTag (Ast0toast.case_line x)
 let mk_string_fragment x  = Ast.StringFragmentTag (Ast0toast.string_fragment x)
+let mk_attribute x= Ast.AttributeTag (Ast0toast.attribute x)
 let mk_const_vol x= Ast.ConstVolTag x
 let mk_token x info   = Ast.Token (x,Some info)
 let mk_meta (_,x) info= Ast.Token (x,Some info)
@@ -751,6 +756,9 @@ let call_collect_plus context_nodes :
   | Ast0.StringFragmentTag(e) ->
  (Ast0.get_index e,
   (collect_plus_nodes e).VT0.combiner_rec_string_fragment e)
+  | Ast0.AttributeTag(e) ->
+  (Ast0.get_index e,
+   (collect_plus_nodes e).VT0.combiner_rec_attribute e)
   | Ast0.TopTag(e) ->
  (Ast0.get_index e,
   (collect_plus_nodes e).VT0.combiner_rec_top_level e)
-- 
2.21.3

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


[Cocci] [PATCH 21/24] ocaml: coccilib: Reflect AttributeTag in the SmPL ASTs

2020-07-16 Thread Jaskaran Singh
AttributeTag is added to the SmPL ASTs. Reflect these changes in
coccilib.mli.

Signed-off-by: Jaskaran Singh 
---
 ocaml/coccilib.mli | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/ocaml/coccilib.mli b/ocaml/coccilib.mli
index 010b8aab..19f1512c 100644
--- a/ocaml/coccilib.mli
+++ b/ocaml/coccilib.mli
@@ -3078,6 +3078,7 @@ module Ast_cocci :
   | ForInfoTag of forinfo
   | CaseLineTag of case_line
   | StringFragmentTag of string_fragment
+  | AttributeTag of attr
   | ConstVolTag of const_vol
   | Token of string * info option
   | Directive of added_string list
@@ -3660,6 +3661,7 @@ module Ast0_cocci :
   | ForInfoTag of forinfo
   | CaseLineTag of case_line
   | StringFragmentTag of string_fragment
+  | AttributeTag of attr
   | TopTag of top_level
   | IsoWhenTag of Ast_cocci.when_modifier
   | IsoWhenTTag of expression
-- 
2.21.3

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


[Cocci] [PATCH 12/24] parsing_cocci: iso_pattern: Reflect AttributeTag in SmPL AST0

2020-07-16 Thread Jaskaran Singh
AttributeTag is added to SmPL AST0. Reflect these changes in
iso_pattern.ml.

Signed-off-by: Jaskaran Singh 
---
 parsing_cocci/iso_pattern.ml | 5 +
 1 file changed, 5 insertions(+)

diff --git a/parsing_cocci/iso_pattern.ml b/parsing_cocci/iso_pattern.ml
index 5200a4c4..24c2927c 100644
--- a/parsing_cocci/iso_pattern.ml
+++ b/parsing_cocci/iso_pattern.ml
@@ -92,6 +92,9 @@ let anything_equal = function
   | (Ast0.StringFragmentTag(d1),Ast0.StringFragmentTag(d2)) ->
   (strip_info.VT0.rebuilder_rec_string_fragment d1) =
   (strip_info.VT0.rebuilder_rec_string_fragment d2)
+  | (Ast0.AttributeTag(d1),Ast0.AttributeTag(d2)) ->
+  (strip_info.VT0.rebuilder_rec_attribute d1) =
+  (strip_info.VT0.rebuilder_rec_attribute d2)
   | (Ast0.TopTag(d1),Ast0.TopTag(d2)) ->
   (strip_info.VT0.rebuilder_rec_top_level d1) =
   (strip_info.VT0.rebuilder_rec_top_level d2)
@@ -2946,6 +2949,8 @@ let rec rewrap_anything = function
   Ast0.CaseLineTag(rewrap.VT0.rebuilder_rec_case_line d)
   | Ast0.StringFragmentTag(d) ->
   Ast0.StringFragmentTag(rewrap.VT0.rebuilder_rec_string_fragment d)
+  | Ast0.AttributeTag(d) ->
+  Ast0.AttributeTag(rewrap.VT0.rebuilder_rec_attribute d)
   | Ast0.TopTag(d) -> Ast0.TopTag(rewrap.VT0.rebuilder_rec_top_level d)
   | Ast0.IsoWhenTag(_) | Ast0.IsoWhenTTag(_) | Ast0.IsoWhenFTag(_) ->
   failwith "only for isos within iso phase"
-- 
2.21.3

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


[Cocci] [PATCH 24/24] tools: spgen: Reflect attributefn in AST0 visitor

2020-07-16 Thread Jaskaran Singh
The SmPL AST0 visitor has a function for attributes. Reflect these
changes in spgen.

Signed-off-by: Jaskaran Singh 
---
 tools/spgen/source/detect_patch.ml  | 3 ++-
 tools/spgen/source/meta_variable.ml | 3 ++-
 tools/spgen/source/rule_body.ml | 3 ++-
 3 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/tools/spgen/source/detect_patch.ml 
b/tools/spgen/source/detect_patch.ml
index 0489afec..7b148a23 100644
--- a/tools/spgen/source/detect_patch.ml
+++ b/tools/spgen/source/detect_patch.ml
@@ -111,6 +111,7 @@ let patch_combiner =
   let paramfn = donothing in
   let forinfofn = donothing in
   let string_fragmentfn = donothing in
+  let attributefn = donothing in
   let topfn = donothing in
   let dotsstmtfn = donothing in
 
@@ -163,7 +164,7 @@ let patch_combiner =
 dotsexprfn dotsinitfn dotsparamfn dotsstmtfn dotsdeclfn dotsfieldfn
 dotsenumdeclfn dotscasefn dotsdefparfn
 identfn exprfn assignOpfn binaryOpfn tyfn initfn paramfn declfn fieldfn
-enumdeclfn stmtfn forinfofn casefn string_fragmentfn topfn
+enumdeclfn stmtfn forinfofn casefn string_fragmentfn attributefn topfn
 
 
 (* - *)
diff --git a/tools/spgen/source/meta_variable.ml 
b/tools/spgen/source/meta_variable.ml
index 31456614..40dcae9c 100644
--- a/tools/spgen/source/meta_variable.ml
+++ b/tools/spgen/source/meta_variable.ml
@@ -396,6 +396,7 @@ let metavar_combiner rn =
   let casefn = donothing in
   let topfn = donothing in
   let enumdeclfn = donothing in
+  let attributefn = donothing in
 
   (* --- These are shortened formatting functions that return MVSets --- *)
 
@@ -577,7 +578,7 @@ let metavar_combiner rn =
 dotsexprfn dotsinitfn dotsparamfn dotsstmtfn dotsdeclfn dotsfieldfn
 dotsenumdeclfn dotscasefn dotsdefparfn
 identfn exprfn assignOpfn binaryOpfn tyfn initfn paramfn declfn fieldfn
-enumdeclfn stmtfn forinfofn casefn string_fragmentfn topfn
+enumdeclfn stmtfn forinfofn casefn string_fragmentfn attributefn topfn
 
 
 (* - *)
diff --git a/tools/spgen/source/rule_body.ml b/tools/spgen/source/rule_body.ml
index 163dff9a..d8aa957e 100644
--- a/tools/spgen/source/rule_body.ml
+++ b/tools/spgen/source/rule_body.ml
@@ -231,6 +231,7 @@ let rec gen_combiner ~context_mode =
   let forinfofn = donothing in
   let casefn = donothing in
   let string_fragmentfn = donothing in
+  let attributefn = donothing in
 
   (* Universal special cases, regardless of no_gen mode:
* Disjunctions with SmPL style pattern-matching may need to be split into
@@ -353,7 +354,7 @@ let rec gen_combiner ~context_mode =
 dotsexprfn dotsinitfn dotsparamfn dotsstmtfn dotsdeclfn dotsfieldfn
 dotsenumdeclfn dotscasefn dotsdefparfn
 identfn exprfn assignOpfn binaryOpfn tyfn initfn paramfn declfn fieldfn
-enumdeclfn stmtfn forinfofn casefn string_fragmentfn topfn
+enumdeclfn stmtfn forinfofn casefn string_fragmentfn attributefn topfn
 
 
 (* - *)
-- 
2.21.3

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


[Cocci] [PATCH 23/24] parsing_cocci: insert_plus: Reflect attributefn in AST0 visitor

2020-07-16 Thread Jaskaran Singh
The SmPL AST0 visitor has a function for attributes. Reflect these
changes in insert_plus.ml.

Signed-off-by: Jaskaran Singh 
---
 parsing_cocci/insert_plus.ml | 10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/parsing_cocci/insert_plus.ml b/parsing_cocci/insert_plus.ml
index 6c11a339..cd45ba8c 100644
--- a/parsing_cocci/insert_plus.ml
+++ b/parsing_cocci/insert_plus.ml
@@ -83,7 +83,8 @@ it *)
   (donothing Ast0.param) (donothing Ast0.decl)
   (donothing Ast0.field) (donothing Ast0.enum_decl) statement
   (donothing Ast0.forinfo) (donothing Ast0.case_line)
-  (donothing Ast0.string_fragment) topfn in
+  (donothing Ast0.string_fragment) (donothing Ast0.attr)
+  topfn in
   res.VT0.combiner_rec_top_level e
 
 (* - *)
@@ -386,7 +387,7 @@ bind to that; not good for isomorphisms *)
 edots idots pdots sdots ddots fdots enumdots cdots dpdots
 ident expression do_nothing do_nothing
 typeC initialiser param decl field do_nothing statement forinfo
-case_line do_nothing do_top
+case_line do_nothing do_nothing do_top
 
 
 let call_collect_minus context_nodes :
@@ -678,7 +679,8 @@ let collect_plus_nodes root =
 (do_nothing mk_declaration) (do_nothing mk_field)
 (do_nothing mk_enum_decl)
 stmt (do_nothing mk_forinfo) (do_nothing mk_case_line)
-(do_nothing mk_string_fragment) toplevel
+(do_nothing mk_string_fragment) (do_nothing mk_attribute)
+toplevel
 
 let call_collect_plus context_nodes :
 (int * (Ast0.info * Ast.count * Ast.anything) list) list =
@@ -1239,7 +1241,7 @@ let reevaluate_contextness =
   donothing donothing donothing donothing donothing donothing stmt
   donothing
   donothing donothing
-  donothing in
+  donothing donothing in
   res.VT0.combiner_rec_top_level
 
 (* - *)
-- 
2.21.3

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


[Cocci] [PATCH 17/24] parsing_cocci: pretty_print_cocci: Reflect AttributeTag in SmPL AST

2020-07-16 Thread Jaskaran Singh
AttributeTag is added to the SmPL AST. Reflect these changes in
pretty_print_cocci.ml.

Signed-off-by: Jaskaran Singh 
---
 parsing_cocci/pretty_print_cocci.ml | 1 +
 1 file changed, 1 insertion(+)

diff --git a/parsing_cocci/pretty_print_cocci.ml 
b/parsing_cocci/pretty_print_cocci.ml
index 1ac6d743..095144b1 100644
--- a/parsing_cocci/pretty_print_cocci.ml
+++ b/parsing_cocci/pretty_print_cocci.ml
@@ -1169,6 +1169,7 @@ let _ =
 | Ast.ForInfoTag(x) -> forinfo x
 | Ast.CaseLineTag(x) -> case_line "" x
 | Ast.StringFragmentTag(x) -> string_fragment x
+| Ast.AttributeTag(x) -> print_attribute x
 | Ast.ConstVolTag(x) -> const_vol x
 | Ast.Token(x,Some info) -> print_string_befaft print_string x info
 | Ast.Token(x,None) -> print_string x
-- 
2.21.3

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


[Cocci] [PATCH 11/24] parsing_cocci: visitor_ast0: Reflect AttributeTag in SmPL AST0

2020-07-16 Thread Jaskaran Singh
AttributeTag is added to SmPL AST0. Reflect these changes in
visitor_ast0.ml.

Signed-off-by: Jaskaran Singh 
---
 parsing_cocci/visitor_ast0.ml | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/parsing_cocci/visitor_ast0.ml b/parsing_cocci/visitor_ast0.ml
index 090fe625..e45f9241 100644
--- a/parsing_cocci/visitor_ast0.ml
+++ b/parsing_cocci/visitor_ast0.ml
@@ -1328,6 +1328,9 @@ let visitor mode bind option_default
   | Ast0.StringFragmentTag(f) ->
  let (f_n,f) = string_fragment f in
  (f_n,Ast0.StringFragmentTag(f))
+  | Ast0.AttributeTag(a) ->
+ let (a_n,a) = attribute a in
+ (a_n,Ast0.AttributeTag(a))
   | Ast0.TopTag(top) ->
  let (top_n,top) = top_level top in
  (top_n,Ast0.TopTag(top))
-- 
2.21.3

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


[Cocci] [PATCH 20/24] parsing_cocci: ast0toast: Reflect AttributeTag in the SmPL ASTs

2020-07-16 Thread Jaskaran Singh
AttributeTag is added to the SmPL ASTs. Reflect these changes in
ast0toast.ml.

Signed-off-by: Jaskaran Singh 
---
 parsing_cocci/ast0toast.ml | 1 +
 1 file changed, 1 insertion(+)

diff --git a/parsing_cocci/ast0toast.ml b/parsing_cocci/ast0toast.ml
index 4ccc259b..b4b7600e 100644
--- a/parsing_cocci/ast0toast.ml
+++ b/parsing_cocci/ast0toast.ml
@@ -1264,6 +1264,7 @@ and anything = function
   | Ast0.ForInfoTag(d) -> Ast.ForInfoTag(forinfo d)
   | Ast0.CaseLineTag(d) -> Ast.CaseLineTag(case_line d)
   | Ast0.StringFragmentTag(d) -> Ast.StringFragmentTag(string_fragment d)
+  | Ast0.AttributeTag(d) -> Ast.AttributeTag(attribute d)
   | Ast0.TopTag(d) -> Ast.Code(top_level d)
   | Ast0.IsoWhenTag(_) -> failwith "not possible"
   | Ast0.IsoWhenTTag(_) -> failwith "not possible"
-- 
2.21.3

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


[Cocci] [PATCH 14/24] parsing_cocci: context_neg: Reflect AttributeTag in SmPL AST0

2020-07-16 Thread Jaskaran Singh
AttributeTag is added to SmPL AST0. Reflect these changes in
context_neg.ml.

Signed-off-by: Jaskaran Singh 
---
 parsing_cocci/context_neg.ml | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/parsing_cocci/context_neg.ml b/parsing_cocci/context_neg.ml
index 6a04f49b..a0d52e9a 100644
--- a/parsing_cocci/context_neg.ml
+++ b/parsing_cocci/context_neg.ml
@@ -46,6 +46,7 @@ let set_mcodekind x mcodekind =
   | Ast0.ForInfoTag(d) -> Ast0.set_mcodekind d mcodekind
   | Ast0.CaseLineTag(d) -> Ast0.set_mcodekind d mcodekind
   | Ast0.StringFragmentTag(d) -> Ast0.set_mcodekind d mcodekind
+  | Ast0.AttributeTag(d) -> Ast0.set_mcodekind d mcodekind
   | Ast0.TopTag(d) -> Ast0.set_mcodekind d mcodekind
   | Ast0.IsoWhenTag(_) -> failwith "only within iso phase"
   | Ast0.IsoWhenTTag(_) -> failwith "only within iso phase"
@@ -81,6 +82,7 @@ let set_index x index =
   | Ast0.ForInfoTag(d) -> Ast0.set_index d index
   | Ast0.CaseLineTag(d) -> Ast0.set_index d index
   | Ast0.StringFragmentTag(d) -> Ast0.set_index d index
+  | Ast0.AttributeTag(d) -> Ast0.set_index d index
   | Ast0.TopTag(d) -> Ast0.set_index d index
   | Ast0.IsoWhenTag(_) -> failwith "only within iso phase"
   | Ast0.IsoWhenTTag(_) -> failwith "only within iso phase"
@@ -115,6 +117,7 @@ let get_index = function
   | Ast0.ForInfoTag(d) -> Index.forinfo d
   | Ast0.CaseLineTag(d) -> Index.case_line d
   | Ast0.StringFragmentTag(d) -> Index.string_fragment d
+  | Ast0.AttributeTag(d) -> Index.attribute d
   | Ast0.TopTag(d) -> Index.top_level d
   | Ast0.IsoWhenTag(_) -> failwith "only within iso phase"
   | Ast0.IsoWhenTTag(_) -> failwith "only within iso phase"
-- 
2.21.3

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


[Cocci] [PATCH 19/24] parsing_cocci: visitor_ast: Reflect AttributeTag in SmPL AST

2020-07-16 Thread Jaskaran Singh
AttributeTag is added to the SmPL AST. Reflect these changes in
visitor_ast.ml.

Signed-off-by: Jaskaran Singh 
---
 parsing_cocci/visitor_ast.ml | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/parsing_cocci/visitor_ast.ml b/parsing_cocci/visitor_ast.ml
index d5819acf..5288c6f2 100644
--- a/parsing_cocci/visitor_ast.ml
+++ b/parsing_cocci/visitor_ast.ml
@@ -990,6 +990,7 @@ let combiner bind option_default
   | Ast.ForInfoTag(rule) -> forinfo rule
   | Ast.CaseLineTag(case) -> case_line case
   | Ast.StringFragmentTag(frag) -> string_fragment frag
+  | Ast.AttributeTag(attr) -> attribute attr
   | Ast.ConstVolTag(cv) -> option_default
   | Ast.Token(tok,info) -> option_default
   | Ast.Directive(str) -> option_default
@@ -1988,6 +1989,7 @@ let rebuilder
   | Ast.CaseLineTag(case) -> Ast.CaseLineTag(case_line case)
   | Ast.StringFragmentTag(frag) ->
  Ast.StringFragmentTag(string_fragment frag)
+  | Ast.AttributeTag(attr) -> Ast.AttributeTag(attribute attr)
   | Ast.ConstVolTag(cv) as x -> x
   | Ast.Token(tok,info) as x -> x
   | Ast.Directive(str) as x -> x
-- 
2.21.3

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


[Cocci] [PATCH 06/24] parsing_cocci: iso_pattern: Reflect attributefn in AST0 visitor

2020-07-16 Thread Jaskaran Singh
The SmPL AST0 visitor has a function for attributes. Reflect these
changes in iso_pattern.ml.

Signed-off-by: Jaskaran Singh 
---
 parsing_cocci/iso_pattern.ml | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/parsing_cocci/iso_pattern.ml b/parsing_cocci/iso_pattern.ml
index 40fd67e8..5200a4c4 100644
--- a/parsing_cocci/iso_pattern.ml
+++ b/parsing_cocci/iso_pattern.ml
@@ -45,7 +45,7 @@ let strip_info =
 donothing donothing donothing donothing donothing donothing donothing
 donothing donothing donothing donothing donothing donothing donothing
 donothing donothing donothing donothing donothing donothing donothing
-donothing donothing donothing
+donothing donothing donothing donothing
 
 let anything_equal = function
 (Ast0.DotsExprTag(d1),Ast0.DotsExprTag(d2)) ->
@@ -478,7 +478,7 @@ let match_maker checks_needed context_required 
whencode_allowed =
   donothing donothing donothing donothing donothing donothing donothing
   donothing donothing
   ident expression assignOp binaryOp typeC init param decl field donothing
-  stmt donothing donothing donothing donothing in
+  stmt donothing donothing donothing donothing donothing in
 
   let add_pure_list_binding name pure is_pure builder1 builder2 lst =
 match (checks_needed,pure) with
@@ -1595,7 +1595,7 @@ let make_minus =
 dots dots dots dots dots dots dots dots dots
 donothing expression donothing donothing donothing initialiser donothing
 declaration field enum_decl statement donothing donothing donothing
-donothing
+donothing donothing
 
 (* - *)
 (* rebuild mcode cells in an instantiated alt *)
@@ -1687,7 +1687,7 @@ let rebuild_mcode start_line =
 donothing donothing donothing donothing donothing donothing donothing
 donothing donothing donothing donothing donothing donothing donothing
 donothing donothing donothing donothing donothing statement donothing
-donothing donothing donothing
+donothing donothing donothing donothing
 
 (* - *)
 (* The problem of whencode.  If an isomorphism contains dots in multiple
@@ -2172,7 +2172,7 @@ let instantiate bindings mv_bindings model =
 (dots elist) donothing (dots plist) (dots slist) donothing donothing
 donothing donothing donothing
 identfn exprfn donothing donothing tyfn initfn paramfn declfn fieldfn
-enumdeclfn stmtfn donothing donothing donothing donothing
+enumdeclfn stmtfn donothing donothing donothing donothing donothing
 
 (* - *)
 
@@ -2902,7 +2902,7 @@ let rewrap =
 donothing donothing donothing donothing donothing donothing donothing
 donothing donothing donothing donothing donothing donothing donothing
 donothing donothing donothing donothing donothing donothing donothing
-donothing donothing donothing
+donothing donothing donothing donothing
 
 let rec rewrap_anything = function
 Ast0.DotsExprTag(d) ->
-- 
2.21.3

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


[Cocci] [PATCH 01/24] parsing_cocci: visitor_ast0: Add attributefn to SmPL AST0 visitor

2020-07-16 Thread Jaskaran Singh
Add a public function for visiting attributes to the SmPL AST0 visitor.

Signed-off-by: Jaskaran Singh 
---
 parsing_cocci/visitor_ast0.ml| 21 +
 parsing_cocci/visitor_ast0.mli   |  2 ++
 parsing_cocci/visitor_ast0_types.ml  |  6 ++
 parsing_cocci/visitor_ast0_types.mli |  6 ++
 4 files changed, 31 insertions(+), 4 deletions(-)

diff --git a/parsing_cocci/visitor_ast0.ml b/parsing_cocci/visitor_ast0.ml
index a5902f8c..090fe625 100644
--- a/parsing_cocci/visitor_ast0.ml
+++ b/parsing_cocci/visitor_ast0.ml
@@ -25,7 +25,7 @@ let visitor mode bind option_default
 dotsenumdeclfn dotscasefn dotsdefparfn
 identfn exprfn assignOpfn binaryOpfn tyfn initfn paramfn declfn fieldfn
 enumdeclfn
-stmtfn forinfofn casefn string_fragmentfn topfn =
+stmtfn forinfofn casefn string_fragmentfn attributefn topfn =
   let multibind l =
 let rec loop = function
[] -> option_default
@@ -1155,7 +1155,7 @@ let visitor mode bind option_default
   Ast0.Attribute(attr) ->
 let (attr_n,attr) = string_mcode attr in
 (attr_n,Ast0.Attribute(attr))) in
-k a
+attributefn all_functions k a
 
   (* we only include the when string mcode w because the parameterised
  string_mcodefn function might have side-effects *)
@@ -1370,6 +1370,7 @@ let visitor mode bind option_default
   VT0.case_line = case_line;
   VT0.define_param = define_param;
   VT0.string_fragment = string_fragment;
+  VT0.attribute = attribute;
   VT0.top_level = top_level;
   VT0.expression_dots = expression_dots;
   VT0.statement_dots = statement_dots;
@@ -1419,6 +1420,7 @@ let combiner_functions =
VT0.combiner_forinfofn = (fun r k e -> k e);
VT0.combiner_casefn = (fun r k e -> k e);
VT0.combiner_string_fragmentfn = (fun r k e -> k e);
+   VT0.combiner_attributefn = (fun r k e -> k e);
VT0.combiner_topfn = (fun r k e -> k e)}
 
 let combiner_dz r =
@@ -1458,6 +1460,8 @@ let combiner_dz r =
   (function e -> let (n,_) = r.VT0.define_param e in n);
   VT0.combiner_rec_string_fragment =
   (function e -> let (n,_) = r.VT0.string_fragment e in n);
+  VT0.combiner_rec_attribute =
+  (function e -> let (n,_) = r.VT0.attribute e in n);
   VT0.combiner_rec_top_level =
   (function e -> let (n,_) = r.VT0.top_level e in n);
   VT0.combiner_rec_expression_dots =
@@ -1524,6 +1528,7 @@ let combiner bind option_default functions =
 (fun r k e -> (functions.VT0.combiner_forinfofn (dz r) (xk k) e, e))
 (fun r k e -> (functions.VT0.combiner_casefn (dz r) (xk k) e, e))
 (fun r k e -> (functions.VT0.combiner_string_fragmentfn (dz r) (xk k) e,e))
+(fun r k e -> (functions.VT0.combiner_attributefn (dz r) (xk k) e, e))
 (fun r k e -> (functions.VT0.combiner_topfn (dz r) (xk k) e, e)))
 
 let flat_combiner bind option_default
@@ -1534,7 +1539,7 @@ let flat_combiner bind option_default
 dotsenumdeclfn dotscasefn dotsdefparfn
 identfn exprfn assignOpfn binaryOpfn tyfn initfn paramfn declfn fieldfn
 enumdeclfn
-stmtfn forinfofn casefn string_fragmentfn topfn =
+stmtfn forinfofn casefn string_fragmentfn attributefn topfn =
   let dz = combiner_dz in
   let xk k e = let (n,_) = k e in n in
   combiner_dz (visitor COMBINER bind option_default
@@ -1575,6 +1580,7 @@ let flat_combiner bind option_default
 (fun r k e -> (forinfofn (dz r) (xk k) e, e))
 (fun r k e -> (casefn (dz r) (xk k) e, e))
 (fun r k e -> (string_fragmentfn (dz r) (xk k) e, e))
+(fun r k e -> (attributefn (dz r) (xk k) e, e))
 (fun r k e -> (topfn (dz r) (xk k) e, e)))
 
 let rebuilder_functions =
@@ -1615,6 +1621,7 @@ let rebuilder_functions =
VT0.rebuilder_forinfofn = (fun r k e -> k e);
VT0.rebuilder_casefn = (fun r k e -> k e);
VT0.rebuilder_string_fragmentfn = (fun r k e -> k e);
+   VT0.rebuilder_attributefn = (fun r k e -> k e);
VT0.rebuilder_topfn = (fun r k e -> k e)}
 
 let rebuilder_dz r =
@@ -1652,6 +1659,8 @@ let rebuilder_dz r =
   (function e -> let (_,e) = r.VT0.case_line e in e);
   VT0.rebuilder_rec_string_fragment =
   (function e -> let (_,e) = r.VT0.string_fragment e in e);
+  VT0.rebuilder_rec_attribute =
+  (function e -> let (_,e) = r.VT0.attribute e in e);
   VT0.rebuilder_rec_top_level =
   (function e -> let (_,e) = r.VT0.top_level e in e);
   VT0.rebuilder_rec_expression_dots =
@@ -1714,6 +1723,7 @@ let rebuilder functions =
 (fun r k e -> ((),functions.VT0.rebuilder_casefn (dz r) (xk k) e))
 (fun r k e ->
   ((),functions.VT0.rebuilder_string_fragmentfn (dz r) (xk k) e))
+(fun r k e -> ((),functions.VT0.rebuilder_attributefn (dz r) (xk k) e))
 (fun r k e -> ((),functions.VT0.rebuilder_topfn (dz r) (xk k) e)))
 
 let flat_rebuilder
@@ -1725,7 +1735,7 @@ let flat_rebuilder
 dotsenumdecl

[Cocci] [PATCH 04/24] parsing_cocci: function_prototypes: Reflect attributefn in AST0 visitor

2020-07-16 Thread Jaskaran Singh
The SmPL AST0 visitor has a function for attributes. Reflect these
changes in function_prototypes.ml.

Signed-off-by: Jaskaran Singh 
---
 parsing_cocci/function_prototypes.ml | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/parsing_cocci/function_prototypes.ml 
b/parsing_cocci/function_prototypes.ml
index 966369b8..94dd2751 100644
--- a/parsing_cocci/function_prototypes.ml
+++ b/parsing_cocci/function_prototypes.ml
@@ -68,7 +68,7 @@ let drop_positions =
 donothing donothing donothing donothing donothing donothing donothing
 donothing donothing donothing donothing donothing donothing donothing
 donothing donothing donothing donothing donothing donothing donothing
-donothing donothing donothing in
+donothing donothing donothing donothing in
   res.VT0.rebuilder_rec_statement
 
 let get_all_functions rule =
@@ -174,7 +174,7 @@ and strip =
 donothing donothing
 ident donothing donothing donothing typeC donothing param
 donothing donothing donothing donothing donothing donothing donothing
-donothing
+donothing donothing
 
 and changed_proto = function
 (mname,mdef,mproto,None) -> true
@@ -198,7 +198,7 @@ let collect_ident_strings id =
   donothing donothing donothing donothing donothing donothing donothing
   donothing donothing donothing donothing donothing donothing donothing
   donothing donothing donothing donothing donothing donothing donothing
-  donothing donothing donothing in
+  donothing donothing donothing donothing in
   v.VT0.combiner_rec_ident id
 
 let right_attach_mcode strings (x,ar,info,mc,pos,adj) =
-- 
2.21.3

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


[Cocci] [PATCH 05/24] parsing_cocci: iso_compile: Reflect attributefn in AST0 visitor

2020-07-16 Thread Jaskaran Singh
The SmPL AST0 visitor has a function for attributes. Reflect these
changes in iso_compile.ml.

Signed-off-by: Jaskaran Singh 
---
 parsing_cocci/iso_compile.ml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/parsing_cocci/iso_compile.ml b/parsing_cocci/iso_compile.ml
index d17e1106..831197d9 100644
--- a/parsing_cocci/iso_compile.ml
+++ b/parsing_cocci/iso_compile.ml
@@ -55,7 +55,7 @@ let sequence_tokens =
 donothing donothing donothing donothing donothing donothing donothing
 donothing donothing donothing donothing donothing donothing donothing
 donothing donothing donothing donothing donothing donothing donothing
-donothing donothing donothing
+donothing donothing donothing donothing
 
 (* In general, we will get a list of lists:
 
-- 
2.21.3

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


[Cocci] [PATCH 03/24] parsing_cocci: check_meta: Reflect attributefn in AST0 visitor

2020-07-16 Thread Jaskaran Singh
The SmPL AST0 visitor has a function for attributes. Reflect these
changes in check_meta.ml.

Signed-off-by: Jaskaran Singh 
---
 parsing_cocci/check_meta.ml | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/parsing_cocci/check_meta.ml b/parsing_cocci/check_meta.ml
index f651ff8b..342cbd87 100644
--- a/parsing_cocci/check_meta.ml
+++ b/parsing_cocci/check_meta.ml
@@ -597,7 +597,7 @@ let positions rname table rules =
   donothing donothing donothing donothing donothing donothing donothing
   donothing donothing donothing donothing donothing donothing donothing
   donothing donothing donothing donothing donothing donothing donothing
-  donothing donothing donothing in
+  donothing donothing donothing donothing in
 
   List.iter fn.VT0.combiner_rec_top_level rules
 
@@ -667,7 +667,7 @@ let dup_positions rules =
   donothing donothing donothing donothing donothing donothing donothing
   donothing donothing donothing expression donothing donothing typeC
   donothing donothing declaration field donothing statement
-  donothing donothing donothing donothing in
+  donothing donothing donothing donothing donothing in
 
   let res =
 List.sort compare
-- 
2.21.3

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


[Cocci] [PATCH 02/24] parsing_cocci: ast0toast: Reflect attributefn in AST0 visitor

2020-07-16 Thread Jaskaran Singh
The SmPL AST0 visitor has a function for attributes. Reflect these
changes in ast0toast.ml.

Signed-off-by: Jaskaran Singh 
---
 parsing_cocci/ast0toast.ml | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/parsing_cocci/ast0toast.ml b/parsing_cocci/ast0toast.ml
index f0cad067..4ccc259b 100644
--- a/parsing_cocci/ast0toast.ml
+++ b/parsing_cocci/ast0toast.ml
@@ -190,7 +190,7 @@ let inline_mcodes =
 do_nothing do_nothing
 do_nothing do_nothing do_nothing do_nothing do_nothing do_nothing
 do_nothing do_nothing do_nothing_end do_nothing_end do_nothing do_nothing
-do_nothing do_nothing do_nothing do_nothing
+do_nothing do_nothing do_nothing do_nothing do_nothing
 
 (* - *)
 (* For function declarations.  Can't use the mcode at the root, because that
@@ -274,7 +274,7 @@ let check_allminus =
 donothing
 donothing ident expression donothing donothing typeC initialiser donothing
 declaration field donothing statement donothing case_line donothing
-donothing
+donothing donothing
 
 (* - *)
 (* - *)
-- 
2.21.3

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


[Cocci] [PATCH 10/24] parsing_cocci: ast0_cocci: Add AttributeTag to SmPL AST0

2020-07-16 Thread Jaskaran Singh
Add the AttributeTag constructor to AST0 of SmPL.

Signed-off-by: Jaskaran Singh 
---
 parsing_cocci/ast0_cocci.ml  | 2 ++
 parsing_cocci/ast0_cocci.mli | 1 +
 2 files changed, 3 insertions(+)

diff --git a/parsing_cocci/ast0_cocci.ml b/parsing_cocci/ast0_cocci.ml
index bfc0d145..d7d81001 100644
--- a/parsing_cocci/ast0_cocci.ml
+++ b/parsing_cocci/ast0_cocci.ml
@@ -577,6 +577,7 @@ and anything =
   | ForInfoTag of forinfo
   | CaseLineTag of case_line
   | StringFragmentTag of string_fragment
+  | AttributeTag of attr
   | TopTag of top_level
   | IsoWhenTag of Ast.when_modifier
   | IsoWhenTTag of expression
@@ -608,6 +609,7 @@ let stmt x = StmtTag x
 let forinfo x = ForInfoTag x
 let case_line x = CaseLineTag x
 let string_fragment x = StringFragmentTag x
+let attr x = AttributeTag x
 let top x = TopTag x
 let enum_decl x = EnumDeclTag x
 
diff --git a/parsing_cocci/ast0_cocci.mli b/parsing_cocci/ast0_cocci.mli
index 20d6e40c..c4b9260b 100644
--- a/parsing_cocci/ast0_cocci.mli
+++ b/parsing_cocci/ast0_cocci.mli
@@ -566,6 +566,7 @@ and anything =
   | ForInfoTag of forinfo
   | CaseLineTag of case_line
   | StringFragmentTag of string_fragment
+  | AttributeTag of attr
   | TopTag of top_level
   | IsoWhenTag of Ast_cocci.when_modifier (*only for when code, in iso phase*)
   | IsoWhenTTag of expression(*only for when code, in iso phase*)
-- 
2.21.3

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


[Cocci] [PATCH 13/24] parsing_cocci: unparse_ast0: Reflect AttributeTag in SmPL AST0

2020-07-16 Thread Jaskaran Singh
AttributeTag is added to SmPL AST0. Reflect these changes in
unparse_ast0.ml.

Signed-off-by: Jaskaran Singh 
---
 parsing_cocci/unparse_ast0.ml | 1 +
 1 file changed, 1 insertion(+)

diff --git a/parsing_cocci/unparse_ast0.ml b/parsing_cocci/unparse_ast0.ml
index 109f1844..875282fb 100644
--- a/parsing_cocci/unparse_ast0.ml
+++ b/parsing_cocci/unparse_ast0.ml
@@ -873,6 +873,7 @@ let rec unparse_anything x =
   | Ast0.ForDecl (_,decl) -> declaration decl)
   | Ast0.CaseLineTag(d)  -> case_line "" d
   | Ast0.StringFragmentTag(d)  -> string_fragment d
+  | Ast0.AttributeTag(d) -> print_attribute d
   | Ast0.TopTag(d)   -> top_level d
   | Ast0.IsoWhenTag(x)   -> U.print_when_modif x
   | Ast0.IsoWhenTTag(e)  -> expression e
-- 
2.21.3

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


  1   2   3   4   5   6   >