diff --git a/infer/src/IR/Annot.re b/infer/src/IR/Annot.re new file mode 100644 index 000000000..f8e52106d --- /dev/null +++ b/infer/src/IR/Annot.re @@ -0,0 +1,107 @@ +/* + * vim: set ft=rust: + * vim: set ft=reason: + * + * Copyright (c) 2009 - 2013 Monoidics ltd. + * Copyright (c) 2013 - present Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + +open! Utils; + + +/** The Smallfoot Intermediate Language: Annotations */ +let module L = Logging; + +let module F = Format; + + +/** Type to represent one @Annotation. */ +type t = { + class_name: string, /** name of the annotation */ + parameters: list string /** currently only one string parameter */ +}; + + +/** Compare function for annotations. */ +let compare a1 a2 => { + let n = string_compare a1.class_name a2.class_name; + if (n != 0) { + n + } else { + IList.compare string_compare a1.parameters a2.parameters + } +}; + + +/** Pretty print an annotation. */ +let pp fmt annotation => F.fprintf fmt "@@%s" annotation.class_name; + +let module Map = PrettyPrintable.MakePPMap { + type nonrec t = t; + let compare = compare; + let pp_key = pp; +}; + +let module Item = { + /** Annotation for one item: a list of annotations with visibility. */ + type nonrec t = list (t, bool); + + /** Compare function for annotation items. */ + let compare ia1 ia2 => { + let cmp (a1, b1) (a2, b2) => { + let n = compare a1 a2; + if (n != 0) { + n + } else { + bool_compare b1 b2 + } + }; + IList.compare cmp ia1 ia2 + }; + + /** Pretty print an item annotation. */ + let pp fmt ann => { + let pp fmt (a, _) => pp fmt a; + F.fprintf fmt "<%a>" (pp_seq pp) ann + }; + let to_string ann => { + let pp fmt () => pp fmt ann; + pp_to_string pp () + }; + + /** Empty item annotation. */ + let empty = []; + + /** Check if the item annodation is empty. */ + let is_empty ia => ia == []; +}; + +let module Class = { + let objc_str = "ObjC-Class"; + let cpp_str = "Cpp-Class"; + let of_string class_string => [({class_name: class_string, parameters: []}, true)]; + let objc = of_string objc_str; + let cpp = of_string cpp_str; +}; + +let module Method = { + /** Annotation for a method: return value and list of parameters. */ + type t = (Item.t, list Item.t); + + /** Compare function for Method annotations. */ + let compare (ia1, ial1) (ia2, ial2) => IList.compare Item.compare [ia1, ...ial1] [ia2, ...ial2]; + + /** Pretty print a method annotation. */ + let pp s fmt (ia, ial) => F.fprintf fmt "%a %s(%a)" Item.pp ia s (pp_seq Item.pp) ial; + + /** Empty method annotation. */ + let empty = ([], []); + + /** Check if the method annodation is empty. */ + let is_empty (ia, ial) => IList.for_all Item.is_empty [ia, ...ial]; +}; diff --git a/infer/src/IR/Annot.rei b/infer/src/IR/Annot.rei new file mode 100644 index 000000000..f5a93b596 --- /dev/null +++ b/infer/src/IR/Annot.rei @@ -0,0 +1,72 @@ +/* + * vim: set ft=rust: + * vim: set ft=reason: + * + * Copyright (c) 2009 - 2013 Monoidics ltd. + * Copyright (c) 2013 - present Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + +open! Utils; + + +/** The Smallfoot Intermediate Language: Annotations */ +let module F = Format; + + +/** Type to represent one @Annotation. */ +type t = { + class_name: string, /** name of the annotation */ + parameters: list string /** currently only one string parameter */ +}; + + +/** Compare function for annotations. */ +let compare: t => t => int; + + +/** Pretty print an annotation. */ +let pp: F.formatter => t => unit; + +let module Map: PrettyPrintable.PPMap with type key = t; + +let module Item: { + /** Annotation for one item: a list of annotations with visibility. */ + type nonrec t = list (t, bool); + + /** Compare function for annotation items. */ + let compare: t => t => int; + + /** Pretty print an item annotation. */ + let pp: F.formatter => t => unit; + let to_string: t => string; + + /** Empty item annotation. */ + let empty: t; + + /** Check if the item annodation is empty. */ + let is_empty: t => bool; +}; + +let module Class: {let objc: Item.t; let cpp: Item.t;}; + +let module Method: { + /** Annotation for a method: return value and list of parameters. */ + type t = (Item.t, list Item.t); + + /** Compare function for Method annotations. */ + let compare: t => t => int; + + /** Empty method annotation. */ + let empty: t; + + /** Check if the method annodation is empty. */ + let is_empty: t => bool; + + /** Pretty print a method annotation. */ + let pp: string => F.formatter => t => unit; +}; diff --git a/infer/src/IR/PredSymb.re b/infer/src/IR/PredSymb.re index f3e96778d..dd341b1f2 100644 --- a/infer/src/IR/PredSymb.re +++ b/infer/src/IR/PredSymb.re @@ -165,7 +165,7 @@ type t = | Aautorelease | Adangling of dangling_kind /** dangling pointer */ /** undefined value obtained by calling the given procedure, plus its return value annots */ - | Aundef of Procname.t Typ.item_annotation Location.t path_pos + | Aundef of Procname.t Annot.Item.t Location.t path_pos | Ataint of taint_info | Auntaint of taint_info | Alocked @@ -175,7 +175,7 @@ type t = /** attributed exp is null due to a call to a method with given path as null receiver */ | Aobjc_null /** value was returned from a call to the given procedure, plus the annots of the return value */ - | Aretval of Procname.t Typ.item_annotation + | Aretval of Procname.t Annot.Item.t /** denotes an object registered as an observers to a notification center */ | Aobserver /** denotes an object unsubscribed from observers of a notification center */ @@ -224,7 +224,7 @@ let compare (att1: t) (att2: t) :int => if (n != 0) { n } else { - Typ.item_annotation_compare annots1 annots2 + Annot.Item.compare annots1 annots2 } | (Aretval _, _) => (-1) | (_, Aretval _) => 1 diff --git a/infer/src/IR/PredSymb.rei b/infer/src/IR/PredSymb.rei index d97184bf1..8f2732938 100644 --- a/infer/src/IR/PredSymb.rei +++ b/infer/src/IR/PredSymb.rei @@ -100,7 +100,7 @@ type t = | Aautorelease | Adangling of dangling_kind /** dangling pointer */ /** undefined value obtained by calling the given procedure, plus its return value annots */ - | Aundef of Procname.t Typ.item_annotation Location.t path_pos + | Aundef of Procname.t Annot.Item.t Location.t path_pos | Ataint of taint_info | Auntaint of taint_info | Alocked @@ -110,7 +110,7 @@ type t = /** attributed exp is null due to a call to a method with given path as null receiver */ | Aobjc_null /** value was returned from a call to the given procedure, plus the annots of the return value */ - | Aretval of Procname.t Typ.item_annotation + | Aretval of Procname.t Annot.Item.t /** denotes an object registered as an observers to a notification center */ | Aobserver /** denotes an object unsubscribed from observers of a notification center */ diff --git a/infer/src/IR/ProcAttributes.re b/infer/src/IR/ProcAttributes.re index 45ada9064..cf4904f3b 100644 --- a/infer/src/IR/ProcAttributes.re +++ b/infer/src/IR/ProcAttributes.re @@ -41,7 +41,7 @@ type t = { language: Config.language, /** language of the procedure */ loc: Location.t, /** location of this procedure in the source code */ mutable locals: list (Mangled.t, Typ.t), /** name and type of local variables */ - method_annotation: Typ.method_annotation, /** annotations for java methods */ + method_annotation: Annot.Method.t, /** annotations for java methods */ objc_accessor: option objc_accessor_type, /** type of ObjC accessor, if any */ proc_flags: proc_flags, /** flags of the procedure */ proc_name: Procname.t, /** name of the procedure */ @@ -68,7 +68,7 @@ let default proc_name language => { language, loc: Location.dummy, locals: [], - method_annotation: Typ.method_annotation_empty, + method_annotation: Annot.Method.empty, objc_accessor: None, proc_flags: proc_flags_empty (), proc_name, diff --git a/infer/src/IR/ProcAttributes.rei b/infer/src/IR/ProcAttributes.rei index 6f76d2023..e44290426 100644 --- a/infer/src/IR/ProcAttributes.rei +++ b/infer/src/IR/ProcAttributes.rei @@ -35,7 +35,7 @@ type t = { language: Config.language, /** language of the procedure */ loc: Location.t, /** location of this procedure in the source code */ mutable locals: list (Mangled.t, Typ.t), /** name and type of local variables */ - method_annotation: Typ.method_annotation, /** annotations for java methods */ + method_annotation: Annot.Method.t, /** annotations for java methods */ objc_accessor: option objc_accessor_type, /** type of ObjC accessor, if any */ proc_flags: proc_flags, /** flags of the procedure */ proc_name: Procname.t, /** name of the procedure */ diff --git a/infer/src/IR/Tenv.rei b/infer/src/IR/Tenv.rei index 55e175682..48206353f 100644 --- a/infer/src/IR/Tenv.rei +++ b/infer/src/IR/Tenv.rei @@ -49,7 +49,7 @@ let mk_struct: statics::Typ.struct_fields? => methods::list Procname.t? => supers::list Typename.t? => - annots::Typ.item_annotation? => + annots::Annot.Item.t? => Typename.t => Typ.struct_typ; diff --git a/infer/src/IR/Typ.re b/infer/src/IR/Typ.re index 421cb26e4..e58b16338 100644 --- a/infer/src/IR/Typ.re +++ b/infer/src/IR/Typ.re @@ -20,104 +20,6 @@ let module L = Logging; let module F = Format; -/** Type to represent one @Annotation. */ -type annotation = { - class_name: string, /** name of the annotation */ - parameters: list string /** currently only one string parameter */ -}; - - -/** Compare function for annotations. */ -let annotation_compare a1 a2 => { - let n = string_compare a1.class_name a2.class_name; - if (n != 0) { - n - } else { - IList.compare string_compare a1.parameters a2.parameters - } -}; - - -/** Pretty print an annotation. */ -let pp_annotation fmt annotation => F.fprintf fmt "@@%s" annotation.class_name; - -let module AnnotMap = PrettyPrintable.MakePPMap { - type t = annotation; - let compare = annotation_compare; - let pp_key = pp_annotation; -}; - - -/** Annotation for one item: a list of annotations with visibility. */ -type item_annotation = list (annotation, bool); - - -/** Compare function for annotation items. */ -let item_annotation_compare ia1 ia2 => { - let cmp (a1, b1) (a2, b2) => { - let n = annotation_compare a1 a2; - if (n != 0) { - n - } else { - bool_compare b1 b2 - } - }; - IList.compare cmp ia1 ia2 -}; - - -/** Pretty print an item annotation. */ -let pp_item_annotation fmt item_annotation => { - let pp fmt (a, _) => pp_annotation fmt a; - F.fprintf fmt "<%a>" (pp_seq pp) item_annotation -}; - -let item_annotation_to_string ann => { - let pp fmt () => pp_item_annotation fmt ann; - pp_to_string pp () -}; - - -/** Empty item annotation. */ -let item_annotation_empty = []; - - -/** Check if the item annodation is empty. */ -let item_annotation_is_empty ia => ia == []; - -let objc_class_str = "ObjC-Class"; - -let cpp_class_str = "Cpp-Class"; - -let class_annotation class_string => [({class_name: class_string, parameters: []}, true)]; - -let objc_class_annotation = class_annotation objc_class_str; - -let cpp_class_annotation = class_annotation cpp_class_str; - - -/** Annotation for a method: return value and list of parameters. */ -type method_annotation = (item_annotation, list item_annotation); - - -/** Compare function for Method annotations. */ -let method_annotation_compare (ia1, ial1) (ia2, ial2) => - IList.compare item_annotation_compare [ia1, ...ial1] [ia2, ...ial2]; - - -/** Pretty print a method annotation. */ -let pp_method_annotation s fmt (ia, ial) => - F.fprintf fmt "%a %s(%a)" pp_item_annotation ia s (pp_seq pp_item_annotation) ial; - - -/** Empty method annotation. */ -let method_annotation_empty = ([], []); - - -/** Check if the method annodation is empty. */ -let method_annotation_is_empty (ia, ial) => IList.for_all item_annotation_is_empty [ia, ...ial]; - - /** Kinds of integers */ type ikind = | IChar /** [char] */ @@ -291,7 +193,7 @@ type t = | Tstruct of Typename.t /** structured value type name */ | Tarray of t static_length /** array type with statically fixed length */; -type struct_fields = list (Ident.fieldname, t, item_annotation); +type struct_fields = list (Ident.fieldname, t, Annot.Item.t); /** Type for a structured value. */ @@ -300,7 +202,7 @@ type struct_typ = { statics: struct_fields, /** static fields */ supers: list Typename.t, /** superclasses */ methods: list Procname.t, /** methods defined */ - annots: item_annotation /** annotations */ + annots: Annot.Item.t /** annotations */ }; type lookup = Typename.t => option struct_typ; @@ -343,7 +245,7 @@ let rec compare t1 t2 => let equal t1 t2 => compare t1 t2 == 0; let fld_typ_ann_compare fta1 fta2 => - triple_compare Ident.fieldname_compare compare item_annotation_compare fta1 fta2; + triple_compare Ident.fieldname_compare compare Annot.Item.compare fta1 fta2; /** Pretty print a type declaration. @@ -443,8 +345,7 @@ let internal_mk_struct annots::annots=? () => { let mk_struct_ - default:: - default={fields: [], statics: [], methods: [], supers: [], annots: item_annotation_empty} + default::default={fields: [], statics: [], methods: [], supers: [], annots: Annot.Item.empty} fields::fields=default.fields statics::statics=default.statics methods::methods=default.methods @@ -578,14 +479,14 @@ let has_block_prefix s => /** Check if type is a type for a block in objc */ let is_block_type typ => has_block_prefix (to_string typ); -let objc_ref_counter_annot = [({class_name: "ref_counter", parameters: []}, false)]; +let objc_ref_counter_annot = [({Annot.class_name: "ref_counter", parameters: []}, false)]; /** Field used for objective-c reference counting */ let objc_ref_counter_field = (Ident.fieldname_hidden, Tint IInt, objc_ref_counter_annot); let is_objc_ref_counter_field (fld, _, a) => - Ident.fieldname_is_hidden fld && item_annotation_compare a objc_ref_counter_annot == 0; + Ident.fieldname_is_hidden fld && Annot.Item.compare a objc_ref_counter_annot == 0; /** Java types by name */ diff --git a/infer/src/IR/Typ.rei b/infer/src/IR/Typ.rei index 4274e642b..16e931b4b 100644 --- a/infer/src/IR/Typ.rei +++ b/infer/src/IR/Typ.rei @@ -18,69 +18,6 @@ open! Utils; let module F = Format; -/** Type to represent one @Annotation. */ -type annotation = { - class_name: string, /** name of the annotation */ - parameters: list string /** currently only one string parameter */ -}; - - -/** Compare function for annotations. */ -let annotation_compare: annotation => annotation => int; - - -/** Pretty print an annotation. */ -let pp_annotation: F.formatter => annotation => unit; - -let module AnnotMap: PrettyPrintable.PPMap with type key = annotation; - - -/** Annotation for one item: a list of annotations with visibility. */ -type item_annotation = list (annotation, bool); - - -/** Compare function for annotation items. */ -let item_annotation_compare: item_annotation => item_annotation => int; - - -/** Pretty print an item annotation. */ -let pp_item_annotation: F.formatter => item_annotation => unit; - -let item_annotation_to_string: item_annotation => string; - - -/** Empty item annotation. */ -let item_annotation_empty: item_annotation; - - -/** Check if the item annodation is empty. */ -let item_annotation_is_empty: item_annotation => bool; - -let objc_class_annotation: item_annotation; - -let cpp_class_annotation: item_annotation; - - -/** Annotation for a method: return value and list of parameters. */ -type method_annotation = (item_annotation, list item_annotation); - - -/** Compare function for Method annotations. */ -let method_annotation_compare: method_annotation => method_annotation => int; - - -/** Empty method annotation. */ -let method_annotation_empty: method_annotation; - - -/** Check if the method annodation is empty. */ -let method_annotation_is_empty: method_annotation => bool; - - -/** Pretty print a method annotation. */ -let pp_method_annotation: string => F.formatter => method_annotation => unit; - - /** Kinds of integers */ type ikind = | IChar /** [char] */ @@ -146,7 +83,7 @@ type t = | Tstruct of Typename.t /** structured value type name */ | Tarray of t static_length /** array type with statically fixed length */; -type struct_fields = list (Ident.fieldname, t, item_annotation); +type struct_fields = list (Ident.fieldname, t, Annot.Item.t); /** Type for a structured value. */ @@ -155,7 +92,7 @@ type struct_typ = private { statics: struct_fields, /** static fields */ supers: list Typename.t, /** supers */ methods: list Procname.t, /** methods defined */ - annots: item_annotation /** annotations */ + annots: Annot.Item.t /** annotations */ }; type lookup = Typename.t => option struct_typ; @@ -163,7 +100,7 @@ type lookup = Typename.t => option struct_typ; /** Comparision for fieldnames * types * item annotations. */ let fld_typ_ann_compare: - (Ident.fieldname, t, item_annotation) => (Ident.fieldname, t, item_annotation) => int; + (Ident.fieldname, t, Annot.Item.t) => (Ident.fieldname, t, Annot.Item.t) => int; /** Comparision for types. */ @@ -217,7 +154,7 @@ let internal_mk_struct: statics::struct_fields? => methods::list Procname.t? => supers::list Typename.t? => - annots::item_annotation? => + annots::Annot.Item.t? => unit => struct_typ; @@ -246,7 +183,7 @@ let struct_typ_fld: lookup::lookup => default::t => Ident.fieldname => t => t; /** Return the type of the field [fn] and its annotation, None if [typ] has no field named [fn] */ let get_field_type_and_annotation: - lookup::lookup => Ident.fieldname => t => option (t, item_annotation); + lookup::lookup => Ident.fieldname => t => option (t, Annot.Item.t); let is_objc_class: t => bool; @@ -266,9 +203,9 @@ let is_block_type: t => bool; /** Field used for objective-c reference counting */ -let objc_ref_counter_field: (Ident.fieldname, t, item_annotation); +let objc_ref_counter_field: (Ident.fieldname, t, Annot.Item.t); -let is_objc_ref_counter_field: (Ident.fieldname, t, item_annotation) => bool; +let is_objc_ref_counter_field: (Ident.fieldname, t, Annot.Item.t) => bool; let unsome: string => option t => t; diff --git a/infer/src/backend/Attribute.mli b/infer/src/backend/Attribute.mli index f894974d4..e0281acd3 100644 --- a/infer/src/backend/Attribute.mli +++ b/infer/src/backend/Attribute.mli @@ -91,8 +91,8 @@ val nullify_exp_with_objc_null : Tenv.t -> Prop.normal Prop.t -> Exp.t -> Prop.n (** mark Exp.Var's or Exp.Lvar's as undefined *) val mark_vars_as_undefined : - Tenv.t -> Prop.normal Prop.t -> Exp.t list -> Procname.t -> Typ.item_annotation -> Location.t -> - PredSymb.path_pos -> Prop.normal Prop.t + Tenv.t -> Prop.normal Prop.t -> Exp.t list -> Procname.t -> Annot.Item.t -> + Location.t -> PredSymb.path_pos -> Prop.normal Prop.t (** type for arithmetic problems *) type arith_problem = diff --git a/infer/src/backend/abs.ml b/infer/src/backend/abs.ml index caca2d126..31fd1ba50 100644 --- a/infer/src/backend/abs.ml +++ b/infer/src/backend/abs.ml @@ -1018,10 +1018,10 @@ let cycle_has_weak_or_unretained_or_assign_field tenv cycle = | [] -> false | att:: _ when Config.unsafe_unret = att || Config.weak = att || Config.assign = att -> true | _:: params' -> has_weak_or_unretained_or_assign params' in - let do_annotation (a, _) = - ((a.Typ.class_name = Config.property_attributes) || - (a.Typ.class_name = Config.ivar_attributes)) - && has_weak_or_unretained_or_assign a.Typ.parameters in + let do_annotation ((a: Annot.t), _) = + ((a.class_name = Config.property_attributes) || + (a.class_name = Config.ivar_attributes)) + && has_weak_or_unretained_or_assign a.parameters in let rec do_cycle c = match c with | [] -> false diff --git a/infer/src/backend/modelBuiltins.ml b/infer/src/backend/modelBuiltins.ml index 82e99d061..c71a6f78d 100644 --- a/infer/src/backend/modelBuiltins.ml +++ b/infer/src/backend/modelBuiltins.ml @@ -850,7 +850,7 @@ let execute_scan_function skip_n_arguments ({ Builtin.args } as call_args) SymExec.unknown_or_scan_call ~is_scan:true None - Typ.item_annotation_empty + Annot.Item.empty { call_args with args = !varargs } | _ -> raise (Exceptions.Wrong_argument_number __POS__) diff --git a/infer/src/backend/prover.ml b/infer/src/backend/prover.ml index 166fcf8eb..ea7db4bab 100644 --- a/infer/src/backend/prover.ml +++ b/infer/src/backend/prover.ml @@ -1495,7 +1495,7 @@ let expand_hpred_pointer = let mangled = Mangled.from_string ("counterfeit" ^ string_of_int !count) in let name = Typename.TN_csu (Struct, mangled) in incr count ; - let fields = [(fld, cnt_typ, Typ.item_annotation_empty)] in + let fields = [(fld, cnt_typ, Annot.Item.empty)] in ignore (Tenv.mk_struct tenv ~fields name) ; Exp.Sizeof (Tstruct name, len, st) | _ -> diff --git a/infer/src/backend/rearrange.ml b/infer/src/backend/rearrange.ml index 76e9c67ad..df34a919a 100644 --- a/infer/src/backend/rearrange.ml +++ b/infer/src/backend/rearrange.ml @@ -642,10 +642,10 @@ let add_guarded_by_constraints tenv prop lexp pdesc = string_is_suffix guarded_by_str fully_qualified_this | _ -> false in let extract_guarded_by_str item_annot = - let annot_extract_guarded_by_str (annot, _) = + let annot_extract_guarded_by_str ((annot: Annot.t), _) = if Annotations.annot_ends_with annot Annotations.guarded_by then - match annot.Typ.parameters with + match annot.parameters with | [guarded_by_str] when not (excluded_guardedby_string guarded_by_str) -> Some guarded_by_str | _ -> diff --git a/infer/src/backend/specs.ml b/infer/src/backend/specs.ml index e6c3cb243..b503e4065 100644 --- a/infer/src/backend/specs.ml +++ b/infer/src/backend/specs.ml @@ -315,7 +315,7 @@ type phase = FOOTPRINT | RE_EXECUTION type dependency_map_t = int Procname.Map.t -type call_summary = CallSite.Set.t Typ.AnnotMap.t +type call_summary = CallSite.Set.t Annot.Map.t (** Payload: results of some analysis *) type payload = diff --git a/infer/src/backend/specs.mli b/infer/src/backend/specs.mli index f8971a0d1..d7b625ff8 100644 --- a/infer/src/backend/specs.mli +++ b/infer/src/backend/specs.mli @@ -119,7 +119,7 @@ type phase = FOOTPRINT | RE_EXECUTION type dependency_map_t = int Procname.Map.t -type call_summary = CallSite.Set.t Typ.AnnotMap.t +type call_summary = CallSite.Set.t Annot.Map.t (** Payload: results of some analysis *) type payload = diff --git a/infer/src/backend/symExec.ml b/infer/src/backend/symExec.ml index 68eba5586..c3fbe83b1 100644 --- a/infer/src/backend/symExec.ml +++ b/infer/src/backend/symExec.ml @@ -953,7 +953,7 @@ let load_ret_annots pname = let ret_annots, _ = attrs.ProcAttributes.method_annotation in ret_annots | None -> - Typ.item_annotation_empty + Annot.Item.empty let execute_store ?(report_deref_errors=true) pname pdesc tenv lhs_exp typ rhs_exp loc prop_ = let execute_store_ pdesc tenv rhs_exp acc_in iter = @@ -1190,7 +1190,7 @@ let rec sym_exec tenv current_pdesc _instr (prop_: Prop.normal Prop.t) path L.d_str "Unknown function pointer "; Sil.d_exp fun_exp; L.d_strln ", returning undefined value."; let callee_pname = Procname.from_string_c_fun "__function_pointer__" in - unknown_or_scan_call ~is_scan:false None Typ.item_annotation_empty Builtin.{ + unknown_or_scan_call ~is_scan:false None Annot.Item.empty Builtin.{ pdesc= current_pdesc; instr; tenv; prop_= prop_r; path; ret_ids; args= n_actual_params; proc_name= callee_pname; loc; } end diff --git a/infer/src/backend/symExec.mli b/infer/src/backend/symExec.mli index 39c7cb6ab..e8e6757ad 100644 --- a/infer/src/backend/symExec.mli +++ b/infer/src/backend/symExec.mli @@ -26,7 +26,7 @@ val diverge : Prop.normal Prop.t -> Paths.Path.t -> (Prop.normal Prop.t * Paths. val proc_call : Specs.summary -> Builtin.t -val unknown_or_scan_call : is_scan:bool -> Typ.t option -> Typ.item_annotation -> Builtin.t +val unknown_or_scan_call : is_scan:bool -> Typ.t option -> Annot.Item.t -> Builtin.t val check_variadic_sentinel : ?fails_on_nil:bool -> int -> int * int -> Builtin.t diff --git a/infer/src/backend/taint.ml b/infer/src/backend/taint.ml index 72ad8f5b8..247b0147a 100644 --- a/infer/src/backend/taint.ml +++ b/infer/src/backend/taint.ml @@ -299,7 +299,7 @@ let func_with_tainted_params = let attrs_opt_get_annots = function | Some attrs -> attrs.ProcAttributes.method_annotation - | None -> Typ.method_annotation_empty + | None -> Annot.Method.empty (* TODO: return a taint kind *) (** returns true if [callee_pname] returns a tainted value *) diff --git a/infer/src/checkers/annotationReachability.ml b/infer/src/checkers/annotationReachability.ml index f78a082fc..c96432009 100644 --- a/infer/src/checkers/annotationReachability.ml +++ b/infer/src/checkers/annotationReachability.ml @@ -13,12 +13,12 @@ module F = Format module L = Logging module CallSiteSet = AbstractDomain.FiniteSet (CallSite.Set) -module CallsDomain = AbstractDomain.Map (Typ.AnnotMap) (CallSiteSet) +module CallsDomain = AbstractDomain.Map (Annot.Map) (CallSiteSet) let dummy_constructor_annot = "__infer_is_constructor" let annotation_of_str annot_str = - { Typ.class_name = annot_str; parameters = []; } + { Annot.class_name = annot_str; parameters = []; } (* TODO: read custom source/sink pairs from user code here *) let src_snk_pairs () = @@ -161,7 +161,7 @@ let method_overrides is_annotated tenv pname = overrides () let method_has_annot annot tenv pname = - let has_annot ia = Annotations.ia_ends_with ia annot.Typ.class_name in + let has_annot ia = Annotations.ia_ends_with ia annot.Annot.class_name in if Annotations.annot_ends_with annot dummy_constructor_annot then is_allocator tenv pname else if Annotations.annot_ends_with annot Annotations.expensive @@ -176,7 +176,7 @@ let lookup_annotation_calls annot pname : CallSite.t list = | Some { Specs.payload = { Specs.calls = Some call_map; }; } -> begin try - Typ.AnnotMap.find annot call_map + Annot.Map.find annot call_map |> CallSiteSet.elements with Not_found -> [] @@ -303,14 +303,14 @@ module TransferFunctions (CFG : ProcCfg.S) = struct (* TODO: generalize this to allow sanitizers for other annotation types, store it in [extras] so we can compute it just once *) let method_is_sanitizer annot tenv pname = - if annot.Typ.class_name = dummy_constructor_annot + if annot.Annot.class_name = dummy_constructor_annot then method_has_ignore_allocation_annot tenv pname else false let add_call call_map tenv callee_pname caller_pname call_site astate = let add_call_for_annot annot _ astate = let calls = - try Typ.AnnotMap.find annot call_map + try Annot.Map.find annot call_map with Not_found -> CallSiteSet.empty in if (not (CallSiteSet.is_empty calls) || method_has_annot annot tenv callee_pname) && (not (method_is_sanitizer annot tenv caller_pname)) @@ -323,7 +323,7 @@ module TransferFunctions (CFG : ProcCfg.S) = struct | Domain.NonBottom (map, _) -> (* for each annotation type T in domain(astate), check if method calls something annotated with T *) - Typ.AnnotMap.fold add_call_for_annot map astate + Annot.Map.fold add_call_for_annot map astate let exec_instr astate { ProcData.pdesc; tenv; } _ = function | Sil.Call ([id], Const (Cfun callee_pname), _, _, _) @@ -338,7 +338,7 @@ module TransferFunctions (CFG : ProcCfg.S) = struct | Some Domain.NonBottom (call_map, _) -> add_call call_map tenv callee_pname caller_pname call_site astate | None -> - add_call Typ.AnnotMap.empty tenv callee_pname caller_pname call_site astate + add_call Annot.Map.empty tenv callee_pname caller_pname call_site astate | Some Domain.Bottom -> astate end @@ -395,17 +395,17 @@ module Interprocedural = struct PatternMatch.proc_iter_overridden_methods check_expensive_subtyping_rules tenv proc_name; - let report_src_snk_paths call_map (src_annot_list, snk_annot) = + let report_src_snk_paths call_map (src_annot_list, (snk_annot: Annot.t)) = let extract_calls_with_annot annot call_map = try - Typ.AnnotMap.find annot call_map + Annot.Map.find annot call_map |> CallSiteSet.elements with Not_found -> [] in - let report_src_snk_path (calls : CallSite.t list) src_annot = + let report_src_snk_path (calls : CallSite.t list) (src_annot: Annot.t) = if method_overrides_annot src_annot tenv proc_name then let f_report = - report_annotation_stack src_annot.Typ.class_name snk_annot.Typ.class_name in + report_annotation_stack src_annot.class_name snk_annot.class_name in report_call_stack (method_has_annot snk_annot tenv) (lookup_annotation_calls snk_annot) diff --git a/infer/src/checkers/annotations.ml b/infer/src/checkers/annotations.ml index e1ee07ef9..bcc59eb9f 100644 --- a/infer/src/checkers/annotations.ml +++ b/infer/src/checkers/annotations.ml @@ -16,19 +16,19 @@ module L = Logging (** Method signature with annotations. *) type annotated_signature = { - ret : Typ.item_annotation * Typ.t; (** Annotated return type. *) - params: (Mangled.t * Typ.item_annotation * Typ.t) list (** Annotated parameters. *) + ret : Annot.Item.t * Typ.t; (** Annotated return type. *) + params: (Mangled.t * Annot.Item.t * Typ.t) list (** Annotated parameters. *) } let param_equal (s1, ia1, t1) (s2, ia2, t2) = Mangled.equal s1 s2 && - Typ.item_annotation_compare ia1 ia2 = 0 && + Annot.Item.compare ia1 ia2 = 0 && Typ.equal t1 t2 let equal as1 as2 = let ia1, t1 = as1.ret and ia2, t2 = as2.ret in - Typ.item_annotation_compare ia1 ia2 = 0 && + Annot.Item.compare ia1 ia2 = 0 && Typ.equal t1 t2 && IList.for_all2 param_equal as1.params as2.params @@ -39,12 +39,12 @@ let ia_iter f = let ann_iter (a, _) = f a in IList.iter ann_iter -let ma_iter f ((ia, ial) : Typ.method_annotation) = +let ma_iter f ((ia, ial) : Annot.Method.t) = IList.iter (ia_iter f) (ia:: ial) let ma_has_annotation_with - (ma: Typ.method_annotation) - (predicate: Typ.annotation -> bool): bool = + (ma: Annot.Method.t) + (predicate: Annot.t -> bool): bool = let found = ref false in ma_iter (fun a -> if predicate a then found := true) @@ -52,8 +52,8 @@ let ma_has_annotation_with !found let ia_has_annotation_with - (ia: Typ.item_annotation) - (predicate: Typ.annotation -> bool): bool = + (ia: Annot.Item.t) + (predicate: Annot.t -> bool): bool = let found = ref false in ia_iter (fun a -> if predicate a then found := true) @@ -66,7 +66,7 @@ let annot_ends_with annot ann_name = let sl = String.length s in let al = String.length ann_name in sl >= al && String.sub s (sl - al) al = ann_name in - filter annot.Typ.class_name + filter annot.Annot.class_name (** Check if there is an annotation in [ia] which ends with the given name *) let ia_ends_with ia ann_name = @@ -76,18 +76,18 @@ let ia_ends_with ia ann_name = let ia_contains ia ann_name = let found = ref false in - ia_iter (fun a -> if ann_name = a.Typ.class_name then found := true) ia; + ia_iter (fun a -> if ann_name = a.Annot.class_name then found := true) ia; !found let ia_get ia ann_name = let found = ref None in - ia_iter (fun a -> if ann_name = a.Typ.class_name then found := Some a) ia; + ia_iter (fun a -> if ann_name = a.Annot.class_name then found := Some a) ia; !found let ma_contains ma ann_names = let found = ref false in ma_iter (fun a -> - if IList.exists (string_equal a.Typ.class_name) ann_names then found := true + if IList.exists (string_equal a.Annot.class_name) ann_names then found := true ) ma; !found @@ -236,7 +236,7 @@ let get_annotated_signature proc_attributes : annotated_signature = | ia :: ial', (name, typ) :: parl' -> (name, ia, typ) :: extract ial' parl' | [], (name, typ) :: parl' -> - (name, Typ.item_annotation_empty, typ) :: extract [] parl' + (name, Annot.Item.empty, typ) :: extract [] parl' | [], [] -> [] | _ :: _, [] -> @@ -251,7 +251,7 @@ let get_annotated_signature proc_attributes : annotated_signature = are called x0, x1, x2. *) let annotated_signature_is_anonymous_inner_class_wrapper ann_sig proc_name = let check_ret (ia, t) = - Typ.item_annotation_is_empty ia && PatternMatch.type_is_object t in + Annot.Item.is_empty ia && PatternMatch.type_is_object t in let x_param_found = ref false in let name_is_x_number name = let name_str = Mangled.to_string name in @@ -270,7 +270,7 @@ let annotated_signature_is_anonymous_inner_class_wrapper ann_sig proc_name = if Mangled.to_string name = "this" then true else name_is_x_number name && - Typ.item_annotation_is_empty ia && + Annot.Item.is_empty ia && PatternMatch.type_is_object t in Procname.java_is_anonymous_inner_class proc_name && check_ret ann_sig.ret @@ -286,7 +286,7 @@ let param_is_nullable pvar ann_sig = (** Pretty print a method signature with annotations. *) let pp_annotated_signature proc_name fmt annotated_signature = - let pp_ia fmt ia = if ia <> [] then F.fprintf fmt "%a " Typ.pp_item_annotation ia in + let pp_ia fmt ia = if ia <> [] then F.fprintf fmt "%a " Annot.Item.pp ia in let pp_annotated_param fmt (p, ia, t) = F.fprintf fmt " %a%a %a" pp_ia ia (Typ.pp_full pe_text) t Mangled.pp p in let ia, ret_type = annotated_signature.ret in @@ -296,7 +296,7 @@ let pp_annotated_signature proc_name fmt annotated_signature = (Procname.to_simplified_string proc_name) (pp_comma_seq pp_annotated_param) annotated_signature.params -let mk_ann_str s = { Typ.class_name = s; Typ.parameters = [] } +let mk_ann_str s = { Annot.class_name = s; parameters = [] } let mk_ann = function | Nullable -> mk_ann_str nullable | Present -> mk_ann_str present diff --git a/infer/src/checkers/annotations.mli b/infer/src/checkers/annotations.mli index 798c0e8ea..33eb04b20 100644 --- a/infer/src/checkers/annotations.mli +++ b/infer/src/checkers/annotations.mli @@ -25,8 +25,8 @@ type annotation = (** Method signature with annotations. *) type annotated_signature = { - ret : Typ.item_annotation * Typ.t; (** Annotated return type. *) - params: (Mangled.t * Typ.item_annotation * Typ.t) list (** Annotated parameters. *) + ret : Annot.Item.t * Typ.t; (** Annotated return type. *) + params: (Mangled.t * Annot.Item.t * Typ.t) list (** Annotated parameters. *) } (** Check if the annotated signature is for a wrapper of an anonymous inner class method. @@ -57,57 +57,57 @@ val get_annotated_signature : ProcAttributes.t -> annotated_signature val nullable : string (** Return true if [annot] ends with [ann_name] *) -val annot_ends_with : Typ.annotation -> string -> bool +val annot_ends_with : Annot.t -> string -> bool (** Check if there is an annotation in [ia] which ends with the given name *) -val ia_ends_with : Typ.item_annotation -> string -> bool +val ia_ends_with : Annot.Item.t -> string -> bool -val ia_contains : Typ.item_annotation -> string -> bool +val ia_contains : Annot.Item.t -> string -> bool -val ia_has_annotation_with : Typ.item_annotation -> (Typ.annotation -> bool) -> bool +val ia_has_annotation_with : Annot.Item.t -> (Annot.t -> bool) -> bool -val ia_get_strict : Typ.item_annotation -> Typ.annotation option +val ia_get_strict : Annot.Item.t -> Annot.t option -val ia_is_false_on_null : Typ.item_annotation -> bool -val ia_is_initializer : Typ.item_annotation -> bool +val ia_is_false_on_null : Annot.Item.t -> bool +val ia_is_initializer : Annot.Item.t -> bool (** Annotations for readonly injectors. The injector framework initializes the field but does not write null into it. *) -val ia_is_field_injector_readonly : Typ.item_annotation -> bool +val ia_is_field_injector_readonly : Annot.Item.t -> bool (** Annotations for read-write injectors. The injector framework initializes the field and can write null into it. *) -val ia_is_field_injector_readwrite : Typ.item_annotation -> bool - -val ia_is_mutable : Typ.item_annotation -> bool -val ia_is_nonnull : Typ.item_annotation -> bool -val ia_is_nullable : Typ.item_annotation -> bool -val ia_is_present : Typ.item_annotation -> bool -val ia_is_true_on_null : Typ.item_annotation -> bool -val ia_is_verify : Typ.item_annotation -> bool -val ia_is_expensive : Typ.item_annotation -> bool -val ia_is_performance_critical : Typ.item_annotation -> bool -val ia_is_no_allocation : Typ.item_annotation -> bool -val ia_is_ignore_allocations : Typ.item_annotation -> bool -val ia_is_suppress_warnings : Typ.item_annotation -> bool -val ia_is_privacy_source : Typ.item_annotation -> bool -val ia_is_privacy_sink : Typ.item_annotation -> bool -val ia_is_integrity_source : Typ.item_annotation -> bool -val ia_is_integrity_sink : Typ.item_annotation -> bool -val ia_is_guarded_by : Typ.item_annotation -> bool - -val ia_iter : (Typ.annotation -> unit) -> Typ.item_annotation -> unit - -val ma_has_annotation_with : Typ.method_annotation -> (Typ.annotation -> bool) -> bool +val ia_is_field_injector_readwrite : Annot.Item.t -> bool + +val ia_is_mutable : Annot.Item.t -> bool +val ia_is_nonnull : Annot.Item.t -> bool +val ia_is_nullable : Annot.Item.t -> bool +val ia_is_present : Annot.Item.t -> bool +val ia_is_true_on_null : Annot.Item.t -> bool +val ia_is_verify : Annot.Item.t -> bool +val ia_is_expensive : Annot.Item.t -> bool +val ia_is_performance_critical : Annot.Item.t -> bool +val ia_is_no_allocation : Annot.Item.t -> bool +val ia_is_ignore_allocations : Annot.Item.t -> bool +val ia_is_suppress_warnings : Annot.Item.t -> bool +val ia_is_privacy_source : Annot.Item.t -> bool +val ia_is_privacy_sink : Annot.Item.t -> bool +val ia_is_integrity_source : Annot.Item.t -> bool +val ia_is_integrity_sink : Annot.Item.t -> bool +val ia_is_guarded_by : Annot.Item.t -> bool + +val ia_iter : (Annot.t -> unit) -> Annot.Item.t -> unit + +val ma_has_annotation_with : Annot.Method.t -> (Annot.t -> bool) -> bool val pdesc_has_annot : Cfg.Procdesc.t -> string -> bool (** Mark the return of the method_annotation with the given annotation. *) val method_annotation_mark_return : - annotation -> Typ.method_annotation -> Typ.method_annotation + annotation -> Annot.Method.t -> Annot.Method.t (** Add the annotation to the item_annotation. *) -val mk_ia : annotation -> Typ.item_annotation -> Typ.item_annotation +val mk_ia : annotation -> Annot.Item.t -> Annot.Item.t val pp_annotated_signature : Procname.t -> Format.formatter -> annotated_signature -> unit diff --git a/infer/src/checkers/checkers.ml b/infer/src/checkers/checkers.ml index 9e8b52c48..c654d1f9b 100644 --- a/infer/src/checkers/checkers.ml +++ b/infer/src/checkers/checkers.ml @@ -89,7 +89,7 @@ module ST = struct - @some.PrefixErrorName where the kind matching is case - insensitive and ignores '-' and '_' characters. *) let suppressed = - let annotation_matches a = + let annotation_matches (a: Annot.t) = let normalize str = Str.global_replace (Str.regexp "[_-]") "" (String.lowercase str) in let drop_prefix str = @@ -98,10 +98,10 @@ module ST = struct string_equal (normalize s1) (normalize s2) in let is_parameter_suppressed = - IList.mem string_equal a.Typ.class_name [Annotations.suppressLint] && - IList.mem normalized_equal kind a.Typ.parameters in + IList.mem string_equal a.class_name [Annotations.suppressLint] && + IList.mem normalized_equal kind a.parameters in let is_annotation_suppressed = - string_is_suffix (normalize (drop_prefix kind)) (normalize a.Typ.class_name) in + string_is_suffix (normalize (drop_prefix kind)) (normalize a.class_name) in is_parameter_suppressed || is_annotation_suppressed in diff --git a/infer/src/checkers/patternMatch.ml b/infer/src/checkers/patternMatch.ml index 05bc585e8..fde20b564 100644 --- a/infer/src/checkers/patternMatch.ml +++ b/infer/src/checkers/patternMatch.ml @@ -77,7 +77,7 @@ let type_get_class_name = function | Typ.Tptr (typ, _) -> Typ.name typ | _ -> None -let type_get_annotation tenv (typ: Typ.t): Typ.item_annotation option = +let type_get_annotation tenv (typ: Typ.t): Annot.Item.t option = match typ with | Tptr (Tstruct name, _) | Tstruct name -> ( diff --git a/infer/src/checkers/patternMatch.mli b/infer/src/checkers/patternMatch.mli index 057e50af7..6c93c223c 100644 --- a/infer/src/checkers/patternMatch.mli +++ b/infer/src/checkers/patternMatch.mli @@ -81,7 +81,7 @@ val proc_calls : Only Java supported at the moment. *) val proc_iter_overridden_methods : (Procname.t -> unit) -> Tenv.t -> Procname.t -> unit -val type_get_annotation : Tenv.t -> Typ.t -> Typ.item_annotation option +val type_get_annotation : Tenv.t -> Typ.t -> Annot.Item.t option (** Get the class name of the type *) val type_get_class_name : Typ.t -> Typename.t option diff --git a/infer/src/clang/cField_decl.ml b/infer/src/clang/cField_decl.ml index 193998bdf..fcc939810 100644 --- a/infer/src/clang/cField_decl.ml +++ b/infer/src/clang/cField_decl.ml @@ -15,7 +15,7 @@ open CFrontend_utils module L = Logging -type field_type = Ident.fieldname * Typ.t * (Typ.annotation * bool) list +type field_type = Ident.fieldname * Typ.t * (Annot.t * bool) list let rec get_fields_super_classes tenv super_class = Printing.log_out " ... Getting fields of superclass '%s'\n" (Typename.to_string super_class); @@ -47,9 +47,11 @@ let build_sil_field type_ptr_to_sil_type tenv field_name type_ptr prop_attribute let typ = type_ptr_to_sil_type tenv type_ptr in let item_annotations = match prop_atts with | [] -> - [({ Typ.class_name = Config.ivar_attributes; parameters = annotation_from_type typ }, true)] + [({ Annot.class_name = Config.ivar_attributes; parameters = annotation_from_type typ }, + true)] | _ -> - [({ Typ.class_name = Config.property_attributes; parameters = prop_atts }, true)] in + [({ Annot.class_name = Config.property_attributes; parameters = prop_atts }, + true)] in fname, typ, item_annotations (* Given a list of declarations in an interface returns a list of fields *) @@ -94,6 +96,6 @@ let modelled_field class_name_info = let class_name_qualified = class_name_info.Clang_ast_t.ni_qual_name in let field_name_qualified = Ast_utils.make_qual_name_decl class_name_qualified field_name in let name = General_utils.mk_class_field_name field_name_qualified in - (name, typ, Typ.item_annotation_empty) :: res + (name, typ, Annot.Item.empty) :: res else res in IList.fold_left modelled_field_in_class [] modelled_fields_in_classes diff --git a/infer/src/clang/cField_decl.mli b/infer/src/clang/cField_decl.mli index 7d8973c99..a5c6c4f82 100644 --- a/infer/src/clang/cField_decl.mli +++ b/infer/src/clang/cField_decl.mli @@ -12,7 +12,7 @@ open! Utils (** Utility module to retrieve fields of structs of classes *) open CFrontend_utils -type field_type = Ident.fieldname * Typ.t * (Typ.annotation * bool) list +type field_type = Ident.fieldname * Typ.t * (Annot.t * bool) list val get_fields : Ast_utils.type_ptr_to_sil_type -> Tenv.t -> CContext.curr_class -> Clang_ast_t.decl list -> field_type list diff --git a/infer/src/clang/cFrontend_utils.ml b/infer/src/clang/cFrontend_utils.ml index 43bbbe234..ef513b88a 100644 --- a/infer/src/clang/cFrontend_utils.ml +++ b/infer/src/clang/cFrontend_utils.ml @@ -494,7 +494,7 @@ struct let append_no_duplicates_annotations list1 list2 = - let eq (annot1, _) (annot2, _) = annot1.Typ.class_name = annot2.Typ.class_name in + let eq (annot1, _) (annot2, _) = annot1.Annot.class_name = annot2.Annot.class_name in append_no_duplicates eq list1 list2 let add_no_duplicates_fields field_tuple l = diff --git a/infer/src/clang/cFrontend_utils.mli b/infer/src/clang/cFrontend_utils.mli index 568225f64..4b5aab9f9 100644 --- a/infer/src/clang/cFrontend_utils.mli +++ b/infer/src/clang/cFrontend_utils.mli @@ -138,7 +138,7 @@ sig val generate_key_decl : Clang_ast_t.decl -> string (** Given an objc impl or interface decl, returns the objc interface decl of - the superclass, if any. *) + the superclass, if any. *) val get_super_if : Clang_ast_t.decl option -> Clang_ast_t.decl option (** Given an objc impl decl info, return the super class's list of decls and @@ -163,9 +163,9 @@ sig val string_from_list : string list -> string - val append_no_duplicates_fields : (Ident.fieldname * Typ.t * Typ.item_annotation) list -> - (Ident.fieldname * Typ.t * Typ.item_annotation) list -> - (Ident.fieldname * Typ.t * Typ.item_annotation) list + val append_no_duplicates_fields : (Ident.fieldname * Typ.t * Annot.Item.t) list -> + (Ident.fieldname * Typ.t * Annot.Item.t) list -> + (Ident.fieldname * Typ.t * Annot.Item.t) list val append_no_duplicates_csu : Typename.t list -> Typename.t list -> Typename.t list @@ -179,8 +179,8 @@ sig (Exp.t * Typ.t) list -> (Exp.t * Typ.t) list -> (Exp.t * Typ.t) list val sort_fields : - (Ident.fieldname * Typ.t * Typ.item_annotation) list -> - (Ident.fieldname * Typ.t * Typ.item_annotation) list + (Ident.fieldname * Typ.t * Annot.Item.t) list -> + (Ident.fieldname * Typ.t * Annot.Item.t) list val sort_fields_tenv : Tenv.t -> unit diff --git a/infer/src/clang/cMethod_trans.ml b/infer/src/clang/cMethod_trans.ml index fc0b805a7..2f7d6d98b 100644 --- a/infer/src/clang/cMethod_trans.ml +++ b/infer/src/clang/cMethod_trans.ml @@ -336,16 +336,16 @@ let should_create_procdesc cfg procname defined = else false | None -> true -let sil_method_annotation_of_args args : Typ.method_annotation = +let sil_method_annotation_of_args args : Annot.Method.t = let default_visibility = true in let mk_annot param_name annot_name = - let annot = { Typ.class_name = annot_name; Typ.parameters = [param_name]; } in + let annot = { Annot.class_name = annot_name; parameters = [param_name]; } in annot, default_visibility in let arg_to_sil_annot (arg_mangled, {Clang_ast_t.qt_type_ptr}) acc = let arg_name = Mangled.to_string arg_mangled in if CFrontend_utils.Ast_utils.is_type_nullable qt_type_ptr then [mk_annot arg_name Annotations.nullable] :: acc - else Typ.item_annotation_empty::acc in + else Annot.Item.empty::acc in let param_annots = IList.fold_right arg_to_sil_annot args [] in (* TODO: parse annotations on return value *) let retval_annot = [] in diff --git a/infer/src/clang/cTrans.ml b/infer/src/clang/cTrans.ml index e44331ea6..6fbe7e10b 100644 --- a/infer/src/clang/cTrans.ml +++ b/infer/src/clang/cTrans.ml @@ -118,7 +118,7 @@ struct let vname = Pvar.get_name var in let qual_name = Ast_utils.make_qual_name_decl [block_name] (Mangled.to_string vname) in let fname = General_utils.mk_class_field_name qual_name in - let item_annot = Typ.item_annotation_empty in + let item_annot = Annot.Item.empty in fname, typ, item_annot in let fields = IList.map mk_field_from_captured_var captured_vars in Printing.log_out "Block %s field:\n" block_name; diff --git a/infer/src/clang/cTypes_decl.ml b/infer/src/clang/cTypes_decl.ml index 003faa280..844e19a15 100644 --- a/infer/src/clang/cTypes_decl.ml +++ b/infer/src/clang/cTypes_decl.ml @@ -182,8 +182,8 @@ and get_record_declaration_struct_type tenv decl = [Typ.objc_ref_counter_field] else [] in let annots = - if csu = Csu.Class Csu.CPP then Typ.cpp_class_annotation - else Typ.item_annotation_empty (* No annotations for structs *) in + if csu = Csu.Class Csu.CPP then Annot.Class.cpp + else Annot.Item.empty (* No annotations for structs *) in if is_complete_definition then ( Ast_utils.update_sil_types_map type_ptr (Typ.Tstruct sil_typename); let non_statics = get_struct_fields tenv decl in diff --git a/infer/src/clang/objcInterface_decl.ml b/infer/src/clang/objcInterface_decl.ml index 808eb22ed..604bc8604 100644 --- a/infer/src/clang/objcInterface_decl.ml +++ b/infer/src/clang/objcInterface_decl.ml @@ -126,7 +126,7 @@ let add_class_to_tenv type_ptr_to_sil_type tenv curr_class decl_info name_info d Printing.log_out "-----> field: '%s'\n" (Ident.fieldname_to_string fn)) all_fields; ignore( Tenv.mk_struct tenv - ~fields: all_fields ~supers ~methods ~annots:Typ.objc_class_annotation interface_name ); + ~fields: all_fields ~supers ~methods ~annots:Annot.Class.objc interface_name ); Printing.log_out " >>>Verifying that Typename '%s' is in tenv\n" (Typename.to_string interface_name); (match Tenv.lookup tenv interface_name with diff --git a/infer/src/clang/printing.ml b/infer/src/clang/printing.ml index 7e1389396..29162c531 100644 --- a/infer/src/clang/printing.ml +++ b/infer/src/clang/printing.ml @@ -21,9 +21,9 @@ let log_err fmt = pp Format.err_formatter fmt -let annotation_to_string (annotation, _) = - "< " ^ annotation.Typ.class_name ^ " : " ^ - (IList.to_string (fun x -> x) annotation.Typ.parameters) ^ " >" +let annotation_to_string ((annotation: Annot.t), _) = + "< " ^ annotation.class_name ^ " : " ^ + (IList.to_string (fun x -> x) annotation.parameters) ^ " >" let field_to_string (fieldname, typ, annotation) = (Ident.fieldname_to_string fieldname) ^ " " ^ @@ -41,7 +41,7 @@ let print_tenv tenv = | Typename.TN_csu (Csu.Class _, _) | Typename.TN_csu (Csu.Protocol, _) -> print_endline ( (Typename.to_string typname) ^ " " ^ - (Typ.item_annotation_to_string struct_t.annots) ^ "\n" ^ + (Annot.Item.to_string struct_t.annots) ^ "\n" ^ "---> superclass and protocols " ^ (IList.to_string (fun tn -> "\t" ^ (Typename.to_string tn) ^ "\n") struct_t.supers) ^ "---> methods " ^ diff --git a/infer/src/clang/printing.mli b/infer/src/clang/printing.mli index 73680ca96..163a73f3b 100644 --- a/infer/src/clang/printing.mli +++ b/infer/src/clang/printing.mli @@ -27,4 +27,4 @@ val print_nodes : Cfg.Node.t list -> unit val instrs_to_string : Sil.instr list -> string -val field_to_string : Ident.fieldname * Typ.t * Typ.item_annotation -> string +val field_to_string : Ident.fieldname * Typ.t * Annot.Item.t -> string diff --git a/infer/src/eradicate/typeAnnotation.mli b/infer/src/eradicate/typeAnnotation.mli index b84f4d719..c03635863 100644 --- a/infer/src/eradicate/typeAnnotation.mli +++ b/infer/src/eradicate/typeAnnotation.mli @@ -19,7 +19,7 @@ val const : Annotations.annotation -> bool -> TypeOrigin.t -> t val descr_origin : Tenv.t -> t -> TypeErr.origin_descr val equal : t -> t -> bool -val from_item_annotation : Typ.item_annotation -> TypeOrigin.t -> t +val from_item_annotation : Annot.Item.t -> TypeOrigin.t -> t val get_origin : t -> TypeOrigin.t val get_value : Annotations.annotation -> t -> bool val join : t -> t -> t option diff --git a/infer/src/eradicate/typeErr.ml b/infer/src/eradicate/typeErr.ml index 630f22b70..2e7663e55 100644 --- a/infer/src/eradicate/typeErr.ml +++ b/infer/src/eradicate/typeErr.ml @@ -280,7 +280,7 @@ module Strict = struct (* Return (Some parameters) if there is a method call on a @Nullable object,*) (* where the origin of @Nullable in the analysis is the return value of a Strict method*) (* with parameters. A method is Strict if it or its class are annotated @Strict. *) - let err_instance_get_strict tenv err_instance : Typ.annotation option = + let err_instance_get_strict tenv err_instance : Annot.t option = match err_instance with | Call_receiver_annotation_inconsistent (Annotations.Nullable, _, _, origin_descr) | Null_field_access (_, _, origin_descr, _) -> diff --git a/infer/src/eradicate/typeErr.mli b/infer/src/eradicate/typeErr.mli index 116724875..11ce8a8c6 100644 --- a/infer/src/eradicate/typeErr.mli +++ b/infer/src/eradicate/typeErr.mli @@ -29,7 +29,8 @@ module InstrRef : InstrRefT module Strict : sig - val signature_get_strict : Tenv.t -> Annotations.annotated_signature -> Typ.annotation option + val signature_get_strict : + Tenv.t -> Annotations.annotated_signature -> Annot.t option end (* Strict *) diff --git a/infer/src/eradicate/typeOrigin.ml b/infer/src/eradicate/typeOrigin.ml index 53a750d30..de5d34409 100644 --- a/infer/src/eradicate/typeOrigin.ml +++ b/infer/src/eradicate/typeOrigin.ml @@ -91,7 +91,7 @@ let get_description tenv origin = let strict = match TypeErr.Strict.signature_get_strict tenv po.annotated_signature with | Some ann -> let str = "@Strict" in - (match ann.Typ.parameters with + (match ann.Annot.parameters with | par1 :: _ -> Printf.sprintf "%s(%s) " str par1 | [] -> Printf.sprintf "%s " str) | None -> "" in diff --git a/infer/src/java/jAnnotation.ml b/infer/src/java/jAnnotation.ml index 3e6801fd8..26782d807 100644 --- a/infer/src/java/jAnnotation.ml +++ b/infer/src/java/jAnnotation.ml @@ -17,12 +17,13 @@ let is_suppress_warnings_annotated = Inferconfig.suppress_warnings_matcher DB.source_file_empty let suppress_warnings = - ({ Typ.class_name = Annotations.suppress_warnings; - Typ.parameters = ["infer"] }, + ({ Annot. + class_name = Annotations.suppress_warnings; + parameters = ["infer"] }, true) (** Translate an annotation. *) -let translate a : Typ.annotation = +let translate a : Annot.t = let class_name = JBasics.cn_name a.JBasics.kind in let translate_value_pair (_, value) = match value with @@ -32,12 +33,13 @@ let translate a : Typ.annotation = s | _ -> "?" in let element_value_pairs = a.JBasics.element_value_pairs in - { Typ.class_name = class_name; - Typ.parameters = IList.map translate_value_pair element_value_pairs } + { Annot. + class_name; + parameters = IList.map translate_value_pair element_value_pairs } (** Translate an item annotation. *) -let translate_item avlist : Typ.item_annotation = +let translate_item avlist : Annot.Item.t = let trans_vis = function | Javalib.RTVisible -> true | Javalib.RTInvisible -> false in @@ -46,7 +48,7 @@ let translate_item avlist : Typ.item_annotation = (** Translate a method annotation. *) -let translate_method proc_name_java ann : Typ.method_annotation = +let translate_method proc_name_java ann : Annot.Method.t = let global_ann = ann.Javalib.ma_global in let param_ann = ann.Javalib.ma_parameters in let ret_item = diff --git a/infer/src/java/jAnnotation.mli b/infer/src/java/jAnnotation.mli index f932f22a7..e619d52c2 100644 --- a/infer/src/java/jAnnotation.mli +++ b/infer/src/java/jAnnotation.mli @@ -14,7 +14,7 @@ open Javalib_pack (** Translate an item annotation. *) -val translate_item : (JBasics.annotation * Javalib.visibility) list -> Typ.item_annotation +val translate_item : (JBasics.annotation * Javalib.visibility) list -> Annot.Item.t (** Translate a method annotation. *) -val translate_method : Procname.java -> Javalib.method_annotations -> Typ.method_annotation +val translate_method : Procname.java -> Javalib.method_annotations -> Annot.Method.t