Skip to contentSkip to conversation

cocci: Add support for meta attributes to SmPL

PATCH Applied Jaskaran Singh 2 participants 46 messages Jul 26, 2020 – Aug 2, 2020

lore
Share & tools
lore
#0 lore raw

cover cocci: Add support for meta attributes to SmPL

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 ++++++++++++------
 parsing_cocci/pretty_print_cocci.ml   |    3 ++
 parsing_cocci/safe_for_multi_decls.ml |    1 
 parsing_cocci/unify_ast.ml            |    2 +
 parsing_cocci/unitary_ast0.ml         |    8 +++++
 parsing_cocci/unparse_ast0.ml         |    1 
 parsing_cocci/visitor_ast.ml          |    7 +++--
 parsing_cocci/visitor_ast0.ml         |    5 ++-
 python/pycocci_aux.ml                 |    2 +
 tests/metaattr.c                      |    5 +++
 tests/metaattr.cocci                  |    9 ++++++
 tests/metaattr.res                    |    5 +++
 tests/remove_metaattr.c               |    5 +++
 tests/remove_metaattr.cocci           |    9 ++++++
 tests/remove_metaattr.res             |    5 +++
 tools/spgen/source/meta_variable.ml   |    8 +++++
 54 files changed, 357 insertions(+), 65 deletions(-)

_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

#1 lore raw

PATCH 1/43 parsing_cocci: ast0_cocci: Add MetaAttribute & MetaAttributeDecl

Add the MetaAttribute and MetaAttributeDecl variants to AST0 of SmPL.

---
 parsing_cocci/ast0_cocci.ml  | 1 +
 parsing_cocci/ast0_cocci.mli | 1 +
 2 files changed, 2 insertions(+)
parsing_cocci/ast0_cocci.ml +1 -0
index d7d810014..eac1d10c7 100644
@@ -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
 
parsing_cocci/ast0_cocci.mli +1 -0
index 6097039fd..431a542f8 100644
@@ -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
 
Signature · 6 lines
2.21.3

_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
#2 lore raw

PATCH 2/43 parsing_cocci: parser: Parse meta attributes and metaattr decls

In reply to 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.

---
 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(-)
parsing_cocci/data.ml +1 -0
index d604fd636..3c5e6c941 100644
@@ -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
 
parsing_cocci/data.mli +1 -0
index 9fa4e45a2..88f29baa7 100644
@@ -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
parsing_cocci/lexer_cocci.mll +12 -0
index f05c6de02..9e85efe48 100644
@@ -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
parsing_cocci/parse_aux.ml +4 -0
index f2036bfc1..7ba7ce861 100644
@@ -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,_) ->
parsing_cocci/parser_cocci_menhir.mly +17 -8
index af9726e10..056ed0048 100644
@@ -254,6 +254,7 @@ let inline_id aft = function
 %token <Parse_aux.expinfo>       TMetaErr
 %token <Parse_aux.cstrinfo>          TMetaParam TMetaStm
 %token <Parse_aux.cstrinfo>          TMetaInit TMetaDecl TMetaField TMeta
+%token <Parse_aux.cstrinfo>          TMetaAttribute
 %token <Parse_aux.list_info>     TMetaParamList TMetaExpList TMetaInitList
 %token <Parse_aux.list_info>     TMetaFieldList TMetaStmList TMetaDParamList
 %token <Parse_aux.typed_expinfo_bitfield> 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=Tattr    fninfo
+  | a=attr    fninfo
       { 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:
     /* empty */ { [] }
@@ -1514,11 +1519,11 @@ fninfo_nt:
 	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=Tattr    fninfo_nt
+  | a=attr    fninfo_nt
       { try
 	let _ = List.find (function Ast0_cocci.FAttr(_) -> true | _ -> false) $2 in
 	raise (Semantic_cocci.Semantic "duplicate init")
-      with Not_found -> (Ast0_cocci.FAttr(Parse_aux.make_attr a))::$2 }
+      with Not_found -> (Ast0_cocci.FAttr(a))::$2 }
 
 storage:
          s=Tstatic      { Parse_aux.clt2mcode Ast_cocci.Static s }
@@ -3228,13 +3233,17 @@ script_virt_name_decl:
 %inline
 attr_list:
                            { [] }
