Coccinelle release 1.0.0c7.
[bpt/coccinelle.git] / parsing_c / unparse_cocci.ml
index c4a4e0d..ca08fd9 100644 (file)
@@ -42,7 +42,7 @@ let unknown = -1
 
 let rec do_all
     (env, pr, pr_celem, pr_cspace, pr_space, pr_arity, pr_barrier,
-     indent, unindent)
+     indent, unindent, eatspace)
     generating xxs before =
 
 (* Just to be able to copy paste the code from pretty_print_cocci.ml. *)
@@ -182,7 +182,9 @@ let mcode fn (s,info,mc,pos) =
       force_newline();
       print_text "- ";
       fn s line lcol; print_pos pos;
-      print_anything plus_stream
+      (match plus_stream with
+       Ast.NOREPLACEMENT -> ()
+      |        Ast.REPLACEMENT(plus_stream,ct) -> print_anything plus_stream)
   | (true, Ast.CONTEXT(_,plus_streams)) ->
       let fn s = force_newline(); fn s line lcol; print_pos pos in
       print_around fn s plus_streams
@@ -324,6 +326,9 @@ let rec expression e =
       mcode print_string_box lp; fullType ty; close_box();
       mcode print_string rp
   | Ast.TypeExp(ty) -> fullType ty
+  | Ast.Constructor(lp,ty,rp,init) ->
+      mcode print_string_box lp; fullType ty; close_box();
+      mcode print_string rp; initialiser true init
 
   | Ast.MetaErr(name,_,_,_) ->
       failwith "metaErr not handled"
@@ -387,6 +392,7 @@ and arg_expression e =
 
 and  unaryOp = function
     Ast.GetRef -> print_string "&"
+  | Ast.GetRefLabel -> print_string "&&"
   | Ast.DeRef -> print_string "*"
   | Ast.UnPlus -> print_string "+"
   | Ast.UnMinus -> print_string "-"
@@ -408,7 +414,7 @@ and  binaryOp = function
   | Ast.Logical(lop) -> logicalOp lop
 
 and  arithOp = function
-    Ast.Plus -> print_string "+"
+   Ast.Plus -> print_string "+"
   | Ast.Minus -> print_string "-"
   | Ast.Mul -> print_string "*"
   | Ast.Div -> print_string "/"
@@ -460,7 +466,8 @@ and typeC ty =
     Ast.BaseType(ty,strings) ->
       print_between pr_space (mcode print_string) strings
   | Ast.SignedT(sgn,ty) -> mcode sign sgn; print_option_prespace typeC ty
-  | Ast.Pointer(ty,star) -> fullType ty; ft_space ty; mcode print_string star
+  | Ast.Pointer(ty,star) ->
+      fullType ty; ft_space ty; mcode print_string star; eatspace()
   | Ast.FunctionPointer(ty,lp1,star,rp1,lp2,params,rp2) ->
       print_function_pointer (ty,lp1,star,rp1,lp2,params,rp2)
        (function _ -> ())
@@ -495,11 +502,15 @@ and baseType = function
     Ast.VoidType -> print_string "void"
   | Ast.CharType -> print_string "char"
   | Ast.ShortType -> print_string "short"
+  | Ast.ShortIntType -> print_string "short int"
   | Ast.IntType -> print_string "int"
   | Ast.DoubleType -> print_string "double"
+  | Ast.LongDoubleType -> print_string "long double"
   | Ast.FloatType -> print_string "float"
   | Ast.LongType -> print_string "long"
+  | Ast.LongIntType -> print_string "long int"
   | Ast.LongLongType -> print_string "long long"
+  | Ast.LongLongIntType -> print_string "long long int"
   | Ast.SizeType -> print_string "size_t "
   | Ast.SSizeType -> print_string "ssize_t "
   | Ast.PtrDiffType -> print_string "ptrdiff_t "
@@ -763,7 +774,7 @@ and rule_elem arity re =
       end_block(); pr_arity arity; mcode print_string brace
 
   | Ast.ExprStatement(exp,sem) ->
-      pr_arity arity; expression exp; mcode print_string sem
+      pr_arity arity; print_option expression exp; mcode print_string sem
 
   | Ast.IfHeader(iff,lp,exp,rp) ->
       pr_arity arity;
@@ -992,7 +1003,7 @@ and case_line arity c =
 let top_level t =
   match Ast.unwrap t with
     Ast.FILEINFO(old_file,new_file) -> raise CantBeInPlus
-  | Ast.DECL(stmt) -> statement "" stmt
+  | Ast.NONDECL(stmt) -> statement "" stmt
   | Ast.CODE(stmt_dots) -> dots force_newline (statement "") stmt_dots
   | Ast.ERRORWORDS(exps) -> raise CantBeInPlus
 in
@@ -1077,6 +1088,8 @@ let rec pp_any = function
   | Ast.SgrepEndTag(x) -> failwith "unexpected end tag"
 in
 
+(*Printf.printf "start of the function\n";*)
+
   anything := (function x -> let _ = pp_any x in ());
 
   (* todo? imitate what is in pretty_print_cocci ? *)
@@ -1146,10 +1159,12 @@ in
                  (match Ast.unwrap x with
                    Ast.IComma _ -> false
                  | _ -> true)
-             | Ast.Token(t,_) when List.mem t [",";";";"(";")"] -> false
+             | Ast.Token(t,_) when List.mem t [",";";";"(";")";".";"->"] ->
+                 false
              | _ -> true in
            let space_needed_after = function
-               Ast.Token(t,_) when List.mem t ["("] -> (*never needed*) false
+               Ast.Token(t,_)
+               when List.mem t ["(";".";"->"] -> (*never needed*) false
              | Ast.Token(t,_) when List.mem t ["if";"for";"while";"do"] ->
                  (* space always needed *)
                  pr_space(); false
@@ -1176,11 +1191,11 @@ in
       newline_after()
 
 let rec pp_list_list_any (envs, pr, pr_celem, pr_cspace, pr_space, pr_arity,
-                         pr_barrier, indent, unindent)
+                         pr_barrier, indent, unindent, eatspace)
     generating xxs before =
   List.iter
     (function env ->
       do_all (env, pr, pr_celem, pr_cspace, pr_space, pr_arity, pr_barrier,
-             indent, unindent)
+             indent, unindent, eatspace)
        generating xxs before)
     envs