X-Git-Url: https://git.hcoop.net/bpt/coccinelle.git/blobdiff_plain/785a3008ddade80f642257bb47d43158ac8b8311..8f657093d128c6436330659d273c2762ac9cbf79:/parsing_cocci/get_constants2.ml diff --git a/parsing_cocci/get_constants2.ml b/parsing_cocci/get_constants2.ml index 5638faa..53e2aa3 100644 --- a/parsing_cocci/get_constants2.ml +++ b/parsing_cocci/get_constants2.ml @@ -1,3 +1,27 @@ +(* + * Copyright 2010, 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 + * 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 . + * + * The authors reserve the right to distribute this or future versions of + * Coccinelle under other licenses. + *) + + module Ast = Ast_cocci module V = Visitor_ast module TC = Type_cocci @@ -245,9 +269,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 @@ -261,6 +286,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 @@ -269,8 +295,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 @@ -319,7 +345,10 @@ let do_get_constants constants keywords env neg_pos = | Ast.IntType -> keywords "int " | Ast.DoubleType -> keywords "double " | Ast.FloatType -> keywords "float " - | Ast.LongType | Ast.LongLongType -> keywords "long " in + | Ast.LongType | Ast.LongLongType -> 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 @@ -332,6 +361,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 @@ -406,7 +437,7 @@ let do_get_constants constants keywords env neg_pos = V.combiner bind option_default mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode - donothing donothing donothing donothing + donothing donothing donothing donothing donothing ident expression fullType typeC initialiser parameter declaration rule_elem statement donothing donothing donothing @@ -439,7 +470,7 @@ let get_all_constants minus_only = V.combiner bind option_default other mcode other other other other other other other other other other - donothing donothing donothing donothing + donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing @@ -483,7 +514,7 @@ let get_plus_constants = V.combiner bind option_default mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode - donothing donothing donothing donothing + donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing donothing rule_elem statement donothing donothing donothing @@ -518,7 +549,7 @@ let all_context = let initialiser r k e = match Ast.unwrap e with - Ast.InitList(all_minus,_,_,_,_) -> + Ast.StrInitList(all_minus,_,_,_,_) -> not all_minus && k e | _ -> k e in @@ -537,7 +568,7 @@ let all_context = V.combiner bind option_default mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode - donothing donothing donothing donothing + donothing donothing donothing donothing donothing donothing donothing donothing donothing initialiser donothing donothing rule_elem statement donothing donothing donothing @@ -620,14 +651,16 @@ let run rules neg_pos_vars = 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)