From 8f32c3cfe1205a591eed80000b359022affde7de Mon Sep 17 00:00:00 2001 From: Jules Villard Date: Mon, 3 Oct 2016 08:25:18 -0700 Subject: [PATCH] [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 --- infer/src/clang/cFrontend.ml | 10 ++++----- infer/src/clang/cFrontend.mli | 10 ++++----- infer/src/clang/cFrontend_checkers_main.ml | 8 +++---- infer/src/clang/cFrontend_decl.ml | 13 ++--------- infer/src/clang/cFrontend_decl.mli | 10 +-------- infer/src/clang/cMain.ml | 2 +- infer/src/clang/cModule_type.ml | 5 +++++ infer/src/clang/cTrans.ml | 26 ++++++---------------- infer/src/clang/cTrans.mli | 14 +----------- infer/src/clang/cTrans_utils.ml | 3 ++- 10 files changed, 32 insertions(+), 69 deletions(-) diff --git a/infer/src/clang/cFrontend.ml b/infer/src/clang/cFrontend.ml index c238e155c..37ef09a3a 100644 --- a/infer/src/clang/cFrontend.ml +++ b/infer/src/clang/cFrontend.ml @@ -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 *) diff --git a/infer/src/clang/cFrontend.mli b/infer/src/clang/cFrontend.mli index 87d855bea..89f429ea4 100644 --- a/infer/src/clang/cFrontend.mli +++ b/infer/src/clang/cFrontend.mli @@ -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 diff --git a/infer/src/clang/cFrontend_checkers_main.ml b/infer/src/clang/cFrontend_checkers_main.ml index cde5368b8..50ee388d5 100644 --- a/infer/src/clang/cFrontend_checkers_main.ml +++ b/infer/src/clang/cFrontend_checkers_main.ml @@ -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 diff --git a/infer/src/clang/cFrontend_decl.ml b/infer/src/clang/cFrontend_decl.ml index b4d792392..132349e7a 100644 --- a/infer/src/clang/cFrontend_decl.ml +++ b/infer/src/clang/cFrontend_decl.ml @@ -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 -> diff --git a/infer/src/clang/cFrontend_decl.mli b/infer/src/clang/cFrontend_decl.mli index f68f8e8f8..535be8011 100644 --- a/infer/src/clang/cFrontend_decl.mli +++ b/infer/src/clang/cFrontend_decl.mli @@ -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 diff --git a/infer/src/clang/cMain.ml b/infer/src/clang/cMain.ml index 5c29f45fa..216dd3dbd 100644 --- a/infer/src/clang/cMain.ml +++ b/infer/src/clang/cMain.ml @@ -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 -> diff --git a/infer/src/clang/cModule_type.ml b/infer/src/clang/cModule_type.ml index deedd3bca..e0ce86fac 100644 --- a/infer/src/clang/cModule_type.ml +++ b/infer/src/clang/cModule_type.ml @@ -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 diff --git a/infer/src/clang/cTrans.ml b/infer/src/clang/cTrans.ml index ef3d63c5c..22b4c00af 100644 --- a/infer/src/clang/cTrans.ml +++ b/infer/src/clang/cTrans.ml @@ -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 diff --git a/infer/src/clang/cTrans.mli b/infer/src/clang/cTrans.mli index c9639e3f8..ad77b73f8 100644 --- a/infer/src/clang/cTrans.mli +++ b/infer/src/clang/cTrans.mli @@ -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 diff --git a/infer/src/clang/cTrans_utils.ml b/infer/src/clang/cTrans_utils.ml index ff6b2dad9..ee2dd3af5 100644 --- a/infer/src/clang/cTrans_utils.ml +++ b/infer/src/clang/cTrans_utils.ml @@ -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