[Infer][Java] Handling assert keyword by adding a special case for the $assertionsDisabled field during translation

master
Sam Blackshear 10 years ago
parent 3a51764d4c
commit 066b132da2

@ -576,6 +576,12 @@ let rec expression context pc expr =
| Called p | Defined p -> p in | Called p | Defined p -> p in
let field_type = (JTransType.get_class_type program tenv (JBasics.make_cn JConfig.string_cl)) in let field_type = (JTransType.get_class_type program tenv (JBasics.make_cn JConfig.string_cl)) in
JTransStaticField.translate_instr_static_field context callee_procdesc fs field_type loc JTransStaticField.translate_instr_static_field context callee_procdesc fs field_type loc
else
if JTransType.is_autogenerated_assert_field field_name
then
(* assume that reading from C.$assertionsDisabled always yields "false". this allows *)
(* Infer to understand the assert keyword in the expected way *)
(idl, instrs, Sil.exp_zero)
else else
let sil_expr = Sil.Lfield (sil_expr, field_name, sil_type) in let sil_expr = Sil.Lfield (sil_expr, field_name, sil_type) in
let tmp_id = Ident.create_fresh Ident.knormal in let tmp_id = Ident.create_fresh Ident.knormal in

@ -342,6 +342,9 @@ let get_class_type program tenv cn =
let t = get_class_type_no_pointer program tenv cn in let t = get_class_type_no_pointer program tenv cn in
Sil.Tptr (t, Sil.Pk_pointer) Sil.Tptr (t, Sil.Pk_pointer)
(** return true if [field_name] is the autogenerated C.$assertionsDisabled field for class C *)
let is_autogenerated_assert_field field_name =
string_equal (Ident.java_fieldname_get_field field_name) "$assertionsDisabled"
(** translate an object type *) (** translate an object type *)
let rec object_type program tenv ot = let rec object_type program tenv ot =

@ -19,6 +19,9 @@ val get_class_type_no_pointer: JClasspath.program -> Sil.tenv -> JBasics.class_n
(** [get_class_type tenv cn] returns the sil type representation of the class *) (** [get_class_type tenv cn] returns the sil type representation of the class *)
val get_class_type : JClasspath.program -> Sil.tenv -> JBasics.class_name -> Sil.typ val get_class_type : JClasspath.program -> Sil.tenv -> JBasics.class_name -> Sil.typ
(** return true if [field_name] is the autogenerated C.$assertionsDisabled field for class C *)
val is_autogenerated_assert_field : Ident.fieldname -> bool
(** transforms a Java object type to a Sil type *) (** transforms a Java object type to a Sil type *)
val object_type : JClasspath.program -> Sil.tenv -> JBasics.object_type -> Sil.typ val object_type : JClasspath.program -> Sil.tenv -> JBasics.object_type -> Sil.typ

Loading…
Cancel
Save