Coccinelle release 0.2.5-rc8
[bpt/coccinelle.git] / parsing_cocci / free_vars.ml
index 32d2584..9313c3a 100644 (file)
@@ -98,11 +98,16 @@ let collect_refs include_constraints =
              | _ -> []
            else [] in
          bind (List.rev metas) [metaid name]
              | _ -> []
            else [] in
          bind (List.rev metas) [metaid name]
+      | Ast.DisjId(ids) -> bind_disj (List.map k ids)
       | _ -> option_default) in
 
   let rec type_collect res = function
       TC.ConstVol(_,ty) | TC.Pointer(ty) | TC.FunctionPointer(ty)
     | TC.Array(ty) -> type_collect res ty
       | _ -> option_default) in
 
   let rec type_collect res = function
       TC.ConstVol(_,ty) | TC.Pointer(ty) | TC.FunctionPointer(ty)
     | TC.Array(ty) -> type_collect res ty
+    | TC.EnumName(TC.MV(tyname,_,_)) ->
+       bind [tyname] res
+    | TC.StructUnionName(_,TC.MV(tyname,_,_)) ->
+       bind [tyname] res
     | TC.MetaType(tyname,_,_) ->
        bind [tyname] res
     | TC.SignedT(_,Some ty) -> type_collect res ty
     | TC.MetaType(tyname,_,_) ->
        bind [tyname] res
     | TC.SignedT(_,Some ty) -> type_collect res ty
@@ -141,6 +146,10 @@ let collect_refs include_constraints =
     bind (k d)
       (match Ast.unwrap d with
        Ast.MetaDecl(name,_,_) | Ast.MetaField(name,_,_) -> [metaid name]
     bind (k d)
       (match Ast.unwrap d with
        Ast.MetaDecl(name,_,_) | Ast.MetaField(name,_,_) -> [metaid name]
+      | Ast.MetaFieldList(name,Ast.MetaListLen(lenname,_,_),_,_) ->
+         [metaid name;metaid lenname]
+      | Ast.MetaFieldList(name,_,_,_) ->
+         [metaid name]
       | Ast.DisjDecl(decls) -> bind_disj (List.map k decls)
       | _ -> option_default) in
 
       | Ast.DisjDecl(decls) -> bind_disj (List.map k decls)
       | _ -> option_default) in
 
@@ -197,7 +206,7 @@ let collect_refs include_constraints =
 
   V.combiner bind option_default
     mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode
 
   V.combiner bind option_default
     mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode
-    donothing donothing donothing donothing
+    donothing donothing donothing donothing donothing
     astfvident astfvexpr astfvfullType astfvtypeC astfvinit astfvparam
     astfvdecls astfvrule_elem astfvstatement donothing donothing donothing_a
 
     astfvident astfvexpr astfvfullType astfvtypeC astfvinit astfvparam
     astfvdecls astfvrule_elem astfvstatement donothing donothing donothing_a
 
@@ -226,13 +235,16 @@ let collect_saved =
       (match Ast.unwrap i with
        Ast.MetaId(name,_,TC.Saved,_)
       | Ast.MetaFunc(name,_,TC.Saved,_)
       (match Ast.unwrap i with
        Ast.MetaId(name,_,TC.Saved,_)
       | Ast.MetaFunc(name,_,TC.Saved,_)
-      | Ast.MetaLocalFunc(name,_,TC.Saved,_) ->
-         [metaid name]
+      | Ast.MetaLocalFunc(name,_,TC.Saved,_) -> [metaid name]
       | _ -> option_default) in
 
   let rec type_collect res = function
       TC.ConstVol(_,ty) | TC.Pointer(ty) | TC.FunctionPointer(ty)
     | TC.Array(ty) -> type_collect res ty
       | _ -> option_default) in
 
   let rec type_collect res = function
       TC.ConstVol(_,ty) | TC.Pointer(ty) | TC.FunctionPointer(ty)
     | TC.Array(ty) -> type_collect res ty
+    | TC.EnumName(TC.MV(tyname,TC.Saved,_)) ->
+       bind [tyname] res
+    | TC.StructUnionName(_,TC.MV(tyname,TC.Saved,_)) ->
+       bind [tyname] res
     | TC.MetaType(tyname,TC.Saved,_) ->
        bind [tyname] res
     | TC.SignedT(_,Some ty) -> type_collect res ty
     | TC.MetaType(tyname,TC.Saved,_) ->
        bind [tyname] res
     | TC.SignedT(_,Some ty) -> type_collect res ty
@@ -281,7 +293,7 @@ let collect_saved =
          let lensaved =
            match ls with TC.Saved -> [metaid lenname] | _ -> [] in
          lensaved @ namesaved
          let lensaved =
            match ls with TC.Saved -> [metaid lenname] | _ -> [] in
          lensaved @ namesaved
-      | Ast.MetaParamList(name,_,_,_) -> [metaid name]
+      | Ast.MetaParamList(name,_,TC.Saved,_) -> [metaid name]
       | _ -> option_default) in
 
   let astfvdecls recursor k d =
       | _ -> option_default) in
 
   let astfvdecls recursor k d =
