Coccinelle release-1.0.0-rc11
[bpt/coccinelle.git] / parsing_c / parse_c.ml
index c47afda..15f43a7 100644 (file)
@@ -834,6 +834,7 @@ let parse_print_error_heuristic2 saved_typedefs saved_macros file =
   (* -------------------------------------------------- *)
   (* call lexer and get all the tokens *)
   (* -------------------------------------------------- *)
+
   LP.lexer_reset_typedef saved_typedefs;
   Parsing_hacks.ifdef_paren_cnt := 0;
 
@@ -1061,7 +1062,7 @@ let parse_cache file =
   if not !Flag_parsing_c.use_cache
   then parse_print_error_heuristic None None file
   else
-  let _ = pr2 "TOFIX: use_cache is not sensitive to changes in the considered macros, include files, etc" in
+  let _ = pr2_once "TOFIX: use_cache is not sensitive to changes in the considered macros, include files, etc" in
   let need_no_changed_files =
     (* should use Sys.argv.(0), would be safer. *)
 
@@ -1074,17 +1075,35 @@ let parse_cache file =
       *)
       !Config.std_h;
       *)
-    ]
-  in
+    ] in
   let need_no_changed_variables =
     (* could add some of the flags of flag_parsing_c.ml *)
-    []
-  in
+    [] in
   Common.cache_computation_robust_in_dir
-    !Flag_parsing_c.cache_prefix
-    file ".ast_raw"
+    !Flag_parsing_c.cache_prefix file ".ast_raw"
     (need_no_changed_files, need_no_changed_variables) ".depend_raw"
-    (fun () -> parse_print_error_heuristic None None file)
+    (fun () ->
+      (* check whether to clear the cache *)
+      (match (!Flag_parsing_c.cache_limit,!Flag_parsing_c.cache_prefix) with
+       (None,_) | (_,None) -> ()
+      |        (Some limit,Some prefix) ->
+         let count =
+           Common.cmd_to_list
+             (Printf.sprintf "test -e %s && find %s -name \"*_raw\" | wc -l"
+                prefix prefix) in
+         match count with
+           [c] ->
+             if int_of_string c >= limit
+             then
+               let _ =
+                 Sys.command
+                   (Printf.sprintf
+                      "find %s -name \"*_raw\" -exec /bin/rm {} \\;"
+                      prefix) in
+               ()
+         | _ -> ());
+      (* recompute *)
+      parse_print_error_heuristic None None file)