X-Git-Url: https://git.hcoop.net/bpt/coccinelle.git/blobdiff_plain/e6509c05b4c77bb8fcffa7f454c1412fcc0c3a15..8babbc8f18fe06ec20e19630a1ec09e759c380e1:/parsing_cocci/check_meta.ml diff --git a/parsing_cocci/check_meta.ml b/parsing_cocci/check_meta.ml index 6fbf9c9..2e9850a 100644 --- a/parsing_cocci/check_meta.ml +++ b/parsing_cocci/check_meta.ml @@ -83,36 +83,50 @@ type context = ID | FIELD | FN | GLOBAL let is_ifdef name = String.length name > 2 && String.uppercase name = name -let ident context old_metas table minus i = +let rec ident context old_metas table minus i = match Ast0.unwrap i with - Ast0.Id((name,_,info,_,_,_) : string Ast0.mcode) -> - let rl = info.Ast0.pos_info.Ast0.line_start in - let is_plus i = - match Ast0.get_mcodekind i with Ast0.PLUS _ -> true | _ -> false in - let err = - if List.exists (function x -> x = name) old_metas + Ast0.Id((name,_,info,_,_,_) : string Ast0.mcode) -> + let rl = info.Ast0.pos_info.Ast0.line_start in + let is_plus i = + match Ast0.get_mcodekind i with Ast0.PLUS _ -> true | _ -> false in + let err = + if List.exists (function x -> x = name) old_metas && (minus || is_plus i) + then + begin + warning + (Printf.sprintf + "line %d: %s, previously declared as a metavariable, is used as an identifier" rl name); + true + end + else false in + (match context with + ID -> + if not (is_ifdef name) && minus && not err(* warn only once per id *) then - begin - warning - (Printf.sprintf - "line %d: %s, previously declared as a metavariable, is used as an identifier" rl name); - true - end - else false in - (match context with - ID -> - if not (is_ifdef name) && minus && not err(* warn only once per id *) - then - warning - (Printf.sprintf "line %d: should %s be a metavariable?" rl name) - | _ -> ()) - | Ast0.MetaId(name,_,_) -> check_table table minus name - | Ast0.MetaFunc(name,_,_) -> check_table table minus name - | Ast0.MetaLocalFunc(name,_,_) -> check_table table minus name - | Ast0.OptIdent(_) | Ast0.UniqueIdent(_) -> - failwith "unexpected code" + warning + (Printf.sprintf "line %d: should %s be a metavariable?" rl name) + | _ -> ()) + | Ast0.MetaId(name,_,seedval,_) -> + check_table table minus name; + seed table minus seedval + | Ast0.MetaFunc(name,_,_) -> check_table table minus name + | Ast0.MetaLocalFunc(name,_,_) -> check_table table minus name + | Ast0.DisjId(_,id_list,_,_) -> + List.iter (ident context old_metas table minus) id_list + | Ast0.OptIdent(_) | Ast0.UniqueIdent(_) -> + failwith "unexpected code" +and seed table minus = function + Ast.NoVal -> () + | Ast.StringSeed _ -> () + | Ast.ListSeed elems -> + List.iter + (function + Ast.SeedString _ -> () + | Ast.SeedId name -> check_table table minus (promote name)) + elems + (* --------------------------------------------------------------------- *) (* Expression *) @@ -231,6 +245,11 @@ and declaration context old_metas table minus d = match Ast0.unwrap d with Ast0.MetaDecl(name,_) | Ast0.MetaField(name,_) -> check_table table minus name + | Ast0.MetaFieldList(name,Ast0.MetaListLen lenname,_) -> + check_table table minus name; + check_table table minus lenname + | Ast0.MetaFieldList(name,_,_) -> + check_table table minus name | Ast0.Init(stg,ty,id,eq,ini,sem) -> (match Ast0.unwrap ini with Ast0.InitExpr exp -> @@ -269,6 +288,11 @@ and initialiser old_metas table minus ini = match Ast0.unwrap ini with Ast0.MetaInit(name,_) -> check_table table minus name + | Ast0.MetaInitList(name,Ast0.MetaListLen lenname,_) -> + check_table table minus name; + check_table table minus lenname + | Ast0.MetaInitList(name,_,_) -> + check_table table minus name | Ast0.InitExpr(exp) -> expression ID old_metas table minus exp | Ast0.InitList(lb,initlist,rb,ordered) -> dots (initialiser old_metas table minus) initlist @@ -322,7 +346,8 @@ and statement old_metas table minus s = match Ast0.unwrap s with Ast0.Decl(_,decl) -> declaration ID old_metas table minus decl | Ast0.Seq(lbrace,body,rbrace) -> dots (statement old_metas table minus) body - | Ast0.ExprStatement(exp,sem) -> expression ID old_metas table minus exp + | Ast0.ExprStatement(exp,sem) -> + get_opt (expression ID old_metas table minus) exp | Ast0.IfThen(iff,lp,exp,rp,branch,_) -> expression ID old_metas table minus exp; statement old_metas table minus branch @@ -375,6 +400,8 @@ and statement old_metas table minus s = parameter_list old_metas table minus params; dots (statement old_metas table minus) body | Ast0.Include(inc,s) -> () (* no metavariables possible *) + | Ast0.Undef(def,id) -> + ident GLOBAL old_metas table minus id | Ast0.Define(def,id,params,body) -> ident GLOBAL old_metas table minus id; define_parameters old_metas table minus params; @@ -438,11 +465,11 @@ let rule old_metas table minus rules = let positions table rules = let mcode x = - match Ast0.get_pos x with - Ast0.MetaPos(name,constraints,_) -> + List.iter + (function Ast0.MetaPos(name,constraints,_) -> let pos = Ast0.unwrap_mcode name in - (find_loop table pos) := true - | _ -> () in + (find_loop table pos) := true) + (Ast0.get_pos x) in let option_default = () in let bind x y = () in let donothing r k e = k e in @@ -457,10 +484,9 @@ let positions table rules = let dup_positions rules = let mcode x = - match Ast0.get_pos x with - Ast0.MetaPos(name,constraints,_) -> - let pos = Ast0.unwrap_mcode name in [pos] - | _ -> [] in + List.map + (function Ast0.MetaPos(name,constraints,_) -> Ast0.unwrap_mcode name) + (Ast0.get_pos x) in let option_default = [] in let bind x y = x@y in