Coccinelle release-1.0.0-rc11
[bpt/coccinelle.git] / parsing_cocci / get_constants2.ml
index 633fcb3..4b7cb1a 100644 (file)
@@ -1,5 +1,7 @@
 (*
- * Copyright 2010, INRIA, University of Copenhagen
+ * Copyright 2012, INRIA
+ * Julia Lawall, Gilles Muller
+ * Copyright 2010-2011, INRIA, University of Copenhagen
  * Julia Lawall, Rene Rydhof Hansen, Gilles Muller, Nicolas Palix
  * Copyright 2005-2009, Ecole des Mines de Nantes, University of Copenhagen
  * Yoann Padioleau, Julia Lawall, Rene Rydhof Hansen, Henrik Stuart, Gilles Muller, Nicolas Palix
@@ -269,9 +271,10 @@ let do_get_constants constants keywords env neg_pos =
     else (try List.assoc nm1 env with Not_found -> False) in
   let minherited name = inherited (Ast.unwrap_mcode name) in
   let mcode _ x =
-    match Ast.get_pos_var x with
-      Ast.MetaPos(name,constraints,_,keep,inh) -> minherited name
-    | _ -> option_default in
+    List.fold_left bind option_default
+      (List.map
+        (function Ast.MetaPos(name,constraints,_,keep,inh) -> minherited name)
+        (Ast.get_pos_var x)) in
 
   (* if one branch gives no information, then we have to take anything *)
   let disj_union_all = List.fold_left build_or False in
@@ -285,6 +288,7 @@ let do_get_constants constants keywords env neg_pos =
          | nm -> constants nm)
     | Ast.MetaId(name,_,_,_) | Ast.MetaFunc(name,_,_,_)
     | Ast.MetaLocalFunc(name,_,_,_) -> bind (k i) (minherited name)
+    | Ast.DisjId(ids) -> disj_union_all (List.map r.V.combiner_ident ids)
     | _ -> k i in
 
   let rec type_collect res = function
@@ -293,8 +297,8 @@ let do_get_constants constants keywords env neg_pos =
     | TC.MetaType(tyname,_,_) ->
        inherited tyname
     | TC.TypeName(s) -> constants s
-    | TC.EnumName(false,s) -> constants s
-    | TC.StructUnionName(_,false,s) -> constants s
+    | TC.EnumName(TC.Name s) -> constants s
+    | TC.StructUnionName(_,TC.Name s) -> constants s
     | ty -> res in
 
   (* no point to do anything special for records because glimpse is
@@ -337,13 +341,19 @@ let do_get_constants constants keywords env neg_pos =
     | _ -> k ft in
 
   let baseType = function
-      Ast.VoidType -> keywords "void "
-    | Ast.CharType -> keywords "char "
-    | Ast.ShortType -> keywords "short "
-    | Ast.IntType -> keywords "int "
-    | Ast.DoubleType -> keywords "double "
-    | Ast.FloatType -> keywords "float "
-    | Ast.LongType | Ast.LongLongType -> keywords "long " in
+      Ast.VoidType -> keywords "void"
+    | Ast.CharType -> keywords "char"
+    | Ast.ShortType -> keywords "short"
+    | Ast.ShortIntType -> keywords "short"
+    | Ast.IntType -> keywords "int"
+    | Ast.DoubleType -> keywords "double"
+    | Ast.LongDoubleType -> keywords "double"
+    | Ast.FloatType -> keywords "float"
+    | Ast.LongType | Ast.LongLongType
+    | Ast.LongIntType | Ast.LongLongIntType -> keywords "long"
+    | Ast.SizeType -> keywords "size_t"
+    | Ast.SSizeType -> keywords "ssize_t"
+    | Ast.PtrDiffType -> keywords "ptrdiff_t" in
 
   let typeC r k ty =
     match Ast.unwrap ty with
@@ -356,6 +366,8 @@ let do_get_constants constants keywords env neg_pos =
     match Ast.unwrap d with
       Ast.MetaDecl(name,_,_) | Ast.MetaField(name,_,_) ->
        bind (k d) (minherited name)
+    | Ast.MetaFieldList(name,Ast.MetaListLen(lenname,_,_),_,_) ->
+       bind (minherited name) (bind (minherited lenname) (k d))
     | Ast.DisjDecl(decls) ->
        disj_union_all (List.map r.V.combiner_declaration decls)
     | Ast.OptDecl(decl) -> option_default
@@ -482,7 +494,7 @@ let get_plus_constants =
             bind ((get_all_constants false).V.combiner_anything cur) prev))
       [] l in
   let process_mcodekind = function
-      Ast.MINUS(_,_,_,anythings) -> recurse anythings
+      Ast.MINUS(_,_,_,Ast.REPLACEMENT(anythings,_)) -> recurse anythings
     | Ast.CONTEXT(_,Ast.BEFORE(a,_)) -> recurse a
     | Ast.CONTEXT(_,Ast.AFTER(a,_)) -> recurse a
     | Ast.CONTEXT(_,Ast.BEFOREAFTER(a1,a2,_)) ->
@@ -626,32 +638,35 @@ let run rules neg_pos_vars =
              (rest_info, in_plus, env, locals)
           | (Ast.CocciRule (nm,(dep,_,_),cur,_,_),neg_pos_vars) ->
              let (cur_info,cur_plus) =
-               rule_fn cur in_plus ((nm,True)::env)
-                 neg_pos_vars in
+               rule_fn cur in_plus ((nm,True)::env) neg_pos_vars in
              (match dependencies env dep with
                False -> (rest_info,cur_plus,env,locals)
              | dependencies ->
                  if List.for_all all_context.V.combiner_top_level cur
-                 then (rest_info,cur_plus,(nm,cur_info)::env,nm::locals)
+                 then
+                   let cur_info = build_and dependencies cur_info in
+                   (rest_info,cur_plus,(nm,cur_info)::env,nm::locals)
                  else
               (* no constants if dependent on another rule; then we need to
                  find the constants of that rule *)
-                   (build_or (build_and dependencies cur_info) rest_info,
-                    cur_plus,env,locals)))
+                     (build_or (build_and dependencies cur_info) rest_info,
+                      cur_plus,(nm,cur_info)::env,locals)))
       (False,[],[],[])
       (List.combine (rules : Ast.rule list) neg_pos_vars) in
   info
     
 let get_constants rules neg_pos_vars =
   match !Flag.scanner with
-    Flag.NoScanner -> (None,None)
+    Flag.NoScanner -> (None,None,None)
   | Flag.Grep ->
       let res = run rules neg_pos_vars in
-      (interpret_grep true res,None)
+      (interpret_grep true res,None,None)
   | Flag.Glimpse ->
       let res = run rules neg_pos_vars in
-      (interpret_grep true res,interpret_glimpse true res)
+      (interpret_grep true res,interpret_glimpse true res,None)
   | Flag.Google _ ->
       let res = run rules neg_pos_vars in
-      (interpret_grep true res,interpret_google true res)
-      
+      (interpret_grep true res,interpret_google true res,None)
+  | Flag.IdUtils ->
+      let res = run rules neg_pos_vars in
+      (interpret_grep true res,None,Some res)