[Cocci] "TODO: FunCall" in python match printing
Carl-Daniel Hailfinger
c-d.hailfinger.devel.2006 at gmx.net
Fri Mar 6 10:39:01 CET 2009
On 06.03.2009 08:56, Julia Lawall wrote:
> Below is a patch for Coccinelle-0.1.5 that solves the Funcall problem. It
> also solves a problem with casts.
>
It seems your copy of 0.1.5 differs from my downloaded source copy of
0.1.5 (coccinelle-0.1.5.tgz).
The hunk affecting coccinelle-0.1.5/python/pycocci.ml does not apply
here and the code it refers to lives in
coccinelle-0.1.5/python/yes_pycocci.ml instead. I changed the patch
accordingly and installed current menhir, but now I get this error:
ocamlc -I ../commons -I ../commons/ocamlextra -I ../globals -I
../pycaml -I ../parsing_c -I ../parsing_cocci -c pycocci.ml
File "pycocci.ml", line 203, characters 45-51:
This expression has type
Ast_c.expression = (Ast_c.expressionbis * Ast_c.exp_info ref) * Ast_c.il
but is here used with type Ast_c.expressionbis
make[2]: *** [pycocci.cmo] Error 2
make[2]: Leaving directory `/sources/tmptrees/coccinelle-0.1.5/python'
make[1]: *** [python] Error 2
make[1]: Leaving directory `/sources/tmptrees/coccinelle-0.1.5'
make: *** [all] Error 2
If you have an updated patch, I'll test.
Regards,
Carl-Daniel
> A small problem is that this patch applies to the code for linking between
> python and ocaml, and this code is a little bit strange because symbolic
> links are used to allow for either the presence or absence of python. So
> I don't know whether this patch will apply correctly to an already
> installed version of Coccinelle. It might work better to just start over
> from the sources on the web site.
>
> diff -u -p -r coccinelle-0.1.5/parsing_cocci/parser_cocci_menhir.mly scratchcocci/parsing_cocci/parser_cocci_menhir.mly
> --- coccinelle-0.1.5/parsing_cocci/parser_cocci_menhir.mly 2009-02-04 22:58:03.000000000 +0100
> +++ scratchcocci/parsing_cocci/parser_cocci_menhir.mly 2009-03-06 08:47:20.000000000 +0100
> @@ -1290,7 +1290,7 @@ unary_expr(r,pe):
> { Ast0.wrap(Ast0.Infix ($2, P.clt2mcode Ast.Inc $1)) }
> | TDec unary_expr(r,pe)
> { Ast0.wrap(Ast0.Infix ($2, P.clt2mcode Ast.Dec $1)) }
> - | unary_op unary_expr(r,pe)
> + | unary_op cast_expr(r,pe)
> { let mcode = $1 in Ast0.wrap(Ast0.Unary($2, mcode)) }
> | TBang unary_expr(r,pe)
> { let mcode = P.clt2mcode Ast.Not $1 in
> diff -u -p -r coccinelle-0.1.5/python/pycocci_aux.ml scratchcocci/python/pycocci_aux.ml
> --- coccinelle-0.1.5/python/pycocci_aux.ml 2009-01-20 22:40:45.000000000 +0100
> +++ scratchcocci/python/pycocci_aux.ml 2009-03-06 08:18:50.000000000 +0100
> @@ -22,33 +22,8 @@
>
> open Ast_c
> open Common
> +open Pycaml
>
> -let rec exprrep expr = match expr with
> - Ast_c.Ident s -> s
> -| Ast_c.Constant c -> constantrep c
> -| Ast_c.FunCall (e,args) -> "TODO: FunCall"
> -| Ast_c.CondExpr (e1,e2,e3) -> "TODO: CondExpr"
> -| Ast_c.Sequence (e1,e2) -> "TODO: Sequence"
> -| Ast_c.Assignment (e1,op,e2) -> "TODO: Assignment"
> -| Ast_c.Postfix (e,op) -> "TODO: Postfix"
> -| Ast_c.Infix (e,op) -> "TODO: Infix"
> -| Ast_c.Unary (e,op) -> "TODO: Unary"
> -| Ast_c.Binary (e1,op,e2) -> "TODO: Binary"
> -| Ast_c.ArrayAccess (e1,e2) -> "TODO: ArrayAccess"
> -| Ast_c.RecordAccess (e1,s) -> "TODO: RecordAccess"
> -| Ast_c.RecordPtAccess (e,s) -> "TODO: RecordPtAccess"
> -| Ast_c.SizeOfExpr e -> "TODO: SizeOfExpr"
> -| Ast_c.SizeOfType t -> "TODO: SizeOfType"
> -| Ast_c.Cast (t,e) -> "TODO: Cast"
> -| Ast_c.StatementExpr c -> "TODO: StatementExpr"
> -| Ast_c.Constructor (t,i) -> "TODO: Constructor"
> -| Ast_c.ParenExpr e -> "TODO: ParenExpr"
> -and constantrep c = match c with
> - Ast_c.String (s,isWchar) -> s
> -| Ast_c.MultiString -> "TODO: MultiString"
> -| Ast_c.Char (s,isWchar) -> s
> -| Ast_c.Int s -> s
> -| Ast_c.Float (s,t) -> s
>
> let call_pretty f a =
> let str = ref ([] : string list) in
> @@ -57,20 +32,25 @@ let call_pretty f a =
> f pr_elem pr_sp a;
> String.concat " " (List.rev !str)
>
> +let exprrep = call_pretty Pretty_print_c.pp_expression_gen
> +
> let stringrep mvb = match mvb with
> Ast_c.MetaIdVal s -> s
> | Ast_c.MetaFuncVal s -> s
> | Ast_c.MetaLocalFuncVal s -> s
> -| Ast_c.MetaExprVal ((expr,_),[il]) -> (exprrep expr)
> +| Ast_c.MetaExprVal expr -> exprrep expr
> | Ast_c.MetaExprVal e -> "TODO: <<MetaExprVal>>"
> | Ast_c.MetaExprListVal expr_list -> "TODO: <<exprlist>>"
> | Ast_c.MetaTypeVal typ -> call_pretty Pretty_print_c.pp_type_gen typ
> +| Ast_c.MetaInitVal ini -> "TODO: <<initiliser>>"
> | Ast_c.MetaStmtVal statement -> "TODO: stmt"
> | Ast_c.MetaParamVal params -> "TODO: <<param>>"
> | Ast_c.MetaParamListVal params -> "TODO: <<paramlist>>"
> | Ast_c.MetaListlenVal n -> string_of_int n
> -| Ast_c.MetaPosVal (pos1, pos2) ->
> - (* Common.sprintf ("pos(%d,%d)") pos1 pos2 *)
> - "TODO: <<posval>>"
> +| Ast_c.MetaPosVal (pos1, pos2) ->
> + let print_pos = function
> + Ast_cocci.Real x -> string_of_int x
> + | Ast_cocci.Virt(x,off) -> Printf.sprintf "%d+%d" x off in
> + Common.sprintf ("pos(%s,%s)") (print_pos pos1) (print_pos pos2)
> | Ast_c.MetaPosValList positions -> "TODO: <<postvallist>>"
>
> diff -u -p -r coccinelle-0.1.5/python/pycocci.ml scratchcocci/python/pycocci.ml
> --- coccinelle-0.1.5/python/pycocci.ml 2009-01-20 22:40:45.000000000 +0100
> +++ scratchcocci/python/pycocci.ml 2009-03-06 08:19:18.000000000 +0100
> @@ -199,7 +199,7 @@ let construct_variables mv e =
> List.iter (function (py,(r,m)) ->
> match find_binding (r,m) with
> None -> ()
> - | Some (_, Ast_c.MetaExprVal ((expr, _), info_list)) ->
> + | Some (_, Ast_c.MetaExprVal expr) ->
> let expr_repr = instantiate_Expression(expr) in
> let _ = build_variable py expr_repr in
> ()
>
>
More information about the Cocci
mailing list