From aa7214425d48f1e44bdb723016058f518f8ee133 Mon Sep 17 00:00:00 2001 From: Coccinelle Date: Sun, 3 Oct 2010 14:03:36 +0200 Subject: [PATCH] Release coccinelle-0.2.2-rc2 Release Candidate 2 for coccinelle-0.2.2 --- changes.txt | 17 +++++++++++-- cocci.ml | 41 +++++++++++++++++++------------- commitmsg | 4 ++-- commons/common.ml | 8 ++++++- docs/manual/main_grammar.pdf | Bin 288802 -> 288802 bytes docs/manual/manual.pdf | Bin 368433 -> 368433 bytes docs/manual/options.pdf | Bin 96143 -> 96147 bytes engine/cocci_vs_c.ml | 22 ++++++++--------- engine/pretty_print_engine.ml | 3 ++- globals/config.ml.in | 2 +- main.ml | 22 +++++++++++------ parsing_c/unparse_c.ml | 1 + parsing_c/unparse_cocci.ml | 5 +++- parsing_cocci/get_constants2.ml | 7 +++--- parsing_cocci/lexer_cocci.mll | 23 +++++++++++++----- parsing_cocci/lexer_script.mll | 7 ++++-- parsing_cocci/type_infer.ml | 10 ++++++-- test.ml | 22 +++++++++++++++++ 18 files changed, 137 insertions(+), 57 deletions(-) diff --git a/changes.txt b/changes.txt index 10b9ddb..78afb2b 100644 --- a/changes.txt +++ b/changes.txt @@ -24,13 +24,13 @@ keywords sush as 'depends on', 'using', 'disable' - better treatment of != 0 in isos, communtativity for ==/!= for all constants -- allow adding // comments +- allow adding // comments and blank lines (even after cocci + code) - Add support for multiple -I options ** Bugfix: - correct interaction between virtual rules and included .cocci files - improvement in treatment of ! in isos, to avoid duplicating + code -- improvement intreatment of metavars as isos, to avoid duplicating + code +- improvement in treatment of metavars as isos, to avoid duplicating + code between toplevel and variable instantiation - test expression of smpl conditional, etc no longer assumed to have type int @@ -44,6 +44,19 @@ - better handling of . or .. in -dir name - allow keywords and metavariable names in identifier constraints (not sure keywords is very useful, though) +- no lubtype on arguments of && and || in SmPL +- allow unknown as type for array indices in SmPL +- support matching of static annotation on functions that are both static + and inline +- support ENOTDIR error in Common.lfile_exists, to allow for the case where + an include file is in a subdirectory that exists but is an ordinary file, + not a directory. +- better management of unbound position variables that appear in + constraints +- cause python parser to skip over // comments, hoping that // is not + meaningful inside python +- require + on every line of a multiline comment +- correct caluation of line numbers when there is script code * 0.2.1 ** Language: diff --git a/cocci.ml b/cocci.ml index 3ab1f4f..59cbe46 100644 --- a/cocci.ml +++ b/cocci.ml @@ -1308,9 +1308,12 @@ let rec apply_cocci_rule r rules_that_have_ever_matched es (new_bindings +> List.map (List.filter - (fun (s,v) -> - List.mem s r.used_after && - not (List.mem s old_variables)))) in + (function + (* see comment before combine_pos *) + (s,Ast_c.MetaPosValList []) -> false + | (s,v) -> + List.mem s r.used_after && + not (List.mem s old_variables)))) in List.map (function new_binding_to_add -> (List.sort compare @@ -1391,22 +1394,28 @@ and reassociate_positions free_vars negated_pos_vars envs = (List.map (function (non_pos,_) -> List.assoc non_pos extended_relevant) splitted_relevant) +(* If the negated posvar is not bound at all, this function will +nevertheless bind it to []. If we get rid of these bindings, then the +matching of the term the position variable with the constraints will fail +because some variables are unbound. So we let the binding be [] and then +we will have to clean these up afterwards. This should be the only way +that a position variable can have an empty binding. *) and combine_pos negated_pos_vars others = List.map (function posvar -> - (posvar, - Ast_c.MetaPosValList - (List.sort compare - (List.fold_left - (function positions -> - function other_list -> - try - match List.assoc posvar other_list with - Ast_c.MetaPosValList l1 -> - Common.union_set l1 positions - | _ -> failwith "bad value for a position variable" - with Not_found -> positions) - [] others)))) + let positions = + List.sort compare + (List.fold_left + (function positions -> + function other_list -> + try + match List.assoc posvar other_list with + Ast_c.MetaPosValList l1 -> + Common.union_set l1 positions + | _ -> failwith "bad value for a position variable" + with Not_found -> positions) + [] others) in + (posvar,Ast_c.MetaPosValList positions)) negated_pos_vars and process_a_generated_a_env_a_toplevel2 r env = function diff --git a/commitmsg b/commitmsg index 7a39b2e..b443914 100644 --- a/commitmsg +++ b/commitmsg @@ -1,3 +1,3 @@ -Release coccinelle-0.2.2-rc1 +Release coccinelle-0.2.2-rc2 -Release Candidate 1 for coccinelle-0.2.2 +Release Candidate 2 for coccinelle-0.2.2 diff --git a/commons/common.ml b/commons/common.ml index 9308319..5bf1316 100644 --- a/commons/common.ml +++ b/commons/common.ml @@ -3238,7 +3238,13 @@ let lfile_exists filename = | (Unix.S_REG | Unix.S_LNK) -> true | _ -> false ) - with Unix.Unix_error (Unix.ENOENT, _, _) -> false + with + Unix.Unix_error (Unix.ENOENT, _, _) -> false + | Unix.Unix_error (Unix.ENOTDIR, _, _) -> false + | Unix.Unix_error (error, _, fl) -> + failwith + (Printf.sprintf "unexpected error %s for file %s" + (Unix.error_message error) fl) let is_directory file = (Unix.stat file).Unix.st_kind =*= Unix.S_DIR diff --git a/docs/manual/main_grammar.pdf b/docs/manual/main_grammar.pdf index 53f8a700bcd6528572feaf573db264b8c94e4ecc..3c125f7f3094a4cfcf3453e2ee04d9b0d42f27e7 100644 GIT binary patch delta 166 zcmZ2W@t3M zmY+oi#@W7rpG7Gm!P3ad#nRQ($kN!{!pX$c!obDF+0n_w(9zA(%+kQg#7@D6ppsYx eJ3Fr8lEk8tilWpsE+aEDBTF+bRaIAiH!c8f3n*6r delta 166 zcmZ2%5d2*gZ4%sgF@pCy#t%+Sol#Kd%Z zEkBD4jI(_KKZ{aCf`y5xg@J*inTxZVrLlplsi~=(nYodHtC_jExvPb#o1KCUK_#&Y ec6MCFC5c5P6-B9OTt;SQMwVt=s;aL3Zd?G|aVYTs diff --git a/docs/manual/manual.pdf b/docs/manual/manual.pdf index 41706484da67885302a733d654410ebb4af8fbed..6813f6298d647c176a0bcc731f3f9cf58872957f 100644 GIT binary patch delta 473 zcmdnEPi*5pu?@W<^=JK#D2TLv|19!Gr}HRx>%Sb+S1F5*ow?E)D1IZT{e*+l?Vf#m zx0nPb$J{M`SW}?KQ03gPF8qVP?fUTaa2xlY$%}L}R#_imQMJ^a*w9mOFyQW@)dXtmAU&@f1!EzDxCemwXIPaVFo) z-yZIEGR{?7!0p9%(}QZuBxJodH%(DmV56L>rnF14cbedyi8H#MbZDw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}!#aw0KTTg?t?nOhwDt&95D)6n zmZ-J5yg;CAxv}+SJb9O~=F&YM<`n_V7pL}`+I+b1%`n-xijvw8A}Jp9$BpAE1*bq8 z+*z}!%YAN?9(f%dklW$LK3CqtPzhq5drQM?`*2*{!+zmg@ zD6t${LO}&>d9&@a>R*^2O-f#u(5!oEPe~B#?YOr1mmvJ|$VqX)qv?(;w_H`xp65MH z$A(PYkSNOSaRH(O`=eU#9aiUUzoG1m{b{Z%yUHxmQP>{I(zk4-YZlD-CFcOYL zAP~r;VjKwi_op8RI&hM~2*LjE33&=Z{=dM;pfRxDFa+{<9!d^=nkOrV{*5Oq3qvPK zd4a@fWiUx*ULboe8T4;D1Oi>t?*&o>aUp+iqGeG@BHkcab& z<}`*vpiX{JkwS9Em(V7%c~vL7f)M$^MrO z!r=cl{M!#Bi-DgG{Z9=2pJBi-7zP28l}p<711Z|Vl|C3@Zq^Jn-_QB$P{PB)X5Dem if equal_storage (term x) stobis then - match iistob with - | [i1] -> - tokenf x i1 >>= (fun x i1 -> - return (Some x, ((stobis, inline), [i1])) - ) - (* or if have inline ? have to do a split_storage_inline a la - * split_signb_baseb_ii *) - | _ -> raise Impossible + let rec loop acc = function + [] -> fail + | i1::iistob -> + let try1 = + tokenf x i1 >>= (fun x i1 -> + let rebuilt = (List.rev acc) @ i1 :: iistob in + return (Some x, ((stobis, inline), rebuilt))) in + let try2 x = loop (i1::acc) iistob x in (* x for laziness *) + try1 >||> try2 in + loop [] iistob else fail ) - - - - and fullType_optional_allminus allminus tya retb = match tya with | None -> diff --git a/engine/pretty_print_engine.ml b/engine/pretty_print_engine.ml index 49a0211..04286bb 100644 --- a/engine/pretty_print_engine.ml +++ b/engine/pretty_print_engine.ml @@ -62,7 +62,8 @@ and pp_binding subst = begin pp "["; Common.print_between (fun () -> pp ";"; Format.print_cut() ) - (fun ((_,s), kind) -> pp s; pp " --> "; pp_binding_kind kind) + (fun ((r,s), kind) -> + pp r; pp "."; pp s; pp " --> "; pp_binding_kind kind) subst; pp "]"; end diff --git a/globals/config.ml.in b/globals/config.ml.in index 769cb48..ca5f236 100644 --- a/globals/config.ml.in +++ b/globals/config.ml.in @@ -1,4 +1,4 @@ -let version = "0.2.2-rc1" +let version = "0.2.2-rc2" let path = try (Sys.getenv "COCCINELLE_HOME") diff --git a/main.ml b/main.ml index b96cba4..f088e9f 100644 --- a/main.ml +++ b/main.ml @@ -331,7 +331,7 @@ let short_options = [ " guess what"; "-date", Arg.Unit (fun () -> - pr2 "version: $Date: 2010/03/05 21:12:11 $"; + pr2 "version: $Date: 2010/03/09 08:29:04 $"; raise (Common.UnixExit 0) ), " guess what"; @@ -974,13 +974,19 @@ let main () = (* --------------------------------------------------------- *) | [x] when !test_mode -> begin + let prefix = "tests/" in try - let prefix = "tests/" in FC.include_path := [prefix^"include"]; Testing.testone prefix x !compare_with_expected - with _ -> - FC.include_path := ["include"]; - Testing.testone "" x !compare_with_expected + with error -> + let testfile = prefix ^ x ^ ".cocci" in + if not (Sys.file_exists testfile) then + begin + FC.include_path := ["include"]; + Testing.testone "" x !compare_with_expected + end + else + raise error end | [] when !test_all -> @@ -1043,8 +1049,10 @@ let main_with_better_error_report () = try main () with - | Unix.Unix_error (_, "stat", filename) -> - pr2 (spf "ERROR: File %s does not exist" filename); + | Unix.Unix_error (e, "stat", filename) -> + pr2 + (spf "ERROR: File %s does not exist: %s" + filename (Unix.error_message e)); raise (UnixExit (-1)) (*****************************************************************************) diff --git a/parsing_c/unparse_c.ml b/parsing_c/unparse_c.ml index 80a3a80..0cabad4 100644 --- a/parsing_c/unparse_c.ml +++ b/parsing_c/unparse_c.ml @@ -790,6 +790,7 @@ let new_tabbing a = let rec adjust_indentation xs = + let _current_tabbing = ref "" in let tabbing_unit = ref None in diff --git a/parsing_c/unparse_cocci.ml b/parsing_c/unparse_cocci.ml index cda9814..6b9cb59 100644 --- a/parsing_c/unparse_cocci.ml +++ b/parsing_c/unparse_cocci.ml @@ -148,11 +148,14 @@ let mcode fn (s,info,mc,pos) = let str = match str with Ast.Noindent s | Ast.Indent s -> s in print_string str line col; Some line | _ -> + force_newline(); + (* not super elegant to put side-effecting unindent in a let + expression... *) let str = match str with Ast.Noindent s -> unindent false; s | Ast.Indent s -> s in - force_newline(); print_string str line col; Some line) + print_string str line col; Some line) lb comments in let line_before = print_comments None info.Ast.strbef in (match line_before with diff --git a/parsing_cocci/get_constants2.ml b/parsing_cocci/get_constants2.ml index 2a8f55a..90a0aa3 100644 --- a/parsing_cocci/get_constants2.ml +++ b/parsing_cocci/get_constants2.ml @@ -514,10 +514,9 @@ let get_constants rules neg_pos_vars = (build_or dependencies rest_info, in_plus, env, locals)) | (Ast.InitialScriptRule (_,deps,_),_) | (Ast.FinalScriptRule (_,deps,_),_) -> - (match dependencies env deps with - False -> (rest_info, in_plus, env, locals) - | dependencies -> - (build_or dependencies rest_info, in_plus, env, locals)) + (* initialize and finalize dependencies are irrelevant to + get_constants *) + (rest_info, in_plus, env, locals) | (Ast.CocciRule (nm,(dep,_,_),cur,_,_),neg_pos_vars) -> let (cur_info,cur_plus) = rule_fn cur in_plus ((nm,True)::env) diff --git a/parsing_cocci/lexer_cocci.mll b/parsing_cocci/lexer_cocci.mll index 49e4503..a9e1e4a 100644 --- a/parsing_cocci/lexer_cocci.mll +++ b/parsing_cocci/lexer_cocci.mll @@ -116,6 +116,10 @@ let check_arity_context_linetype s = | (D.UNIQUE,_,_) | (D.OPT,_,_) -> () | _ -> lexerr "invalid in a nonempty context: " s +let check_comment s = + if not !current_line_started + then lexerr "+ expected at the beginning of the line" s + let process_include start finish str = (match !current_line_type with (D.PLUS,_,_) | (D.PLUSPLUS,_,_) -> @@ -694,7 +698,7 @@ rule token = parse | "/*" { start_line true; check_plus_linetype (tok lexbuf); (* second argument to TPragma is not quite right, because - it represents only the first token of the comemnt, but that + it represents only the first token of the comment, but that should be good enough *) TPragma (Ast.Indent("/*"^(comment lexbuf)), get_current_line_type lexbuf) } @@ -779,16 +783,23 @@ and string = parse | _ { lexerr "unrecognised symbol: " (tok lexbuf) } and comment = parse - | "*/" { start_line true; tok lexbuf } + | "*/" { let s = tok lexbuf in check_comment s; start_line true; s } | ['\n' '\r' '\011' '\012'] - { reset_line lexbuf; let s = tok lexbuf in s ^ comment lexbuf } + { let s = tok lexbuf in + (* even blank line should have a + *) + check_comment s; + reset_line lexbuf; s ^ comment lexbuf } | "+" { pass_zero(); if !current_line_started then (start_line true; let s = tok lexbuf in s^(comment lexbuf)) - else comment lexbuf } + else (start_line true; comment lexbuf) } (* noteopti: *) - | [^ '*'] { start_line true; let s = tok lexbuf in s ^ comment lexbuf } - | [ '*'] { start_line true; let s = tok lexbuf in s ^ comment lexbuf } + | [^ '*'] + { let s = tok lexbuf in + check_comment s; start_line true; s ^ comment lexbuf } + | [ '*'] + { let s = tok lexbuf in + check_comment s; start_line true; s ^ comment lexbuf } | _ { start_line true; let s = tok lexbuf in Common.pr2 ("LEXER: unrecognised symbol in comment:"^s); diff --git a/parsing_cocci/lexer_script.mll b/parsing_cocci/lexer_script.mll index 512f905..1cab41c 100644 --- a/parsing_cocci/lexer_script.mll +++ b/parsing_cocci/lexer_script.mll @@ -26,16 +26,19 @@ module D = Data module Ast = Ast_cocci exception Lexical of string let tok = Lexing.lexeme +let inc_line _ = Lexer_cocci.line := !Lexer_cocci.line + 1 } (* ---------------------------------------------------------------------- *) (* tokens *) -let myrule = [^'"''@']+ +let myrule = [^'"''@''/''\n''\r''\011''\012']+ rule token = parse - | myrule { TScriptData (tok lexbuf) } + | myrule { TScriptData (tok lexbuf) } + | ['\n' '\r' '\011' '\012'] { inc_line(); TScriptData (tok lexbuf) } | "@@" { TArobArob } | "@" { TArob } + | "/" { TScriptData (tok lexbuf) } | "//" [^ '\n']* { token lexbuf } (* skip SmPL comments *) | '"' { TScriptData (Printf.sprintf "\"%s\"" (string lexbuf)) } | eof { EOF } diff --git a/parsing_cocci/type_infer.ml b/parsing_cocci/type_infer.ml index 1fc1e1c..04b0ca7 100644 --- a/parsing_cocci/type_infer.ml +++ b/parsing_cocci/type_infer.ml @@ -189,15 +189,21 @@ let rec propagate_types env = Ast0.set_type exp1 ty; Ast0.set_type exp2 ty; ty in (match Ast0.unwrap_mcode op with Ast.Arith(op) -> same_type (ty1, ty2) + | Ast.Logical(Ast.AndLog) | Ast.Logical(Ast.OrLog) -> + Some(bool_type) | Ast.Logical(op) -> let ty = lub_type ty1 ty2 in - Ast0.set_type exp1 ty; Ast0.set_type exp2 ty; - Some(bool_type)) + Ast0.set_type exp1 ty; Ast0.set_type exp2 ty; + Some(bool_type)) | Ast0.Paren(lp,exp,rp) -> Ast0.get_type exp | Ast0.ArrayAccess(exp1,lb,exp2,rb) -> (match strip_cv (Ast0.get_type exp2) with None -> Ast0.set_type exp2 (Some(int_type)) | Some(ty) when is_int_type ty -> () + | Some(Type_cocci.Unknown) -> + (* unknown comes from param types, not sure why this + is not just None... *) + Ast0.set_type exp2 (Some(int_type)) | Some ty -> err exp2 ty "bad type for an array index"); (match strip_cv (Ast0.get_type exp1) with None -> None diff --git a/test.ml b/test.ml index 02d038d..8ee1f16 100644 --- a/test.ml +++ b/test.ml @@ -64,6 +64,28 @@ *) +(* + * Copyright 2005-2010, Ecole des Mines de Nantes, University of Copenhagen + * Yoann Padioleau, Julia Lawall, Rene Rydhof Hansen, Henrik Stuart, Gilles Muller, Nicolas Palix + * This file is part of Coccinelle. + * + * Coccinelle is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, according to version 2 of the License. + * + * Coccinelle is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Coccinelle. If not, see . + * + * The authors reserve the right to distribute this or future versions of + * Coccinelle under other licenses. + *) + + (* * Copyright 2005-2009, Ecole des Mines de Nantes, University of Copenhagen * Yoann Padioleau, Julia Lawall, Rene Rydhof Hansen, Henrik Stuart, Gilles Muller, Nicolas Palix -- 2.20.1