- | Tattr f=full_attr_list
-    { let a = Parse_aux.make_attr $1 in a::f }
+ | a=attr f=full_attr_list  { a::f }
 
 full_attr_list:
                            { [] }
- | Tattr f=full_attr_list
-    { let a = Parse_aux.make_attr $1 in a::f }
+ | a=attr f=full_attr_list  { a::f }
+
+attr:
+   Tattr { Parse_aux.make_attr $1 }
+ | TMetaAttribute
+    { let (nm,cstr,pure,clt) = $1 in
+      Ast0_cocci.wrap(Ast0_cocci.MetaAttribute(Parse_aux.clt2mcode nm clt,cstr,pure)) }
 
 anything: /* used for script code */
    TIdentifier { "identifier" }
Signature · 6 lines
2.21.3

_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
#3 lore raw

PATCH 3/43 parsing_cocci: parse_cocci: Reflect MetaAttribute & MetaAttributeDecl

In reply to Jaskaran Singh

MetaAttribute and MetaAttributeDecl are added to the SmPL AST. Reflect these changes in parse_cocci.ml.

---
 parsing_cocci/parse_cocci.ml | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
parsing_cocci/parse_cocci.ml +9 -2
index e455fce06..e8dca63a3 100644
@@ -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)
Signature · 6 lines
2.21.3

_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
#4 lore raw

PATCH 4/43 parsing_cocci: ast_cocci: Add MetaAttribute & MetaAttributeDecl

In reply to Jaskaran Singh

Add the MetaAttribute and MetaAttributeDecl consturctors the SmPL AST.

---
 parsing_cocci/ast_cocci.ml  | 3 +++
 parsing_cocci/ast_cocci.mli | 2 ++
 2 files changed, 5 insertions(+)
parsing_cocci/ast_cocci.ml +3 -0
index 666629c58..656c3d929 100644
@@ -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
parsing_cocci/ast_cocci.mli +2 -0
index 983449123..9495e83c8 100644
@@ -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
 
Signature · 6 lines
2.21.3

_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
#5 lore raw

PATCH 5/43 parsing_cocci: iso_pattern: Reflect MetaAttribute & MetaAttributeDecl

In reply to Jaskaran Singh

MetaAttribute and MetaAttributeDecl are added to the SmPL AST. Reflect these changes in iso_pattern.ml.

---
 parsing_cocci/iso_pattern.ml | 2 ++
 1 file changed, 2 insertions(+)
parsing_cocci/iso_pattern.ml +2 -0
index 24c2927c9..4a9a80b4f 100644
@@ -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) ->
Signature · 6 lines
2.21.3

_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
#6 lore raw

PATCH 6/43 parsing_c: unparse_hrule: Reflect MetaAttribute & MetaAttributeDecl

In reply to Jaskaran Singh

MetaAttribute and MetaAttributeDecl are added to the SmPL AST. Reflect these changes in unparse_hrule.ml.

---
 parsing_c/unparse_hrule.ml | 2 ++
 1 file changed, 2 insertions(+)
parsing_c/unparse_hrule.ml +2 -0
index 3078dde41..4d7ba93cc 100644
@@ -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) ->
Signature · 6 lines
2.21.3

_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
#7 lore raw

PATCH 7/43 parsing_cocci: pretty_print_cocci: Reflect MetaAttribute & MetaAttributeDecl

In reply to Jaskaran Singh

MetaAttribute and MetaAttributeDecl are added to the SmPL AST. Reflect these changes in pretty_print_cocci.ml.

---
 parsing_cocci/pretty_print_cocci.ml | 2 ++
 1 file changed, 2 insertions(+)
parsing_cocci/pretty_print_cocci.ml +2 -0
index 095144b17..fe54a8d61 100644
@@ -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 ";"
Signature · 6 lines
2.21.3

_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
#8 lore raw

PATCH 8/43 ocaml: coccilib: Reflect MetaAttribute & MetaAttributeDecl

In reply to Jaskaran Singh

MetaAttribute and MetaAttributeDecl are added to the SmPL AST. Reflect these changes in coccilib.mli.

---
 ocaml/coccilib.mli | 4 ++++
 1 file changed, 4 insertions(+)
ocaml/coccilib.mli +4 -0
index 19f1512cd..3960d1046 100644
@@ -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 =
Signature · 6 lines
2.21.3

_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
#9 lore raw

PATCH 9/43 ocaml: yes_prepare_ocamlcocci: Reflect MetaAttribute & MetaAttributeDecl

