From f01a639605c14f4af354db9d0fb9d94125dca378 Mon Sep 17 00:00:00 2001 From: Andrzej Kotulski Date: Thu, 8 Oct 2015 10:08:20 -0700 Subject: [PATCH] Slight improvement of block function handling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: @​public remove `is_instance` function parameter that was used for blocks only. Instead, pass context everywhere - it holds information that is very relevant when defining block. Reviewed By: @dulmarod Differential Revision: D2521772 fb-gh-sync-id: 5fb53f9 --- infer/src/clang/cMethod_decl.ml | 4 +++- infer/src/clang/cMethod_trans.ml | 28 ++++++++++++++-------------- infer/src/clang/cModule_type.ml | 2 +- infer/src/clang/cTrans.ml | 2 +- 4 files changed, 19 insertions(+), 17 deletions(-) diff --git a/infer/src/clang/cMethod_decl.ml b/infer/src/clang/cMethod_decl.ml index 0e284076b..337194e4a 100644 --- a/infer/src/clang/cMethod_decl.ml +++ b/infer/src/clang/cMethod_decl.ml @@ -93,7 +93,9 @@ struct CTrans_utils.GotoLabel.reset_all_labels (); (* C Language Std 6.8.6.1-1 *) let is_anonym_block, captured_vars, curr_class = match block_data_opt with - | Some (_, _, _, captured_vars, curr_class) -> true, captured_vars, curr_class + | Some (context, _, _, captured_vars) -> + let curr_class = context.CContext.curr_class in + true, captured_vars, curr_class | None -> false, [], CContext.ContextNoCls in let class_name = if curr_class = CContext.ContextNoCls then None else Some (CContext.get_curr_class_name curr_class) in diff --git a/infer/src/clang/cMethod_trans.ml b/infer/src/clang/cMethod_trans.ml index 404023657..024f6e8d1 100644 --- a/infer/src/clang/cMethod_trans.ml +++ b/infer/src/clang/cMethod_trans.ml @@ -31,18 +31,18 @@ type function_method_decl_info = | Func_decl_info of Clang_ast_t.function_decl_info * Clang_ast_t.type_ptr * CFrontend_config.lang | Cpp_Meth_decl_info of Clang_ast_t.function_decl_info * string * Clang_ast_t.type_ptr | ObjC_Meth_decl_info of Clang_ast_t.obj_c_method_decl_info * string - | Block_decl_info of Clang_ast_t.block_decl_info * Clang_ast_t.type_ptr + | Block_decl_info of Clang_ast_t.block_decl_info * Clang_ast_t.type_ptr * CContext.t -let is_instance_method function_method_decl_info is_instance = +let is_instance_method function_method_decl_info = match function_method_decl_info with | Func_decl_info (function_decl_info, _, _) -> false | Cpp_Meth_decl_info _ -> true | ObjC_Meth_decl_info (method_decl_info, _) -> method_decl_info.Clang_ast_t.omdi_is_instance_method - | Block_decl_info (block_decl_info, _) -> is_instance + | Block_decl_info (_, _, context) -> context.CContext.is_instance let get_class_param function_method_decl_info = - if (is_instance_method function_method_decl_info false) then + if (is_instance_method function_method_decl_info) then match function_method_decl_info with | Cpp_Meth_decl_info (_, class_name, _) -> let class_type = Ast_expressions.create_class_type class_name in @@ -58,7 +58,7 @@ let get_param_decls function_method_decl_info = | Func_decl_info (function_decl_info, _, _) | Cpp_Meth_decl_info (function_decl_info, _, _) -> function_decl_info.Clang_ast_t.fdi_parameters | ObjC_Meth_decl_info (method_decl_info, _) -> method_decl_info.Clang_ast_t.omdi_parameters - | Block_decl_info (block_decl_info, _) -> block_decl_info.Clang_ast_t.bdi_parameters + | Block_decl_info (block_decl_info, _, _) -> block_decl_info.Clang_ast_t.bdi_parameters let get_language function_method_decl_info = match function_method_decl_info with @@ -82,13 +82,13 @@ let get_return_type function_method_decl_info = match function_method_decl_info with | Func_decl_info (_, typ, _) | Cpp_Meth_decl_info (_, _, typ) - | Block_decl_info (_, typ) -> CTypes.return_type_of_function_type typ + | Block_decl_info (_, typ, _) -> CTypes.return_type_of_function_type typ | ObjC_Meth_decl_info (method_decl_info, _) -> method_decl_info.Clang_ast_t.omdi_result_type -let build_method_signature decl_info procname function_method_decl_info is_instance is_anonym_block is_generated = +let build_method_signature decl_info procname function_method_decl_info is_anonym_block is_generated = let source_range = decl_info.Clang_ast_t.di_source_range in let tp = get_return_type function_method_decl_info in - let is_instance_method = is_instance_method function_method_decl_info is_instance in + let is_instance_method = is_instance_method function_method_decl_info in let parameters = get_parameters function_method_decl_info in let attributes = decl_info.Clang_ast_t.di_attributes in let lang = get_language function_method_decl_info in @@ -104,13 +104,13 @@ let method_signature_of_decl class_name_opt meth_decl block_data_opt = let func_decl = Func_decl_info (fdi, tp, language) in let function_info = Some (decl_info, fdi) in let procname = General_utils.mk_procname_from_function name function_info tp language in - let ms = build_method_signature decl_info procname func_decl false false false in + let ms = build_method_signature decl_info procname func_decl false false in ms, fdi.Clang_ast_t.fdi_body, fdi.Clang_ast_t.fdi_parameters | CXXMethodDecl (decl_info, name_info, tp, fdi), _, Some class_name -> let method_name = name_info.Clang_ast_t.ni_name in let procname = General_utils.mk_procname_from_cpp_method class_name method_name tp in let method_decl = Cpp_Meth_decl_info (fdi, class_name, tp) in - let ms = build_method_signature decl_info procname method_decl false false false in + let ms = build_method_signature decl_info procname method_decl false false in ms, fdi.Clang_ast_t.fdi_body, fdi.Clang_ast_t.fdi_parameters | ObjCMethodDecl (decl_info, name_info, mdi), _, Some class_name -> let method_name = name_info.ni_name in @@ -119,12 +119,12 @@ let method_signature_of_decl class_name_opt meth_decl block_data_opt = let procname = General_utils.mk_procname_from_objc_method class_name method_name method_kind in let method_decl = ObjC_Meth_decl_info (mdi, class_name) in let is_generated = Ast_utils.is_generated name_info in - let ms = build_method_signature decl_info procname method_decl false false is_generated in + let ms = build_method_signature decl_info procname method_decl false is_generated in ms, mdi.omdi_body, mdi.omdi_parameters | BlockDecl (decl_info, decl_list, decl_context_info, bdi), - Some (tp, is_instance, procname, _, _), _ -> - let func_decl = Block_decl_info (bdi, tp) in - let ms = build_method_signature decl_info procname func_decl is_instance true false in + Some (context, tp, procname, _), _ -> + let func_decl = Block_decl_info (bdi, tp, context) in + let ms = build_method_signature decl_info procname func_decl true false in ms, bdi.bdi_body, bdi.bdi_parameters | _ -> raise Invalid_declaration diff --git a/infer/src/clang/cModule_type.ml b/infer/src/clang/cModule_type.ml index 3d3952762..e0c2401ce 100644 --- a/infer/src/clang/cModule_type.ml +++ b/infer/src/clang/cModule_type.ml @@ -7,7 +7,7 @@ * of patent rights can be found in the PATENTS file in the same directory. *) -type block_data = Clang_ast_t.type_ptr * bool * Procname.t * (Mangled.t * Sil.typ * bool) list * CContext.curr_class +type block_data = CContext.t * Clang_ast_t.type_ptr * Procname.t * (Mangled.t * Sil.typ * bool) list module type CTranslation = sig diff --git a/infer/src/clang/cTrans.ml b/infer/src/clang/cTrans.ml index 1765ac264..d6773b263 100644 --- a/infer/src/clang/cTrans.ml +++ b/infer/src/clang/cTrans.ml @@ -1766,7 +1766,7 @@ struct let all_captured_vars = captured_vars @ static_vars in let ids_instrs = list_map assign_captured_var all_captured_vars in let ids, instrs = list_split ids_instrs in - let block_data = (type_ptr, context.is_instance, block_pname, all_captured_vars, context.curr_class) in + let block_data = (context, type_ptr, block_pname, all_captured_vars) in M.function_decl context.tenv context.cfg context.cg context.namespace decl (Some block_data); Cfg.set_procname_priority context.cfg block_pname; let captured_exps = list_map (fun id -> Sil.Var id) ids in