@@ -289,6 +301,13 @@ let collect_saved =
       (match Ast.unwrap d with
        Ast.MetaDecl(name,TC.Saved,_) | Ast.MetaField(name,TC.Saved,_) ->
          [metaid name]
       (match Ast.unwrap d with
        Ast.MetaDecl(name,TC.Saved,_) | Ast.MetaField(name,TC.Saved,_) ->
          [metaid name]
+      | Ast.MetaFieldList(name,Ast.MetaListLen (lenname,ls,_),ns,_) ->
+         let namesaved =
+           match ns with TC.Saved -> [metaid name] | _ -> [] in
+         let lensaved =
+           match ls with TC.Saved -> [metaid lenname] | _ -> [] in
+         lensaved @ namesaved
+      | Ast.MetaFieldList(name,_,TC.Saved,_) -> [metaid name]
       | _ -> option_default) in
 
   let astfvrule_elem recursor k re =
       | _ -> option_default) in
 
   let astfvrule_elem recursor k re =
@@ -307,7 +326,7 @@ let collect_saved =
 
   V.combiner bind option_default
     mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode
 
   V.combiner bind option_default
     mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode
-    donothing donothing donothing donothing
+    donothing donothing donothing donothing donothing
     astfvident astfvexpr donothing astfvtypeC astfvinit astfvparam
     astfvdecls astfvrule_elem donothing donothing donothing donothing
 
     astfvident astfvexpr donothing astfvtypeC astfvinit astfvparam
     astfvdecls astfvrule_elem donothing donothing donothing donothing
 
@@ -420,7 +439,7 @@ let collect_in_plus_term =
 
   V.combiner bind option_default
     mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode
 
   V.combiner bind option_default
     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
     donothing astfvrule_elem astfvstatement donothing donothing donothing
 
     donothing donothing donothing donothing donothing donothing
     donothing astfvrule_elem astfvstatement donothing donothing donothing
 
@@ -491,6 +510,12 @@ let classify_variables metavar_decls minirules used_after =
     | TC.Pointer(ty) -> TC.Pointer(type_infos ty)
     | TC.FunctionPointer(ty) -> TC.FunctionPointer(type_infos ty)
     | TC.Array(ty) -> TC.Array(type_infos ty)
     | TC.Pointer(ty) -> TC.Pointer(type_infos ty)
     | TC.FunctionPointer(ty) -> TC.FunctionPointer(type_infos ty)
     | TC.Array(ty) -> TC.Array(type_infos ty)
+    | TC.EnumName(TC.MV(name,_,_)) ->
+       let (unitary,inherited) = classify (name,(),(),Ast.NoMetaPos) in
+       TC.EnumName(TC.MV(name,unitary,inherited))
+    | TC.StructUnionName(su,TC.MV(name,_,_)) ->
+       let (unitary,inherited) = classify (name,(),(),Ast.NoMetaPos) in
+       TC.StructUnionName(su,TC.MV(name,unitary,inherited))
     | TC.MetaType(name,_,_) ->
        let (unitary,inherited) = classify (name,(),(),Ast.NoMetaPos) in
        Type_cocci.MetaType(name,unitary,inherited)
     | TC.MetaType(name,_,_) ->
        let (unitary,inherited) = classify (name,(),(),Ast.NoMetaPos) in
        Type_cocci.MetaType(name,unitary,inherited)
@@ -567,6 +592,16 @@ let classify_variables metavar_decls minirules used_after =
     | Ast.MetaField(name,_,_) ->
        let (unitary,inherited) = classify name in
        Ast.rewrap e (Ast.MetaField(name,unitary,inherited))
     | Ast.MetaField(name,_,_) ->
        let (unitary,inherited) = classify name in
        Ast.rewrap e (Ast.MetaField(name,unitary,inherited))
+    | Ast.MetaFieldList(name,Ast.MetaListLen (lenname,_,_),_,_) ->
+       let (unitary,inherited) = classify name in
+       let (lenunitary,leninherited) = classify lenname in
+       Ast.rewrap e
+         (Ast.MetaFieldList
+            (name,Ast.MetaListLen(lenname,lenunitary,leninherited),
+             unitary,inherited))
+    | Ast.MetaFieldList(name,lenname,_,_) ->
+       let (unitary,inherited) = classify name in
+       Ast.rewrap e (Ast.MetaFieldList(name,lenname,unitary,inherited))
     | _ -> e in
 
   let rule_elem r k e =
     | _ -> e in
 
   let rule_elem r k e =
@@ -582,7 +617,7 @@ let classify_variables metavar_decls minirules used_after =
 
   let fn = V.rebuilder
       mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode
 
   let fn = V.rebuilder
       mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode
-      donothing donothing donothing donothing
+      donothing donothing donothing donothing donothing
       ident expression donothing typeC init param decl rule_elem
       donothing donothing donothing donothing in
 
       ident expression donothing typeC init param decl rule_elem
       donothing donothing donothing donothing in
 
@@ -714,7 +749,7 @@ let astfvs metavars bound =
 
   V.rebuilder
     mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode
 
   V.rebuilder
     mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode
-    donothing donothing astfvstatement_dots donothing
+    donothing donothing astfvstatement_dots donothing donothing
     donothing donothing donothing donothing donothing donothing donothing
     astfvrule_elem astfvstatement astfvcase_line astfvtoplevel donothing
 
     donothing donothing donothing donothing donothing donothing donothing
     astfvrule_elem astfvstatement astfvcase_line astfvtoplevel donothing
 
@@ -776,7 +811,7 @@ let get_neg_pos_list (_,rule) used_after_list =
   let v =
     V.combiner bind option_default
     mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode
   let v =
     V.combiner bind option_default
     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
     donothing donothing donothing donothing donothing donothing in
   match rule with
     donothing donothing donothing donothing donothing donothing
     donothing donothing donothing donothing donothing donothing in
   match rule with