diff --git a/infer/src/java/jMain.ml b/infer/src/java/jMain.ml index 3fca7177a..a0f6f7612 100644 --- a/infer/src/java/jMain.ml +++ b/infer/src/java/jMain.ml @@ -130,7 +130,7 @@ let load_tenv program = (* Store to a file the type environment containing all the types required to perform the analysis *) let save_tenv classpath tenv = - JTransType.saturate_tenv_with_classpath classpath tenv; + if not Config.analyze_models then JTransType.add_models_types tenv; let tenv_filename = DB.global_tenv_fname () in (* TODO: this prevents per compilation step incremental analysis at this stage *) if DB.file_exists tenv_filename then DB.file_remove tenv_filename; diff --git a/infer/src/java/jTransType.ml b/infer/src/java/jTransType.ml index 21b555f3e..2985fa94d 100644 --- a/infer/src/java/jTransType.ml +++ b/infer/src/java/jTransType.ml @@ -456,56 +456,28 @@ let update_tenv tenv program = JBasics.ClassMap.iter add (JClasspath.get_classmap program) -(* Update a type environment with the types found in the classpath *) -let saturate_tenv_with_classpath classpath tenv = +let add_models_types tenv = let jar_tenv_filename = let root = Filename.concat Config.default_in_zip_results_dir Config.captured_dir_name in Filename.concat root Config.global_tenv_filename in let temp_tenv_filename = DB.filename_from_string (Filename.temp_file "tmp_" Config.global_tenv_filename) in - let typename_of_classname classname = - Sil.TN_csu (Sil.Class, classname) in - let rec is_useful_subtype jar_tenv = function - | Sil.TN_csu (Sil.Class, classname) when - Mangled.equal classname JConfig.java_lang_object_classname -> false - | typename when Sil.tenv_mem tenv typename -> true - | typename -> - begin - match Sil.tenv_lookup jar_tenv typename with - | None - | Some (Sil.Tstruct (_, _, _, _, [], _, _)) -> false - | Some (Sil.Tstruct (_, _, _, _, supers, _, _)) -> - list_exists - (is_useful_subtype jar_tenv) - (list_map (fun (_, c) -> typename_of_classname c) supers) - | _ -> assert false - end in - let transfer_type jar_tenv typename typ = - if not (Sil.tenv_mem tenv typename) then - if is_useful_subtype jar_tenv typename then - Sil.tenv_add tenv typename typ in - let extract_tenv zip_channel = + let add_type t typename typ = + if not (Sil.tenv_mem t typename) then + Sil.tenv_add tenv typename typ in + let models_tenv = try + let zip_channel = Zip.open_in !JClasspath.models_jar in let entry = Zip.find_entry zip_channel jar_tenv_filename in let temp_tenv_file = DB.filename_to_string temp_tenv_filename in let () = Zip.copy_entry_to_file zip_channel entry temp_tenv_file in match Sil.load_tenv_from_file temp_tenv_filename with - | None -> None - | Some jar_tenv -> Some jar_tenv - with Not_found -> None in - let update path = - if not (Filename.check_suffix path ".jar") then () - else - let zip_channel = Zip.open_in path in - match extract_tenv zip_channel with - | None -> () - | Some jar_tenv -> Sil.tenv_iter (transfer_type jar_tenv) jar_tenv; - Zip.close_in zip_channel in - let paths = - let l = JClasspath.split_classpath classpath in - if !JClasspath.models_jar = "" then l - else !JClasspath.models_jar :: l in - list_iter update paths; + | None -> failwith "Models tenv file could not be loaded" + | Some tenv -> tenv + with + | Not_found -> failwith "Models tenv not found in jar file" + | Sys_error msg -> failwith ("Models jar could not be opened "^msg) in + Sil.tenv_iter (add_type tenv) models_tenv; DB.file_remove temp_tenv_filename diff --git a/infer/src/java/jTransType.mli b/infer/src/java/jTransType.mli index ee570ce84..3e86bcead 100644 --- a/infer/src/java/jTransType.mli +++ b/infer/src/java/jTransType.mli @@ -87,8 +87,8 @@ val cn_to_java_type : JBasics.class_name -> Procname.java_type (** [update_tenv program] update the type environment with all the types found in [program] *) val update_tenv : Sil.tenv -> JClasspath.program -> unit -(** Update a type environment with the types found in the classpath *) -val saturate_tenv_with_classpath : string -> Sil.tenv -> unit +(** Add the types of the models to the type environment passed as parameter *) +val add_models_types : Sil.tenv -> unit (** list of methods that are never returning null *) val never_returning_null : Procname.t list