In reply to Jaskaran Singh

MetaAttribute and MetaAttributeDecl are added to the SmPL AST. Reflect these changes in yes_prepare_ocamlcocci.ml.

---
 ocaml/yes_prepare_ocamlcocci.ml | 1 +
 1 file changed, 1 insertion(+)
ocaml/yes_prepare_ocamlcocci.ml +1 -0
index aa6a1b606..fef237189 100644
@@ -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"
Signature · 6 lines
2.21.3

_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
#10 lore raw

PATCH 10/43 parsing_c: ast_c: Add MetaAttributeVal

In reply to Jaskaran Singh

Add the MetaAttributeVal constructor to the C AST.

---
 parsing_c/ast_c.ml  | 1 +
 parsing_c/ast_c.mli | 1 +
 2 files changed, 2 insertions(+)
parsing_c/ast_c.ml +1 -0
index 645f9e183..2c682fe21 100644
@@ -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
parsing_c/ast_c.mli +1 -0
index a4d1f40d8..d03b5cf2b 100644
@@ -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
Signature · 6 lines
2.21.3

_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
#11 lore raw

PATCH 11/43 parsing_c: unparse_hrule: Reflect MetaAttributeVal

In reply to Jaskaran Singh

MetaAttributeVal is added to the C AST. Reflect these changes in unparse_hrule.ml.

---
 parsing_c/unparse_hrule.ml | 3 +++
 1 file changed, 3 insertions(+)
parsing_c/unparse_hrule.ml +3 -0
index 4d7ba93cc..9d6421f31 100644
@@ -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) ->
Signature · 6 lines
2.21.3

_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
#12 lore raw

PATCH 12/43 engine: cocci_vs_c: Reflect MetaAttributeVal

In reply to Jaskaran Singh

MetaAttributeVal is added to the C AST. Reflect these changes in cocci_vs_c.ml.

---
 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(-)
engine/cocci_vs_c.ml +6 -2
index cba6c8d01..ed91a4785 100644
@@ -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)
 
parsing_c/lib_parsing_c.ml +3 -0
index 99e43be3b..687833604 100644
@@ -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)
parsing_c/lib_parsing_c.mli +3 -0
index d9578f3ca..0e53f9060 100644
@@ -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
Signature · 6 lines
2.21.3

_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
#13 lore raw

PATCH 13/43 engine: pattern_c: Reflect MetaAttributeVal

In reply to Jaskaran Singh

MetaAttributeVal is added to the C AST. Reflect these changes in pattern_c.ml.

---
 engine/pattern_c.ml | 6 ++++++
 1 file changed, 6 insertions(+)
engine/pattern_c.ml +6 -0
index 821a5900e..7d9a2dcc1 100644
@@ -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))
Signature · 6 lines
2.21.3

_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
#14 lore raw

PATCH 14/43 engine: pretty_print_engine: Add MetaAttributeVal

In reply to Jaskaran Singh

MetaAttributeVal is added to the C AST. Reflect these changes in pretty_print_engine.ml.

---
 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(+)
engine/pretty_print_engine.ml +1 -0
index 383016ce3..b825fac39 100644
@@ -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 "<<param>>"
parsing_c/pretty_print_c.ml +12 -0
index 74b57344e..6ac3e4767 100644
@@ -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
 
parsing_c/pretty_print_c.mli +5 -0
index 5cfcc779d..daaad2061 100644
@@ -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
Signature · 6 lines
2.21.3

_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
#15 lore raw

PATCH 15/43 ocaml: coccilib: Reflect MetaAttributeVal

In reply to Jaskaran Singh

MetaAttributeVal is added to the C AST. Reflect these changes in coccilib.ml and coccilib.mli.

---
 ocaml/coccilib.ml  | 1 +
 ocaml/coccilib.mli | 3 +++
 2 files changed, 4 insertions(+)
ocaml/coccilib.ml +1 -0
index 0a7e0eb98..459f4c6be 100644
@@ -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
 
ocaml/coccilib.mli +3 -0
index 3960d1046..970229ee9 100644
@@ -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 :
Signature · 6 lines
2.21.3

_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
#16 lore raw

PATCH 16/43 ocaml: ocamlcocci_aux: Reflect MetaAttributeVal

In reply to Jaskaran Singh

