X-Git-Url: https://git.hcoop.net/bpt/coccinelle.git/blobdiff_plain/c491d8eea333ab3273dc415c7d7af192e1d0b682..17ba07880e1838028b4516ba7a2db2147b3aa1c9:/python/yes_pycocci.ml diff --git a/python/yes_pycocci.ml b/python/yes_pycocci.ml index 80b996b..c1792b6 100644 --- a/python/yes_pycocci.ml +++ b/python/yes_pycocci.ml @@ -1,5 +1,7 @@ (* - * Copyright 2010, INRIA, University of Copenhagen + * Copyright 2012, INRIA + * Julia Lawall, Gilles Muller + * Copyright 2010-2011, INRIA, University of Copenhagen * Julia Lawall, Rene Rydhof Hansen, Gilles Muller, Nicolas Palix * Copyright 2005-2009, Ecole des Mines de Nantes, University of Copenhagen * Yoann Padioleau, Julia Lawall, Rene Rydhof Hansen, Henrik Stuart, Gilles Muller, Nicolas Palix @@ -115,6 +117,7 @@ let pycocci_instantiate_class fqn args = (* end python interaction *) let inc_match = ref true +let exited = ref false let include_match v = let truth = pyobject_istrue (pytuple_getitem (v, 1)) in @@ -122,6 +125,10 @@ let include_match v = inc_match := truth != 0; _pycocci_none () +let sp_exit _ = + exited := true; + _pycocci_none () + let build_method (mname, camlfunc, args) pymodule classx classdict = let cmx = pymethod_new(pywrap_closure camlfunc, args, classx) in let v = pydict_setitemstring(classdict, mname, cmx) in @@ -186,7 +193,8 @@ let pycocci_init () = coccinelle_module := pymodule_new "coccinelle"; let mx = !coccinelle_module in let (cd, cx) = build_class "Cocci" (!Flag.pyoutput) - [("include_match", include_match, (pynull())); + [("exit", sp_exit, (pynull())); + ("include_match", include_match, (pynull())); ("has_env_binding", has_environment_binding, (pynull()))] mx in pyoutputinstance := cx; pyoutputdict := cd; @@ -206,12 +214,13 @@ let added_variables = ref [] let build_classes env = let _ = pycocci_init () in inc_match := true; + exited := false; the_environment := env; let mx = !coccinelle_module in let dict = pymodule_getdict mx in List.iter (function - "include_match" | "has_env_binding" -> () + "include_match" | "has_env_binding" | "exit" -> () | name -> let v = pydict_delitemstring(dict,name) in check_int_return_value v) @@ -244,29 +253,52 @@ let construct_variables mv e = with Not_found -> None in +(* Only string in this representation, so no point let instantiate_Expression(x) = let str = pystring_fromstring (Pycocci_aux.exprrep x) in pycocci_instantiate_class "coccilib.elems.Expression" (pytuple_fromsingle (str)) in +*) +(* Only string in this representation, so no point let instantiate_Identifier(x) = let str = pystring_fromstring x in pycocci_instantiate_class "coccilib.elems.Identifier" (pytuple_fromsingle (str)) in +*) + + let instantiate_term_list py printer lst = + let (str,elements) = printer lst in + let str = pystring_fromstring str in + let elements = + pytuple_fromarray + (Array.of_list (List.map pystring_fromstring elements)) in + let repr = + pycocci_instantiate_class "coccilib.elems.TermList" + (pytuple_fromarray (Array.of_list [str;elements])) in + let _ = build_variable py repr in () in List.iter (function (py,(r,m),_) -> match find_binding (r,m) with None -> () - | Some (_, Ast_c.MetaExprVal (expr,_)) -> +(* | Some (_, Ast_c.MetaExprVal (expr,_)) -> let expr_repr = instantiate_Expression(expr) in let _ = build_variable py expr_repr in - () - | Some (_, Ast_c.MetaIdVal (id,_)) -> + () *) + (* | Some (_, Ast_c.MetaIdVal (id,_)) -> let id_repr = instantiate_Identifier(id) in let _ = build_variable py id_repr in - () + () *) + | Some (_, Ast_c.MetaExprListVal (exprlist)) -> + instantiate_term_list py Pycocci_aux.exprlistrep exprlist + | Some (_, Ast_c.MetaParamListVal (paramlist)) -> + instantiate_term_list py Pycocci_aux.paramlistrep paramlist + | Some (_, Ast_c.MetaInitListVal (initlist)) -> + instantiate_term_list py Pycocci_aux.initlistrep initlist + | Some (_, Ast_c.MetaFieldListVal (fieldlist)) -> + instantiate_term_list py Pycocci_aux.fieldlistrep fieldlist | Some (_, Ast_c.MetaPosValList l) -> let locs = List.map @@ -293,11 +325,10 @@ let construct_variables mv e = let construct_script_variables mv = List.iter (function (_,py) -> - let vl = - let str = pystring_fromstring "initial value" in - pycocci_instantiate_class "coccilib.elems.Identifier" - (pytuple_fromsingle (str)) in - let _ = build_variable py vl in + let str = + pystring_fromstring + "initial value: consider using coccinelle.varname" in + let _ = build_variable py str in ()) mv