Problem solved.  A patch is below.

julia

diff -u -p a/commons/common.ml b/commons/common.ml
--- a/commons/common.ml 2010-05-24 08:06:28.000000000 +0200
+++ b/commons/common.ml 2010-08-29 17:56:13.000000000 +0200
@@ -3691,14 +3691,15 @@ let rec group_by_mapped_key fkey l =
 
 let (exclude_but_keep_attached: ('a -> bool) -> 'a list -> ('a * 'a list) 
list)=
  fun f xs ->
-   let rec aux_filter acc = function
-   | [] -> [] (* drop what was accumulated because nothing to attach to *)
+   let rec aux_filter acc ans = function
+   | [] -> (* drop what was accumulated because nothing to attach to *)
+       List.rev ans
    | x::xs ->
        if f x
-       then aux_filter (x::acc) xs
-       else (x, List.rev acc)::aux_filter [] xs
+       then aux_filter (x::acc) ans xs
+       else aux_filter [] ((x, List.rev acc)::ans) xs
    in
-   aux_filter [] xs
+   aux_filter [] [] xs
 let _ = example
   (exclude_but_keep_attached (fun x -> x =|= 3) [3;3;1;3;2;3;3;3] =*=
       [(1,[3;3]);(2,[3])])
@@ -5235,6 +5236,12 @@ let head = List.hd
 let tail = List.tl
 let is_singleton = fun xs -> List.length xs =|= 1
 
+let tail_map f l = (* tail recursive map, using rev *)
+  let rec loop acc = function
+      [] -> acc
+    | x::xs -> loop ((f x) :: acc) xs in
+  List.rev(loop [] l)
+
 (*****************************************************************************)
 (* Geometry (raytracer) *)
 (*****************************************************************************)
diff -u -p a/commons/common.mli b/commons/common.mli
--- a/commons/common.mli        2010-01-28 15:25:04.000000000 +0100
+++ b/commons/common.mli        2010-08-29 17:29:56.000000000 +0200
@@ -1757,6 +1757,7 @@ val empty_graph : 'a list * 'b list
 (* mostly alias to functions in List *)
 
 val map : ('a -> 'b) -> 'a list -> 'b list
+val tail_map : ('a -> 'b) -> 'a list -> 'b list
 val filter : ('a -> bool) -> 'a list -> 'a list
 val fold : ('a -> 'b -> 'a) -> 'a -> 'b list -> 'a
 
diff -u -p a/parsing_c/parse_c.ml b/parsing_c/parse_c.ml
--- a/parsing_c/parse_c.ml      2010-01-28 15:25:06.000000000 +0100
+++ b/parsing_c/parse_c.ml      2010-08-29 17:30:50.000000000 +0200
@@ -613,7 +613,7 @@ let get_one_elem ~pass tr (file, filelin
       (* Call parser *)
       (* -------------------------------------------------- *)
       Common.profile_code_exclusif "YACC" (fun () ->
-        Left (Parser_c.celem (lexer_function ~pass tr) lexbuf_fake)
+       Left (Parser_c.celem (lexer_function ~pass tr) lexbuf_fake)
       )
     with e ->
       LP.restore_typedef_state();
@@ -691,7 +691,7 @@ let find_optional_macro_to_expand2 ~defs
 
   let defs = Common.hash_of_list defs in
 
-  let toks = toks +> Common.map (function
+  let toks = toks +> Common.tail_map (function
 
     (* special cases to undo *)
     | Parser_c.TMacroIterator (s, ii) ->
_______________________________________________
Cocci mailing list
[email protected]
http://lists.diku.dk/mailman/listinfo/cocci
(Web access from inside DIKUs LAN only)

Reply via email to