MetaAttributeVal is added to the C AST. Reflect these changes in ocamlcocci_aux.ml.

---
 ocaml/ocamlcocci_aux.ml | 2 ++
 1 file changed, 2 insertions(+)
ocaml/ocamlcocci_aux.ml +2 -0
index 7ec3a964f..ccbf6858e 100644
@@ -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
Signature · 6 lines
2.21.3

_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
#17 lore raw

PATCH 17/43 ocaml: run_ocamlcocci: Reflect MetaAttributeVal

In reply to Jaskaran Singh

MetaAttributeVal is added to the C AST. Reflect these changes in run_ocamlcocci.ml.

---
 ocaml/run_ocamlcocci.ml | 1 +
 1 file changed, 1 insertion(+)
ocaml/run_ocamlcocci.ml +1 -0
index 065428391..14decf886 100644
@@ -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
 
Signature · 6 lines
2.21.3

_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
#18 lore raw

PATCH 18/43 python: pycocci_aux: Reflect MetaAttributeVal

In reply to Jaskaran Singh

MetaAttributeVal is added to the C AST. Reflect these changes in pycocci_aux.ml.

---
 python/pycocci_aux.ml | 2 ++
 1 file changed, 2 insertions(+)
python/pycocci_aux.ml +2 -0
index d83059455..85a8eefe3 100644
@@ -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
Signature · 6 lines
2.21.3

_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
#19 lore raw

PATCH 19/43 parsing_cocci: visitor_ast0: Reflect MetaAttribute

In reply to Jaskaran Singh

MetaAttribute is added to the SmPL AST. Visit meta attributes in the SmPL AST0 visitor.

---
 parsing_cocci/visitor_ast0.ml | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
parsing_cocci/visitor_ast0.ml +4 -1
index e45f92415..0a5db947b 100644
@@ -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
Signature · 6 lines
2.21.3

_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
#20 lore raw

PATCH 20/43 parsing_cocci: check_meta: Reflect MetaAttribute

In reply to Jaskaran Singh

MetaAttribute is added to the SmPL AST. Reflect these changes in check_meta.ml.

---
 parsing_cocci/check_meta.ml | 27 +++++++++++++++++++--------
 1 file changed, 19 insertions(+), 8 deletions(-)
parsing_cocci/check_meta.ml +19 -8
index 342cbd87f..fb8d05ccc 100644
@@ -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
Signature · 6 lines
2.21.3

_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
#21 lore raw

PATCH 21/43 parsing_cocci: adjust_pragmas: Reflect MetaAttribute

In reply to Jaskaran Singh

MetaAttribute is added to the SmPL AST. Reflect these changes in adjust_pragmas.ml.

---
 parsing_cocci/adjust_pragmas.ml | 3 +++
 1 file changed, 3 insertions(+)
parsing_cocci/adjust_pragmas.ml +3 -0
index 8f24fa718..6891d886f 100644
@@ -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 =
Signature · 6 lines
2.21.3

_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
#22 lore raw

PATCH 22/43 parsing_cocci: context_neg: Reflect MetaAttribute

In reply to Jaskaran Singh

MetaAttribute is added to the SmPL AST. Reflect these changes in context_neg.ml.

---
 parsing_cocci/context_neg.ml | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)
parsing_cocci/context_neg.ml +12 -6
index ebb93806b..8b2512c9b 100644
@@ -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,_,_,_)) ->
Signature · 6 lines
2.21.3

_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
#23 lore raw

PATCH 23/43 parsing_cocci: compute_lines: Reflect MetaAttribute

In reply to Jaskaran Singh

MetaAttribute is added to the SmPL AST. Reflect these changes in compute_lines.ml.

---
 parsing_cocci/compute_lines.ml | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
parsing_cocci/compute_lines.ml +9 -5
index 4420e9524..4042b1025 100644
@@ -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
 
 
 (* --------------------------------------------------------------------- *)
Signature · 6 lines
2.21.3

_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
#24 lore raw

PATCH 24/43 parsing_cocci: iso_pattern: Reflect MetaAttribute

In reply to Jaskaran Singh

MetaAttribute is added to the SmPL AST. Reflect these changes in iso_pattern.ml.

---
 parsing_cocci/iso_pattern.ml | 44 +++++++++++++++++++++++++++++++-----
 1 file changed, 38 insertions(+), 6 deletions(-)
