Release coccinelle-0.2.3rc1
[bpt/coccinelle.git] / parsing_cocci / function_prototypes.ml
index 95fe86b..c503d12 100644 (file)
@@ -1,23 +1,45 @@
 (*
-* Copyright 2005-2009, Ecole des Mines de Nantes, University of Copenhagen
-* Yoann Padioleau, Julia Lawall, Rene Rydhof Hansen, Henrik Stuart, Gilles Muller
-* This file is part of Coccinelle.
-* 
-* Coccinelle is free software: you can redistribute it and/or modify
-* it under the terms of the GNU General Public License as published by
-* the Free Software Foundation, according to version 2 of the License.
-* 
-* Coccinelle is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-* GNU General Public License for more details.
-* 
-* You should have received a copy of the GNU General Public License
-* along with Coccinelle.  If not, see <http://www.gnu.org/licenses/>.
-* 
-* The authors reserve the right to distribute this or future versions of
-* Coccinelle under other licenses.
-*)
+ * Copyright 2005-2010, Ecole des Mines de Nantes, University of Copenhagen
+ * Yoann Padioleau, Julia Lawall, Rene Rydhof Hansen, Henrik Stuart, Gilles Muller, Nicolas Palix
+ * This file is part of Coccinelle.
+ *
+ * Coccinelle is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, according to version 2 of the License.
+ *
+ * Coccinelle is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Coccinelle.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * The authors reserve the right to distribute this or future versions of
+ * Coccinelle under other licenses.
+ *)
+
+
+(*
+ * Copyright 2005-2010, Ecole des Mines de Nantes, University of Copenhagen
+ * Yoann Padioleau, Julia Lawall, Rene Rydhof Hansen, Henrik Stuart, Gilles Muller, Nicolas Palix
+ * This file is part of Coccinelle.
+ *
+ * Coccinelle is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, according to version 2 of the License.
+ *
+ * Coccinelle is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Coccinelle.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * The authors reserve the right to distribute this or future versions of
+ * Coccinelle under other licenses.
+ *)
 
 
 module Ast0 = Ast0_cocci
@@ -25,21 +47,25 @@ module Ast = Ast_cocci
 module V0 = Visitor_ast0
 module VT0 = Visitor_ast0_types
 
-type id = Id of string | Meta of (string * string)
+type id = Id of string | Meta of Ast.meta_name
 
 let rec get_name name =
   match Ast0.unwrap name with
-    Ast0.Id(nm) -> Id(Ast0.unwrap_mcode nm)
-  | Ast0.MetaId(nm,_,_) | Ast0.MetaFunc(nm,_,_)
-  | Ast0.MetaLocalFunc(nm,_,_) -> Meta(Ast0.unwrap_mcode nm)
-  | Ast0.OptIdent(id) | Ast0.UniqueIdent(id) ->
-      get_name id
+      Ast0.Id(nm) -> Id(Ast0.unwrap_mcode nm)
+    | Ast0.MetaId(nm,_,_) | Ast0.MetaFunc(nm,_,_)
+    | Ast0.MetaLocalFunc(nm,_,_) -> Meta(Ast0.unwrap_mcode nm)
+    | Ast0.OptIdent(id) | Ast0.UniqueIdent(id) ->
+       get_name id
 
 (* --------------------------------------------------------------------- *)
 (* collect all of the functions *)
 
-let brace_to_semi (_,arity,info,mcodekind,pos) =
-  (";",Ast0.NONE,info,mcodekind,pos)
+let brace_to_semi (_,arity,info,mcodekind,pos,adj) =
+  let info =
+    (* drop column information, so that with -smpl_spacing the semicolon
+       will come out right after the close parenthesis *)
+    {info with Ast0.pos_info = {info.Ast0.pos_info with Ast0.column = -1}} in
+  (";",Ast0.NONE,info,mcodekind,pos,adj)
 
 let collect_function (stm : Ast0.statement) =
   match Ast0.unwrap stm with
@@ -122,9 +148,11 @@ let rec align all_minus all_plus =
 
 and strip =
   let donothing r k e =
-    {(Ast0.wrap (Ast0.unwrap (k e))) with Ast0.mcodekind = ref Ast0.PLUS} in
-  let mcode (mc,_,_,_,_) =
-    (mc,Ast0.NONE,Ast0.default_info(),Ast0.PLUS,ref Ast0.NoMetaPos) in
+    {(Ast0.wrap (Ast0.unwrap (k e))) with
+      Ast0.mcodekind = ref  (Ast0.PLUS Ast.ONE)} in
+  let mcode (mc,_,_,_,_,_) =
+    (mc,Ast0.NONE,Ast0.default_info(),Ast0.PLUS Ast.ONE,
+     ref Ast0.NoMetaPos,-1) in
 
   (* need a case for everything that has an unvisited component and can be in
      a function prototype *)
@@ -221,12 +249,14 @@ let rec rename_param old_name all param =
   match Ast0.unwrap param with
     Ast0.Param(ty,Some id) when all ->
       (match Ast0.unwrap id with
-       Ast0.MetaId(((_,name),arity,info,mcodekind,pos),constraints,pure) ->
+       Ast0.MetaId
+         (((_,name),arity,info,mcodekind,pos,adj),constraints,pure) ->
          let nm = ("__no_name__",new_name name) in
          let new_id =
            Ast0.rewrap id
              (Ast0.MetaId
-                ((nm,arity,info,mcodekind,pos),constraints,Ast0.Pure)) in
+                ((nm,arity,info,mcodekind,pos,adj),constraints,
+                 Ast0.Pure)) in
          ([Ast.MetaIdDecl(Ast.NONE,nm)],
           Ast0.rewrap param (Ast0.Param(ty,Some new_id)))
       |        _ -> ([],param))
@@ -318,7 +348,7 @@ let no_names dec =
                                    Ast0.get_mcode_mcodekind lp in
                                  let pdots =
                                    ("...",Ast0.NONE,info,mcodekind,
-                                    ref Ast0.NoMetaPos) in
+                                    ref Ast0.NoMetaPos,-1) in
                                  Ast0.DOTS
                                    ([Ast0.rewrap params
                                         (Ast0.Pdots(pdots))])),
@@ -330,9 +360,11 @@ let no_names dec =
 
 let merge mproto pproto =
   let mproto =
-    Compute_lines.compute_lines [Ast0.copywrap mproto (Ast0.DECL mproto)] in
+    Compute_lines.compute_lines true
+      [Ast0.copywrap mproto (Ast0.DECL mproto)] in
   let pproto =
-    Compute_lines.compute_lines [Ast0.copywrap pproto (Ast0.DECL pproto)] in
+    Compute_lines.compute_lines true
+      [Ast0.copywrap pproto (Ast0.DECL pproto)] in
   let (m,p) = List.split(Context_neg.context_neg mproto pproto) in
   Insert_plus.insert_plus m p true (* no isos for protos *);
   (* convert to ast so that the + code will fall down to the tokens