From: Jaskaran Singh <jaskaransingh7654321@gmail.com>
To: cocci@systeme.lip6.fr
Cc: linux-kernel-mentees@lists.linuxfoundation.org
Subject: [Cocci] [PATCH 10/13] engine: cocci_vs_c: Match enumerators properly as per enum_decl
Date: Sun, 8 Mar 2020 14:13:53 +0530 [thread overview]
Message-ID: <20200308084356.14506-11-jaskaransingh7654321@gmail.com> (raw)
In-Reply-To: <20200308084356.14506-1-jaskaransingh7654321@gmail.com>
The SmPL AST has a separate enum_decl type for an enumerator.
Make corresponding changes in Cocci_vs_c to correctly match
enumerators.
Signed-off-by: Jaskaran Singh <jaskaransingh7654321@gmail.com>
---
engine/cocci_vs_c.ml | 44 ++++++++++++++++++--------------------------
1 file changed, 18 insertions(+), 26 deletions(-)
diff --git a/engine/cocci_vs_c.ml b/engine/cocci_vs_c.ml
index 5d123164..1a9b3671 100644
--- a/engine/cocci_vs_c.ml
+++ b/engine/cocci_vs_c.ml
@@ -3304,14 +3304,14 @@ and (struct_field: (A.annotated_field, B.field) matcher) =
and enum_fields = fun eas ebs ->
let match_dots ea =
match A.unwrap ea with
- A.Edots(mcode, optexpr) -> Some (mcode, optexpr)
+ A.EnumDots(mcode, optexpr) -> Some (mcode, optexpr)
| _ -> None in
- let build_dots (mcode, optexpr) = A.Edots(mcode, optexpr) in
+ let build_dots (mcode, optexpr) = A.EnumDots(mcode, optexpr) in
let match_comma ea =
match A.unwrap ea with
- A.EComma ia1 -> Some ia1
+ A.EnumComma ia1 -> Some ia1
| _ -> None in
- let build_comma ia1 = A.EComma ia1 in
+ let build_comma ia1 = A.EnumComma ia1 in
let match_metalist ea = None in
let build_metalist _ (ida,leninfo,cstr,keep,inherited) =
failwith "enum: build meta list: not possible" in
@@ -3326,29 +3326,21 @@ and enum_fields = fun eas ebs ->
and enum_field ida idb =
X.all_bound (A.get_inherited ida) >&&>
match A.unwrap ida, idb with
- A.Ident(id),(nameidb,None) ->
- ident_cpp DontKnow id nameidb >>= (fun id nameidb ->
- return ((A.Ident id) +> A.rewrap ida, (nameidb,None)))
- | A.Ident(id),(nameidb,Some _) -> fail (* should we have an iso? *)
- | A.Assignment(ea1,opa,ea2,init),(nameidb,Some(opbi,eb2)) ->
- (match A.unwrap ea1 with
- A.Ident(id) ->
- let assignOp opa0 opbi =
- match A.unwrap opa0 with
- A.SimpleAssign oa ->
- tokenf oa opbi >>= fun oa opbi ->
- return
- (A.rewrap opa (A.SimpleAssign oa), opbi)
- | _ -> failwith "only simple assignment possible here" in
- ident_cpp DontKnow id nameidb >>= (fun id nameidb ->
- expression ea2 eb2 >>= (fun ea2 eb2 ->
- assignOp opa opbi >>= (fun opa opbi ->(* only one kind of assignop *)
+ A.Enum(nameida,enum_vala),(nameidb,enum_valb) ->
+ (match enum_vala,enum_valb with
+ (None, Some _)
+ | (Some _, None) -> fail
+ | (None, None) ->
+ ident_cpp DontKnow nameida nameidb >>=
+ (fun nameida nameidb ->
+ return (A.Enum(nameida,None) +> A.rewrap ida, (nameidb,None)))
+ | (Some (eqa,evala), Some(eqb,evalb)) ->
+ ident_cpp DontKnow nameida nameidb >>= (fun nameida nameidb ->
+ tokenf eqa eqb >>= (fun eqa eqb ->
+ expression evala evalb >>= (fun ea eb ->
return (
- (A.Assignment((A.Ident(id)) +> A.rewrap ea1,opa,ea2,init)) +>
- A.rewrap ida,
- (nameidb,Some(opbi,eb2))))))
- | _ -> failwith "enum: assignment: not possible")
- | A.Assignment(ea1,opa,ea2,init),(nameidb,None) -> fail
+ (A.Enum(nameida,Some(eqa,ea)) +> A.rewrap ida),
+ (nameidb,Some(eqb,eb)))))))
| _ -> failwith ("not possible: "^(Dumper.dump (A.unwrap ida)))
(* ------------------------------------------------------------------------- *)
--
2.21.1
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci
next prev parent reply other threads:[~2020-03-08 8:45 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-08 8:43 [Cocci] [PATCH 00/13] cocci: Align the C AST and SmPL AST for enum Jaskaran Singh
2020-03-08 8:43 ` [Cocci] [PATCH 01/13] parsing_cocci: Align " Jaskaran Singh
2020-03-08 8:43 ` [Cocci] [PATCH 02/13] ocaml: coccilib: Reflect changes in SmPL AST for EnumDef Jaskaran Singh
2020-03-08 8:43 ` [Cocci] [PATCH 03/13] parsing_cocci: parser: Parse enumerators correctly Jaskaran Singh
2020-03-08 8:43 ` [Cocci] [PATCH 04/13] parsing_cocci: Add EnumDeclTag and EnumDeclDotsTag to SmPL ASTs Jaskaran Singh
2020-03-08 8:43 ` [Cocci] [PATCH 05/13] ocaml: coccilib: Reflect EnumDeclTag and EnumDeclDotsTag Jaskaran Singh
2020-03-08 8:43 ` [Cocci] [PATCH 06/13] parsing_cocci: visitor_ast0: Add visitor functions for enum_decl Jaskaran Singh
2020-03-08 8:43 ` [Cocci] [PATCH 07/13] parsing_cocci: Reflect visitor_ast0 changes in parsing_cocci Jaskaran Singh
2020-03-08 8:43 ` [Cocci] [PATCH 08/13] parsing_cocci: Add visitor functions for enum_decl in visitor_ast Jaskaran Singh
2020-03-08 8:43 ` [Cocci] [PATCH 09/13] cocci: Reflect changes in SmPL visitor_ast in codebase Jaskaran Singh
2020-03-08 8:43 ` Jaskaran Singh [this message]
2020-03-08 8:43 ` [Cocci] [PATCH 11/13] cocci: pretty print EnumDef as per enum_decl type Jaskaran Singh
2020-03-08 8:43 ` [Cocci] [PATCH 12/13] tests: Add test case for assigned enumerator Jaskaran Singh
2020-03-08 8:43 ` [Cocci] [PATCH 13/13] tools: spgen: Reflect visitor changes Jaskaran Singh
2020-03-09 14:15 ` [Cocci] [PATCH 00/13] cocci: Align the C AST and SmPL AST for enum Julia Lawall
2020-03-09 14:51 ` 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=20200308084356.14506-11-jaskaransingh7654321@gmail.com \
--to=jaskaransingh7654321@gmail.com \
--cc=cocci@systeme.lip6.fr \
--cc=linux-kernel-mentees@lists.linuxfoundation.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).