All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jaskaran Singh <jaskaran.singh@collabora.com>
To: cocci@systeme.lip6.fr
Subject: [Cocci] [PATCH 02/43] parsing_cocci: parser: Parse meta attributes and metaattr decls
Date: Sun, 26 Jul 2020 18:21:00 +0530	[thread overview]
Message-ID: <20200726125141.17787-3-jaskaran.singh@collabora.com> (raw)
In-Reply-To: <20200726125141.17787-1-jaskaran.singh@collabora.com>

Introduce changes to parse meta attributes and meta attribute
declarations in SmPL rules. Currently, meta attributes are only parsed
in context and minus code.

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

diff --git a/parsing_cocci/data.ml b/parsing_cocci/data.ml
index d604fd636..3c5e6c941 100644
--- a/parsing_cocci/data.ml
+++ b/parsing_cocci/data.ml
@@ -132,6 +132,7 @@ let add_binaryOp_meta:
 
 let add_type_name: (string -> unit) ref = ref uninitialized_add_meta
 let add_attribute: (string -> unit) ref = ref uninitialized_add_meta
+let add_attribute_meta: cstr_meta_type ref = ref uninitialized_add_meta
 let add_declarer_name: (string -> unit) ref = ref uninitialized_add_meta
 let add_iterator_name: (string -> unit) ref = ref uninitialized_add_meta
 
diff --git a/parsing_cocci/data.mli b/parsing_cocci/data.mli
index 9fa4e45a2..88f29baa7 100644
--- a/parsing_cocci/data.mli
+++ b/parsing_cocci/data.mli
@@ -112,6 +112,7 @@ val add_binaryOp_meta:
 
 val add_type_name: (string -> unit) ref
 val add_attribute: (string -> unit) ref
+val add_attribute_meta: cstr_meta_type ref
 val add_declarer_name: (string -> unit) ref
 val add_iterator_name: (string -> unit) ref
 val init_rule: (unit -> unit) ref
diff --git a/parsing_cocci/lexer_cocci.mll b/parsing_cocci/lexer_cocci.mll
index f05c6de02..9e85efe48 100644
--- a/parsing_cocci/lexer_cocci.mll
+++ b/parsing_cocci/lexer_cocci.mll
@@ -533,6 +533,18 @@ let init _ = (* per file, first .cocci then iso *)
 	    TDirective (Ast.Space name, clt)
 	| _ -> Tattr (name, clt) in
       Hashtbl.replace attr_names name fn);
