Release coccinelle-0.1.2
[bpt/coccinelle.git] / parsing_cocci / context_neg.ml
index abc2054..86d6a8f 100644 (file)
@@ -875,6 +875,12 @@ let rec is_ty s =
   | Ast0.Disj(_,stmts,_,_) -> isall is_ty stmts
   | _ -> false
 
+let rec is_init s =
+  match Ast0.unwrap s with
+    Ast0.TopInit(e) -> true
+  | Ast0.Disj(_,stmts,_,_) -> isall is_init stmts
+  | _ -> false
+
 let rec is_decl s =
   match Ast0.unwrap s with
     Ast0.Decl(_,e) -> true
@@ -920,17 +926,23 @@ let check_compatible m p =
       let v2 = is_decl decl2 in
       if v1 && not v2 then fail()
   | (Ast0.CODE(code1),Ast0.CODE(code2)) ->
-      let testers = [is_exp;is_ty] in
-      List.iter
-       (function tester ->
-         let v1 = isonly tester code1 in
-         let v2 = isonly tester code2 in
-         if (v1 && not v2) or (!Flag.make_hrule = None && v2 && not v1)
-         then fail())
-       testers;
-      let v1 = isonly is_fndecl code1 in
-      let v2 = List.for_all is_toplevel (Ast0.undots code2) in
-      if !Flag.make_hrule = None && v1 && not v2 then fail()
+      let v1 = isonly is_init code1 in
+      let v2a = isonly is_init code2 in
+      let v2b = isonly is_exp code2 in
+      if v1
+      then (if not (v2a || v2b) then fail())
+      else
+       let testers = [is_exp;is_ty] in
+       List.iter
+         (function tester ->
+           let v1 = isonly tester code1 in
+           let v2 = isonly tester code2 in
+           if (v1 && not v2) or (!Flag.make_hrule = None && v2 && not v1)
+           then fail())
+         testers;
+       let v1 = isonly is_fndecl code1 in
+       let v2 = List.for_all is_toplevel (Ast0.undots code2) in
+       if !Flag.make_hrule = None && v1 && not v2 then fail()
   | (Ast0.FILEINFO(_,_),Ast0.FILEINFO(_,_)) -> ()
   | (Ast0.OTHER(_),Ast0.OTHER(_)) -> ()
   | _ -> fail()