Re: [Cocci] [PATCH 20/32] parsing_c: ast_c: Add Cast attributes
On Tue, 28 Apr 2020, Jaskaran Singh wrote: > Add cast attributes to the C AST. This is a list of attributes in the > Cast type of the C AST. > > Signed-off-by: Jaskaran Singh > --- > parsing_c/ast_c.ml | 2 +- > parsing_c/ast_c.mli | 2 +- > 2 files changed, 2 insertions(+), 2 deletions(-) > > diff --git a/parsing_c/ast_c.ml b/parsing_c/ast_c.ml > index f25f9b55..6a828943 100644 > --- a/parsing_c/ast_c.ml > +++ b/parsing_c/ast_c.ml > @@ -343,7 +343,7 @@ and expression = (expressionbis * exp_info ref (* > semantic: *)) wrap3 > >| SizeOfExpr of expression >| SizeOfType of fullType > - | Cast of fullType * expression > + | Cast of fullType * expression * attribute list > >(* gccext: *) >| StatementExpr of compound wrap (* ( ) new scope *) > diff --git a/parsing_c/ast_c.mli b/parsing_c/ast_c.mli > index 8923a335..8a9a6f66 100644 > --- a/parsing_c/ast_c.mli > +++ b/parsing_c/ast_c.mli > @@ -104,7 +104,7 @@ and expressionbis = >| RecordPtAccess of expression * name >| SizeOfExpr of expression >| SizeOfType of fullType > - | Cast of fullType * expression > + | Cast of fullType * expression * attribute list Maybe it would make more sense to put the attribute list after the fullType, as is done for the SmPL AST? julia >| StatementExpr of compound wrap >| Constructor of fullType * initialiser >| ParenExpr of expression > -- > 2.21.1 > > ___ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
Re: [Cocci] [PATCH 22/32] parsing_c: pretty_print_c: Reflect Cast attributes
On Tue, 28 Apr 2020, Jaskaran Singh wrote: > Cast attributes are added to the SmPL AST. Print these attributes in > pretty_print_c.ml. > > Signed-off-by: Jaskaran Singh > --- > parsing_c/pretty_print_c.ml | 7 --- > 1 file changed, 4 insertions(+), 3 deletions(-) > > diff --git a/parsing_c/pretty_print_c.ml b/parsing_c/pretty_print_c.ml > index 99a7e0ed..96a11d72 100644 > --- a/parsing_c/pretty_print_c.ml > +++ b/parsing_c/pretty_print_c.ml > @@ -146,8 +146,9 @@ let mk_pretty_printers > pp_expression e > | SizeOfType (t), [i1;i2;i3] -> > pr_elem i1; pr_elem i2; pp_type t; pr_elem i3 > -| Cast(t, e), [i1;i2] -> > -pr_elem i1; pp_type t; pr_elem i2; pp_expression e > +| Cast(t, e, a), [i1;i2] -> Less space in front of the [ julia > +pr_elem i1; pp_type t; pr_elem i2; pp_expression e; > +a +> pp_attributes pr_elem pr_space > > | StatementExpr (statxs, [ii1;ii2]), [i1;i2] -> > pr_elem i1; > @@ -184,7 +185,7 @@ let mk_pretty_printers > | CondExpr (_,_,_) | Sequence (_,_) | Assignment (_,_,_) > | Postfix (_,_) | Infix (_,_) | Unary (_,_) | Binary (_,_,_) > | ArrayAccess (_,_) | RecordAccess (_,_) | RecordPtAccess (_,_) > -| SizeOfExpr (_) | SizeOfType (_) | Cast (_,_) > +| SizeOfExpr (_) | SizeOfType (_) | Cast (_,_,_) > | StatementExpr (_) | Constructor _ > | ParenExpr (_) | New (_) | Delete (_,_) > | Defined (_)),_ -> raise (Impossible 95) > -- > 2.21.1 > > ___ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
Re: [Cocci] [PATCH 15/32] parsing_cocci: visitor_ast: Visit cast attributes
On Tue, 28 Apr 2020, Jaskaran Singh wrote: > Cast attributes are added to AST0 of SmPL. Visit these attributes in the AST0 -> AST julia > SmPL AST visitor. > > Signed-off-by: Jaskaran Singh > --- > parsing_cocci/visitor_ast.ml | 10 ++ > 1 file changed, 6 insertions(+), 4 deletions(-) > > diff --git a/parsing_cocci/visitor_ast.ml b/parsing_cocci/visitor_ast.ml > index 8e530114..644bcd5d 100644 > --- a/parsing_cocci/visitor_ast.ml > +++ b/parsing_cocci/visitor_ast.ml > @@ -198,12 +198,13 @@ let combiner bind option_default > let lar = string_mcode ar in > let lfield = ident field in > multibind [lexp; lar; lfield] > - | Ast.Cast(lp,ty,rp,exp) -> > + | Ast.Cast(lp,ty,attr,rp,exp) -> > let llp = string_mcode lp in > let lty = fullType ty in > + let lattr = multibind (List.map string_mcode attr) in > let lrp = string_mcode rp in > let lexp = expression exp in > - multibind [llp; lty; lrp; lexp] > + multibind [llp; lty; lattr; lrp; lexp] >| Ast.SizeOfExpr(szf,exp) -> > let lszf = string_mcode szf in > let lexp = expression exp in > @@ -1184,12 +1185,13 @@ let rebuilder > let lar = string_mcode ar in > let lfield = ident field in > Ast.RecordPtAccess(lexp, lar, lfield) > - | Ast.Cast(lp,ty,rp,exp) -> > + | Ast.Cast(lp,ty,attr,rp,exp) -> > let llp = string_mcode lp in > let lty = fullType ty in > + let lattr = List.map string_mcode attr in > let lrp = string_mcode rp in > let lexp = expression exp in > - Ast.Cast(llp, lty, lrp, lexp) > + Ast.Cast(llp, lty, lattr, lrp, lexp) > | Ast.SizeOfExpr(szf,exp) -> > let lszf = string_mcode szf in > let lexp = expression exp in > -- > 2.21.1 > > ___ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
Re: [Cocci] [PATCH 09/32] parsing_cocci: arity: Reflect Cast attributes
On Tue, 28 Apr 2020, Jaskaran Singh wrote: > Cast attributes are added to the SmPL AST. Reflect these changes in > arity.ml. > > Signed-off-by: Jaskaran Singh > --- > parsing_cocci/arity.ml | 5 +++-- > 1 file changed, 3 insertions(+), 2 deletions(-) > > diff --git a/parsing_cocci/arity.ml b/parsing_cocci/arity.ml > index 8ee6d33f..880cd7a3 100644 > --- a/parsing_cocci/arity.ml > +++ b/parsing_cocci/arity.ml > @@ -254,13 +254,14 @@ let rec top_expression opt_allowed tgt expr = >let ar = mcode ar in >let field = ident false arity field in >make_exp expr tgt arity (Ast0.RecordPtAccess(exp,ar,field)) > - | Ast0.Cast(lp,ty,rp,exp) -> > + | Ast0.Cast(lp,ty,attr,rp,exp) -> >let arity = exp_same (mcode2line lp) [mcode2arity lp;mcode2arity rp] in >let lp = mcode lp in >let ty = typeC arity ty in > + let attr = List.map mcode attr in Since attrs are mcodes, they should be reflected in the list that is given to exp_same. julia >let rp = mcode rp in >let exp = expression arity exp in > - make_exp expr tgt arity (Ast0.Cast(lp,ty,rp,exp)) > + make_exp expr tgt arity (Ast0.Cast(lp,ty,attr,rp,exp)) >| Ast0.SizeOfExpr(szf,exp) -> >let arity = exp_same (mcode2line szf) [mcode2arity szf] in >let szf = mcode szf in > -- > 2.21.1 > > ___ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
Re: [Cocci] [PATCH 03/32] parsing_cocci: parser: Parse cast attributes
On Tue, 28 Apr 2020, Jaskaran Singh wrote: > Cast attributes are added to the SmPL ASTs. Parse these attributes in > the SmPL parser and place them in the SmPL AST. The added production > only supports attributes after the type and before the expression. It would be good to say that on matching the attributes will be searched for anywhere, if that is the case. julia > > Signed-off-by: Jaskaran Singh > --- > parsing_cocci/parser_cocci_menhir.mly | 9 + > 1 file changed, 5 insertions(+), 4 deletions(-) > > diff --git a/parsing_cocci/parser_cocci_menhir.mly > b/parsing_cocci/parser_cocci_menhir.mly > index db5661bd..38b0e039 100644 > --- a/parsing_cocci/parser_cocci_menhir.mly > +++ b/parsing_cocci/parser_cocci_menhir.mly > @@ -2176,11 +2176,12 @@ arith_expr_bis: > > cast_expr(r,pe): > unary_expr(r,pe) { $1 } > - | lp=TOPar t=ctype rp=TCPar e=cast_expr(r,pe) > - { Ast0.wrap(Ast0.Cast (P.clt2mcode "(" lp, t, > + | lp=TOPar t=ctype ar=attr_list rp=TCPar e=cast_expr(r,pe) > + { Ast0.wrap(Ast0.Cast (P.clt2mcode "(" lp, t, ar, > P.clt2mcode ")" rp, e)) } > - | lp=TOPar t=ctype d=direct_abstract_d rp=TCPar e=cast_expr(r,pe) > - { Ast0.wrap(Ast0.Cast (P.clt2mcode "(" lp, d t, > + | lp=TOPar t=ctype d=direct_abstract_d ar=attr_list rp=TCPar > +e=cast_expr(r,pe) > + { Ast0.wrap(Ast0.Cast (P.clt2mcode "(" lp, d t, ar, >P.clt2mcode ")" rp, e)) } > > unary_expr(r,pe): > -- > 2.21.1 > > ___ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
Re: [Cocci] [PATCH 01/32] parsing_c: parser: Pass attribute list from type_name
On Tue, 28 Apr 2020, Jaskaran Singh wrote: > To add Cast attributes to the C AST, pass attributes from the type_name > rule of the C parser. I'm not sure what you mean by "pass". Normally, one passes something to something else, but it's not clear what the something else is. > > Signed-off-by: Jaskaran Singh > --- > ocaml/coccilib.mli | 3 ++- > parsing_c/parse_c.ml | 4 +++- > parsing_c/parser_c.mly | 16 > 3 files changed, 13 insertions(+), 10 deletions(-) > > diff --git a/ocaml/coccilib.mli b/ocaml/coccilib.mli > index 0e807c9a..a305d616 100644 > --- a/ocaml/coccilib.mli > +++ b/ocaml/coccilib.mli > @@ -791,7 +791,8 @@ module Parser_c : >(Lexing.lexbuf -> token) -> Lexing.lexbuf -> Ast_c.statement > val expr : (Lexing.lexbuf -> token) -> Lexing.lexbuf -> Ast_c.expression > val type_name : > - (Lexing.lexbuf -> token) -> Lexing.lexbuf -> Ast_c.fullType > + (Lexing.lexbuf -> token) -> Lexing.lexbuf -> > + Ast_c.attribute list * Ast_c.fullType >end > module Lexer_c : >sig > diff --git a/parsing_c/parse_c.ml b/parsing_c/parse_c.ml > index 0d3a189a..5f8d5e2d 100644 > --- a/parsing_c/parse_c.ml > +++ b/parsing_c/parse_c.ml > @@ -370,7 +370,9 @@ let parse_gen ~cpp ~tos parsefunc s = >result > > (* Please DO NOT remove this code, even though most of it is not used *) > -let type_of_string = parse_gen ~cpp:false ~tos:true Parser_c.type_name > +let type_of_string s = > + let typname = parse_gen ~cpp:false ~tos:true Parser_c.type_name s in > + Common.snd typname > let statement_of_string = parse_gen ~cpp:false ~tos:false Parser_c.statement > let expression_of_string = parse_gen ~cpp:false ~tos:false Parser_c.expr > let cpp_expression_of_string = parse_gen ~cpp:true ~tos:false Parser_c.expr > diff --git a/parsing_c/parser_c.mly b/parsing_c/parser_c.mly > index aedde179..0abcc9b0 100644 > --- a/parsing_c/parser_c.mly > +++ b/parsing_c/parser_c.mly > @@ -665,7 +665,7 @@ let postfakeInfo pii = > > %type statement > %type expr > -%type type_name > +%type type_name > > %% > > /*(*)*/ > @@ -818,7 +818,7 @@ arith_expr: > > cast_expr: > | unary_expr{ $1 } > - | topar2 type_name tcpar2 cast_expr { mk_e(Cast ($2, $4)) [$1;$3] } > + | topar2 type_name tcpar2 cast_expr { mk_e(Cast (snd $2, $4)) [$1;$3] } > /* > It could be useful to have the following, but there is no place for the > attribute in the AST. > @@ -831,7 +831,7 @@ unary_expr: > | TDec unary_expr { mk_e(Infix ($2, Dec))[$1] } > | unary_op cast_expr { mk_e(Unary ($2, fst $1)) [snd $1] } > | Tsizeof unary_expr { mk_e(SizeOfExpr ($2))[$1] } > - | Tsizeof topar2 type_name tcpar2 { mk_e(SizeOfType ($3))[$1;$2;$4] } > + | Tsizeof topar2 type_name tcpar2 { mk_e(SizeOfType (snd $3))[$1;$2;$4] > } There could be less white space in front of the [ julia > | Tnew new_argument { mk_e(New (None, $2)) [$1] } > | Tnew TOPar argument_list_ne TCPar new_argument { mk_e(New (Some $3, $5)) >[$1; $2; $4] } > | Tdelete cast_expr { mk_e(Delete(false, $2)) [$1] } > @@ -897,9 +897,9 @@ postfix_expr: > > /*(* gccext: also called compound literals *)*/ > | topar2 type_name tcpar2 TOBrace TCBrace > - { mk_e(Constructor ($2, (InitList [], [$4;$5]))) [$1;$3] } > + { mk_e(Constructor (snd $2, (InitList [], [$4;$5]))) [$1;$3] } > | topar2 type_name tcpar2 TOBrace initialize_list gcc_comma_opt_struct > TCBrace > - { mk_e(Constructor ($2, (InitList (List.rev $5),[$4;$7] @ $6))) [$1;$3] > } > + { mk_e(Constructor (snd $2, (InitList (List.rev $5),[$4;$7] @ $6))) > [$1;$3] } > > > primary_expr: > @@ -1298,7 +1298,7 @@ type_spec2: > Right3 (TypeName (name, Ast_c.noTypedefDef())),[] } > > | Ttypeof TOPar assign_expr TCPar { Right3 (TypeOfExpr ($3)), [$1;$2;$4] } > - | Ttypeof TOPar type_name TCPar { Right3 (TypeOfType ($3)), [$1;$2;$4] } > + | Ttypeof TOPar type_name TCPar { Right3 (TypeOfType (snd $3)), > [$1;$2;$4] } > > /*(**)*/ > /*(* workarounds *)*/ > @@ -1531,12 +1531,12 @@ type_qualif_list: > type_name: > | spec_qualif_list > { let (attrs, ds) = $1 in > - let (returnType, _) = fixDeclSpecForDecl ds in returnType } > + let (returnType, _) = fixDeclSpecForDecl ds in (attrs, returnType) } > | spec_qualif_list abstract_declaratort > { let (attrs1, ds) = $1 in > let (attrs2, fn) = $2 in > let (returnType, _) = fixDeclSpecForDecl ds in > - fn returnType } > + (attrs1@attrs2, fn returnType) } > > > > -- > 2.21.1 > > ___ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
Re: [Cocci] Checking the application of the SmPL isomorphism “drop_else”
> I hoped for another clarification also for the message “warning: iso drop_else > does not match the code below on line 55” (and the corresponding debug > display). I imagine that there is another bit of fine-tuning possible. >> There is an isomorphism that drops else's in ifs, but that only applies if >> the else is a metavariable that is not used elsewhere. > > I am looking for further improvements in this software area. https://github.com/coccinelle/coccinelle/blob/6b4bb692f208bfe86e62a616724570d9310c7150/standard.iso#L421 It seems that the code transformations “neg_if” and “ne_if” are applied before “drop_else”. Should the warning be avoided then if the else branch became non-empty because of the conversion? Regards, Markus ___ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci