[clang] minor cleanups

Summary:
- Use the module types in cModule_types.ml instead of redefining them.
- A few occurrences of \n in formatted output replaced by @\n to let the
  formatter know of line breaks (by no means complete, these were just a few I
  came across while doing something else)

Reviewed By: jberdine

Differential Revision: D3944081

fbshipit-source-id: 4460427
master
Jules Villard 8 years ago committed by Facebook Github Bot
parent f59c18cc44
commit 8f32c3cfe1

@ -14,9 +14,9 @@ module L = Logging
open CFrontend_utils
module rec CTransImpl : CTrans.CTrans =
module rec CTransImpl : CModule_type.CTranslation =
CTrans.CTrans_funct(CFrontend_declImpl)
and CFrontend_declImpl : CFrontend_decl.CFrontend_decl =
and CFrontend_declImpl : CModule_type.CFrontend =
CFrontend_decl.CFrontend_decl_funct(CTransImpl)
(* Translates a file by translating the ast into a cfg. *)
@ -24,7 +24,7 @@ let compute_icfg source tenv ast =
match ast with
| Clang_ast_t.TranslationUnitDecl(_, decl_list, _, _) ->
CFrontend_config.global_translation_unit_decls := decl_list;
Logging.out_debug "\n Start creating icfg\n";
Logging.out_debug "@\n Start creating icfg@\n";
let cg = Cg.create (Some source) in
let cfg = Cfg.Node.create_cfg () in
IList.iter (CFrontend_declImpl.translate_one_declaration tenv cg cfg `DeclTraversal)
@ -43,10 +43,10 @@ let do_source_file source_file ast =
CTypes_decl.add_predefined_types tenv;
init_global_state_capture ();
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"
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 source_file tenv ast in
Logging.out_debug "\n End building call/cfg graph for '%s'.\n"
Logging.out_debug "@\n End building call/cfg graph for '%s'.@\n"
(DB.source_file_to_string source_file);
(* This part below is a boilerplate in every frontends. *)
(* This could be moved in the cfg_infer module *)

@ -9,10 +9,8 @@
open! Utils
(** Translate one file into a cfg. Create a tenv, cg and cfg file for a source file *)
(** given its ast in json format. Translate the json file into a cfg by adding all *)
(** the type and class declarations to the tenv, adding all the functions and methods *)
(** declarations as procdescs to the cfg, and adding the control flow graph of all the *)
(** code of those functions and methods to the cfg *)
(** Translate one file into a cfg. Create a tenv, cg and cfg file for a source file given its ast in
json format. Translate the json file into a cfg by adding all the type and class declarations to
the tenv, adding all the functions and methods declarations as procdescs to the cfg, and adding
the control flow graph of all the code of those functions and methods to the cfg. *)
val do_source_file : DB.source_file -> Clang_ast_t.decl -> unit

@ -81,7 +81,7 @@ let store_issues source_file =
let do_frontend_checks source_file ast =
try
Logging.out "Start linting file %s\n" (DB.source_file_to_string source_file);
Logging.out "Start linting file %s@\n" (DB.source_file_to_string source_file);
match ast with
| Clang_ast_t.TranslationUnitDecl(_, decl_list, _, _) ->
let context = context_with_ck_set CLintersContext.empty decl_list in
@ -92,9 +92,9 @@ let do_frontend_checks source_file ast =
IList.iter (do_frontend_checks_decl context) allowed_decls;
if (LintIssues.exists_issues ()) then
store_issues source_file;
Logging.out "End linting file %s\n" (DB.source_file_to_string source_file)
| _ -> assert false (* NOTE: Assumes that an AST alsways starts with a TranslationUnitDecl *)
Logging.out "End linting file %s@\n" (DB.source_file_to_string source_file)
| _ -> assert false (* NOTE: Assumes that an AST always starts with a TranslationUnitDecl *)
with
| Assert_failure (file, line, column) ->
Logging.out "Fatal error: exception Assert_failure(%s, %d, %d)\n%!" file line column;
Logging.err "Fatal error: exception Assert_failure(%s, %d, %d)@\n%!" file line column;
exit 1

@ -15,17 +15,8 @@ module L = Logging
open CFrontend_utils
module type CFrontend_decl = sig
val function_decl : Tenv.t -> Cfg.cfg -> Cg.t -> Clang_ast_t.decl ->
CModule_type.block_data option -> unit
val translate_one_declaration :
Tenv.t -> Cg.t -> Cfg.cfg -> CModule_type.decl_trans_context -> Clang_ast_t.decl -> unit
end
module CFrontend_decl_funct(T: CModule_type.CTranslation) : CFrontend_decl =
module CFrontend_decl_funct(T: CModule_type.CTranslation) : CModule_type.CFrontend =
struct
let model_exists procname =
Specs.summary_exists_in_models procname && not Config.models_mode
@ -33,7 +24,7 @@ struct
let add_method tenv cg cfg class_decl_opt procname body has_return_param is_objc_method
outer_context_opt extra_instrs =
Logging.out_debug
"\n\n>>---------- ADDING METHOD: '%s' ---------<<\n@." (Procname.to_string procname);
"@\n@\n>>---------- ADDING METHOD: '%s' ---------<<@\n@." (Procname.to_string procname);
try
(match Cfg.Procdesc.find_from_name cfg procname with
| Some procdesc ->

@ -11,12 +11,4 @@ open! Utils
(** Translate declarations **)
module type CFrontend_decl = sig
val function_decl : Tenv.t -> Cfg.cfg -> Cg.t -> Clang_ast_t.decl ->
CModule_type.block_data option -> unit
val translate_one_declaration : Tenv.t -> Cg.t -> Cfg.cfg ->
CModule_type.decl_trans_context -> Clang_ast_t.decl -> unit
end
module CFrontend_decl_funct(T: CModule_type.CTranslation) : CFrontend_decl
module CFrontend_decl_funct(T: CModule_type.CTranslation) : CModule_type.CFrontend

@ -77,7 +77,7 @@ let do_run source_path ast_path =
CFrontend_checkers_main.do_frontend_checks source_file ast_decl;
if Config.clang_frontend_do_capture then
CFrontend.do_source_file source_file ast_decl;
Logging.out "End translation AST file %s... OK!\n" !CFrontend_config.json;
Logging.out "End translation AST file %s... OK!@\n" !CFrontend_config.json;
print_elapsed ();
with
(Yojson.Json_error s) as exc ->

@ -20,6 +20,11 @@ type decl_trans_context = [ `DeclTraversal | `Translation ]
module type CTranslation =
sig
(** Translates instructions: (statements and expressions) from the ast into sil *)
(** It receives the context, a list of statements from clang ast, list of custom statments to be
added before clang statements and the exit node and it returns a list of cfg nodes that
represent the translation of the stmts into sil. *)
val instructions_trans : CContext.t -> Clang_ast_t.stmt -> instr_type list ->
Cfg.Node.t -> Cfg.Node.t list
end

@ -17,25 +17,13 @@ open CFrontend_utils
open CTrans_utils.Nodes
module L = Logging
module type CTrans = sig
(** Translates instructions: (statements and expressions) from the ast into sil *)
(** It receives the context, a list of statements from clang ast, list of custom statments to be
added before clang statements and the exit node and it returns a list of cfg nodes that
reporesent the translation of the stmts into sil. *)
val instructions_trans : CContext.t -> Clang_ast_t.stmt -> CModule_type.instr_type list ->
Cfg.Node.t -> Cfg.Node.t list
end
module CTrans_funct(F: CModule_type.CFrontend) : CTrans =
module CTrans_funct(F: CModule_type.CFrontend) : CModule_type.CTranslation =
struct
(*Returns the procname and whether is instance, according to the selector *)
(* information and according to the method signature with the following priority: *)
(* 1. method is a predefined model *)
(* 2. method is found by clang's resolution*)
(* 3. Method is found by our resolution *)
(* Returns the procname and whether is instance, according to the selector information and
according to the method signature with the following priority:
1. method is a predefined model
2. method is found by clang's resolution
3. Method is found by our resolution *)
let get_callee_objc_method context obj_c_message_expr_info act_params =
let open CContext in
let (selector, method_pointer_opt, mc_type) =
@ -664,7 +652,7 @@ struct
| _ -> res_trans
and decl_ref_trans trans_state pre_trans_result stmt_info decl_ref ~is_constructor_init =
Logging.out_debug " priority node free = '%s'\n@."
Logging.out_debug " priority node free = '%s'@\n@."
(string_of_bool (PriorityNode.is_priority_free trans_state));
let decl_kind = decl_ref.Clang_ast_t.dr_kind in
match decl_kind with

@ -9,16 +9,4 @@
open! Utils
module type CTrans = sig
(** Translates instructions: (statements and expressions) from the ast into sil. It receives the
context, a list of statements from clang ast, list of custom statments to be added before
clang statements and the exit node and it returns a list of cfg nodes that reporesent the
translation of the stmts into sil. *)
val instructions_trans : CContext.t -> Clang_ast_t.stmt -> CModule_type.instr_type list ->
Cfg.Node.t -> Cfg.Node.t list
end
module CTrans_funct(F: CModule_type.CFrontend) : CTrans
module CTrans_funct(F: CModule_type.CFrontend) : CModule_type.CTranslation

@ -570,7 +570,8 @@ let rec get_type_from_exp_stmt stmt =
| ImplicitCastExpr(_, stmt_list, _, _) ->
get_type_from_exp_stmt (extract_stmt_from_singleton stmt_list "WARNING: We expect only one stmt.")
| DeclRefExpr(_, _, _, info) -> do_decl_ref_exp info
| _ -> Logging.err_debug "Failing with: %s \n%!" (Clang_ast_j.string_of_stmt stmt);
| _ ->
Logging.err_debug "Failing with: %s@\n%!" (Clang_ast_j.string_of_stmt stmt);
Printing.print_failure_info "";
assert false

Loading…
Cancel
Save