parsing_cocci/iso_pattern.ml +38 -6
index 4a9a80b4f..c800665fd 100644
@@ -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
 
 (* --------------------------------------------------------------------- *)
 
Signature · 6 lines
2.21.3

_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
#25 lore raw

PATCH 25/43 parsing_cocci: function_prototypes: Reflect MetaAttribute

In reply to Jaskaran Singh

MetaAttribute is added to the SmPL AST. Reflect these changes in function_prototypes.ml.

---
 parsing_cocci/function_prototypes.ml | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
parsing_cocci/function_prototypes.ml +9 -1
index 94dd2751a..8c6e559ac 100644
@@ -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
Signature · 6 lines
2.21.3

_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
#26 lore raw

PATCH 26/43 parsing_cocci: arity: Reflect MetaAttribute

In reply to Jaskaran Singh

MetaAttribute is added to the SmPL AST. Reflect these changes in arity.ml.

---
 parsing_cocci/arity.ml | 29 +++++++++++++++++++----------
 1 file changed, 19 insertions(+), 10 deletions(-)
parsing_cocci/arity.ml +19 -10
index 23eb32f9a..28ab8410d 100644
@@ -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)
Signature · 6 lines
2.21.3

_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
#27 lore raw

PATCH 27/43 parsing_cocci: unitary_ast0: Reflect MetaAttribute

In reply to Jaskaran Singh

MetaAttribute is added to the SmPL AST. Reflect these changes in unitary_ast0.ml.

---
 parsing_cocci/unitary_ast0.ml | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
parsing_cocci/unitary_ast0.ml +7 -1
index fadfa4707..294dc91ff 100644
@@ -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))
Signature · 6 lines
2.21.3

_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
#28 lore raw

PATCH 28/43 parsing_cocci: unparse_ast0: Reflect MetaAttribute

In reply to Jaskaran Singh

MetaAttribute is added to the SmPL AST. Reflect these changes in unparse_ast0.ml.

---
 parsing_cocci/unparse_ast0.ml | 1 +
 1 file changed, 1 insertion(+)
parsing_cocci/unparse_ast0.ml +1 -0
index 875282fb0..e2556cb80 100644
@@ -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) ->
Signature · 6 lines
2.21.3

_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
#29 lore raw

PATCH 29/43 parsing_cocci: ast0toast: Reflect MetaAttribute

In reply to Jaskaran Singh

MetaAttribute is added to the SmPL AST. Reflect these changes in ast0toast.ml.

---
 parsing_cocci/ast0toast.ml | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
parsing_cocci/ast0toast.ml +3 -1
index b4b7600ed..16a2ffd30 100644
@@ -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]
Signature · 6 lines
2.21.3

_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
#30 lore raw

PATCH 30/43 parsing_cocci: visitor_ast: Reflect MetaAttribute

In reply to Jaskaran Singh

MetaAttribute is added to the SmPL AST. Visit it in the SmPL AST visitor.

---
 parsing_cocci/visitor_ast.ml | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
parsing_cocci/visitor_ast.ml +5 -2
index 17afc5183..315b94243 100644
@@ -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
Signature · 6 lines
2.21.3

_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
#31 lore raw

PATCH 31/43 parsing_cocci: cleanup_rules: Reflect MetaAttribute

In reply to Jaskaran Singh

MetaAttribute is added to the SmPL AST. Reflect these changes in cleanup_rules.ml.

---
 parsing_cocci/cleanup_rules.ml | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
parsing_cocci/cleanup_rules.ml +9 -1
index 7f03f98fd..e11484539 100644
@@ -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;
Signature · 6 lines
2.21.3

_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
#32 lore raw

PATCH 32/43 parsing_cocci: free_vars: Reflect MetaAttribute

In reply to Jaskaran Singh

MetaAttribute is added to the SmPL AST. Reflect these changes in free_vars.ml.

---
 parsing_cocci/free_vars.ml | 28 +++++++++++++++++++++++++---
 1 file changed, 25 insertions(+), 3 deletions(-)
parsing_cocci/free_vars.ml +25 -3
index 6958f48ee..404e2d549 100644
@@ -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
 
Signature · 6 lines
2.21.3

_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
#33 lore raw

PATCH 33/43 parsing_cocci: get_constants: Reflect MetaAttribute

In reply to Jaskaran Singh

