- Try to do better pretty printing when array elements are individually
[bpt/coccinelle.git] / parsing_c / type_annoter_c.ml
index 46d3abd..d4fd615 100644 (file)
@@ -202,10 +202,10 @@ let initial_env = ref [
 
   (*
    VarOrFunc("malloc",
-            (Lib.al_type(Parse_c.type_of_string "void* (*)(int size)"),
+            (Lib.al_type(Parse_c.type_of_string "void* ( * )(int size)"),
            Ast_c.NotLocalVar));
    VarOrFunc("free",
-            (Lib.al_type(Parse_c.type_of_string "void (*)(void *ptr)"),
+            (Lib.al_type(Parse_c.type_of_string "void ( * )(void *ptr)"),
            Ast_c.NotLocalVar));
   *)
   ]
@@ -838,7 +838,6 @@ let annotater_expr_visitor_subpart = (fun (k,bigf) expr ->
     (* fields *)
     | RecordAccess  (e, namefld)
     | RecordPtAccess (e, namefld) as x ->
-
         let fld = Ast_c.str_of_name namefld in
 
         k expr; (* recurse to set the types-ref of sub expressions *)
@@ -853,7 +852,7 @@ let annotater_expr_visitor_subpart = (fun (k,bigf) expr ->
                 | Pointer (t) -> Some t
                 | _ -> None
                 )
-            | _ -> raise Impossible
+            | _ -> raise (Impossible 159)
 
           in
           (match topt with
@@ -1097,8 +1096,17 @@ let rec visit_toplevel ~just_add_in_env ~depth elem =
              match (sto,local) with
              | (_,Ast_c.NotLocalDecl) -> Ast_c.NotLocalVar
              | ((Ast_c.Sto Ast_c.Static, _), Ast_c.LocalDecl) ->
-                 Ast_c.StaticLocalVar (Ast_c.info_of_type t)
-             | (_,Ast_c.LocalDecl) -> Ast_c.LocalVar (Ast_c.info_of_type t)
+                 (match Ast_c.info_of_type t with
+                   (* if there is no info about the type it must not be
+                      present, so we don't know what the variable is *)
+                   None -> Ast_c.NotLocalVar
+                 | Some ii -> Ast_c.StaticLocalVar ii)
+             | (_,Ast_c.LocalDecl) ->
+                 (match Ast_c.info_of_type t with
+                   (* if there is no info about the type it must not be
+                      present, so we don't know what the variable is *)
+                   None -> Ast_c.NotLocalVar
+                 | Some ii -> Ast_c.LocalVar ii)
             in
             var +> Common.do_option (fun (name, iniopt) ->
               let s = Ast_c.str_of_name name in
@@ -1124,7 +1132,7 @@ let rec visit_toplevel ~just_add_in_env ~depth elem =
                   end
             );
           );
-      | MacroDecl _ ->
+      | MacroDecl _ | MacroDeclInit _ ->
           if need_annotate_body
           then k d
       );
@@ -1193,7 +1201,7 @@ let rec visit_toplevel ~just_add_in_env ~depth elem =
                *)
             | iifunc1::iifunc2::ibrace1::ibrace2::ifakestart::isto ->
                 iifunc1, iifunc2
-            | _ -> raise Impossible
+            | _ -> raise (Impossible 160)
           in
           let funcs = Ast_c.str_of_name name in
 
@@ -1211,7 +1219,14 @@ let rec visit_toplevel ~just_add_in_env ~depth elem =
                     match nameopt with
                     | Some name ->
                         let s = Ast_c.str_of_name name in
-                       let local = Ast_c.LocalVar (Ast_c.info_of_type t) in
+                       let local =
+                         (match Ast_c.info_of_type t with
+                           (* if there is no info about the type it must
+                              not be present, so we don't know what the
+                              variable is *)
+                           None -> Ast_c.NotLocalVar
+                         | Some ii -> Ast_c.LocalVar ii)
+                       in
                        add_binding (VarOrFunc (s,(Lib.al_type t,local))) true
                     | None ->
                     pr2 "no type, certainly because Void type ?"