[infer][java] Use the global logging function for the Java frontend

Summary: No need to have several ways of logging things

Reviewed By: jberdine

Differential Revision: D4067806

fbshipit-source-id: 96ba92c
master
Jeremy Dubreil 8 years ago committed by Facebook Github Bot
parent 319463b3bc
commit c7318ee27e

@ -229,14 +229,14 @@ let lookup_node cn program =
try
Some (JBasics.ClassMap.find cn (get_classmap program))
with Not_found ->
try
let jclass = Javalib.get_class (get_classpath program) cn in
add_class cn jclass program;
Some jclass
with
| JBasics.No_class_found _
| JBasics.Class_structure_error _
| Invalid_argument _ -> None
try
let jclass = Javalib.get_class (get_classpath program) cn in
add_class cn jclass program;
Some jclass
with
| JBasics.No_class_found _
| JBasics.Class_structure_error _
| Invalid_argument _ -> None
let classname_of_class_filename class_filename =
@ -274,7 +274,7 @@ let collect_classes classmap jar_filename =
let load_program classpath classes =
JUtils.log "loading program ... %!";
L.stdout "loading program ... %!";
let models =
if !models_jar = "" then JBasics.ClassMap.empty
else collect_classes JBasics.ClassMap.empty !models_jar in
@ -286,12 +286,5 @@ let load_program classpath classes =
JBasics.ClassSet.iter
(fun cn -> ignore (lookup_node cn program))
classes;
JUtils.log "done@.";
L.stdout "done@.";
program
(*
let classmap_of_classpath classpath =
let jar_filenames =
IList.filter (fun p -> not (Sys.is_directory p)) (split_classpath classpath) in
IList.fold_left collect_classes JBasics.ClassMap.empty jar_filenames
*)

@ -147,7 +147,7 @@ let is_classname_cached cn =
In init - mode, finds out whether this class contains initializers at all,
in this case translates it. In standard mode, all methods are translated *)
let create_icfg source_file linereader program icfg cn node =
JUtils.log "\tclassname: %s@." (JBasics.cn_name cn);
L.stdout "\tclassname: %s@." (JBasics.cn_name cn);
if Config.dependency_mode && not (is_classname_cached cn) then
cache_classname cn;
let translate m =

@ -66,7 +66,7 @@ let store_icfg source_file tenv cg cfg =
let do_source_file
linereader classes program tenv
source_basename package_opt source_file =
JUtils.log "\nfilename: %s (%s)@."
L.stdout "\nfilename: %s (%s)@."
(DB.source_file_to_string source_file) source_basename;
let call_graph, cfg =
JFrontend.compute_source_icfg
@ -111,13 +111,13 @@ let save_tenv tenv =
if not Config.models_mode then JTransType.add_models_types tenv;
(* TODO: this prevents per compilation step incremental analysis at this stage *)
if DB.file_exists DB.global_tenv_fname then DB.file_remove DB.global_tenv_fname;
JUtils.log "writing new tenv %s@." (DB.filename_to_string DB.global_tenv_fname);
L.stdout "writing new tenv %s@." (DB.filename_to_string DB.global_tenv_fname);
Tenv.store_to_file DB.global_tenv_fname tenv
(* The program is loaded and translated *)
let do_all_files classpath sources classes =
JUtils.log "Translating %d source files (%d classes)@."
L.stdout "Translating %d source files (%d classes)@."
(StringMap.cardinal sources)
(JBasics.ClassSet.cardinal classes);
let program = JClasspath.load_program classpath classes in
@ -149,7 +149,7 @@ let do_all_files classpath sources classes =
capture_libs linereader program tenv;
save_tenv tenv;
JClasspath.cleanup program;
JUtils.log "done @."
L.stdout "done @."
(* loads the source files and translates them *)

@ -112,7 +112,7 @@ let get_field_name program static tenv cn fs =
fieldname
| exception Not_found ->
(* TODO: understand why fields cannot be found here *)
JUtils.log "cannot find %s.%s@." (JBasics.cn_name cn) (JBasics.fs_name fs);
L.stdout "cannot find %s.%s@." (JBasics.cn_name cn) (JBasics.fs_name fs);
raise (Frontend_error "Cannot find fieldname")
@ -213,7 +213,7 @@ let get_implementation cm =
| Javalib.Native ->
let cms = cm.Javalib.cm_class_method_signature in
let cn, ms = JBasics.cms_split cms in
JUtils.log "native method %s found in %s@." (JBasics.ms_name ms) (JBasics.cn_name cn);
L.stdout "native method %s found in %s@." (JBasics.ms_name ms) (JBasics.cn_name cn);
assert false
| Javalib.Java t ->
JBir.transform ~bcv: false ~ch_link: false ~formula: false ~formula_cmd:[] cm (Lazy.force t)
@ -238,7 +238,7 @@ let create_procdesc source_file program linereader icfg m : Cfg.Procdesc.t optio
if JClasspath.is_model proc_name then
begin
(* do not translate the method if there is a model for it *)
JUtils.log "Skipping method with a model: %s@." (Procname.to_string proc_name);
L.stdout "Skipping method with a model: %s@." (Procname.to_string proc_name);
None
end
else
@ -351,7 +351,7 @@ let create_sil_deref exp typ loc =
(** translate an expression used as an r-value *)
let rec expression (context : JContext.t) pc expr =
(* JUtils.log "\t\t\t\texpr: %s@." (JBir.print_expr expr); *)
(* L.stdout "\t\t\t\texpr: %s@." (JBir.print_expr expr); *)
let program = context.program in
let loc = get_location context.source_file context.impl pc in
let file = loc.Location.file in
@ -666,7 +666,7 @@ let instruction_array_call ms obj_type obj args var_opt =
let instruction_thread_start (context : JContext.t) cn ms obj args var_opt =
match JClasspath.lookup_node cn context.program with
| None ->
let () = JUtils.log "\t\t\tWARNING: %s should normally be found@." (JBasics.cn_name cn) in
let () = L.stderr "\t\t\tWARNING: %s should normally be found@." (JBasics.cn_name cn) in
None
| Some node ->
begin
@ -1061,5 +1061,5 @@ let rec instruction (context : JContext.t) pc instr : translation =
| _ -> Skip
with Frontend_error s ->
JUtils.log "Skipping because of: %s@." s;
L.stderr "Skipping because of: %s@." s;
Skip

@ -1,34 +0,0 @@
(*
* 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
let rec log fmt =
if Config.debug_mode then
Logging.stdout fmt
else
Obj.magic log
(*
open Javalib_pack
let get_native_methods program =
let select_native m l =
let is_native cm = (cm.Javalib.cm_implementation = Javalib.Native) in
match m with
| Javalib.ConcreteMethod cm when is_native cm ->
let (cn, ms) = JBasics.cms_split cm.Javalib.cm_class_method_signature in
((JBasics.cn_name cn)^"."^(JBasics.ms_name ms)):: l
| _ -> l in
let collect _ node l =
(Javalib.m_fold select_native node l) in
JBasics.ClassMap.fold collect program []
*)

@ -1,14 +0,0 @@
(*
* 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
(** TODO: replace by a Infer-wide debug mode printing *)
val log : ('a, Format.formatter, unit) format -> 'a
Loading…
Cancel
Save