From: Coccinelle Date: Mon, 6 Jun 2011 09:36:19 +0000 (+0200) Subject: Coccinelle release 1.0.0-rc3 X-Git-Url: http://git.hcoop.net/bpt/coccinelle.git/commitdiff_plain/65038c617fe3e5d7a284059fbfa78dddfbb9b9c4 Coccinelle release 1.0.0-rc3 ** Language: - Addition of initializer list metavariables. Thanks to Michael Stefaniuc for noticing the need for them. - Allow multiple position variables per token - ++ can now be associated with - code - Allow /* */ comments as smpl comments, not only as + code - Add support for && (label addresses) - local idexpression metavariable no longer matches static local x ** Features: - Preserve spacing before // comments when not at the beginning of a line - Adjusted parsing of endif to put it after jump code - Improve warning message when using -use_cache - More helpful initial value for exported variables in python - Support - on expression nests - Better handling of the case of a matched declaration that should only be replaced by other top level things. ** Bugfix: - Corrected parsing of script strings delimited by a single quote. Thanks to Eugeniy Meshcheryakov for reporting the problem. - Improved indentation of added ifdefs. - Allow added comments and #ifdefs to precede other added code. Thanks to Jani Monoses for noticing the problem. - Corrected failure to due missing ocamlfind. Thanks to Derek M. Jones for reporting the problem. - Allow fake nodes to be - in the allminus case, to drop tokens related to a function definition or forward declaration but before the first code mentioned in the semantic patch. - Drop __init etc when deleting a whole function. - Cause appropriate newlines to be preserved when multiple matches (trees) contain adjacent modifications derived from the same SmPL code. - check_meta takes into account fresh identifier seed information. - Types for worth-trying optimization should not be followed by space - Improved filtering of result of matching atomic patterns - Drop positions before creating function prototype rules - Adjust position of { introduced by adding multiple statements in a single-statement position - Drop newline after function call ( when all arguments on that line are eliminated - Accept removal of a single declaration, replaced by arbitrary, non-declaration code - smpl_spacing takes into account newlines, indentation --- diff --git a/Makefile b/Makefile index fa0db61..ad9a778 100644 --- a/Makefile +++ b/Makefile @@ -323,6 +323,7 @@ install-common: mkdir -p $(DESTDIR)$(SHAREDIR)/globals mkdir -p $(DESTDIR)$(SHAREDIR)/parsing_c mkdir -p $(DESTDIR)$(MANDIR)/man1 + mkdir -p $(DESTDIR)$(MANDIR)/man3 $(INSTALL_DATA) standard.h $(DESTDIR)$(SHAREDIR) $(INSTALL_DATA) standard.iso $(DESTDIR)$(SHAREDIR) $(INSTALL_DATA) ocaml/coccilib.cmi $(DESTDIR)$(SHAREDIR)/ocaml/ @@ -330,6 +331,7 @@ install-common: $(INSTALL_DATA) commons/*.cmi $(DESTDIR)$(SHAREDIR)/commons/ $(INSTALL_DATA) globals/iteration.cmi $(DESTDIR)$(SHAREDIR)/globals/ $(INSTALL_DATA) docs/spatch.1 $(DESTDIR)$(MANDIR)/man1/ + $(INSTALL_DATA) docs/Coccilib.3cocci $(DESTDIR)$(MANDIR)/man3/ @if [ $(FEATURE_PYTHON) -eq 1 ]; then $(MAKE) install-python; fi install-bash: @@ -409,6 +411,7 @@ uninstall: rmdir $(DESTDIR)$(SHAREDIR)/ocaml rmdir $(DESTDIR)$(SHAREDIR) rm -f $(DESTDIR)$(MANDIR)/man1/spatch.1 + rm -f $(DESTDIR)$(MANDIR)/man3/Coccilib.3cocci uninstall-bash: rm -f $(DESTDIR)$(BASH_COMPLETION_DIR)/spatch diff --git a/Makefile.release b/Makefile.release index eec6b57..576f0ce 100644 --- a/Makefile.release +++ b/Makefile.release @@ -6,7 +6,7 @@ PACKAGE=$(PRJNAME)-$(VERSION) CCPACKAGE=coccicheck-$(CCVERSION) -EXCLUDE=debian +EXCLUDE=$(PACKAGE)/debian .depend BINSRC=spatch env.sh env.csh standard.h standard.iso \ *.txt \ @@ -15,7 +15,7 @@ BINSRC=spatch env.sh env.csh standard.h standard.iso \ demos/* BINSRC-PY=$(BINSRC) $(PYLIB) python/coccilib/ -EXCL=$(EXCLUDE:%=--exclude=$(PACKAGE)/%) +EXCL=$(EXCLUDE:%=--exclude=%) BINSRC2=$(BINSRC:%=$(PACKAGE)/%) BINSRC2-PY=$(BINSRC-PY:%=$(PACKAGE)/%) diff --git a/changes.txt b/changes.txt index 84e71b5..6ed8ca9 100644 --- a/changes.txt +++ b/changes.txt @@ -28,9 +28,10 @@ - Preserve spacing before // comments when not at the beginning of a line - Adjusted parsing of endif to put it after jump code - Improve warning message when using -use_cache -- Allow - nest expressions - More helpful initial value for exported variables in python - Support - on expression nests +- Better handling of the case of a matched declaration that should only + be replaced by other top level things. ** Bugfix: - Corrected parsing of script strings delimited by a single quote. Thanks @@ -48,7 +49,15 @@ contain adjacent modifications derived from the same SmPL code. - check_meta takes into account fresh identifier seed information. - Types for worth-trying optimization should not be followed by space -- Improved pretty printing when the first parameter of a function is dropped +- Improved filtering of result of matching atomic patterns +- Drop positions before creating function prototype rules +- Adjust position of { introduced by adding multiple statements in a + single-statement position +- Drop newline after function call ( when all arguments on that line are + eliminated +- Accept removal of a single declaration, replaced by arbitrary, + non-declaration code +- smpl_spacing takes into account newlines, indentation * 0.2.5 ** Language: diff --git a/cocci.ml b/cocci.ml index ff638fb..ef8c893 100644 --- a/cocci.ml +++ b/cocci.ml @@ -335,6 +335,12 @@ let show_or_not_diff a b = let show_or_not_ctl_tex2 astcocci ctls = if !Flag_cocci.show_ctl_tex then begin + let ctls = + List.map + (List.map + (function ((Asttoctl2.NONDECL ctl | Asttoctl2.CODE ctl),x) -> + (ctl,x))) + ctls in Ctltotex.totex ("/tmp/__cocci_ctl.tex") astcocci ctls; Common.command2 ("cd /tmp; latex __cocci_ctl.tex; " ^ "dvips __cocci_ctl.dvi -o __cocci_ctl.ps;" ^ @@ -380,7 +386,7 @@ let show_or_not_ctl_text2 ctl ast rulenb = ); pr "CTL = "; - let (ctl,_) = ctl in + let ((Asttoctl2.CODE ctl | Asttoctl2.NONDECL ctl),_) = ctl in adjust_pp_with_indent (fun () -> Format.force_newline(); Pretty_print_engine.pp_ctlcocci @@ -843,7 +849,7 @@ type toplevel_cocci_info_script_rule = { } type toplevel_cocci_info_cocci_rule = { - ctl: Lib_engine.ctlcocci * (CCI.pred list list); + ctl: Asttoctl2.top_formula * (CCI.pred list list); metavars: Ast_cocci.metavar list; ast_rule: Ast_cocci.rule; isexp: bool; (* true if + code is an exp, only for Flag.make_hrule *) @@ -1607,47 +1613,57 @@ and process_a_generated_a_env_a_toplevel rule env ccs = (* does side effects on C ast and on Cocci info rule *) and process_a_ctl_a_env_a_toplevel2 r e c f = indent_do (fun () -> - show_or_not_celem "trying" c.ast_c; - Flag.currentfile := Some (f ^ ":" ^get_celem c.ast_c); - let (trans_info, returned_any_states, inherited_bindings, newbindings) = - Common.save_excursion Flag_ctl.loop_in_src_code (fun () -> - Flag_ctl.loop_in_src_code := !Flag_ctl.loop_in_src_code||c.contain_loop; + show_or_not_celem "trying" c.ast_c; + Flag.currentfile := Some (f ^ ":" ^get_celem c.ast_c); + match (r.ctl,c.ast_c) with + ((Asttoctl2.NONDECL ctl,t),Ast_c.Declaration _) -> None + | ((Asttoctl2.NONDECL ctl,t), _) + | ((Asttoctl2.CODE ctl,t), _) -> + let ctl = (ctl,t) in (* ctl and other info *) + let (trans_info, returned_any_states, inherited_bindings, newbindings) = + Common.save_excursion Flag_ctl.loop_in_src_code (fun () -> + Flag_ctl.loop_in_src_code := + !Flag_ctl.loop_in_src_code||c.contain_loop; (***************************************) (* !Main point! The call to the engine *) (***************************************) - let model_ctl = CCI.model_for_ctl r.dropped_isos (Common.some c.flow) e - in CCI.mysat model_ctl r.ctl (r.rule_info.used_after, e) - ) - in - if not returned_any_states - then None - else begin - show_or_not_celem "found match in" c.ast_c; - show_or_not_trans_info trans_info; - List.iter (show_or_not_binding "out") newbindings; - - r.rule_info.was_matched := true; - - if not (null trans_info) && - not (!Flag.sgrep_mode2 && not !Flag_cocci.show_diff) - then begin - c.was_modified := true; - try - (* les "more than one var in a decl" et "already tagged token" - * font crasher coccinelle. Si on a 5 fichiers, donc on a 5 - * failed. Le try limite le scope des crashes pendant la - * trasformation au fichier concerne. *) - - (* modify ast via side effect *) - ignore(Transformation_c.transform r.rule_info.rulename r.dropped_isos - inherited_bindings trans_info (Common.some c.flow)); - with Timeout -> raise Timeout | UnixExit i -> raise (UnixExit i) - end; - - Some (List.map (function x -> x@inherited_bindings) newbindings) - end - ) + let model_ctl = + CCI.model_for_ctl r.dropped_isos (Common.some c.flow) e + in CCI.mysat model_ctl ctl (r.rule_info.used_after, e)) + in + if not returned_any_states + then None + else + begin + show_or_not_celem "found match in" c.ast_c; + show_or_not_trans_info trans_info; + List.iter (show_or_not_binding "out") newbindings; + + r.rule_info.was_matched := true; + + if not (null trans_info) && + not (!Flag.sgrep_mode2 && not !Flag_cocci.show_diff) + then + begin + c.was_modified := true; + try + (* les "more than one var in a decl" et "already tagged token" + * font crasher coccinelle. Si on a 5 fichiers, donc on a 5 + * failed. Le try limite le scope des crashes pendant la + * trasformation au fichier concerne. *) + + (* modify ast via side effect *) + ignore + (Transformation_c.transform r.rule_info.rulename + r.dropped_isos + inherited_bindings trans_info (Common.some c.flow)); + with Timeout -> raise Timeout | UnixExit i -> raise (UnixExit i) + end; + + Some (List.map (function x -> x@inherited_bindings) newbindings) + end + ) and process_a_ctl_a_env_a_toplevel a b c f= Common.profile_code "process_a_ctl_a_env_a_toplevel" diff --git a/ctl/.depend b/ctl/.depend deleted file mode 100644 index 9e82586..0000000 --- a/ctl/.depend +++ /dev/null @@ -1,25 +0,0 @@ -ctl_engine.cmi: ../commons/ograph_extended.cmi ast_ctl.cmo -pretty_print_ctl.cmi: ast_ctl.cmo -wrapper_ctl.cmi: ctl_engine.cmi ast_ctl.cmo -ast_ctl.cmo: -ast_ctl.cmx: -ctl_engine.cmo: pretty_print_ctl.cmi ../commons/ograph_extended.cmi \ - flag_ctl.cmo ../globals/flag.cmo ../commons/common.cmi ast_ctl.cmo \ - ctl_engine.cmi -ctl_engine.cmx: pretty_print_ctl.cmx ../commons/ograph_extended.cmx \ - flag_ctl.cmx ../globals/flag.cmx ../commons/common.cmx ast_ctl.cmx \ - ctl_engine.cmi -flag_ctl.cmo: -flag_ctl.cmx: -pretty_print_ctl.cmo: flag_ctl.cmo ../commons/common.cmi ast_ctl.cmo \ - pretty_print_ctl.cmi -pretty_print_ctl.cmx: flag_ctl.cmx ../commons/common.cmx ast_ctl.cmx \ - pretty_print_ctl.cmi -test_ctl.cmo: wrapper_ctl.cmi ../commons/ograph_extended.cmi ctl_engine.cmi \ - ast_ctl.cmo -test_ctl.cmx: wrapper_ctl.cmx ../commons/ograph_extended.cmx ctl_engine.cmx \ - ast_ctl.cmx -wrapper_ctl.cmo: ../globals/flag.cmo ctl_engine.cmi ../commons/common.cmi \ - ast_ctl.cmo wrapper_ctl.cmi -wrapper_ctl.cmx: ../globals/flag.cmx ctl_engine.cmx ../commons/common.cmx \ - ast_ctl.cmx wrapper_ctl.cmi diff --git a/ctl/ctl_engine.ml b/ctl/ctl_engine.ml index 4577176..776dcc6 100644 --- a/ctl/ctl_engine.ml +++ b/ctl/ctl_engine.ml @@ -1525,19 +1525,20 @@ let satLabel label required p = (List.map (function (st,th,_) -> (st,th)) triples); triples else setify(label p) in - normalize - (if !pREQUIRED_ENV_OPT - then - foldl - (function rest -> - function ((s,th,_) as t) -> - if List.for_all - (List.exists (function th' -> not(conj_subst th th' = None))) - required - then t::rest - else rest) - [] triples - else triples) + (* normalize first; conj_subst relies on sorting *) + let ntriples = normalize triples in + if !pREQUIRED_ENV_OPT + then + foldl + (function rest -> + function ((s,th,_) as t) -> + if List.for_all + (List.exists (function th' -> not(conj_subst th th' = None))) + required + then t::rest + else rest) + [] ntriples + else ntriples let get_required_states l = if !pREQUIRED_STATES_OPT && not !Flag_ctl.partial_match diff --git a/docs/Coccilib.3cocci b/docs/Coccilib.3cocci index f7733a7..7e5956d 100644 --- a/docs/Coccilib.3cocci +++ b/docs/Coccilib.3cocci @@ -1,6 +1,6 @@ .\" -*- nroff -*- .\" Please adjust this date whenever revising the manpage. -.TH SPATCH 1 "may 18, 2011" +.TH COCCILIB 3COCCI "May 18, 2011" .\" see http://www.fnal.gov/docs/products/ups/ReferenceManual/html/manpages.html .\" see http://www.linuxjournal.com/article/1158 diff --git a/docs/manual/macros.tex b/docs/manual/macros.tex index d3f7fc8..887b09d 100644 --- a/docs/manual/macros.tex +++ b/docs/manual/macros.tex @@ -4,5 +4,5 @@ \newcommand{\cpp}{\texttt{cpp}\xspace} -\newcommand{\cocciversion}{0.2.5\xspace} +\newcommand{\cocciversion}{1.0.0-rc3\xspace} diff --git a/docs/manual/main_grammar.pdf b/docs/manual/main_grammar.pdf index cf6ef04..6561629 100644 Binary files a/docs/manual/main_grammar.pdf and b/docs/manual/main_grammar.pdf differ diff --git a/docs/manual/manual.pdf b/docs/manual/manual.pdf index 54edcb5..19cfa01 100644 Binary files a/docs/manual/manual.pdf and b/docs/manual/manual.pdf differ diff --git a/docs/manual/options.pdf b/docs/manual/options.pdf index 58df703..a8d4eb4 100644 Binary files a/docs/manual/options.pdf and b/docs/manual/options.pdf differ diff --git a/engine/asttoctl2.ml b/engine/asttoctl2.ml index 05bf39c..b5abb46 100644 --- a/engine/asttoctl2.ml +++ b/engine/asttoctl2.ml @@ -37,8 +37,8 @@ module CTL = Ast_ctl let warning s = Printf.fprintf stderr "warning: %s\n" s type cocci_predicate = Lib_engine.predicate * Ast.meta_name Ast_ctl.modif -type formula = - (cocci_predicate,Ast.meta_name, Wrapper_ctl.info) Ast_ctl.generic_ctl +type formula = Lib_engine.ctlcocci +type top_formula = NONDECL of Lib_engine.ctlcocci | CODE of Lib_engine.ctlcocci let union = Common.union_set let intersect l1 l2 = List.filter (function x -> List.mem x l2) l1 @@ -2473,13 +2473,15 @@ let top_level name ((ua,pos),fua) (fuas,t) = used_after := ua; saved := Ast.get_saved t; let quantified = Common.minus_set (Common.union_set ua fuas) pos in - quantify false quantified - (match Ast.unwrap t with + let (wrap,formula) = + match Ast.unwrap t with Ast.FILEINFO(old_file,new_file) -> failwith "not supported fileinfo" - | Ast.DECL(stmt) -> + | Ast.NONDECL(stmt) -> let unopt = elim_opt.V.rebuilder_statement stmt in let unopt = preprocess_dots_e unopt in - cleanup(statement unopt VeryEnd quantified [] None None None false) + let formula = + cleanup(statement unopt VeryEnd quantified [] None None None false) in + ((function x -> NONDECL x), formula) | Ast.CODE(stmt_dots) -> let unopt = elim_opt.V.rebuilder_statement_dots stmt_dots in let unopt = preprocess_dots unopt in @@ -2501,17 +2503,20 @@ let top_level name ((ua,pos),fua) (fuas,t) = let res = statement_list unopt VeryEnd quantified [] None None None false false in - cleanup - (if starts_with_dots - then + let formula = + cleanup + (if starts_with_dots + then (* EX because there is a loop on enter/top *) - ctl_and CTL.NONSTRICT (toppred None) (ctl_ex res) - else if starts_with_brace - then - ctl_and CTL.NONSTRICT - (ctl_not(CTL.EX(CTL.BACKWARD,(funpred None)))) res - else res) - | Ast.ERRORWORDS(exps) -> failwith "not supported errorwords") + ctl_and CTL.NONSTRICT (toppred None) (ctl_ex res) + else if starts_with_brace + then + ctl_and CTL.NONSTRICT + (ctl_not(CTL.EX(CTL.BACKWARD,(funpred None)))) res + else res) in + ((function x -> CODE x), formula) + | Ast.ERRORWORDS(exps) -> failwith "not supported errorwords" in + wrap (quantify false quantified formula) (* --------------------------------------------------------------------- *) (* Entry points *) @@ -2544,7 +2549,7 @@ let asttoctl r used_after positions = Ast.ScriptRule _ | Ast.InitialScriptRule _ | Ast.FinalScriptRule _ -> [] | Ast.CocciRule (a,b,c,_,Ast_cocci.Normal) -> asttoctlz (a,b,c) used_after positions - | Ast.CocciRule (a,b,c,_,Ast_cocci.Generated) -> [CTL.True] + | Ast.CocciRule (a,b,c,_,Ast_cocci.Generated) -> [CODE CTL.True] let pp_cocci_predicate (pred,modif) = Pretty_print_engine.pp_predicate pred diff --git a/engine/asttoctl2.mli b/engine/asttoctl2.mli index a6732d7..4a71f6a 100644 --- a/engine/asttoctl2.mli +++ b/engine/asttoctl2.mli @@ -23,8 +23,7 @@ type cocci_predicate = Lib_engine.predicate * Ast_cocci.meta_name Ast_ctl.modif -type formula = - (cocci_predicate,Ast_cocci.meta_name, Wrapper_ctl.info) Ast_ctl.generic_ctl +type top_formula = NONDECL of Lib_engine.ctlcocci | CODE of Lib_engine.ctlcocci val asttoctl : Ast_cocci.rule -> @@ -32,7 +31,7 @@ val asttoctl : Ast_cocci.meta_name list list (* fresh used after *) * Ast_cocci.meta_name list list (* fresh used after seeds *)) -> Ast_cocci.meta_name list list (* positions *) -> - formula list + top_formula list val pp_cocci_predicate : cocci_predicate -> unit diff --git a/engine/asttomember.ml b/engine/asttomember.ml index 1c4a90c..f65a100 100644 --- a/engine/asttomember.ml +++ b/engine/asttomember.ml @@ -270,7 +270,7 @@ and case_line testfn mcode tail case = let top_level testfn mcode t : 'a list list = match Ast.unwrap t with Ast.FILEINFO(old_file,new_file) -> failwith "not supported fileinfo" - | Ast.DECL(stmt) -> statement testfn mcode false stmt + | Ast.NONDECL(stmt) -> statement testfn mcode false stmt | Ast.CODE(stmt_dots) -> statement_list testfn mcode false stmt_dots | Ast.ERRORWORDS(exps) -> failwith "not supported errorwords" diff --git a/engine/cocci_vs_c.ml b/engine/cocci_vs_c.ml index aa3849e..a5e297c 100644 --- a/engine/cocci_vs_c.ml +++ b/engine/cocci_vs_c.ml @@ -738,6 +738,7 @@ but I don't know how to declare polymorphism across functors *) let dots2metavar (_,info,mcodekind,pos) = (("","..."),info,mcodekind,pos) let metavar2dots (_,info,mcodekind,pos) = ("...",info,mcodekind,pos) +let metavar2ndots (_,info,mcodekind,pos) = ("<+...",info,mcodekind,pos) let satisfies_regexpconstraint c id : bool = match c with @@ -1345,7 +1346,7 @@ let rec (expression: (A.expression, Ast_c.expression) matcher) = X.distrf_e (dots2metavar starter) eb >>= (fun mcode eb -> return ( (A.NestExpr - (metavar2dots mcode, + (metavar2ndots mcode, A.rewrap exps (A.DOTS [exp]),ender,None,true)) +> wa, eb ) diff --git a/engine/ctltotex.mli b/engine/ctltotex.mli index a403d62..a6de606 100644 --- a/engine/ctltotex.mli +++ b/engine/ctltotex.mli @@ -25,7 +25,5 @@ val totex : string -> Ast_cocci.rule list -> - ((Lib_engine.predicate * Ast_cocci.meta_name Ast_ctl.modif, - Ast_cocci.meta_name,Wrapper_ctl.info) - Ast_ctl.generic_ctl * 'a) list list -> - unit + (Lib_engine.ctlcocci * 'a) list list -> + unit diff --git a/globals/config.ml.in b/globals/config.ml.in index 26b2e40..c254ac2 100644 --- a/globals/config.ml.in +++ b/globals/config.ml.in @@ -1,4 +1,4 @@ -let version = "1.0.0-rc2" +let version = "1.0.0-rc3" let path = try (Sys.getenv "COCCINELLE_HOME") diff --git a/parsing_c/lexer_parser.ml b/parsing_c/lexer_parser.ml index cd19ee3..c32677d 100644 --- a/parsing_c/lexer_parser.ml +++ b/parsing_c/lexer_parser.ml @@ -57,7 +57,8 @@ type identkind = TypeDefI | IdentI let (_typedef : (string, identkind) Common.scoped_h_env ref) = ref (Common.empty_scoped_h_env ()) -let is_typedef s = if !_handle_typedef || !_always_look_typedef then +let is_typedef s = + if !_handle_typedef || !_always_look_typedef then (match (Common.optionise (fun () -> Common.lookup_h_env s !_typedef)) with | Some TypeDefI -> true | Some IdentI -> false diff --git a/parsing_c/unparse_c.ml b/parsing_c/unparse_c.ml index 2996d18..5b0670a 100644 --- a/parsing_c/unparse_c.ml +++ b/parsing_c/unparse_c.ml @@ -767,7 +767,7 @@ let adjust_after_paren toks = else x :: search_paren xs | x::xs -> x :: search_paren xs and search_minus seen_minus xs = - let (spaces, rest) = Common.span is_space xs in + let (spaces, rest) = Common.span is_whitespace xs in (* only delete spaces if something is actually deleted *) match rest with ((T2(_,Min _,_)) as a)::rerest -> (* minus *) @@ -779,6 +779,24 @@ let adjust_after_paren toks = | _ -> if seen_minus then rest else xs in (* drop trailing space *) search_paren toks +(* this is for the case where braces are added around an if branch *) +let paren_then_brace toks = + let rec search_paren = function + [] -> [] + | ((T2(_,Ctx,_)) as x)::xs -> + if List.mem (str_of_token2 x) [")"] + then x :: search_paren(search_plus xs) + else x :: search_paren xs + | x::xs -> x :: search_paren xs + and search_plus xs = + let (spaces, rest) = Common.span is_whitespace xs in + match rest with + (* move the brace up to the previous line *) + ((Cocci2("{",_,_,_,_)) as x) :: (((Cocci2 _) :: _) as rest) -> + (C2 " ") :: x :: spaces @ rest + | _ -> xs in + search_paren toks + let is_ident_like s = s ==~ Common.regexp_alpha let rec drop_space_at_endline = function @@ -830,6 +848,15 @@ let rec add_space xs = something should be done to add newlines too, rather than printing them explicitly in unparse_cocci. *) x::C2 (String.make (lcoly-rcolx) ' ')::add_space (y::xs) + | (Cocci2(sx,lnx,_,rcolx,_) as x)::((Cocci2(sy,lny,lcoly,_,_)) as y)::xs + when !Flag_parsing_c.spacing = Flag_parsing_c.SMPL && + not (lnx = -1) && lnx < lny && not (rcolx = -1) -> + (* this only works within a line. could consider whether + something should be done to add newlines too, rather than + printing them explicitly in unparse_cocci. *) + x::C2 (String.make (lny-lnx) '\n'):: + C2 (String.make (lcoly-1) ' '):: (* -1 is for the + *) + add_space (y::xs) | ((T2(_,Ctx,_)) as x)::((Cocci2 _) as y)::xs -> (* add space on boundary *) let sx = str_of_token2 x in let sy = str_of_token2 y in @@ -954,7 +981,7 @@ let new_tabbing a = let rec adjust_indentation xs = - let _current_tabbing = ref "" in + let _current_tabbing = ref ([] : string list) in let tabbing_unit = ref None in let string_of_list l = String.concat "" (List.map string_of_char l) in @@ -972,15 +999,18 @@ let rec adjust_indentation xs = | (o::os,n::ns) -> loop (os,ns) in (* could check for equality *) loop (old_tab,new_tab) in +(* let remtab tu current_tab = let current_tab = List.rev(list_of_string current_tab) in let rec loop = function ([],new_tab) -> string_of_list (List.rev new_tab) - | (_,[]) -> "" (*weird; tabbing unit used up more than the current tab*) + | (_,[]) -> (-*weird; tabbing unit used up more than the current tab*-) + "" | (t::ts,n::ns) when t =<= n -> loop (ts,ns) - | (_,ns) -> (* mismatch; remove what we can *) + | (_,ns) -> (-* mismatch; remove what we can *-) string_of_list (List.rev ns) in loop (tu,current_tab) in +*) let rec find_first_tab started = function [] -> () @@ -1018,27 +1048,36 @@ let rec adjust_indentation xs = | ((T2 (Parser_c.TCommentNewline s, _, _)) as x)::xs when balanced 0 (fst(Common.span (function x -> not(is_newline x)) xs)) -> let old_tabbing = !_current_tabbing in - str_of_token2 x +> new_tabbing +> (fun s -> _current_tabbing := s); + str_of_token2 x +> new_tabbing +> (fun s -> _current_tabbing := [s]); (* only trust the indentation after the first { *) (if started - then adjust_tabbing_unit old_tabbing !_current_tabbing); + then + adjust_tabbing_unit + (String.concat "" old_tabbing) + (String.concat "" !_current_tabbing)); let coccis_rest = Common.span all_coccis xs in (match coccis_rest with (_::_,((T2 (tok,_,_)) as y)::_) when str_of_token2 y =$= "}" -> (* the case where cocci code has been added before a close } *) x::aux started (Indent_cocci2::xs) | _ -> x::aux started xs) + | Indent_cocci2::((Cocci2(sy,lny,lcoly,_,_)) as y)::xs + when !Flag_parsing_c.spacing = Flag_parsing_c.SMPL -> + let tu = String.make (lcoly-1) ' ' in + _current_tabbing := tu::(!_current_tabbing); + C2 (tu)::aux started (y::xs) | Indent_cocci2::xs -> (match !tabbing_unit with None -> aux started xs | Some (tu,_) -> - _current_tabbing := (!_current_tabbing)^tu; - Cocci2 (tu,-1,-1,-1,None)::aux started xs) + _current_tabbing := tu::(!_current_tabbing); + (* can't be C2, for later phases *) + Cocci2 (tu,-1,-1,-1,None)::aux started xs) | Unindent_cocci2(permanent)::xs -> - (match !tabbing_unit with - None -> aux started xs - | Some (_,tu) -> - _current_tabbing := remtab tu (!_current_tabbing); + (match !_current_tabbing with + [] -> aux started xs + | _::new_tabbing -> + _current_tabbing := new_tabbing; aux started xs) (* border between existing code and cocci code *) | ((T2 (tok,_,_)) as x)::((Cocci2("\n",_,_,_,_)) as y)::xs @@ -1052,7 +1091,8 @@ let rec adjust_indentation xs = | ((Cocci2("{",_,_,_,_)) as a)::xs -> a::aux true xs | ((Cocci2("\n",_,_,_,_)) as x)::xs -> (* dont inline in expr because of weird eval order of ocaml *) - let s = !_current_tabbing in + let s = String.concat "" !_current_tabbing in + (* can't be C2, for later phases *) x::Cocci2 (s,-1,-1,-1,None)::aux started xs | x::xs -> x::aux started xs in (aux false xs,!tabbing_unit) @@ -1225,7 +1265,7 @@ let pp_program2 xs outfile = drop_expanded(drop_fake(drop_minus toks)) else (* phase2: can now start to filter and adjust *) - let (toks,tu) = adjust_indentation toks in + (let (toks,tu) = adjust_indentation toks in let toks = adjust_before_semicolon toks in(*before remove minus*) let toks = adjust_after_paren toks in(*also before remove minus*) let toks = drop_space_at_endline toks in @@ -1235,8 +1275,9 @@ let pp_program2 xs outfile = (* assert Origin + Cocci + C and no minus *) let toks = add_space toks in let toks = add_newlines toks tu in + let toks = paren_then_brace toks in let toks = fix_tokens toks in - toks in + toks) in (* in theory here could reparse and rework the ast! or * apply some SP. Not before cos julia may have generated diff --git a/parsing_c/unparse_cocci.ml b/parsing_c/unparse_cocci.ml index 80f052e..d7d5912 100644 --- a/parsing_c/unparse_cocci.ml +++ b/parsing_c/unparse_cocci.ml @@ -995,7 +995,7 @@ and case_line arity c = let top_level t = match Ast.unwrap t with Ast.FILEINFO(old_file,new_file) -> raise CantBeInPlus - | Ast.DECL(stmt) -> statement "" stmt + | Ast.NONDECL(stmt) -> statement "" stmt | Ast.CODE(stmt_dots) -> dots force_newline (statement "") stmt_dots | Ast.ERRORWORDS(exps) -> raise CantBeInPlus in diff --git a/parsing_c/unparse_hrule.ml b/parsing_c/unparse_hrule.ml index b4d506c..4d182a9 100644 --- a/parsing_c/unparse_hrule.ml +++ b/parsing_c/unparse_hrule.ml @@ -448,7 +448,7 @@ let pp_rule local_metas ast env srcfile = Ast.CocciRule(_,_,[body],_,_) -> (* could extend to use attributes *) (body, match Ast.unwrap body with - Ast.DECL(s) -> [[Ast.StatementTag s]] + Ast.NONDECL(s) -> [[Ast.StatementTag s]] | Ast.CODE(ss) -> [[Ast.StmtDotsTag ss]] | _ -> error body "bad rule body") | _ -> failwith "bad rule" in diff --git a/parsing_cocci/.depend b/parsing_cocci/.depend deleted file mode 100644 index ff3ef36..0000000 --- a/parsing_cocci/.depend +++ /dev/null @@ -1,206 +0,0 @@ -adjust_pragmas.cmi: ast0_cocci.cmi -arity.cmi: ast0_cocci.cmi -ast0_cocci.cmi: type_cocci.cmi ast_cocci.cmi -ast0toast.cmi: ast_cocci.cmi ast0_cocci.cmi -ast_cocci.cmi: type_cocci.cmi -check_meta.cmi: ast_cocci.cmi ast0_cocci.cmi -comm_assoc.cmi: ast0_cocci.cmi -compute_lines.cmi: ast0_cocci.cmi -context_neg.cmi: ../commons/common.cmi ast0_cocci.cmi -data.cmi: type_cocci.cmi ../commons/common.cmi ast_cocci.cmi ast0_cocci.cmi -disjdistr.cmi: ast_cocci.cmi -free_vars.cmi: ast_cocci.cmi -function_prototypes.cmi: ast_cocci.cmi ast0_cocci.cmi -get_constants.cmi: ast_cocci.cmi -get_constants2.cmi: ast_cocci.cmi -id_utils.cmi: get_constants2.cmi -index.cmi: ast0_cocci.cmi -insert_plus.cmi: ast0_cocci.cmi -iso_compile.cmi: iso_pattern.cmi -iso_pattern.cmi: visitor_ast0_types.cmo ast_cocci.cmi ast0_cocci.cmi -merge.cmi: ast_cocci.cmi ast0_cocci.cmi -parse_cocci.cmi: get_constants2.cmi ast_cocci.cmi -plus.cmi: ast_cocci.cmi -pretty_print_cocci.cmi: ast_cocci.cmi -safe_for_multi_decls.cmi: ast_cocci.cmi -simple_assignments.cmi: ast0_cocci.cmi -single_statement.cmi: ast0_cocci.cmi -test_exps.cmi: ast0_cocci.cmi -top_level.cmi: ast0_cocci.cmi -type_cocci.cmi: -type_infer.cmi: ast0_cocci.cmi -unify_ast.cmi: ast_cocci.cmi -unitary_ast0.cmi: ast0_cocci.cmi -unparse_ast0.cmi: ast0_cocci.cmi -visitor_ast.cmi: ast_cocci.cmi -visitor_ast0.cmi: visitor_ast0_types.cmo ast_cocci.cmi ast0_cocci.cmi -adjacency.cmo: visitor_ast0_types.cmo visitor_ast0.cmi ast0_cocci.cmi \ - adjacency.cmi -adjacency.cmx: visitor_ast0_types.cmx visitor_ast0.cmx ast0_cocci.cmx \ - adjacency.cmi -adjust_pragmas.cmo: visitor_ast0_types.cmo visitor_ast0.cmi ast_cocci.cmi \ - ast0_cocci.cmi adjust_pragmas.cmi -adjust_pragmas.cmx: visitor_ast0_types.cmx visitor_ast0.cmx ast_cocci.cmx \ - ast0_cocci.cmx adjust_pragmas.cmi -arity.cmo: ast_cocci.cmi ast0_cocci.cmi arity.cmi -arity.cmx: ast_cocci.cmx ast0_cocci.cmx arity.cmi -ast0_cocci.cmo: type_cocci.cmi ../globals/flag.cmo ../commons/common.cmi \ - ast_cocci.cmi ast0_cocci.cmi -ast0_cocci.cmx: type_cocci.cmx ../globals/flag.cmx ../commons/common.cmx \ - ast_cocci.cmx ast0_cocci.cmi -ast0toast.cmo: visitor_ast0_types.cmo visitor_ast0.cmi type_cocci.cmi \ - ../globals/flag.cmo ../commons/ocamlextra/dumper.cmi ast_cocci.cmi \ - ast0_cocci.cmi ast0toast.cmi -ast0toast.cmx: visitor_ast0_types.cmx visitor_ast0.cmx type_cocci.cmx \ - ../globals/flag.cmx ../commons/ocamlextra/dumper.cmx ast_cocci.cmx \ - ast0_cocci.cmx ast0toast.cmi -ast_cocci.cmo: type_cocci.cmi ../commons/common.cmi ast_cocci.cmi -ast_cocci.cmx: type_cocci.cmx ../commons/common.cmx ast_cocci.cmi -check_meta.cmo: visitor_ast0_types.cmo visitor_ast0.cmi type_cocci.cmi \ - ../commons/common.cmi ast_cocci.cmi ast0_cocci.cmi check_meta.cmi -check_meta.cmx: visitor_ast0_types.cmx visitor_ast0.cmx type_cocci.cmx \ - ../commons/common.cmx ast_cocci.cmx ast0_cocci.cmx check_meta.cmi -comm_assoc.cmo: visitor_ast0_types.cmo visitor_ast0.cmi unparse_ast0.cmi \ - ../globals/flag.cmo ast_cocci.cmi ast0_cocci.cmi comm_assoc.cmi -comm_assoc.cmx: visitor_ast0_types.cmx visitor_ast0.cmx unparse_ast0.cmx \ - ../globals/flag.cmx ast_cocci.cmx ast0_cocci.cmx comm_assoc.cmi -compute_lines.cmo: ast_cocci.cmi ast0_cocci.cmi compute_lines.cmi -compute_lines.cmx: ast_cocci.cmx ast0_cocci.cmx compute_lines.cmi -context_neg.cmo: visitor_ast0_types.cmo visitor_ast0.cmi unparse_ast0.cmi \ - index.cmi ../globals/flag.cmo compute_lines.cmi ../commons/common.cmi \ - ast_cocci.cmi ast0_cocci.cmi context_neg.cmi -context_neg.cmx: visitor_ast0_types.cmx visitor_ast0.cmx unparse_ast0.cmx \ - index.cmx ../globals/flag.cmx compute_lines.cmx ../commons/common.cmx \ - ast_cocci.cmx ast0_cocci.cmx context_neg.cmi -data.cmo: type_cocci.cmi ../commons/common.cmi ast_cocci.cmi ast0_cocci.cmi \ - data.cmi -data.cmx: type_cocci.cmx ../commons/common.cmx ast_cocci.cmx ast0_cocci.cmx \ - data.cmi -disjdistr.cmo: visitor_ast.cmi ../globals/flag.cmo ../commons/common.cmi \ - ast_cocci.cmi disjdistr.cmi -disjdistr.cmx: visitor_ast.cmx ../globals/flag.cmx ../commons/common.cmx \ - ast_cocci.cmx disjdistr.cmi -flag_parsing_cocci.cmo: -flag_parsing_cocci.cmx: -free_vars.cmo: visitor_ast.cmi type_cocci.cmi ../commons/common.cmi \ - ast_cocci.cmi free_vars.cmi -free_vars.cmx: visitor_ast.cmx type_cocci.cmx ../commons/common.cmx \ - ast_cocci.cmx free_vars.cmi -function_prototypes.cmo: visitor_ast0_types.cmo visitor_ast0.cmi \ - iso_pattern.cmi insert_plus.cmi context_neg.cmi compute_lines.cmi \ - ast_cocci.cmi ast0toast.cmi ast0_cocci.cmi function_prototypes.cmi -function_prototypes.cmx: visitor_ast0_types.cmx visitor_ast0.cmx \ - iso_pattern.cmx insert_plus.cmx context_neg.cmx compute_lines.cmx \ - ast_cocci.cmx ast0toast.cmx ast0_cocci.cmx function_prototypes.cmi -get_constants.cmo: visitor_ast.cmi type_cocci.cmi ../globals/flag.cmo \ - ../commons/common.cmi ast_cocci.cmi get_constants.cmi -get_constants.cmx: visitor_ast.cmx type_cocci.cmx ../globals/flag.cmx \ - ../commons/common.cmx ast_cocci.cmx get_constants.cmi -get_constants2.cmo: visitor_ast.cmi type_cocci.cmi ../globals/flag.cmo \ - ../commons/common.cmi ast_cocci.cmi get_constants2.cmi -get_constants2.cmx: visitor_ast.cmx type_cocci.cmx ../globals/flag.cmx \ - ../commons/common.cmx ast_cocci.cmx get_constants2.cmi -id_utils.cmo: get_constants2.cmi ../commons/common.cmi id_utils.cmi -id_utils.cmx: get_constants2.cmx ../commons/common.cmx id_utils.cmi -index.cmo: ast_cocci.cmi ast0_cocci.cmi index.cmi -index.cmx: ast_cocci.cmx ast0_cocci.cmx index.cmi -insert_plus.cmo: visitor_ast0_types.cmo visitor_ast0.cmi \ - pretty_print_cocci.cmi context_neg.cmi ast_cocci.cmi ast0toast.cmi \ - ast0_cocci.cmi insert_plus.cmi -insert_plus.cmx: visitor_ast0_types.cmx visitor_ast0.cmx \ - pretty_print_cocci.cmx context_neg.cmx ast_cocci.cmx ast0toast.cmx \ - ast0_cocci.cmx insert_plus.cmi -iso_compile.cmo: visitor_ast0_types.cmo visitor_ast0.cmi \ - ../commons/common.cmi ast_cocci.cmi ast0_cocci.cmi iso_compile.cmi -iso_compile.cmx: visitor_ast0_types.cmx visitor_ast0.cmx \ - ../commons/common.cmx ast_cocci.cmx ast0_cocci.cmx iso_compile.cmi -iso_pattern.cmo: visitor_ast0_types.cmo visitor_ast0.cmi unparse_ast0.cmi \ - type_cocci.cmi flag_parsing_cocci.cmo ../globals/flag.cmo \ - ../commons/ocamlextra/dumper.cmi compute_lines.cmi ../commons/common.cmi \ - ast_cocci.cmi ast0_cocci.cmi iso_pattern.cmi -iso_pattern.cmx: visitor_ast0_types.cmx visitor_ast0.cmx unparse_ast0.cmx \ - type_cocci.cmx flag_parsing_cocci.cmx ../globals/flag.cmx \ - ../commons/ocamlextra/dumper.cmx compute_lines.cmx ../commons/common.cmx \ - ast_cocci.cmx ast0_cocci.cmx iso_pattern.cmi -main.cmo: parse_cocci.cmi -main.cmx: parse_cocci.cmx -merge.cmo: visitor_ast0.cmi ast_cocci.cmi ast0_cocci.cmi merge.cmi -merge.cmx: visitor_ast0.cmx ast_cocci.cmx ast0_cocci.cmx merge.cmi -parse_aux.cmo: type_cocci.cmi semantic_cocci.cmo ../globals/flag.cmo data.cmi \ - ../commons/common.cmi ast_cocci.cmi ast0_cocci.cmi -parse_aux.cmx: type_cocci.cmx semantic_cocci.cmx ../globals/flag.cmx data.cmx \ - ../commons/common.cmx ast_cocci.cmx ast0_cocci.cmx -parse_cocci.cmo: visitor_ast0_types.cmo visitor_ast0.cmi unitary_ast0.cmi \ - type_infer.cmi test_exps.cmi single_statement.cmi simple_assignments.cmi \ - semantic_cocci.cmo safe_for_multi_decls.cmi pretty_print_cocci.cmi \ - parse_aux.cmo iso_pattern.cmi iso_compile.cmi insert_plus.cmi \ - get_constants2.cmi function_prototypes.cmi free_vars.cmi \ - flag_parsing_cocci.cmo ../globals/flag.cmo \ - ../commons/ocamlextra/dumper.cmi disjdistr.cmi data.cmi context_neg.cmi \ - compute_lines.cmi ../commons/common.cmi comm_assoc.cmi check_meta.cmi \ - ast_cocci.cmi ast0toast.cmi ast0_cocci.cmi arity.cmi adjust_pragmas.cmi \ - adjacency.cmi parse_cocci.cmi -parse_cocci.cmx: visitor_ast0_types.cmx visitor_ast0.cmx unitary_ast0.cmx \ - type_infer.cmx test_exps.cmx single_statement.cmx simple_assignments.cmx \ - semantic_cocci.cmx safe_for_multi_decls.cmx pretty_print_cocci.cmx \ - parse_aux.cmx iso_pattern.cmx iso_compile.cmx insert_plus.cmx \ - get_constants2.cmx function_prototypes.cmx free_vars.cmx \ - flag_parsing_cocci.cmx ../globals/flag.cmx \ - ../commons/ocamlextra/dumper.cmx disjdistr.cmx data.cmx context_neg.cmx \ - compute_lines.cmx ../commons/common.cmx comm_assoc.cmx check_meta.cmx \ - ast_cocci.cmx ast0toast.cmx ast0_cocci.cmx arity.cmx adjust_pragmas.cmx \ - adjacency.cmx parse_cocci.cmi -plus.cmo: visitor_ast.cmi ast_cocci.cmi plus.cmi -plus.cmx: visitor_ast.cmx ast_cocci.cmx plus.cmi -pretty_print_cocci.cmo: type_cocci.cmi ../globals/flag.cmo \ - ../commons/common.cmi ast_cocci.cmi pretty_print_cocci.cmi -pretty_print_cocci.cmx: type_cocci.cmx ../globals/flag.cmx \ - ../commons/common.cmx ast_cocci.cmx pretty_print_cocci.cmi -safe_for_multi_decls.cmo: visitor_ast.cmi ast_cocci.cmi \ - safe_for_multi_decls.cmi -safe_for_multi_decls.cmx: visitor_ast.cmx ast_cocci.cmx \ - safe_for_multi_decls.cmi -semantic_cocci.cmo: -semantic_cocci.cmx: -simple_assignments.cmo: visitor_ast0_types.cmo visitor_ast0.cmi \ - ../globals/flag.cmo ../commons/common.cmi ast_cocci.cmi ast0_cocci.cmi \ - simple_assignments.cmi -simple_assignments.cmx: visitor_ast0_types.cmx visitor_ast0.cmx \ - ../globals/flag.cmx ../commons/common.cmx ast_cocci.cmx ast0_cocci.cmx \ - simple_assignments.cmi -single_statement.cmo: visitor_ast0_types.cmo visitor_ast0.cmi iso_pattern.cmi \ - flag_parsing_cocci.cmo compute_lines.cmi ast_cocci.cmi ast0_cocci.cmi \ - single_statement.cmi -single_statement.cmx: visitor_ast0_types.cmx visitor_ast0.cmx iso_pattern.cmx \ - flag_parsing_cocci.cmx compute_lines.cmx ast_cocci.cmx ast0_cocci.cmx \ - single_statement.cmi -test_exps.cmo: visitor_ast0_types.cmo visitor_ast0.cmi ast_cocci.cmi \ - ast0_cocci.cmi test_exps.cmi -test_exps.cmx: visitor_ast0_types.cmx visitor_ast0.cmx ast_cocci.cmx \ - ast0_cocci.cmx test_exps.cmi -top_level.cmo: ast0_cocci.cmi top_level.cmi -top_level.cmx: ast0_cocci.cmx top_level.cmi -type_cocci.cmo: type_cocci.cmi -type_cocci.cmx: type_cocci.cmi -type_infer.cmo: visitor_ast0_types.cmo visitor_ast0.cmi type_cocci.cmi \ - ast_cocci.cmi ast0_cocci.cmi type_infer.cmi -type_infer.cmx: visitor_ast0_types.cmx visitor_ast0.cmx type_cocci.cmx \ - ast_cocci.cmx ast0_cocci.cmx type_infer.cmi -unify_ast.cmo: visitor_ast.cmi ast_cocci.cmi unify_ast.cmi -unify_ast.cmx: visitor_ast.cmx ast_cocci.cmx unify_ast.cmi -unitary_ast0.cmo: visitor_ast0_types.cmo visitor_ast0.cmi ../globals/flag.cmo \ - ast_cocci.cmi ast0_cocci.cmi unitary_ast0.cmi -unitary_ast0.cmx: visitor_ast0_types.cmx visitor_ast0.cmx ../globals/flag.cmx \ - ast_cocci.cmx ast0_cocci.cmx unitary_ast0.cmi -unparse_ast0.cmo: type_cocci.cmi pretty_print_cocci.cmi ../commons/common.cmi \ - ast_cocci.cmi ast0_cocci.cmi unparse_ast0.cmi -unparse_ast0.cmx: type_cocci.cmx pretty_print_cocci.cmx ../commons/common.cmx \ - ast_cocci.cmx ast0_cocci.cmx unparse_ast0.cmi -visitor_ast.cmo: ast_cocci.cmi ast0_cocci.cmi visitor_ast.cmi -visitor_ast.cmx: ast_cocci.cmx ast0_cocci.cmx visitor_ast.cmi -visitor_ast0.cmo: visitor_ast0_types.cmo ast_cocci.cmi ast0_cocci.cmi \ - visitor_ast0.cmi -visitor_ast0.cmx: visitor_ast0_types.cmx ast_cocci.cmx ast0_cocci.cmx \ - visitor_ast0.cmi -visitor_ast0_types.cmo: ast_cocci.cmi ast0_cocci.cmi -visitor_ast0_types.cmx: ast_cocci.cmx ast0_cocci.cmx diff --git a/parsing_cocci/arity.ml b/parsing_cocci/arity.ml index c2ced71..16f6141 100644 --- a/parsing_cocci/arity.ml +++ b/parsing_cocci/arity.ml @@ -1108,10 +1108,11 @@ let top_level tgt t = if mcode2arity old_file = Ast0.NONE && mcode2arity new_file = Ast0.NONE then Ast0.FILEINFO(mcode old_file,mcode new_file) else fail t "unexpected arity for file info" - | Ast0.DECL(stmt) -> - Ast0.DECL(statement tgt stmt) + | Ast0.NONDECL(stmt) -> + Ast0.NONDECL(statement tgt stmt) | Ast0.CODE(rule_elem_dots) -> Ast0.CODE(concat_dots (statement tgt) rule_elem_dots) + | Ast0.TOPCODE(rule_elem_dots) -> fail t "eliminated by top_level" | Ast0.ERRORWORDS(exps) -> Ast0.ERRORWORDS(List.map (top_expression false Ast0.NONE) exps) | Ast0.OTHER(_) -> fail t "eliminated by top_level") diff --git a/parsing_cocci/ast0_cocci.ml b/parsing_cocci/ast0_cocci.ml index 00eb537..b724c68 100644 --- a/parsing_cocci/ast0_cocci.ml +++ b/parsing_cocci/ast0_cocci.ml @@ -402,7 +402,8 @@ and meta_pos = (* Top-level code *) and base_top_level = - DECL of statement + NONDECL of statement + | TOPCODE of statement dots | CODE of statement dots | FILEINFO of string mcode (* old file *) * string mcode (* new file *) | ERRORWORDS of expression list @@ -572,7 +573,7 @@ let rec ast0_type_to_type ty = | Pointer(ty,_) -> TC.Pointer(ast0_type_to_type ty) | FunctionPointer(ty,_,_,_,_,params,_) -> TC.FunctionPointer(ast0_type_to_type ty) - | FunctionType _ -> failwith "not supported" + | FunctionType _ -> TC.Unknown (*failwith "not supported"*) | Array(ety,_,_,_) -> TC.Array(ast0_type_to_type ety) | EnumName(su,Some tag) -> (match unwrap tag with diff --git a/parsing_cocci/ast0_cocci.mli b/parsing_cocci/ast0_cocci.mli index d8d98a6..be53d5a 100644 --- a/parsing_cocci/ast0_cocci.mli +++ b/parsing_cocci/ast0_cocci.mli @@ -391,7 +391,8 @@ and meta_pos = (* Top-level code *) and base_top_level = - DECL of statement + NONDECL of statement (* cannot match all of a top-level declaration *) + | TOPCODE of statement dots | CODE of statement dots | FILEINFO of string mcode (* old file *) * string mcode (* new file *) | ERRORWORDS of expression list diff --git a/parsing_cocci/ast0toast.ml b/parsing_cocci/ast0toast.ml index b05d7e7..40afef3 100644 --- a/parsing_cocci/ast0toast.ml +++ b/parsing_cocci/ast0toast.ml @@ -1078,11 +1078,10 @@ and top_level t = (match Ast0.unwrap t with Ast0.FILEINFO(old_file,new_file) -> Ast.FILEINFO(mcode old_file,mcode new_file) - | Ast0.DECL(stmt) -> Ast.DECL(statement stmt) - | Ast0.CODE(rule_elem_dots) -> - Ast.CODE(statement_dots rule_elem_dots) + | Ast0.NONDECL(stmt) -> Ast.NONDECL(statement stmt) + | Ast0.CODE(rule_elem_dots) -> Ast.CODE(statement_dots rule_elem_dots) | Ast0.ERRORWORDS(exps) -> Ast.ERRORWORDS(List.map expression exps) - | Ast0.OTHER(_) -> failwith "eliminated by top_level") + | Ast0.OTHER(_) | Ast0.TOPCODE(_) -> failwith "eliminated by top_level") (* --------------------------------------------------------------------- *) (* Entry point for minus code *) diff --git a/parsing_cocci/ast_cocci.ml b/parsing_cocci/ast_cocci.ml index c95eab5..3fe0de4 100644 --- a/parsing_cocci/ast_cocci.ml +++ b/parsing_cocci/ast_cocci.ml @@ -565,7 +565,7 @@ and inc_elem = | IncDots and base_top_level = - DECL of statement + NONDECL of statement | CODE of statement dots | FILEINFO of string mcode (* old file *) * string mcode (* new file *) | ERRORWORDS of expression list diff --git a/parsing_cocci/ast_cocci.mli b/parsing_cocci/ast_cocci.mli index 9726fb0..217a75d 100644 --- a/parsing_cocci/ast_cocci.mli +++ b/parsing_cocci/ast_cocci.mli @@ -537,7 +537,7 @@ and inc_elem = | IncDots and base_top_level = - DECL of statement + NONDECL of statement (* cannot match all of a top-level declaration *) | CODE of statement dots | FILEINFO of string mcode (* old file *) * string mcode (* new file *) | ERRORWORDS of expression list diff --git a/parsing_cocci/check_meta.ml b/parsing_cocci/check_meta.ml index 2e9850a..ba64535 100644 --- a/parsing_cocci/check_meta.ml +++ b/parsing_cocci/check_meta.ml @@ -452,8 +452,9 @@ and case_line old_metas table minus c = let top_level old_metas table minus t = match Ast0.unwrap t with - Ast0.DECL(stmt) -> statement old_metas table minus stmt - | Ast0.CODE(stmt_dots) -> dots (statement old_metas table minus) stmt_dots + Ast0.NONDECL(stmt) -> statement old_metas table minus stmt + | Ast0.CODE(stmt_dots) | Ast0.TOPCODE(stmt_dots) -> + dots (statement old_metas table minus) stmt_dots | Ast0.ERRORWORDS(exps) -> List.iter (expression FN old_metas table minus) exps | _ -> () (* no metavariables possible *) diff --git a/parsing_cocci/compute_lines.ml b/parsing_cocci/compute_lines.ml index 6c2c566..291a1a9 100644 --- a/parsing_cocci/compute_lines.ml +++ b/parsing_cocci/compute_lines.ml @@ -1092,13 +1092,13 @@ and statement_dots x = dots is_stm_dots None statement x let top_level t = match Ast0.unwrap t with Ast0.FILEINFO(old_file,new_file) -> t - | Ast0.DECL(stmt) -> - let stmt = statement stmt in mkres t (Ast0.DECL(stmt)) stmt stmt + | Ast0.NONDECL(stmt) -> + let stmt = statement stmt in mkres t (Ast0.NONDECL(stmt)) stmt stmt | Ast0.CODE(rule_elem_dots) -> let rule_elem_dots = dots is_stm_dots None statement rule_elem_dots in mkres t (Ast0.CODE(rule_elem_dots)) rule_elem_dots rule_elem_dots | Ast0.ERRORWORDS(exps) -> t - | Ast0.OTHER(_) -> failwith "eliminated by top_level" + | Ast0.OTHER(_) | Ast0.TOPCODE(_) -> failwith "eliminated by top_level" (* --------------------------------------------------------------------- *) (* Entry points *) diff --git a/parsing_cocci/context_neg.ml b/parsing_cocci/context_neg.ml index b1cfe9b..11e310d 100644 --- a/parsing_cocci/context_neg.ml +++ b/parsing_cocci/context_neg.ml @@ -741,7 +741,7 @@ let equal_case_line c1 c2 = let rec equal_top_level t1 t2 = match (Ast0.unwrap t1,Ast0.unwrap t2) with - (Ast0.DECL(_),Ast0.DECL(_)) -> true + (Ast0.NONDECL(_),Ast0.NONDECL(_)) -> true | (Ast0.FILEINFO(old_file1,new_file1),Ast0.FILEINFO(old_file2,new_file2)) -> equal_mcode old_file1 old_file2 && equal_mcode new_file1 new_file2 | (Ast0.CODE(_),Ast0.CODE(_)) -> true @@ -861,10 +861,11 @@ let plus_table = let iscode t = match Ast0.unwrap t with - Ast0.DECL(_) -> true + Ast0.NONDECL(_) -> true | Ast0.FILEINFO(_) -> true | Ast0.ERRORWORDS(_) -> false | Ast0.CODE(_) -> true + | Ast0.TOPCODE(_) | Ast0.OTHER(_) -> failwith "unexpected top level code" (* ------------------------------------------------------------------- *) @@ -878,7 +879,7 @@ let concat = function [] -> [] | x::rest -> (match Ast0.unwrap x with - Ast0.DECL(s) -> let stms = loop rest in s::stms + Ast0.NONDECL(s) -> let stms = loop rest in s::stms | Ast0.CODE(ss) -> let stms = loop rest in (match Ast0.unwrap ss with @@ -968,6 +969,8 @@ let rec is_toplevel s = | Ast0.Define(_,_,_,_) -> true | _ -> false +(* consider code and topcode to be the same; difference handled +in top_level.ml *) let check_compatible m p = let fail _ = failwith @@ -975,17 +978,21 @@ let check_compatible m p = "incompatible minus and plus code starting on lines %d and %d" (Ast0.get_line m) (Ast0.get_line p)) in match (Ast0.unwrap m, Ast0.unwrap p) with - (Ast0.DECL(decl1),Ast0.DECL(decl2)) -> + (Ast0.NONDECL(decl1),Ast0.NONDECL(decl2)) -> if not (is_decl decl1 && is_decl decl2) then fail() - | (Ast0.DECL(decl1),Ast0.CODE(code2)) -> + | (Ast0.NONDECL(decl1),Ast0.CODE(code2)) -> + (* This is probably the only important case. We don't want to + replace top-level declarations by arbitrary code. *) let v1 = is_decl decl1 in let v2 = List.for_all is_toplevel (Ast0.undots code2) in - if !Flag.make_hrule = None && v1 && not v2 then fail() - | (Ast0.CODE(code1),Ast0.DECL(decl2)) -> + if !Flag.make_hrule = None && v1 && not v2 + then fail() + | (Ast0.CODE(code1),Ast0.NONDECL(decl2)) -> let v1 = List.for_all is_toplevel (Ast0.undots code1) in let v2 = is_decl decl2 in - if v1 && not v2 then fail() + if v1 && not v2 + then fail() | (Ast0.CODE(code1),Ast0.CODE(code2)) -> let v1 = isonly is_init code1 in let v2a = isonly is_init code2 in @@ -1003,7 +1010,8 @@ let check_compatible m p = testers; let v1 = isonly is_fndecl code1 in let v2 = List.for_all is_toplevel (Ast0.undots code2) in - if !Flag.make_hrule = None && v1 && not v2 then fail() + if !Flag.make_hrule = None && v1 && not v2 + then fail() | (Ast0.FILEINFO(_,_),Ast0.FILEINFO(_,_)) -> () | (Ast0.OTHER(_),Ast0.OTHER(_)) -> () | _ -> fail() diff --git a/parsing_cocci/function_prototypes.ml b/parsing_cocci/function_prototypes.ml index 7ecb83d..2f2225a 100644 --- a/parsing_cocci/function_prototypes.ml +++ b/parsing_cocci/function_prototypes.ml @@ -76,16 +76,30 @@ let collect_function (stm : Ast0.statement) = let collect_functions stmt_dots = List.concat (List.map collect_function (Ast0.undots stmt_dots)) +let drop_positions = + let mcode (term,arity,info,mc,_,adj) = + (term,arity,info,mc,ref [],adj) in + let donothing r k e = k e in + let res = + V0.flat_rebuilder + mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode + donothing donothing donothing donothing donothing donothing + donothing donothing donothing donothing donothing donothing donothing + donothing donothing in + res.VT0.rebuilder_rec_statement + let get_all_functions rule = let res = match Ast0.unwrap rule with - Ast0.DECL(stmt) -> collect_function stmt + Ast0.NONDECL(stmt) -> collect_function stmt | Ast0.CODE(rule_elem_dots) -> collect_functions rule_elem_dots | _ -> [] in List.map (function (nm,def,vl) -> (nm, - (def,(Iso_pattern.rebuild_mcode None).VT0.rebuilder_rec_statement vl))) + (def, + drop_positions + ((Iso_pattern.rebuild_mcode None).VT0.rebuilder_rec_statement vl)))) res (* --------------------------------------------------------------------- *) @@ -343,21 +357,20 @@ let no_names dec = | _ -> dec) | _ -> dec +let mkcode proto = + Ast0.copywrap proto (Ast0.CODE(Ast0.copywrap proto (Ast0.DOTS [proto]))) + let merge mproto pproto = - let mproto = - Compute_lines.compute_lines true - [Ast0.copywrap mproto (Ast0.DECL mproto)] in - let pproto = - Compute_lines.compute_lines true - [Ast0.copywrap pproto (Ast0.DECL pproto)] in + let mproto = Compute_lines.compute_lines true [mkcode mproto] in + let pproto = Compute_lines.compute_lines true [mkcode pproto] in let (m,p) = List.split(Context_neg.context_neg mproto pproto) in Insert_plus.insert_plus m p true (* no isos for protos *); (* convert to ast so that the + code will fall down to the tokens - and off the artificially added Ast0.DECL *) + and off the artificially added Ast0.CODE *) let mproto = Ast0toast.ast0toast_toplevel (List.hd mproto) in (* clean up the wrapping added above *) match Ast.unwrap mproto with - Ast.DECL mproto -> mproto + Ast.CODE mproto -> List.hd (Ast.undots mproto) | _ -> failwith "not possible" let make_rule rule_name = function @@ -385,10 +398,10 @@ let reinsert mdefs minus = List.map (function x -> match Ast0.unwrap x with - Ast0.DECL(stmt) -> + Ast0.NONDECL(stmt) -> (match Ast0.unwrap stmt with Ast0.FunDecl(_,fninfo,name,lp,params,rp,lbrace,body,rbrace) -> - (try Ast0.rewrap x (Ast0.DECL(List.assoc name table)) + (try Ast0.rewrap x (Ast0.NONDECL(List.assoc name table)) with Not_found -> x) | _ -> x) | Ast0.CODE(rule_elem_dots) -> @@ -405,6 +418,9 @@ let rec split4 = function | (a,b,c,d)::rest -> let (ax,bx,cx,dx) = split4 rest in (a::ax,b::bx,c::cx,d::dx) +let mk_ast_code proto = + Ast.rewrap proto (Ast.CODE(Ast.rewrap proto (Ast.DOTS [proto]))) + let process rule_name rule_metavars dropped_isos minus plus ruletype = let minus_functions = List.concat (List.map get_all_functions minus) in match minus_functions with @@ -430,7 +446,7 @@ let process rule_name rule_metavars dropped_isos minus plus ruletype = Ast.CocciRule ("proto for "^rule_name, (Ast.Dep rule_name,dropped_isos,Ast.Forall), - [Ast.rewrap x (Ast.DECL x)], + [mk_ast_code x], [false],ruletype))) | x::_ -> let drules = @@ -439,6 +455,6 @@ let process rule_name rule_metavars dropped_isos minus plus ruletype = Ast.CocciRule ("proto for "^rule_name, (Ast.Dep rule_name,dropped_isos,Ast.Forall), - [Ast.rewrap x (Ast.DECL (Ast.rewrap x (Ast.Disj drules)))], + [mk_ast_code (Ast.rewrap x (Ast.Disj drules))], [false],ruletype) in ((mdef_metavars,minus),Some(metavars,res)) diff --git a/parsing_cocci/index.ml b/parsing_cocci/index.ml index f4ee7cb..a6aea02 100644 --- a/parsing_cocci/index.ml +++ b/parsing_cocci/index.ml @@ -23,7 +23,7 @@ (* create an index for each constructor *) -(* current max is 153 *) +(* current max is 154 *) (* doesn't really work - requires that identical terms with no token subterms (eg dots) not appear on the same line *) @@ -222,10 +222,11 @@ let case_line c = let top_level t = match Ast0.unwrap t with - Ast0.DECL(stmt) -> [90] + Ast0.NONDECL(stmt) -> [90] | Ast0.FILEINFO(old_file,new_file) -> [92] | Ast0.CODE(stmt_dots) -> [94] | Ast0.ERRORWORDS(exps) -> [95] | Ast0.OTHER(_) -> [96] + | Ast0.TOPCODE(_) -> [154] (* 99-101 already used *) diff --git a/parsing_cocci/insert_plus.ml b/parsing_cocci/insert_plus.ml index c664b07..74854aa 100644 --- a/parsing_cocci/insert_plus.ml +++ b/parsing_cocci/insert_plus.ml @@ -529,7 +529,7 @@ let collect_plus_nodes root = let toplevel r k e = match Ast0.unwrap e with - Ast0.DECL(s) -> r.VT0.combiner_rec_statement s + Ast0.NONDECL(s) -> r.VT0.combiner_rec_statement s | Ast0.CODE(sdots) -> r.VT0.combiner_rec_statement_dots sdots | _ -> do_nothing mk_code r k e in @@ -789,10 +789,8 @@ let attachbefore (infop,c,p) = function (match repl with Ast.NOREPLACEMENT -> let (bef,ti) = init p infop in - Printf.printf "attachbefore 1 %s\n" (it2c c); replacements := (Ast.REPLACEMENT(bef,c),ti) | Ast.REPLACEMENT(repl,it) -> - Printf.printf "attachbefore 2 %s %s\n" (it2c c) (it2c it); let it = Ast.lub_count it c in let (bef,ti) = insert p infop repl ti in replacements := (Ast.REPLACEMENT(bef,it),ti)) diff --git a/parsing_cocci/iso_pattern.ml b/parsing_cocci/iso_pattern.ml index 3bd0ef6..bdbb350 100644 --- a/parsing_cocci/iso_pattern.ml +++ b/parsing_cocci/iso_pattern.ml @@ -2421,7 +2421,7 @@ let transform_stmt (metavars,alts,name) e = (* sort of a hack, because there is no disj at top level *) let transform_top (metavars,alts,name) e = match Ast0.unwrap e with - Ast0.DECL(declstm) -> + Ast0.NONDECL(declstm) -> (try let strip alts = List.map @@ -2434,7 +2434,7 @@ let transform_top (metavars,alts,name) e = | _ -> raise (Failure ""))) alts in let (count,mv,s) = transform_stmt (metavars,strip alts,name) declstm in - (count,mv,Ast0.rewrap e (Ast0.DECL(s))) + (count,mv,Ast0.rewrap e (Ast0.NONDECL(s))) with Failure _ -> (0,[],e)) | Ast0.CODE(stmts) -> let (count,mv,res) = diff --git a/parsing_cocci/parse_cocci.ml b/parsing_cocci/parse_cocci.ml index a18abbc..f721e53 100644 --- a/parsing_cocci/parse_cocci.ml +++ b/parsing_cocci/parse_cocci.ml @@ -1709,11 +1709,25 @@ let parse file = then (* not actually used for anything, except context_neg *) List.map (Iso_pattern.rebuild_mcode None).VT0.rebuilder_rec_top_level - minus_res + (Top_level.top_level false minus_res) else if is_expression then parse_one "plus" PC.plus_exp_main file plus_tokens else parse_one "plus" PC.plus_main file plus_tokens in + let plus_res = Top_level.top_level false plus_res in + (* minus code has to be CODE if the + code is CODE, otherwise + doesn't matter if + code is CODE or DECL or TOPCODE *) + let minus_res = + let any_code = + List.exists + (function x -> + match Ast0.unwrap x with Ast0.CODE _ -> true | _ -> false) + plus_res in + if any_code + then Top_level.top_level true minus_res + else Top_level.top_level false minus_res in + let minus_res = Top_level.clean minus_res in + let plus_res = Top_level.clean plus_res in (* Unparse_ast0.unparse plus_res; Printf.printf "after plus parse\n"; diff --git a/parsing_cocci/parser_cocci_menhir.ml b/parsing_cocci/parser_cocci_menhir.ml index a5cd51a..0dc8361 100644 --- a/parsing_cocci/parser_cocci_menhir.ml +++ b/parsing_cocci/parser_cocci_menhir.ml @@ -23270,7 +23270,7 @@ module MenhirInterpreter = MenhirLib.TableInterpreter.Make (struct # 816 "parser_cocci_menhir.mly" ( match f@b(*@ew*) with [] -> raise (Semantic_cocci.Semantic "minus slice can't be empty") - | code -> Top_level.top_level code ) + | code -> code ) # 23275 "parser_cocci_menhir.ml" in _menhir_env.MenhirLib.EngineTypes.stack <- { @@ -23302,7 +23302,7 @@ module MenhirInterpreter = MenhirLib.TableInterpreter.Make (struct # 830 "parser_cocci_menhir.mly" ( match f@[b](*@ew*) with [] -> raise (Semantic_cocci.Semantic "minus slice can't be empty") - | code -> Top_level.top_level code ) + | code -> code ) # 23307 "parser_cocci_menhir.ml" in _menhir_env.MenhirLib.EngineTypes.stack <- { @@ -23518,7 +23518,7 @@ module MenhirInterpreter = MenhirLib.TableInterpreter.Make (struct let _endpos = _endpos__1_ in let _v : 'tv_minus_start = # 2078 "parser_cocci_menhir.mly" - ( [Ast0.wrap(Ast0.DECL(_1))] ) + ( [Ast0.wrap(Ast0.OTHER(_1))] ) # 23523 "parser_cocci_menhir.ml" in _menhir_env.MenhirLib.EngineTypes.stack <- { @@ -28257,7 +28257,7 @@ module MenhirInterpreter = MenhirLib.TableInterpreter.Make (struct let _endpos = _endpos__2_ in let _v : 'tv_plus_after_dots = # 2149 "parser_cocci_menhir.mly" - ( Ast0.wrap(Ast0.DECL(_1))::_2 ) + ( Ast0.wrap(Ast0.OTHER(_1))::_2 ) # 28262 "parser_cocci_menhir.ml" in _menhir_env.MenhirLib.EngineTypes.stack <- { @@ -28411,7 +28411,7 @@ module MenhirInterpreter = MenhirLib.TableInterpreter.Make (struct let _endpos = _endpos__2_ in let _v : 'tv_plus_after_stm = # 2156 "parser_cocci_menhir.mly" - ( Ast0.wrap(Ast0.DECL(_1))::_2 ) + ( Ast0.wrap(Ast0.OTHER(_1))::_2 ) # 28416 "parser_cocci_menhir.ml" in _menhir_env.MenhirLib.EngineTypes.stack <- { @@ -28471,7 +28471,7 @@ module MenhirInterpreter = MenhirLib.TableInterpreter.Make (struct let _endpos = _endpos_b_ in let _v : 'tv_plus_body = # 824 "parser_cocci_menhir.mly" - ( Top_level.top_level (f@b(*@ew*)) ) + ( f@b(*@ew*) ) # 28476 "parser_cocci_menhir.ml" in _menhir_env.MenhirLib.EngineTypes.stack <- { @@ -28501,7 +28501,7 @@ module MenhirInterpreter = MenhirLib.TableInterpreter.Make (struct let _endpos = _endpos_b_ in let _v : 'tv_plus_exp_body = # 838 "parser_cocci_menhir.mly" - ( Top_level.top_level (f@[b](*@ew*)) ) + ( f@[b](*@ew*) ) # 28506 "parser_cocci_menhir.ml" in _menhir_env.MenhirLib.EngineTypes.stack <- { @@ -28831,7 +28831,7 @@ module MenhirInterpreter = MenhirLib.TableInterpreter.Make (struct let _endpos = _endpos__2_ in let _v : 'tv_plus_start = # 2136 "parser_cocci_menhir.mly" - ( Ast0.wrap(Ast0.DECL(_1))::_2 ) + ( Ast0.wrap(Ast0.OTHER(_1))::_2 ) # 28836 "parser_cocci_menhir.ml" in _menhir_env.MenhirLib.EngineTypes.stack <- { diff --git a/parsing_cocci/parser_cocci_menhir.mly b/parsing_cocci/parser_cocci_menhir.mly index fb706ab..ef6df83 100644 --- a/parsing_cocci/parser_cocci_menhir.mly +++ b/parsing_cocci/parser_cocci_menhir.mly @@ -815,13 +815,13 @@ minus_body: /*ew=loption(error_words)*/ { match f@b(*@ew*) with [] -> raise (Semantic_cocci.Semantic "minus slice can't be empty") - | code -> Top_level.top_level code } + | code -> code } plus_body: f=loption(filespec) b=loption(plus_start) /*ew=loption(error_words)*/ - { Top_level.top_level (f@b(*@ew*)) } + { f@b(*@ew*) } minus_exp_body: f=loption(filespec) @@ -829,13 +829,13 @@ minus_exp_body: /*ew=loption(error_words)*/ { match f@[b](*@ew*) with [] -> raise (Semantic_cocci.Semantic "minus slice can't be empty") - | code -> Top_level.top_level code } + | code -> code } plus_exp_body: f=loption(filespec) b=top_eexpr /*ew=loption(error_words)*/ - { Top_level.top_level (f@[b](*@ew*)) } + { f@[b](*@ew*) } filespec: TMinusFile TPlusFile @@ -2075,7 +2075,7 @@ when_body_sequence. /* doesn't allow only ... */ minus_start: - fundecl { [Ast0.wrap(Ast0.DECL($1))] } + fundecl { [Ast0.wrap(Ast0.OTHER($1))] } | ctype { [Ast0.wrap(Ast0.OTHER(Ast0.wrap(Ast0.Ty($1))))] } | top_init { [Ast0.wrap(Ast0.OTHER(Ast0.wrap(Ast0.TopInit($1))))] } | toplevel_seq_startne(toplevel_after_dots_init) @@ -2133,7 +2133,7 @@ plus_start: { (Ast0.wrap(Ast0.OTHER($1)))::$2 } | expr plus_after_exp { (Ast0.wrap(Ast0.OTHER(Ast0.wrap(Ast0.Exp($1)))))::$2 } -| fundecl plus_after_stm { Ast0.wrap(Ast0.DECL($1))::$2 } +| fundecl plus_after_stm { Ast0.wrap(Ast0.OTHER($1))::$2 } | decl_statement_expr plus_after_stm { (List.map (function x -> Ast0.wrap(Ast0.OTHER(x))) $1)@$2 } @@ -2146,14 +2146,14 @@ plus_after_dots: | TNothing plus_after_exp {$2} | expr plus_after_exp { (Ast0.wrap(Ast0.OTHER(Ast0.wrap(Ast0.Exp($1)))))::$2 } -| fundecl plus_after_stm { Ast0.wrap(Ast0.DECL($1))::$2 } +| fundecl plus_after_stm { Ast0.wrap(Ast0.OTHER($1))::$2 } | decl_statement_expr plus_after_stm { (List.map (function x -> Ast0.wrap(Ast0.OTHER(x))) $1)@$2 } plus_after_stm: /* empty */ {[]} | stm_dots plus_after_dots { (Ast0.wrap(Ast0.OTHER($1)))::$2 } -| fundecl plus_after_stm { Ast0.wrap(Ast0.DECL($1))::$2 } +| fundecl plus_after_stm { Ast0.wrap(Ast0.OTHER($1))::$2 } | decl_statement plus_after_stm { (List.map (function x -> Ast0.wrap(Ast0.OTHER(x))) $1)@$2 } diff --git a/parsing_cocci/pretty_print_cocci.ml b/parsing_cocci/pretty_print_cocci.ml index 74f792a..ac84a5e 100644 --- a/parsing_cocci/pretty_print_cocci.ml +++ b/parsing_cocci/pretty_print_cocci.ml @@ -791,7 +791,7 @@ let top_level t = Ast.FILEINFO(old_file,new_file) -> print_string "--- "; mcode print_string old_file; force_newline(); print_string "+++ "; mcode print_string new_file - | Ast.DECL(stmt) -> statement "" stmt + | Ast.NONDECL(stmt) -> statement "" stmt | Ast.CODE(stmt_dots) -> dots force_newline (statement "") stmt_dots | Ast.ERRORWORDS(exps) -> diff --git a/parsing_cocci/single_statement.ml b/parsing_cocci/single_statement.ml index d3bfde8..a5ed9dc 100644 --- a/parsing_cocci/single_statement.ml +++ b/parsing_cocci/single_statement.ml @@ -660,7 +660,7 @@ and statement_dots dots_before dots_after d = let top_level t = Ast0.rewrap t (match Ast0.unwrap t with - Ast0.DECL(stmt_dots) -> Ast0.DECL(statement true true stmt_dots) + Ast0.NONDECL(stmt_dots) -> Ast0.NONDECL(statement true true stmt_dots) | Ast0.CODE(stmt_dots) -> Ast0.CODE(statement_dots true true stmt_dots) | t -> t) diff --git a/parsing_cocci/top_level.ml b/parsing_cocci/top_level.ml index 6dd7eed..a9e7a2a 100644 --- a/parsing_cocci/top_level.ml +++ b/parsing_cocci/top_level.ml @@ -45,56 +45,76 @@ let top_dots l = then Ast0.wrap (Ast0.STARS(l)) else Ast0.wrap (Ast0.DOTS(l)) -let scan_code l = - let statements = ref false in +let rec is_decl s = + match Ast0.unwrap s with + Ast0.Decl(_,e) -> true + | _ -> false + +let isonly f l = match Ast0.undots l with [s] -> f s | _ -> false +let isall f l = List.for_all (isonly f) l + +let rec is_toplevel s = + match Ast0.unwrap s with + Ast0.Decl(_,e) -> true + | Ast0.FunDecl(_,_,_,_,_,_,_,_,_) -> true + | Ast0.Disj(_,stmts,_,_) -> isall is_toplevel stmts + | Ast0.ExprStatement(Some fc,_) -> false + | Ast0.Include(_,_) -> true + | Ast0.Undef(_,_) -> true + | Ast0.Define(_,_,_,_) -> true + | _ -> false + +let scan_code must_be_code l = let rec loop = function [] -> ([],[]) | (x::xs) as all -> - (match Ast0.unwrap x with - (Ast0.OTHER(code)) -> - (match Ast0.unwrap code with - Ast0.Decl(_) -> - let (front,rest) = loop xs in - (code::front,rest) - | _ -> - statements := true; - let (front,rest) = loop xs in - (code::front,rest)) - | _ -> ([],all)) in + (match Ast0.unwrap x with + (Ast0.OTHER(code)) -> + let (front,rest) = loop xs in + (code::front,rest) + | _ -> ([],all)) in match loop l with ([],_) as res -> res | (code,rest) -> - if !statements = true - then ([Ast0.wrap(Ast0.CODE(top_dots code))],rest) - else - (List.map - (function d -> - match Ast0.unwrap d with - Ast0.Decl(bef,x) -> Ast0.wrap (Ast0.DECL(d)) - | _ -> failwith "impossible") - code, - rest) + (match code with + | [x] when is_decl x && must_be_code -> + ([Ast0.wrap(Ast0.NONDECL x)],rest) + | _ when List.for_all is_toplevel code -> + ([Ast0.wrap(Ast0.TOPCODE(top_dots code))],rest) + | _ -> + ([Ast0.wrap(Ast0.CODE(top_dots code))],rest)) let rec scan_top_decl = function [] -> ([],[]) | ((topdecl::rest) as all) -> (match Ast0.unwrap topdecl with Ast0.OTHER(_) -> ([],all) - | _ -> let (front,rest) = scan_top_decl rest in (topdecl::front,rest)) + | _ -> + let (front,rest) = scan_top_decl rest + in (topdecl::front,rest)) (* for debugging *) let l2c l = match Ast0.unwrap l with - Ast0.DECL(_) -> "decl" + Ast0.NONDECL(_) -> "decl" | Ast0.CODE(_) -> "code" + | Ast0.TOPCODE(_) -> "code" | Ast0.FILEINFO(_,_) -> "fileinfo" | Ast0.ERRORWORDS(_) -> "errorwords" | Ast0.OTHER(_) -> "other" -let rec top_level l = - match scan_code l with +let rec top_level must_be_code l = + match scan_code must_be_code l with (code,[]) -> code | (code,rest) -> (match scan_top_decl rest with (top_decls,[]) -> code@top_decls - | (top_decls,rest) -> code @ top_decls @ (top_level rest)) + | (top_decls,rest) -> code @ top_decls @ (top_level must_be_code rest)) + +let clean l = + List.map + (function tl -> + match Ast0.unwrap tl with + Ast0.TOPCODE x -> Ast0.rewrap tl (Ast0.CODE x) + | _ -> tl) + l diff --git a/parsing_cocci/top_level.mli b/parsing_cocci/top_level.mli index 289f997..da2f172 100644 --- a/parsing_cocci/top_level.mli +++ b/parsing_cocci/top_level.mli @@ -22,4 +22,7 @@ *) -val top_level : Ast0_cocci.rule -> Ast0_cocci.rule +val top_level : + bool (* true if must be code *) -> Ast0_cocci.rule -> Ast0_cocci.rule + +val clean : Ast0_cocci.rule -> Ast0_cocci.rule diff --git a/parsing_cocci/unparse_ast0.ml b/parsing_cocci/unparse_ast0.ml index 105476b..9ac3697 100644 --- a/parsing_cocci/unparse_ast0.ml +++ b/parsing_cocci/unparse_ast0.ml @@ -631,8 +631,8 @@ let top_level t = Ast0.FILEINFO(old_file,new_file) -> print_string "--- "; mcode print_string old_file; force_newline(); print_string "+++ "; mcode print_string new_file - | Ast0.DECL(stmt) -> statement "" stmt - | Ast0.CODE(stmt_dots) -> + | Ast0.NONDECL(stmt) -> statement "" stmt + | Ast0.CODE(stmt_dots) | Ast0.TOPCODE(stmt_dots) -> dots force_newline (statement "") stmt_dots | Ast0.ERRORWORDS(exps) -> print_string "error words = ["; diff --git a/parsing_cocci/visitor_ast.ml b/parsing_cocci/visitor_ast.ml index 799b3f2..f5519f3 100644 --- a/parsing_cocci/visitor_ast.ml +++ b/parsing_cocci/visitor_ast.ml @@ -485,7 +485,7 @@ let combiner bind option_default match Ast.unwrap t with Ast.FILEINFO(old_file,new_file) -> bind (string_mcode old_file) (string_mcode new_file) - | Ast.DECL(stmt) -> statement stmt + | Ast.NONDECL(stmt) -> statement stmt | Ast.CODE(stmt_dots) -> statement_dots stmt_dots | Ast.ERRORWORDS(exps) -> multibind (List.map expression exps) in topfn all_functions k t @@ -1010,7 +1010,7 @@ let rebuilder (match Ast.unwrap t with Ast.FILEINFO(old_file,new_file) -> Ast.FILEINFO (string_mcode old_file, string_mcode new_file) - | Ast.DECL(stmt) -> Ast.DECL(statement stmt) + | Ast.NONDECL(stmt) -> Ast.NONDECL(statement stmt) | Ast.CODE(stmt_dots) -> Ast.CODE(statement_dots stmt_dots) | Ast.ERRORWORDS(exps) -> Ast.ERRORWORDS (List.map expression exps)) in topfn all_functions k t diff --git a/parsing_cocci/visitor_ast0.ml b/parsing_cocci/visitor_ast0.ml index 81b445d..175153a 100644 --- a/parsing_cocci/visitor_ast0.ml +++ b/parsing_cocci/visitor_ast0.ml @@ -839,12 +839,15 @@ let visitor mode bind option_default let (old_file_n,old_file) = string_mcode old_file in let (new_file_n,new_file) = string_mcode new_file in (bind old_file_n new_file_n,Ast0.FILEINFO(old_file,new_file)) - | Ast0.DECL(statement_dots) -> + | Ast0.NONDECL(statement_dots) -> let (n,statement_dots) = statement statement_dots in - (n,Ast0.DECL(statement_dots)) + (n,Ast0.NONDECL(statement_dots)) | Ast0.CODE(stmt_dots) -> let (stmt_dots_n,stmt_dots) = statement_dots stmt_dots in (stmt_dots_n, Ast0.CODE(stmt_dots)) + | Ast0.TOPCODE(stmt_dots) -> + let (stmt_dots_n,stmt_dots) = statement_dots stmt_dots in + (stmt_dots_n, Ast0.TOPCODE(stmt_dots)) | Ast0.ERRORWORDS(exps) -> let (n,exps) = map_split_bind expression exps in (n, Ast0.ERRORWORDS(exps)) diff --git a/popl/popl.mli b/popl/popl.mli index 1185a79..7716982 100644 --- a/popl/popl.mli +++ b/popl/popl.mli @@ -26,4 +26,4 @@ type cocci_predicate = Lib_engine.predicate * Ast_cocci.meta_name Ast_ctl.modif type formula = (cocci_predicate,Ast_cocci.meta_name, Wrapper_ctl.info) Ast_ctl.generic_ctl -val popl : Ast_cocci.rule -> formula list +val popl : Ast_cocci.rule -> Asttoctl2.top_formula list diff --git a/popl/popltoctl.ml b/popl/popltoctl.ml index 590d071..7bb9787 100644 --- a/popl/popltoctl.ml +++ b/popl/popltoctl.ml @@ -201,4 +201,4 @@ and guard_ctl_dots keep_wit = function (* --------------------------------------------------------------------- *) -let toctl sl = ctl_seq true ctl_true sl +let toctl sl = Asttoctl2.CODE (ctl_seq true ctl_true sl) diff --git a/popl/popltoctl.mli b/popl/popltoctl.mli index c8dd49e..a65c5ca 100644 --- a/popl/popltoctl.mli +++ b/popl/popltoctl.mli @@ -26,4 +26,4 @@ type cocci_predicate = Lib_engine.predicate * Ast_cocci.meta_name Ast_ctl.modif type formula = (cocci_predicate,Ast_cocci.meta_name, Wrapper_ctl.info) Ast_ctl.generic_ctl -val toctl : Ast_popl.sequence -> formula +val toctl : Ast_popl.sequence -> Asttoctl2.top_formula diff --git a/popl09/.depend b/popl09/.depend deleted file mode 100644 index c88af14..0000000 --- a/popl09/.depend +++ /dev/null @@ -1,35 +0,0 @@ -asttopopl.cmi: ast_popl.cmo ../parsing_cocci/ast_cocci.cmi -insert_quantifiers.cmi: ast_popl.cmo -popl.cmi: ../ctl/wrapper_ctl.cmi ../engine/lib_engine.cmo ../ctl/ast_ctl.cmo \ - ../parsing_cocci/ast_cocci.cmi -popltoctl.cmi: ../ctl/wrapper_ctl.cmi ../engine/lib_engine.cmo ast_popl.cmo \ - ../ctl/ast_ctl.cmo ../parsing_cocci/ast_cocci.cmi -pretty_print_popl.cmi: ast_popl.cmo -ast_popl.cmo: ../parsing_cocci/ast_cocci.cmi -ast_popl.cmx: ../parsing_cocci/ast_cocci.cmx -asttopopl.cmo: ../parsing_cocci/pretty_print_cocci.cmi ast_popl.cmo \ - ../parsing_cocci/ast_cocci.cmi asttopopl.cmi -asttopopl.cmx: ../parsing_cocci/pretty_print_cocci.cmx ast_popl.cmx \ - ../parsing_cocci/ast_cocci.cmx asttopopl.cmi -flag_popl.cmo: -flag_popl.cmx: -insert_quantifiers.cmo: ../commons/common.cmi ast_popl.cmo \ - ../parsing_cocci/ast_cocci.cmi insert_quantifiers.cmi -insert_quantifiers.cmx: ../commons/common.cmx ast_popl.cmx \ - ../parsing_cocci/ast_cocci.cmx insert_quantifiers.cmi -popl.cmo: ../ctl/wrapper_ctl.cmi popltoctl.cmi ../engine/lib_engine.cmo \ - insert_quantifiers.cmi asttopopl.cmi ../ctl/ast_ctl.cmo \ - ../parsing_cocci/ast_cocci.cmi popl.cmi -popl.cmx: ../ctl/wrapper_ctl.cmx popltoctl.cmx ../engine/lib_engine.cmx \ - insert_quantifiers.cmx asttopopl.cmx ../ctl/ast_ctl.cmx \ - ../parsing_cocci/ast_cocci.cmx popl.cmi -popltoctl.cmo: ../ctl/wrapper_ctl.cmi ../parsing_cocci/visitor_ast.cmi \ - ../engine/lib_engine.cmo flag_popl.cmo ast_popl.cmo ../ctl/ast_ctl.cmo \ - ../parsing_cocci/ast_cocci.cmi popltoctl.cmi -popltoctl.cmx: ../ctl/wrapper_ctl.cmx ../parsing_cocci/visitor_ast.cmx \ - ../engine/lib_engine.cmx flag_popl.cmx ast_popl.cmx ../ctl/ast_ctl.cmx \ - ../parsing_cocci/ast_cocci.cmx popltoctl.cmi -pretty_print_popl.cmo: ../parsing_cocci/pretty_print_cocci.cmi ast_popl.cmo \ - ../parsing_cocci/ast_cocci.cmi pretty_print_popl.cmi -pretty_print_popl.cmx: ../parsing_cocci/pretty_print_cocci.cmx ast_popl.cmx \ - ../parsing_cocci/ast_cocci.cmx pretty_print_popl.cmi diff --git a/popl09/popl.mli b/popl09/popl.mli index 1185a79..7716982 100644 --- a/popl09/popl.mli +++ b/popl09/popl.mli @@ -26,4 +26,4 @@ type cocci_predicate = Lib_engine.predicate * Ast_cocci.meta_name Ast_ctl.modif type formula = (cocci_predicate,Ast_cocci.meta_name, Wrapper_ctl.info) Ast_ctl.generic_ctl -val popl : Ast_cocci.rule -> formula list +val popl : Ast_cocci.rule -> Asttoctl2.top_formula list diff --git a/popl09/popltoctl.ml b/popl09/popltoctl.ml index a2a5c4a..6fe9963 100644 --- a/popl09/popltoctl.ml +++ b/popl09/popltoctl.ml @@ -236,4 +236,4 @@ and do_between_dots keep_wit ba term after = (* --------------------------------------------------------------------- *) -let toctl sl = ctl_seq true ctl_true sl +let toctl sl = Asttoctl2.CODE (ctl_seq true ctl_true sl) diff --git a/popl09/popltoctl.mli b/popl09/popltoctl.mli index c8dd49e..a65c5ca 100644 --- a/popl09/popltoctl.mli +++ b/popl09/popltoctl.mli @@ -26,4 +26,4 @@ type cocci_predicate = Lib_engine.predicate * Ast_cocci.meta_name Ast_ctl.modif type formula = (cocci_predicate,Ast_cocci.meta_name, Wrapper_ctl.info) Ast_ctl.generic_ctl -val toctl : Ast_popl.sequence -> formula +val toctl : Ast_popl.sequence -> Asttoctl2.top_formula diff --git a/python/.depend b/python/.depend deleted file mode 100644 index facc6d2..0000000 --- a/python/.depend +++ /dev/null @@ -1,12 +0,0 @@ -pycocci.cmi: ../parsing_cocci/ast_cocci.cmi ../parsing_c/ast_c.cmo -pycocci_aux.cmi: ../parsing_c/ast_c.cmo -no_pycocci.cmo: pycocci_aux.cmi ../commons/common.cmi ../parsing_c/ast_c.cmo -no_pycocci.cmx: pycocci_aux.cmx ../commons/common.cmx ../parsing_c/ast_c.cmx -pycocci_aux.cmo: ../parsing_c/pretty_print_c.cmi ../commons/common.cmi \ - ../parsing_cocci/ast_cocci.cmi ../parsing_c/ast_c.cmo pycocci_aux.cmi -pycocci_aux.cmx: ../parsing_c/pretty_print_c.cmx ../commons/common.cmx \ - ../parsing_cocci/ast_cocci.cmx ../parsing_c/ast_c.cmx pycocci_aux.cmi -yes_pycocci.cmo: pycocci_aux.cmi ../globals/flag.cmo ../commons/common.cmi \ - ../parsing_c/ast_c.cmo -yes_pycocci.cmx: pycocci_aux.cmx ../globals/flag.cmx ../commons/common.cmx \ - ../parsing_c/ast_c.cmx diff --git a/scripts/coccicheck/configure b/scripts/coccicheck/configure index 1b7e105..fdb4b16 100755 --- a/scripts/coccicheck/configure +++ b/scripts/coccicheck/configure @@ -97,5 +97,8 @@ clean: distclean: rm -rf \$(RESULTS) +maintclean: distclean + rm Makefile + depend: update EOF diff --git a/tests/SCORE_expected.sexp b/tests/SCORE_expected.sexp index 1a4a3f0..7a6e0dd 100644 --- a/tests/SCORE_expected.sexp +++ b/tests/SCORE_expected.sexp @@ -1,9 +1,9 @@ ((a.res Ok) (a3d.res Ok) (a_and_e.res Ok) (a_and_e_ver1.res Ok) (ab.res Ok) (addaft.res Ok) (addbefore.res Ok) (addbeforeafter.res Ok) (addelse.res Ok) - (addif.res Ok) (addif1.res Ok) (addif2.res Ok) (addtoo.res Ok) - (after_if.res Ok) (anon.res Ok) (ar.res Ok) (arg.res Ok) (argument.res Ok) - (arparam.res Ok) (array_init.res Ok) (array_size.res Ok) (arraysz.res Ok) - (attradd.res Ok) (b1.res Ok) (b2.res Ok) + (addfield.res Ok) (addif.res Ok) (addif1.res Ok) (addif2.res Ok) + (addtoo.res Ok) (after_if.res Ok) (anon.res Ok) (ar.res Ok) (arg.res Ok) + (argument.res Ok) (arparam.res Ok) (array_init.res Ok) (array_size.res Ok) + (arraysz.res Ok) (attradd.res Ok) (b1.res Ok) (b2.res Ok) (bad_iso_example.res (Pb "INCORRECT:diff token: ( VS x\nFile \"tests/bad_iso_example.c\", line 2, column 6, charpos = 19\n around = '(', whole content = if ((x = 3)) return;\nFile \"tests/bad_iso_example.res\", line 2, column 6, charpos = 19\n around = 'x', whole content = if (x) return;\n\n diff (result(<) vs expected_result(>)) = \n @@ -1,4 +1,4 @@\n int main() {\n - if ((x = 3)) return;\n + if (x) return;\n }\n \n")) @@ -126,11 +126,11 @@ "INCORRECT:diff token: init_MUTEX VS mutex_init\nFile \"tests/serio.c\", line 7, column 1, charpos = 130\n around = 'init_MUTEX', whole content = \tinit_MUTEX(&serio->drv_sem);\nFile \"tests/serio.res\", line 7, column 1, charpos = 130\n around = 'mutex_init', whole content = \tmutex_init(&serio->new_lock);\n\n diff (result(<) vs expected_result(>)) = \n @@ -4,5 +4,5 @@\n \n static void serio_init_port(struct serio *serio)\n {\n -\tinit_MUTEX(&serio->drv_sem);\n +\tmutex_init(&serio->new_lock);\n }\n")) (shared_brace.res Ok) (signed.res Ok) (sis.res Ok) (sizeof.res Ok) (sizeof_julia.res Ok) (sizeptr.res Ok) (sizestar.res Ok) (skip.res Ok) - (sp.res Ok) (spaces.res Ok) (spl.res Ok) (static.res Ok) (stm1.res Ok) - (stm10.res Ok) (stm10_ver1.res Ok) (stm2.res Ok) (stm3.res Ok) (stm4.res Ok) - (stm5.res Ok) (stm6.res Ok) (stm7.res Ok) (stm8.res Ok) (stmt.res Ok) - (str_init.res Ok) (strangeorder.res Ok) (strid.res Ok) (strid2.res Ok) - (string.res Ok) (struct.res Ok) (struct_metavar.res Ok) + (sp.res Ok) (spaces.res Ok) (spacing.res Ok) (spl.res Ok) (static.res Ok) + (stm1.res Ok) (stm10.res Ok) (stm10_ver1.res Ok) (stm2.res Ok) (stm3.res Ok) + (stm4.res Ok) (stm5.res Ok) (stm6.res Ok) (stm7.res Ok) (stm8.res Ok) + (stmt.res Ok) (str_init.res Ok) (strangeorder.res Ok) (strid.res Ok) + (strid2.res Ok) (string.res Ok) (struct.res Ok) (struct_metavar.res Ok) (struct_typedef.res Ok) (structfoo.res Ok) (substruct.res Ok) (sw.res Ok) (switch.res Ok) (switchdecl.res Ok) (td.res Ok) (tern.res Ok) (test0.res Ok) (test1.res Ok) (test10.res Ok) (test10_ver1.res Ok) (test11.res Ok) diff --git a/tests/SCORE_expected_orig.sexp b/tests/SCORE_expected_orig.sexp index 1f260db..07f0d75 100644 --- a/tests/SCORE_expected_orig.sexp +++ b/tests/SCORE_expected_orig.sexp @@ -1,9 +1,9 @@ ((a.res Ok) (a3d.res Ok) (a_and_e.res Ok) (a_and_e_ver1.res Ok) (ab.res Ok) (addaft.res Ok) (addbefore.res Ok) (addbeforeafter.res Ok) (addelse.res Ok) - (addif.res Ok) (addif1.res Ok) (addif2.res Ok) (addtoo.res Ok) - (after_if.res Ok) (anon.res Ok) (ar.res Ok) (arg.res Ok) (argument.res Ok) - (arparam.res Ok) (array_init.res Ok) (array_size.res Ok) (arraysz.res Ok) - (attradd.res Ok) (b1.res Ok) (b2.res Ok) + (addfield.res Ok) (addif.res Ok) (addif1.res Ok) (addif2.res Ok) + (addtoo.res Ok) (after_if.res Ok) (anon.res Ok) (ar.res Ok) (arg.res Ok) + (argument.res Ok) (arparam.res Ok) (array_init.res Ok) (array_size.res Ok) + (arraysz.res Ok) (attradd.res Ok) (b1.res Ok) (b2.res Ok) (bad_iso_example.res (Pb "INCORRECT:diff token: ( VS x\nFile \"tests/bad_iso_example.c\", line 2, column 6, charpos = 19\n around = '(', whole content = if ((x = 3)) return;\nFile \"tests/bad_iso_example.res\", line 2, column 6, charpos = 19\n around = 'x', whole content = if (x) return;\n\n diff (result(<) vs expected_result(>)) = \n @@ -1,4 +1,4 @@\n int main() {\n - if ((x = 3)) return;\n + if (x) return;\n }\n \n")) @@ -126,7 +126,7 @@ "INCORRECT:diff token: init_MUTEX VS mutex_init\nFile \"tests/serio.c\", line 7, column 1, charpos = 130\n around = 'init_MUTEX', whole content = \tinit_MUTEX(&serio->drv_sem);\nFile \"tests/serio.res\", line 7, column 1, charpos = 130\n around = 'mutex_init', whole content = \tmutex_init(&serio->new_lock);\n\n diff (result(<) vs expected_result(>)) = \n @@ -4,5 +4,5 @@\n \n static void serio_init_port(struct serio *serio)\n {\n -\tinit_MUTEX(&serio->drv_sem);\n +\tmutex_init(&serio->new_lock);\n }\n")) (shared_brace.res Ok) (signed.res Ok) (sis.res Ok) (sizeof.res Ok) (sizeof_julia.res Ok) (sizeptr.res Ok) (sizestar.res Ok) (skip.res Ok) - (sp.res Ok) (spaces.res Ok) (spl.res Ok) (static.res Ok) + (sp.res Ok) (spaces.res Ok) (spacing.res Ok) (spl.res Ok) (static.res Ok) (stm1.res (Pb "PROBLEM\n exn = Failure(\"no python\")\n")) (stm10.res Ok) (stm10_ver1.res Ok) (stm2.res Ok) (stm3.res Ok) (stm4.res Ok) (stm5.res Ok) (stm6.res Ok) (stm7.res (Pb "PROBLEM\n exn = Failure(\"no python\")\n")) diff --git a/tests/addfield.c b/tests/addfield.c new file mode 100644 index 0000000..64e75df --- /dev/null +++ b/tests/addfield.c @@ -0,0 +1,9 @@ +@@ +identifier I; +expression E; +@@ + +struct i2c_client I = { + .name = E, + .foo = 16 +}; diff --git a/tests/addfield.cocci b/tests/addfield.cocci new file mode 100644 index 0000000..d407075 --- /dev/null +++ b/tests/addfield.cocci @@ -0,0 +1,10 @@ +@@ +identifier I; +expression E; +@@ + +struct i2c_client I = { +- .name = E, +..., ++ .dev = { .name = E, }, +}; diff --git a/tests/addfield.res b/tests/addfield.res new file mode 100644 index 0000000..168c1a0 --- /dev/null +++ b/tests/addfield.res @@ -0,0 +1,11 @@ +@@ +identifier I; +expression E; +@@ + +struct i2c_client I = { + .foo = 16, + .dev = { + .name = E, + }, +}; diff --git a/tests/spacing.c b/tests/spacing.c new file mode 100644 index 0000000..10eba55 --- /dev/null +++ b/tests/spacing.c @@ -0,0 +1,8 @@ +typedef int *foo; + +int f(int x) { + one(); + if (x) { + two(); + } +} diff --git a/tests/spacing.cocci b/tests/spacing.cocci new file mode 100644 index 0000000..a7f81bf --- /dev/null +++ b/tests/spacing.cocci @@ -0,0 +1,24 @@ +@@ +@@ + typedef int *foo; ++void *bar(int *baz) ++{ ++ return baz; ++} + +@@ +identifier f,x; +@@ + f(int x) { ... } ++void *bar(int *baz) ++{ ++ return baz; ++} + +@@ +@@ + +two(); ++if (y) { ++ test(); ++} diff --git a/tests/spacing.res b/tests/spacing.res new file mode 100644 index 0000000..e3b4949 --- /dev/null +++ b/tests/spacing.res @@ -0,0 +1,19 @@ +typedef int *foo; + +void *bar(int *baz) { +return baz; +} + +int f(int x) { + one(); + if (x) { + two(); + if (y) { + test(); + } + } +} + +void *bar(int *baz) { + return baz; +} diff --git a/tests/top.cocci b/tests/top.cocci index 9b073c1..0eda2cb 100644 --- a/tests/top.cocci +++ b/tests/top.cocci @@ -1,5 +1,6 @@ @@ declarer name MODULE_PARM; +declarer name module_param; @@ - MODULE_PARM(...);