MetaAttribute is added to the SmPL AST. Reflect these changes in get_constants.ml.

---
 parsing_cocci/get_constants.ml | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
parsing_cocci/get_constants.ml +6 -1
index a23f2e4f8..ebab24871 100644
@@ -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
 
 (* ------------------------------------------------------------------------ *)
 
Signature · 6 lines
2.21.3

_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
#34 lore raw

PATCH 34/43 parsing_cocci: get_constants2: Reflect MetaAttribute

In reply to Jaskaran Singh

MetaAttribute is added to the SmPL AST. Reflect these changes in get_constants2.ml.

---
 parsing_cocci/get_constants2.ml | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
parsing_cocci/get_constants2.ml +5 -4
index 8fffe1955..33d8ccf5a 100644
@@ -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
 
 (* ------------------------------------------------------------------------ *)
Signature · 6 lines
2.21.3

_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
#35 lore raw

PATCH 35/43 parsing_cocci: index: Reflect MetaAttribute

In reply to Jaskaran Singh

MetaAttribute is added to the SmPL AST. Reflect these changes in index.ml.

---
 parsing_cocci/index.ml | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
parsing_cocci/index.ml +2 -1
index cb3ac7ecd..ca54bc85d 100644
@@ -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
Signature · 6 lines
2.21.3

_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
#36 lore raw

PATCH 36/43 parsing_cocci: pretty_print_cocci: Reflect MetaAttribute

In reply to Jaskaran Singh

MetaAttribute is added to the SmPL AST. Reflect these changes in pretty_print_cocci.ml.

---
 parsing_cocci/pretty_print_cocci.ml | 1 +
 1 file changed, 1 insertion(+)
parsing_cocci/pretty_print_cocci.ml +1 -0
index fe54a8d61..c4de73f1f 100644
@@ -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
Signature · 6 lines
2.21.3

_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
#37 lore raw

PATCH 37/43 parsing_cocci: safe_for_multi_decls: Reflect MetaAttribute

In reply to Jaskaran Singh

MetaAttribute is added to the SmPL AST. Reflect these changes in safe_for_multi_decls.ml.

---
 parsing_cocci/safe_for_multi_decls.ml | 1 +
 1 file changed, 1 insertion(+)
parsing_cocci/safe_for_multi_decls.ml +1 -0
index ee3741b96..a4ad2f36c 100644
@@ -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
Signature · 6 lines
2.21.3

_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
#38 lore raw

PATCH 38/43 parsing_cocci: unify_ast: Reflect MetaAttribute

In reply to Jaskaran Singh

MetaAttribute is added to the SmPL AST. Reflect these changes in unify_ast.ml.

---
 parsing_cocci/unify_ast.ml | 2 ++
 1 file changed, 2 insertions(+)
parsing_cocci/unify_ast.ml +2 -0
index 98e2ab1dd..811c91f30 100644
@@ -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
Signature · 6 lines
2.21.3

_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
#39 lore raw

PATCH 39/43 parsing_c: unparse_cocci: Reflect MetaAttribute

In reply to Jaskaran Singh

MetaAttribute is added to the SmPL AST. Reflect these changes in unparse_cocci.ml.

---
 parsing_c/unparse_cocci.ml | 6 ++++++
 1 file changed, 6 insertions(+)
parsing_c/unparse_cocci.ml +6 -0
index e544336d0..7be18bf1c 100644
@@ -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
Signature · 6 lines
2.21.3

_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
#40 lore raw

PATCH 40/43 engine: cocci_vs_c: Reflect MetaAttribute

In reply to Jaskaran Singh

MetaAttribute is added to the SmPL AST. Reflect these changes in cocci_vs_c.ml.

---
 engine/cocci_vs_c.ml | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)
engine/cocci_vs_c.ml +14 -1
index ed91a4785..0b698287d 100644
@@ -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
 
 (*---------------------------------------------------------------------------*)
Signature · 6 lines
2.21.3

_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
#41 lore raw

PATCH 41/43 tools: spgen: Reflect MetaAttribute

In reply to Jaskaran Singh

MetaAttribute is added to the SmPL AST. Reflect these changes in spgen.

---
 tools/spgen/source/meta_variable.ml | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
tools/spgen/source/meta_variable.ml +7 -1
index 40dcae9c2..70a9fe878 100644
@@ -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
Signature · 6 lines
2.21.3

_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
#42 lore raw

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

