Release coccinelle-0.2.5-rc1
[bpt/coccinelle.git] / parsing_c / unparse_cocci.ml
index d5f24ef..4a75d68 100644 (file)
@@ -287,7 +287,7 @@ let rec expression e =
   | Ast.CondExpr(exp1,why,exp2,colon,exp3) ->
       expression exp1; pr_space(); mcode print_string why;
       print_option (function e -> pr_space(); expression e) exp2;
-      pr_space(); mcode print_string colon; expression exp3
+      pr_space(); mcode print_string colon; pr_space(); expression exp3
   | Ast.Postfix(exp,op) -> expression exp; mcode fixOp op
   | Ast.Infix(exp,op) -> mcode fixOp op; expression exp
   | Ast.Unary(exp,op) -> mcode unaryOp op; expression exp
@@ -460,8 +460,14 @@ and typeC ty =
   | Ast.Array(ty,lb,size,rb) ->
       fullType ty; mcode print_string lb; print_option expression size;
       mcode print_string rb
-  | Ast.EnumName(kind,name) -> mcode print_string kind; pr_space();
-      ident name
+  | Ast.EnumName(kind,name) ->
+      mcode print_string kind;
+      print_option_prespace ident name
+  | Ast.EnumDef(ty,lb,ids,rb) ->
+      fullType ty; ft_space ty;
+      mcode print_string lb;
+      dots force_newline expression ids;
+      mcode print_string rb
   | Ast.StructUnionName(kind,name) ->
       mcode structUnion kind; print_option_prespace ident name
   | Ast.StructUnionDef(ty,lb,decls,rb) ->
@@ -485,6 +491,9 @@ and baseType = function
   | Ast.FloatType -> print_string "float"
   | Ast.LongType -> print_string "long"
   | Ast.LongLongType -> print_string "long long"
+  | Ast.SizeType -> print_string "size_t "
+  | Ast.SSizeType -> print_string "ssize_t "
+  | Ast.PtrDiffType -> print_string "ptrdiff_t "
 
 and structUnion = function
     Ast.Struct -> print_string "struct"
@@ -564,7 +573,19 @@ and ft_space ty =
 
 and declaration d =
   match Ast.unwrap d with
-    Ast.Init(stg,ty,id,eq,ini,sem) ->
+    Ast.MetaDecl(name,_,_) ->
+      handle_metavar name
+       (function
+           Ast_c.MetaDeclVal d ->
+              pretty_print_c.Pretty_print_c.decl d
+          | _ -> raise Impossible)
+  | Ast.MetaField(name,_,_) ->
+      handle_metavar name
+       (function
+           Ast_c.MetaFieldVal d ->
+              pretty_print_c.Pretty_print_c.field d
+          | _ -> raise Impossible)
+  | Ast.Init(stg,ty,id,eq,ini,sem) ->
       print_option (mcode storage) stg;
       print_option (function _ -> pr_space()) stg;
       print_named_type ty id;
@@ -584,7 +605,7 @@ and declaration d =
       mcode print_string stg;
       fullType ty; typeC id;
       mcode print_string sem
-  | Ast.DisjDecl(_) | Ast.MetaDecl(_,_,_) -> raise CantBeInPlus
+  | Ast.DisjDecl(_) -> raise CantBeInPlus
   | Ast.Ddots(_,_) -> raise CantBeInPlus
   | Ast.OptDecl(decl)  | Ast.UniqueDecl(decl) ->
       raise CantBeInPlus
@@ -600,7 +621,16 @@ and initialiser nlcomma i =
             pretty_print_c.Pretty_print_c.init ini
         | _ -> raise Impossible)
   | Ast.InitExpr(exp) -> expression exp
-  | Ast.InitList(_,lb,initlist,rb,[]) ->
+  | Ast.ArInitList(lb,initlist,rb) ->
+      (match Ast.undots initlist with
+       [] -> mcode print_string lb; mcode print_string rb
+      |        _ ->
+         mcode print_string lb; start_block();
+         dots force_newline (initialiser false) initlist;
+         end_block(); mcode print_string rb)
+  | Ast.StrInitList(_,lb,[],rb,[]) ->
+      mcode print_string lb; mcode print_string rb
+  | Ast.StrInitList(_,lb,initlist,rb,[]) ->
       mcode print_string lb; start_block();
       (* awkward, because the comma is separate from the initialiser *)
       let rec loop = function
@@ -609,7 +639,8 @@ and initialiser nlcomma i =
        | x::xs -> initialiser nlcomma x; loop xs in
       loop initlist;
       end_block(); mcode print_string rb
-  | Ast.InitList(_,lb,initlist,rb,_) -> failwith "unexpected whencode in plus"
+  | Ast.StrInitList(_,lb,initlist,rb,_) ->
+      failwith "unexpected whencode in plus"
   | Ast.InitGccExt(designators,eq,ini) ->
       List.iter designator designators; pr_space();
       mcode print_string eq; pr_space(); initialiser nlcomma ini
@@ -618,6 +649,17 @@ and initialiser nlcomma i =
   | Ast.IComma(comma) ->
       mcode print_string comma;
       if nlcomma then force_newline()
+  | Ast.Idots(dots,Some whencode) ->
+      if generating
+      then
+       (mcode print_string dots;
+        print_text "   when != ";
+        initialiser nlcomma whencode)
+      else raise CantBeInPlus
+  | Ast.Idots(dots,None) ->
+      if generating
+      then mcode print_string dots
+      else raise CantBeInPlus
   | Ast.OptIni(ini) | Ast.UniqueIni(ini) ->
       raise CantBeInPlus