kill Location.nLOC

Summary:
Location.nLOC was introducing a lot of complexity for little benefit (and edge cases were wrong anyway).
We can restore it in some simplified way if we find that we need it

Reviewed By: jeremydubreil

Differential Revision: D4139868

fbshipit-source-id: 4f8e033
master
Andrzej Kotulski 8 years ago committed by Facebook Github Bot
parent f35a969def
commit 459ec32081

@ -43,8 +43,7 @@ type node_info = {
/** Type for call graph */
type t = {
mutable source: DB.source_file, /** path for the source file */
mutable nLOC: int, /** number of LOC */
source: DB.source_file, /** path for the source file */
node_map: Procname.Hash.t node_info /** map from node to node_info */
};
@ -54,7 +53,7 @@ let create source_opt => {
| None => DB.source_file_empty
| Some source => source
};
{source, nLOC: !Config.nLOC, node_map: Procname.Hash.create 3}
{source, node_map: Procname.Hash.create 3}
};
let add_node g n defined::defined =>
@ -341,10 +340,6 @@ let get_defined_nodes (g: t) => {
let get_source (g: t) => g.source;
/** Return the number of LOC of the source file */
let get_nLOC (g: t) => g.nLOC;
/** [extend cg1 gc2] extends [cg1] in place with nodes and edges from [gc2];
undefined nodes become defined if at least one side is. */
let extend cg_old cg_new => {
@ -355,14 +350,14 @@ let extend cg_old cg_new => {
/** Begin support for serialization */
let callgraph_serializer: Serialization.serializer (DB.source_file, int, nodes_and_edges) = Serialization.create_serializer Serialization.cg_key;
let callgraph_serializer: Serialization.serializer (DB.source_file, nodes_and_edges) = Serialization.create_serializer Serialization.cg_key;
/** Load a call graph from a file */
let load_from_file (filename: DB.filename) :option t =>
switch (Serialization.from_file callgraph_serializer filename) {
| None => None
| Some (source, nLOC, (nodes, edges)) =>
| Some (source, (nodes, edges)) =>
let g = create (Some source);
IList.iter
(
@ -373,7 +368,6 @@ let load_from_file (filename: DB.filename) :option t =>
)
nodes;
IList.iter (fun (nfrom, nto) => add_edge g nfrom nto) edges;
g.nLOC = nLOC;
Some g
};
@ -381,9 +375,7 @@ let load_from_file (filename: DB.filename) :option t =>
/** Save a call graph into a file */
let store_to_file (filename: DB.filename) (call_graph: t) =>
Serialization.to_file
callgraph_serializer
filename
(call_graph.source, call_graph.nLOC, get_nodes_and_edges call_graph);
callgraph_serializer filename (call_graph.source, get_nodes_and_edges call_graph);
let pp_graph_dotty get_specs (g: t) fmt => {
let nodes_with_calls = get_all_nodes g;

@ -79,10 +79,6 @@ let get_defined_children: t => Procname.t => Procname.Set.t;
let get_dependents: t => Procname.t => Procname.Set.t;
/** Return the number of LOC of the source file */
let get_nLOC: t => int;
/** Return the list of nodes with calls */
let get_nodes_and_calls: t => list (Procname.t, in_out_calls);

@ -17,8 +17,7 @@ let module L = Logging;
type t = {
line: int, /** The line number. -1 means "do not know" */
col: int, /** The column number. -1 means "do not know" */
file: DB.source_file, /** The name of the source file */
nLOC: int /** Lines of code in the source file */
file: DB.source_file /** The name of the source file */
};
let compare loc1 loc2 => {
@ -36,7 +35,7 @@ let d (loc: t) => L.add_print_action (L.PTloc, Obj.repr loc);
/** Dummy location */
let dummy = {line: (-1), col: (-1), file: DB.source_file_empty, nLOC: (-1)};
let dummy = {line: (-1), col: (-1), file: DB.source_file_empty};
let equal loc1 loc2 => compare loc1 loc2 == 0;

@ -14,7 +14,6 @@ type t = {
line: int, /** The line number. -1 means "do not know" */
col: int, /** The column number. -1 means "do not know" */
file: DB.source_file, /** The name of the source file */
nLOC: int /** Lines of code in the source file */
};
let compare: t => t => int;

@ -141,7 +141,6 @@ type summary_val = {
vfile: string,
vflags: proc_flags,
vline: int,
vloc: int,
vtop: string,
vsignature: string,
vweight: int,
@ -207,7 +206,6 @@ let summary_values top_proc_set summary => {
vflags: attributes.ProcAttributes.proc_flags,
vfile: DB.source_file_to_string attributes.ProcAttributes.loc.Location.file,
vline: attributes.ProcAttributes.loc.Location.line,
vloc: attributes.ProcAttributes.loc.Location.nLOC,
vtop: if is_top {"Y"} else {"N"},
vsignature: signature,
vweight: nodes_nr,
@ -258,7 +256,6 @@ let module ProcsCsv = {
pp "%d," sv.verr;
pp "%s," sv.vfile;
pp "%d," sv.vline;
pp "%d," sv.vloc;
pp "%s," sv.vtop;
pp "\"%s\"," (Escape.escape_csv sv.vsignature);
pp "%d," sv.vweight;
@ -290,7 +287,6 @@ let module ProcsXml = {
subtree Io_infer.Xml.tag_err (string_of_int sv.verr),
subtree Io_infer.Xml.tag_file sv.vfile,
subtree Io_infer.Xml.tag_line (string_of_int sv.vline),
subtree Io_infer.Xml.tag_loc (string_of_int sv.vloc),
subtree Io_infer.Xml.tag_top sv.vtop,
subtree Io_infer.Xml.tag_signature (Escape.escape_xml sv.vsignature),
subtree Io_infer.Xml.tag_weight (string_of_int sv.vweight),
@ -769,7 +765,6 @@ let module Stats = {
mutable nerrors: int,
mutable ninfos: int,
mutable nadvice: int,
mutable nLOC: int,
mutable nprocs: int,
mutable nspecs: int,
mutable ntimeouts: int,
@ -784,7 +779,6 @@ let module Stats = {
nerrors: 0,
ninfos: 0,
nadvice: 0,
nLOC: 0,
nprocs: 0,
nspecs: 0,
ntimeouts: 0,
@ -794,9 +788,7 @@ let module Stats = {
};
let process_loc loc stats =>
try (Hashtbl.find stats.files loc.Location.file) {
| Not_found =>
stats.nLOC = stats.nLOC + loc.Location.nLOC;
Hashtbl.add stats.files loc.Location.file ()
| Not_found => Hashtbl.add stats.files loc.Location.file ()
};
let loc_trace_to_string_list linereader indent_num ltr => {
let res = ref [];
@ -893,7 +885,6 @@ let module Stats = {
let num_files stats => Hashtbl.length stats.files;
let pp fmt stats => {
F.fprintf fmt "Files: %d@\n" (num_files stats);
F.fprintf fmt "LOC: %d@\n" stats.nLOC;
F.fprintf fmt "Specs: %d@\n" stats.nspecs;
F.fprintf fmt "Timeouts: %d@\n" stats.ntimeouts;
F.fprintf fmt "Procedures: %d@\n" stats.nprocs;

@ -17,14 +17,12 @@ module L = Logging
(** per-file data: type environment and cfg *)
type file_data =
{ source: DB.source_file;
nLOC : int;
tenv_file: DB.filename;
mutable tenv: Tenv.t option;
cfg_file: DB.filename;
mutable cfg: Cfg.cfg option;
}
(** get the path to the tenv file, which either one tenv file per source file or a global tenv file *)
let tenv_filename file_base =
let per_source_tenv_filename = DB.filename_add_suffix file_base ".tenv" in
@ -41,24 +39,23 @@ module FilenameHash = Hashtbl.Make(
end)
(** create a new file_data *)
let new_file_data source nLOC cg_fname =
let new_file_data source cg_fname =
let file_base = DB.chop_extension cg_fname in
let tenv_file = tenv_filename file_base in
let cfg_file = DB.filename_add_suffix file_base ".cfg" in
{ source = source;
nLOC = nLOC;
tenv_file = tenv_file;
tenv = None; (* Sil.load_tenv_from_file tenv_file *)
cfg_file = cfg_file;
cfg = None; (* Cfg.load_cfg_from_file cfg_file *)
}
let create_file_data table source nLOC cg_fname =
let create_file_data table source cg_fname =
match FilenameHash.find table cg_fname with
| file_data ->
file_data
| exception Not_found ->
let file_data = new_file_data source nLOC cg_fname in
let file_data = new_file_data source cg_fname in
FilenameHash.add table cg_fname file_data;
file_data
@ -129,12 +126,10 @@ let get_file_data exe_env pname =
L.err "can't find tenv_cfg_object for %a@." Procname.pp pname;
None
| Some proc_attributes ->
let loc = proc_attributes.ProcAttributes.loc in
let source_file = proc_attributes.ProcAttributes.source_file_captured in
let nLOC = loc.Location.nLOC in
let source_dir = DB.source_dir_from_source_file source_file in
let cg_fname = DB.source_dir_get_internal_file source_dir ".cg" in
let file_data = create_file_data exe_env.file_map source_file nLOC cg_fname in
let file_data = create_file_data exe_env.file_map source_file cg_fname in
Procname.Hash.replace exe_env.proc_map pname file_data;
Some file_data
end
@ -201,7 +196,6 @@ let iter_files f exe_env =
then seen_files_acc
else
begin
Config.nLOC := file_data.nLOC;
Option.may (fun cfg -> f fname cfg) (file_data_to_cfg file_data);
DB.SourceFileSet.add fname seen_files_acc
end in

@ -413,13 +413,11 @@ let check_assignement_guard pdesc node =
| _ -> false) succs in
let succs_same_loc_as_node () =
if verbose then
(L.d_str ("LOCATION NODE: line: " ^ (string_of_int l_node.Location.line) ^
" nLOC: " ^ (string_of_int l_node.Location.nLOC));
(L.d_str ("LOCATION NODE: line: " ^ (string_of_int l_node.Location.line));
L.d_strln " ");
IList.for_all (fun l ->
if verbose then
(L.d_str ("LOCATION l: line: " ^ (string_of_int l.Location.line) ^
" nLOC: " ^ (string_of_int l.Location.nLOC));
(L.d_str ("LOCATION l: line: " ^ (string_of_int l.Location.line));
L.d_strln " ");
Location.equal l l_node) succs_loc in
(* check that the guards of the succs are a var or its negation *)
@ -1579,9 +1577,8 @@ let print_stats_cfg proc_shadowed source cfg =
(* F.fprintf fmt "VISITED: %a@\n" (pp_seq pp_node) nodes_visited;
F.fprintf fmt "TOTAL: %a@\n" (pp_seq pp_node) nodes_total; *)
F.fprintf fmt "@\n++++++++++++++++++++++++++++++++++++++++++++++++++@\n";
F.fprintf fmt "+ FILE: %s LOC: %n VISITED: %d/%d SYMOPS: %d@\n"
F.fprintf fmt "+ FILE: %s VISITED: %d/%d SYMOPS: %d@\n"
(DB.source_file_to_string source)
!Config.nLOC
(IList.length nodes_visited)
(IList.length nodes_total)
!tot_symops;

@ -1626,9 +1626,6 @@ let run_in_re_execution_mode f x =
(** Set in the middle of forcing delayed prints *)
let forcing_delayed_prints = ref false
(** Number of lines of code in original file *)
let nLOC = ref 0
(** if true, user simple pretty printing *)
let pp_simple = ref true

@ -293,7 +293,6 @@ val run_in_footprint_mode : ('a -> 'b) -> 'a -> 'b
val run_in_re_execution_mode : ('a -> 'b) -> 'a -> 'b
val forcing_delayed_prints : bool ref
val nLOC : int ref
val pp_simple : bool ref

@ -392,21 +392,6 @@ let copy_file fname_from fname_to =
cleanup();
None
(** count lines of code of files and keep processed results in a cache *)
module FileLOC = struct
let include_loc_hash = Hashtbl.create 1
let reset () = Hashtbl.clear include_loc_hash
let file_get_loc fname =
try Hashtbl.find include_loc_hash fname with Not_found ->
let loc = match read_file fname with
| None -> 0
| Some l -> IList.length l in
Hashtbl.add include_loc_hash fname loc;
loc
end
(** type for files used for printing *)
type outfile =
{ fname : string; (** name of the file *)

@ -228,13 +228,6 @@ val filename_to_absolute : string -> string
(** Convert an absolute filename to one relative to a root directory *)
val filename_to_relative : string -> string -> string
(** count lines of code of files and keep processed results in a cache *)
module FileLOC : sig
val reset: unit -> unit (** reset the cache *)
val file_get_loc : string -> int (** get the LOC of the file *)
end
(** type for files used for printing *)
type outfile =
{ fname : string; (** name of the file *)

@ -44,7 +44,6 @@ let do_source_file translation_unit_context ast =
CType_decl.add_predefined_types tenv;
init_global_state_capture ();
let source_file = translation_unit_context.CFrontend_config.source_file in
Config.nLOC := FileLOC.file_get_loc (DB.source_file_to_string source_file);
Logging.out_debug "@\n Start building call/cfg graph for '%s'....@\n"
(DB.source_file_to_string source_file);
let call_graph, cfg = compute_icfg translation_unit_context tenv ast in

@ -27,8 +27,7 @@ let clang_to_sil_location trans_unit_ctx clang_loc =
let col = Option.default (-1) clang_loc.Clang_ast_t.sl_column in
let file = Option.map_default source_file_from_path
trans_unit_ctx.CFrontend_config.source_file clang_loc.Clang_ast_t.sl_file in
let nLOC = -1 in
Location.{line; col; file; nLOC}
Location.{line; col; file}
let file_in_project file =
(* Look at file paths before resolving them to real paths. Do it to

@ -268,9 +268,9 @@ let inhabit_trace tenv trace harness_name cg cfg =
if IList.length trace > 0 then
let source_file = Cg.get_source cg in
let harness_file = create_dummy_harness_file harness_name in
let start_line = (Cg.get_nLOC cg) + 1 in
let start_line = 1 in
let empty_env =
let pc = { Location.line = start_line; col = 1; file = source_file; nLOC = 0; } in
let pc = { Location.line = start_line; col = 1; file = source_file; } in
{ instrs = [];
cache = TypMap.empty;
pc = pc;

@ -40,9 +40,7 @@ let init_global_state source_file =
Config.curr_language := Config.Java;
DB.Results_dir.init source_file;
Ident.NameGenerator.reset ();
JContext.reset_exn_node_table ();
let nLOC = FileLOC.file_get_loc (DB.source_file_to_string source_file) in
Config.nLOC := nLOC
JContext.reset_exn_node_table ()
let store_icfg source_file tenv cg cfg =

@ -66,8 +66,7 @@ let get_location source_file impl pc =
| Some n -> n in
{ Location.line = line_number;
col = -1;
file = source_file;
nLOC = !Config.nLOC }
file = source_file }
let get_undefined_method_call ovt =
let get_undefined_method ovt =

Loading…
Cancel
Save