Release coccinelle-0.2.3rc1
[bpt/coccinelle.git] / parsing_cocci / context_neg.ml
index 93997b5..eafd4d2 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.
+ *)
 
 
 (* Detects subtrees that are all minus/plus and nodes that are "binding
@@ -141,7 +163,7 @@ let collect_plus_lines top =
   let donothing r k e = k e in
   let mcode (_,_,info,mcodekind,_,_) =
     match mcodekind with
-      Ast0.PLUS -> insert info.Ast0.pos_info.Ast0.line_start
+      Ast0.PLUS -> insert info.Ast0.pos_info.Ast0.line_start
     | _ -> () in
   let fn =
     V0.flat_combiner bind option_default
@@ -153,7 +175,8 @@ let collect_plus_lines top =
 
 (* --------------------------------------------------------------------- *)
 
-type kind = Neutral | AllMarked | NotAllMarked (* marked means + or - *)
+type kind =
+    Neutral | AllMarked of Ast.count | NotAllMarked (* marked means + or - *)
 
 (* --------------------------------------------------------------------- *)
 (* The first part analyzes each of the minus tree and the plus tree
@@ -176,7 +199,7 @@ type node =
 
 let kind2c = function
     Neutral -> "neutral"
-  | AllMarked -> "allmarked"
+  | AllMarked -> "allmarked"
   | NotAllMarked -> "notallmarked"
 
 let node2c = function
@@ -189,8 +212,8 @@ tokens *)
 let bind c1 c2 =
   let lub = function
       (k1,k2) when k1 = k2 -> k1
-    | (Neutral,AllMarked) -> AllMarked
-    | (AllMarked,Neutral) -> AllMarked
+    | (Neutral,AllMarked c) -> AllMarked c
+    | (AllMarked c,Neutral) -> AllMarked c
     | _ -> NotAllMarked in
   match (c1,c2) with
     (* token/token *)
@@ -231,8 +254,8 @@ let option_default = (*Bind(Neutral,[],[],[],[],[])*)
 let mcode (_,_,info,mcodekind,pos,_) =
   let offset = info.Ast0.pos_info.Ast0.offset in
   match mcodekind with
-    Ast0.MINUS(_) -> Token(AllMarked,offset,mcodekind,[])
-  | Ast0.PLUS -> Token(AllMarked,offset,mcodekind,[])
+    Ast0.MINUS(_) -> Token(AllMarked Ast.ONE,offset,mcodekind,[])
+  | Ast0.PLUS c -> Token(AllMarked c,offset,mcodekind,[])
   | Ast0.CONTEXT(_) -> Token(NotAllMarked,offset,mcodekind,[offset])
   | _ -> failwith "not possible"
 
@@ -240,7 +263,7 @@ let neutral_mcode (_,_,info,mcodekind,pos,_) =
   let offset = info.Ast0.pos_info.Ast0.offset in
   match mcodekind with
     Ast0.MINUS(_) -> Token(Neutral,offset,mcodekind,[])
-  | Ast0.PLUS -> Token(Neutral,offset,mcodekind,[])
+  | Ast0.PLUS -> Token(Neutral,offset,mcodekind,[])
   | Ast0.CONTEXT(_) -> Token(Neutral,offset,mcodekind,[offset])
   | _ -> failwith "not possible"
 
@@ -250,8 +273,8 @@ let nc_mcode (_,_,info,mcodekind,pos,_) =
   (* distinguish from the offset of some real token *)
   let offset = (-1) * info.Ast0.pos_info.Ast0.offset in
   match mcodekind with
-    Ast0.MINUS(_) -> Token(AllMarked,offset,mcodekind,[])
-  | Ast0.PLUS -> Token(AllMarked,offset,mcodekind,[])
+    Ast0.MINUS(_) -> Token(AllMarked Ast.ONE,offset,mcodekind,[])
+  | Ast0.PLUS c -> Token(AllMarked c,offset,mcodekind,[])
   | Ast0.CONTEXT(_) ->
       (* Unlike the other mcode cases, we drop the offset from the context
         offsets.  This is because we don't know whether the term this is
@@ -269,9 +292,10 @@ let union_all l = List.fold_left Common.union_set [] l
 intermingled with plus code.  it is used in disj_cases *)
 let classify is_minus all_marked table code =
   let mkres builder k il tl bil btl l e =
-    (if k = AllMarked
-    then Ast0.set_mcodekind e (all_marked()) (* definitive *)
-    else
+    (match k with
+      AllMarked count ->
+       Ast0.set_mcodekind e (all_marked count) (* definitive *)
+    | _ ->
       let check_index il tl =
        if List.for_all is_context tl
        then
@@ -1025,7 +1049,7 @@ let context_neg minus plus =
              classify true
                (function _ -> Ast0.MINUS(ref([],Ast0.default_token_info)))
                minus_table m in
-           let _ = classify false (function _ -> Ast0.PLUS) plus_table p in
+           let _ = classify false (function c -> Ast0.PLUS c) plus_table p in
            traverse minus_table plus_table;
            (m,p)::loop(minus,plus)
          end