X-Git-Url: https://git.hcoop.net/bpt/coccinelle.git/blobdiff_plain/951c78018cc91c58699aef95c0ccc20f34065162..f537ebc4bbd27866c9ac3e1198b6756ebab7f2ba:/parsing_cocci/insert_plus.ml diff --git a/parsing_cocci/insert_plus.ml b/parsing_cocci/insert_plus.ml index 792c78c..e19ab82 100644 --- a/parsing_cocci/insert_plus.ml +++ b/parsing_cocci/insert_plus.ml @@ -1,4 +1,6 @@ (* + * Copyright 2010, INRIA, University of Copenhagen + * Julia Lawall, Rene Rydhof Hansen, Gilles Muller, Nicolas Palix * Copyright 2005-2009, Ecole des Mines de Nantes, University of Copenhagen * Yoann Padioleau, Julia Lawall, Rene Rydhof Hansen, Henrik Stuart, Gilles Muller, Nicolas Palix * This file is part of Coccinelle. @@ -158,7 +160,7 @@ let collect_minus_join_points root = let bind x y = x @ y in let option_default = [] in - let mcode (_,_,info,mcodekind,_,_) = + let mcode (x,_,info,mcodekind,_,_) = if List.mem (info.Ast0.pos_info.Ast0.offset) unfavored_tokens then [(Unfavored,info,mcodekind)] else [(Favored,info,mcodekind)] in @@ -390,7 +392,7 @@ let verify l = then failwith (Printf.sprintf - "error in collection of - tokens %d less than %d" + "error in collection of - tokens: line %d less than line %d" (token_real_start_line cur) real_prev); (token_end_line cur,token_real_end_line cur)) (token_end_line (List.hd l1), token_real_end_line (List.hd l1)) @@ -400,6 +402,7 @@ let verify l = l let process_minus minus = + Hashtbl.clear root_token_table; create_root_token_table minus; List.concat (List.map @@ -697,7 +700,12 @@ let decl = function Decl -> true | Favored | Unfavored | Toplevel -> false let favored = function Favored -> true | Unfavored | Toplevel | Decl -> false let top_code = - List.for_all (List.for_all (function Ast.Code _ -> true | _ -> false)) + List.for_all + (List.for_all (function Ast.Code _ | Ast.Pragma _ -> true | _ -> false)) + +let storage_code = + List.for_all + (List.for_all (function Ast.StorageTag _ -> true | _ -> false)) (* The following is probably not correct. The idea is to detect what should be placed completely before the declaration. So type/storage @@ -847,16 +855,22 @@ let allminus = function let rec before_m1 ((f1,infom1,m1) as x1) ((f2,infom2,m2) as x2) rest = function [] -> () - | (((infop,_,_) as p) :: ps) as all -> + | (((infop,_,pcode) as p) :: ps) as all -> if less_than_start infop infom1 or (allminus m1 && less_than_end infop infom1) (* account for trees *) then - if good_start infom1 - then (attachbefore p m1; before_m1 x1 x2 rest ps) + if toplevel f1 + then + if storage_code pcode + then before_m2 x2 rest all (* skip fake token for storage *) + else (attachbefore p m1; before_m1 x1 x2 rest ps) else - failwith - (pr "%d: no available token to attach to" - infop.Ast0.pos_info.Ast0.line_start) + if good_start infom1 + then (attachbefore p m1; before_m1 x1 x2 rest ps) + else + failwith + (pr "%d: no available token to attach to" + infop.Ast0.pos_info.Ast0.line_start) else after_m1 x1 x2 rest all and after_m1 ((f1,infom1,m1) as x1) ((f2,infom2,m2) as x2) rest = function @@ -957,7 +971,7 @@ let merge_one : (minus_join_point * Ast0.info * 'a) list * m; Printf.printf "plus code\n"; List.iter - (function (info,p) -> + (function (info,_,p) -> Printf.printf "start %d end %d real_start %d real_end %d\n" info.Ast0.pos_info.Ast0.logical_start info.Ast0.pos_info.Ast0.logical_end