X-Git-Url: http://git.hcoop.net/bpt/coccinelle.git/blobdiff_plain/3a31414346dd7d7e8baa4cb8b804a2d5e1797962..65038c617fe3e5d7a284059fbfa78dddfbb9b9c4:/parsing_cocci/single_statement.ml diff --git a/parsing_cocci/single_statement.ml b/parsing_cocci/single_statement.ml index 9a5bc11..a5ed9dc 100644 --- a/parsing_cocci/single_statement.ml +++ b/parsing_cocci/single_statement.ml @@ -80,10 +80,10 @@ let modif_before x = | Ast0.MINUS mc -> (match !mc with (* do better for the common case of replacing a stmt by another one *) - ([[Ast.StatementTag(s)]],ti) -> + ((Ast.REPLACEMENT([[Ast.StatementTag(s)]],c)) as old,ti) -> (match Ast.unwrap s with Ast.IfThen(_,_,_) -> true (* potentially dangerous *) - | _ -> mc := ([[Ast.StatementTag(s)]],ti); false) + | _ -> mc := (old,ti); false) | (_,_) -> true) | Ast0.CONTEXT mc | Ast0.MIXED mc -> (match !mc with @@ -97,11 +97,11 @@ let modif_after x = | Ast0.MINUS mc -> (match !mc with (* do better for the common case of replacing a stmt by another one *) - ([[Ast.StatementTag(s)]],ti) -> + ((Ast.REPLACEMENT([[Ast.StatementTag(s)]],count)) as old,ti) -> (match Ast.unwrap s with Ast.IfThen(_,_,_) -> true (* potentially dangerous *) - | _ -> mc := ([[Ast.StatementTag(s)]],ti); false) - | (l,_) when any_statements l -> true + | _ -> mc := (old,ti); false) + | (Ast.REPLACEMENT(l,_),_) when any_statements l -> true | (l,ti) -> mc := (l,ti); false) | Ast0.CONTEXT mc | Ast0.MIXED mc -> (match !mc with @@ -114,9 +114,10 @@ let rec left_ident i = modif_before i or match Ast0.unwrap i with Ast0.Id(name) -> modif_before_mcode name - | Ast0.MetaId(name,_,_) -> modif_before_mcode name + | Ast0.MetaId(name,_,_,_) -> modif_before_mcode name | Ast0.MetaFunc(name,_,_) -> modif_before_mcode name | Ast0.MetaLocalFunc(name,_,_) -> modif_before_mcode name + | Ast0.DisjId(_,id_list,_,_) -> List.exists left_ident id_list | Ast0.OptIdent(id) -> left_ident id | Ast0.UniqueIdent(id) -> left_ident id @@ -124,9 +125,10 @@ let rec right_ident i = modif_after i or match Ast0.unwrap i with Ast0.Id(name) -> modif_after_mcode name - | Ast0.MetaId(name,_,_) -> modif_after_mcode name + | Ast0.MetaId(name,_,_,_) -> modif_after_mcode name | Ast0.MetaFunc(name,_,_) -> modif_after_mcode name | Ast0.MetaLocalFunc(name,_,_) -> modif_after_mcode name + | Ast0.DisjId(_,id_list,_,_) -> List.exists right_ident id_list | Ast0.OptIdent(id) -> right_ident id | Ast0.UniqueIdent(id) -> right_ident id @@ -197,7 +199,9 @@ and left_typeC t = and left_declaration d = modif_before d or match Ast0.unwrap d with - Ast0.MetaDecl(name,_) | Ast0.MetaField(name,_) -> modif_before_mcode name + Ast0.MetaDecl(name,_) | Ast0.MetaField(name,_) + | Ast0.MetaFieldList(name,_,_) -> + modif_before_mcode name | Ast0.Init(Some stg,ty,id,eq,ini,sem) -> modif_before_mcode stg | Ast0.Init(None,ty,id,eq,ini,sem) -> left_typeC ty | Ast0.UnInit(Some stg,ty,id,sem) -> modif_before_mcode stg @@ -213,7 +217,9 @@ and left_declaration d = and right_declaration d = modif_before d or match Ast0.unwrap d with - Ast0.MetaDecl(name,_) | Ast0.MetaField(name,_) -> modif_before_mcode name + Ast0.MetaDecl(name,_) | Ast0.MetaField(name,_) + | Ast0.MetaFieldList(name,_,_) -> + modif_before_mcode name | Ast0.Init(_,ty,id,eq,ini,sem) -> modif_after_mcode sem | Ast0.UnInit(_,ty,id,sem) -> modif_after_mcode sem | Ast0.MacroDecl(name,lp,args,rp,sem) -> modif_after_mcode sem @@ -234,7 +240,8 @@ and left_statement s = (* irrelevant *) false | Ast0.Decl(_,decl) -> left_declaration decl | Ast0.Seq(lbrace,body,rbrace) -> modif_before_mcode lbrace - | Ast0.ExprStatement(exp,sem) -> left_expression exp + | Ast0.ExprStatement(Some exp,sem) -> left_expression exp + | Ast0.ExprStatement(None,sem) -> modif_before_mcode sem | Ast0.IfThen(iff,lp,exp,rp,branch1,(info,aft)) -> modif_before_mcode iff | Ast0.IfThenElse(iff,lp,exp,rp,branch1,els,branch2,(info,aft)) -> modif_before_mcode iff @@ -322,10 +329,10 @@ let rec adding_something s = Ast0.MINUS(mc) -> (match !mc with (* do better for the common case of replacing a stmt by another one *) - ([[Ast.StatementTag(s)]],ti) -> + ((Ast.REPLACEMENT([[Ast.StatementTag(s)]],c)) as old,ti) -> (match Ast.unwrap s with Ast.IfThen(_,_,_) -> true (* potentially dangerous *) - | _ -> mc := ([[Ast.StatementTag(s)]],ti); false) + | _ -> mc := (old,ti); false) | (_,_) -> true) | Ast0.CONTEXT(mc) -> let (text,tinfo1,tinfo2) = !mc in @@ -342,7 +349,7 @@ and contains_only_minus = let mcodekind = function Ast0.MINUS(mc) -> (match !mc with - ([],_) -> true + (Ast.NOREPLACEMENT,_) -> true | _ -> false) | Ast0.CONTEXT(mc) -> false | _ -> false in @@ -355,6 +362,13 @@ and contains_only_minus = Ast0.DOTS([]) | Ast0.CIRCLES([]) | Ast0.STARS([]) -> true | _ -> k e in + let identifier r k e = + mcodekind (Ast0.get_mcodekind e) && + match Ast0.unwrap e with + Ast0.DisjId(starter,id_list,mids,ender) -> + List.for_all r.VT0.combiner_rec_ident id_list + | _ -> k e in + let expression r k e = mcodekind (Ast0.get_mcodekind e) && match Ast0.unwrap e with @@ -393,7 +407,7 @@ and contains_only_minus = V0.flat_combiner bind option_default mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode dots dots dots dots dots dots - donothing expression typeC donothing donothing declaration + identifier expression typeC donothing donothing declaration statement case_line donothing @@ -420,7 +434,14 @@ let add_braces orig_s = match Ast0.get_mcodekind s with Ast0.MINUS(mc) -> let (text,tinfo) = !mc in - Ast0.MINUS(ref([Ast.mkToken "{"]::text@[[Ast.mkToken "}"]],tinfo)) + let inner_text = + match text with + Ast.NOREPLACEMENT -> [[Ast.mkToken "{}"]] + | Ast.REPLACEMENT(anythings,Ast.ONE) -> + [Ast.mkToken "{"]::anythings@[[Ast.mkToken "}"]] + | Ast.REPLACEMENT(anythings,Ast.MANY) -> + failwith "++ not supported when braces must be added" in + Ast0.MINUS(ref(Ast.REPLACEMENT(inner_text,Ast.ONE),tinfo)) | Ast0.CONTEXT(mc) -> let (text,tinfo1,tinfo2) = !mc in let new_text = @@ -478,7 +499,8 @@ let all_minus s = let rec unchanged_minus s = match Ast0.get_mcodekind s with - Ast0.MINUS(mc) -> (match !mc with ([],_) -> true | _ -> false) + Ast0.MINUS(mc) -> + (match !mc with (Ast.NOREPLACEMENT,_) -> true | _ -> false) | _ -> false let rec do_branch s = @@ -638,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)