+  Data.add_attribute_meta :=
+    (fun name cstr pure ->
+      let fn ((d,ln,_,_,_,_,_,_,_,_) as clt) =
+        if (match d with (Data.PLUS | Data.PLUSPLUS) -> true | _ -> false)
+        then
+          (* TODO support meta attributes in plus code *)
+	  failwith
+	    (Printf.sprintf
+             "%d: meta attributes currently only allowed in context/minus code"
+             ln);
+        TMetaAttribute(name,cstr,pure,clt) in
+      Hashtbl.replace metavariables (get_name name) fn);
   Data.add_declarer_name :=
     (function name ->
       let fn clt = TDeclarerId(name,clt) in
diff --git a/parsing_cocci/parse_aux.ml b/parsing_cocci/parse_aux.ml
index f2036bfc1..7ba7ce861 100644
--- a/parsing_cocci/parse_aux.ml
+++ b/parsing_cocci/parse_aux.ml
@@ -345,6 +345,10 @@ let check_meta_tyopt type_irrelevant v =
       (match meta_lookup rule name v with
 	Ast.MetaFragListDecl(_,_,_) -> ()
       | _ -> fail name)
+  | Ast.MetaAttributeDecl(Ast.NONE,(rule,name)) ->
+      (match meta_lookup rule name v with
+	Ast.MetaAttributeDecl(_,_) -> ()
+      | _ -> fail name)
   | Ast.MetaAnalysisDecl(analyzer,(rule,name)) ->
       (match meta_lookup rule name v with
 	Ast.MetaAnalysisDecl(analyzer1,_) ->
diff --git a/parsing_cocci/parser_cocci_menhir.mly b/parsing_cocci/parser_cocci_menhir.mly
index af9726e10..056ed0048 100644
--- a/parsing_cocci/parser_cocci_menhir.mly
+++ b/parsing_cocci/parser_cocci_menhir.mly
@@ -254,6 +254,7 @@ let inline_id aft = function
 %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" }
-- 
2.21.3

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

  parent reply	other threads:[~2020-07-26 12:52 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-26 12:50 [Cocci] [PATCH 00/43] cocci: Add support for meta attributes to SmPL Jaskaran Singh
2020-07-26 12:50 ` [Cocci] [PATCH 01/43] parsing_cocci: ast0_cocci: Add MetaAttribute & MetaAttributeDecl Jaskaran Singh
2020-07-26 12:51 ` Jaskaran Singh [this message]
2020-07-26 12:51 ` [Cocci] [PATCH 03/43] parsing_cocci: parse_cocci: Reflect " Jaskaran Singh
2020-07-26 12:51 ` [Cocci] [PATCH 04/43] parsing_cocci: ast_cocci: Add " Jaskaran Singh
2020-07-26 12:51 ` [Cocci] [PATCH 05/43] parsing_cocci: iso_pattern: Reflect " Jaskaran Singh
2020-07-26 12:51 ` [Cocci] [PATCH 06/43] parsing_c: unparse_hrule: " Jaskaran Singh
2020-07-26 12:51 ` [Cocci] [PATCH 07/43] parsing_cocci: pretty_print_cocci: " Jaskaran Singh
2020-07-26 12:51 ` [Cocci] [PATCH 08/43] ocaml: coccilib: " Jaskaran Singh
2020-07-26 12:51 ` [Cocci] [PATCH 09/43] ocaml: yes_prepare_ocamlcocci: " Jaskaran Singh
2020-07-26 12:51 ` [Cocci] [PATCH 10/43] parsing_c: ast_c: Add MetaAttributeVal Jaskaran Singh
2020-07-26 12:51 ` [Cocci] [PATCH 11/43] parsing_c: unparse_hrule: Reflect MetaAttributeVal Jaskaran Singh
2020-07-26 12:51 ` [Cocci] [PATCH 12/43] engine: cocci_vs_c: " Jaskaran Singh
2020-07-26 12:51 ` [Cocci] [PATCH 13/43] engine: pattern_c: " Jaskaran Singh
2020-07-26 12:51 ` [Cocci] [PATCH 14/43] engine: pretty_print_engine: Add MetaAttributeVal Jaskaran Singh
2020-07-26 12:51 ` [Cocci] [PATCH 15/43] ocaml: coccilib: Reflect MetaAttributeVal Jaskaran Singh
2020-07-26 12:51 ` [Cocci] [PATCH 16/43] ocaml: ocamlcocci_aux: " Jaskaran Singh
2020-07-26 12:51 ` [Cocci] [PATCH 17/43] ocaml: run_ocamlcocci: " Jaskaran Singh
2020-07-26 12:51 ` [Cocci] [PATCH 18/43] python: pycocci_aux: " Jaskaran Singh
2020-07-26 12:51 ` [Cocci] [PATCH 19/43] parsing_cocci: visitor_ast0: Reflect MetaAttribute Jaskaran Singh
2020-07-26 12:51 ` [Cocci] [PATCH 20/43] parsing_cocci: check_meta: " Jaskaran Singh
2020-07-26 12:51 ` [Cocci] [PATCH 21/43] parsing_cocci: adjust_pragmas: " Jaskaran Singh
2020-07-26 12:51 ` [Cocci] [PATCH 22/43] parsing_cocci: context_neg: " Jaskaran Singh
2020-07-26 12:51 ` [Cocci] [PATCH 23/43] parsing_cocci: compute_lines: " Jaskaran Singh
2020-07-26 12:51 ` [Cocci] [PATCH 24/43] parsing_cocci: iso_pattern: " Jaskaran Singh
2020-07-26 12:51 ` [Cocci] [PATCH 25/43] parsing_cocci: function_prototypes: " Jaskaran Singh
2020-07-26 12:51 ` [Cocci] [PATCH 26/43] parsing_cocci: arity: " Jaskaran Singh
2020-07-26 12:51 ` [Cocci] [PATCH 27/43] parsing_cocci: unitary_ast0: " Jaskaran Singh
2020-07-26 12:51 ` [Cocci] [PATCH 28/43] parsing_cocci: unparse_ast0: " Jaskaran Singh
2020-07-26 12:51 ` [Cocci] [PATCH 29/43] parsing_cocci: ast0toast: " Jaskaran Singh
2020-07-26 12:51 ` [Cocci] [PATCH 30/43] parsing_cocci: visitor_ast: " Jaskaran Singh
2020-07-26 12:51 ` [Cocci] [PATCH 31/43] parsing_cocci: cleanup_rules: " Jaskaran Singh
2020-07-26 12:51 ` [Cocci] [PATCH 32/43] parsing_cocci: free_vars: " Jaskaran Singh
2020-07-26 12:51 ` [Cocci] [PATCH 33/43] parsing_cocci: get_constants: " Jaskaran Singh
2020-07-26 12:51 ` [Cocci] [PATCH 34/43] parsing_cocci: get_constants2: " Jaskaran Singh
2020-07-26 12:51 ` [Cocci] [PATCH 35/43] parsing_cocci: index: " Jaskaran Singh
2020-07-26 12:51 ` [Cocci] [PATCH 36/43] parsing_cocci: pretty_print_cocci: " Jaskaran Singh
2020-07-26 12:51 ` [Cocci] [PATCH 37/43] parsing_cocci: safe_for_multi_decls: " Jaskaran Singh
2020-07-26 12:51 ` [Cocci] [PATCH 38/43] parsing_cocci: unify_ast: " Jaskaran Singh
2020-07-26 12:51 ` [Cocci] [PATCH 39/43] parsing_c: unparse_cocci: " Jaskaran Singh
2020-07-26 12:51 ` [Cocci] [PATCH 40/43] engine: cocci_vs_c: " Jaskaran Singh
2020-07-26 12:51 ` [Cocci] [PATCH 41/43] tools: spgen: " Jaskaran Singh
2020-07-26 12:51 ` [Cocci] [PATCH 42/43] tests: Add test case to match meta attribute Jaskaran Singh
2020-07-26 12:51 ` [Cocci] [PATCH 43/43] tests: Add test case to remove a " Jaskaran Singh
2020-08-01 20:36 ` [Cocci] [PATCH 00/43] cocci: Add support for meta attributes to SmPL Julia Lawall
2020-08-02 12:16   ` Jaskaran Singh

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200726125141.17787-3-jaskaran.singh@collabora.com \
    --to=jaskaran.singh@collabora.com \
    --cc=cocci@systeme.lip6.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.