Coccinelle release 0.2.5-rc5
[bpt/coccinelle.git] / parsing_cocci / type_infer.ml
index 7a24026..51e6ebe 100644 (file)
@@ -107,6 +107,14 @@ let rec propagate_types env =
     | Ast0.MetaId(id,_,_) ->
        (try Some(List.assoc (Meta(Ast0.unwrap_mcode id)) env)
        with Not_found -> None)
+    | Ast0.DisjId(_,id_list,_,_) ->
+       let types = List.map Ast0.get_type id_list in
+       let combined = List.fold_left lub_type None types in
+       (match combined with
+         None -> None
+       | Some t ->
+           List.iter (function i -> Ast0.set_type i (Some t)) id_list;
+           Some t)
     | _ -> k i in
 
   let strip_cv = function
@@ -274,10 +282,11 @@ let rec propagate_types env =
 
   let rec strip id =
     match Ast0.unwrap id with
-      Ast0.Id(name)                -> Id(Ast0.unwrap_mcode name)
-    | Ast0.MetaId(name,_,_)        -> Meta(Ast0.unwrap_mcode name)
-    | Ast0.MetaFunc(name,_,_)      -> Meta(Ast0.unwrap_mcode name)
-    | Ast0.MetaLocalFunc(name,_,_) -> Meta(Ast0.unwrap_mcode name)
+      Ast0.Id(name)                -> [Id(Ast0.unwrap_mcode name)]
+    | Ast0.MetaId(name,_,_)        -> [Meta(Ast0.unwrap_mcode name)]
+    | Ast0.MetaFunc(name,_,_)      -> [Meta(Ast0.unwrap_mcode name)]
+    | Ast0.MetaLocalFunc(name,_,_) -> [Meta(Ast0.unwrap_mcode name)]
+    | Ast0.DisjId(_,id_list,_,_)   -> List.concat (List.map strip id_list)
     | Ast0.OptIdent(id)            -> strip id
     | Ast0.UniqueIdent(id)         -> strip id in
 
@@ -322,9 +331,11 @@ let rec propagate_types env =
     | Ast0.Init(_,ty,id,_,exp,_) ->
        let _ =
          (propagate_types env).VT0.combiner_rec_initialiser exp in
-       [(strip id,Ast0.ast0_type_to_type ty)]
+       let ty = Ast0.ast0_type_to_type ty in
+       List.map (function i -> (i,ty)) (strip id)
     | Ast0.UnInit(_,ty,id,_) ->
-       [(strip id,Ast0.ast0_type_to_type ty)]
+       let ty = Ast0.ast0_type_to_type ty in
+       List.map (function i -> (i,ty)) (strip id)
     | Ast0.MacroDecl(_,_,_,_,_) -> []
     | Ast0.TyDecl(ty,_) -> []
               (* pad: should handle typedef one day and add a binding *)
@@ -364,7 +375,8 @@ let rec propagate_types env =
        let rec get_binding p =
          match Ast0.unwrap p with
            Ast0.Param(ty,Some id) ->
-             [(strip id,Ast0.ast0_type_to_type ty)]
+             let ty = Ast0.ast0_type_to_type ty in
+             List.map (function i -> (i,ty)) (strip id)
          | Ast0.OptParam(param) -> get_binding param
          | _ -> [] in
        let fenv = List.concat (List.map get_binding (Ast0.undots params)) in