In reply to Jaskaran Singh

Meta attributes are added to SmPL. Add test case to match and detect a meta attribute in C code.

---
 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
tests/metaattr.c new file +5 -0
new file mode 100644
index 000000000..d3b091cd9
@@ -0,0 +1,5 @@
+int main() {
+	int b __attr__ = 1;
+	int b = 1;
+	return 0;
+}
tests/metaattr.cocci new file +9 -0
new file mode 100644
index 000000000..a325ad06f
@@ -0,0 +1,9 @@
+@@
+attribute name __attr__;
+attribute a;
+identifier b;
+@@
+
+-	int
++	char
+  b a = 1;
tests/metaattr.res new file +5 -0
new file mode 100644
index 000000000..9cd2014f2
@@ -0,0 +1,5 @@
+int main() {
+	char b __attr__ = 1;
+	int b = 1;
+	return 0;
+}
Signature · 6 lines
2.21.3

_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
#43 lore raw

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

In reply to Jaskaran Singh

Meta attributes are added to SmPL. Add a test case to match and remove a meta attribute from C code.

---
 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
tests/remove_metaattr.c new file +5 -0
new file mode 100644
index 000000000..d3b091cd9
@@ -0,0 +1,5 @@
+int main() {
+	int b __attr__ = 1;
+	int b = 1;
+	return 0;
+}
tests/remove_metaattr.cocci new file +9 -0
new file mode 100644
index 000000000..e35bc7e3c
@@ -0,0 +1,9 @@
+@@
+attribute name __attr__;
+attribute a;
+identifier b;
+@@
+
+int b
+-	a
+	= 1;
tests/remove_metaattr.res new file +5 -0
new file mode 100644
index 000000000..7d9292a55
@@ -0,0 +1,5 @@
+int main() {
+	int b = 1;
+	int b = 1;
+	return 0;
+}
Signature · 6 lines
2.21.3

_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci
Applied
#44 lore raw
In reply to Jaskaran Singh
Quoted 7 lines · 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.

Applied.

Is this the end of atributes?

julia

Quoted 93 lines

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 ++++++++++++------
 parsing_cocci/pretty_print_cocci.ml   |    3 ++
 parsing_cocci/safe_for_multi_decls.ml |    1
 parsing_cocci/unify_ast.ml            |    2 +
 parsing_cocci/unitary_ast0.ml         |    8 +++++
 parsing_cocci/unparse_ast0.ml         |    1
 parsing_cocci/visitor_ast.ml          |    7 +++--
 parsing_cocci/visitor_ast0.ml         |    5 ++-
 python/pycocci_aux.ml                 |    2 +
Quoted 11 lines
 tests/metaattr.c                      |    5 +++
 tests/metaattr.cocci                  |    9 ++++++
 tests/metaattr.res                    |    5 +++
 tests/remove_metaattr.c               |    5 +++
 tests/remove_metaattr.cocci           |    9 ++++++
 tests/remove_metaattr.res             |    5 +++
 tools/spgen/source/meta_variable.ml   |    8 +++++
 54 files changed, 357 insertions(+), 65 deletions(-)

_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

#45 lore raw
Quoted 11 lines · Julia Lawall
Quoted 8 lines · 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.

Quoted 7 lines
Quoted 2 lines

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.

Quoted 114 lines

julia

Quoted 112 lines

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 ++++++++++++------
 parsing_cocci/pretty_print_cocci.ml   |    3 ++
 parsing_cocci/safe_for_multi_decls.ml |    1
 parsing_cocci/unify_ast.ml            |    2 +
 parsing_cocci/unitary_ast0.ml         |    8 +++++
 parsing_cocci/unparse_ast0.ml         |    1
 parsing_cocci/visitor_ast.ml          |    7 +++--
 parsing_cocci/visitor_ast0.ml         |    5 ++-
 python/pycocci_aux.ml                 |    2 +
 tests/metaattr.c                      |    5 +++
 tests/metaattr.cocci                  |    9 ++++++
 tests/metaattr.res                    |    5 +++
 tests/remove_metaattr.c               |    5 +++
 tests/remove_metaattr.cocci           |    9 ++++++
 tests/remove_metaattr.res             |    5 +++
 tools/spgen/source/meta_variable.ml   |    8 +++++
 54 files changed, 357 insertions(+), 65 deletions(-)

_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci