diff --git a/infer/src/clang/CType_decl.ml b/infer/src/clang/CType_decl.ml index 4262edb2f..2b9847261 100644 --- a/infer/src/clang/CType_decl.ml +++ b/infer/src/clang/CType_decl.ml @@ -79,21 +79,22 @@ module BuildMethodSignature = struct (** Returns parameters of a function/method. They will have following order: 1. normal parameters 2. return parameter (optional) *) - let get_parameters qual_type_to_sil_type ~is_cpp tenv ~block_return_type method_decl = + let get_parameters qual_type_to_sil_type tenv ~block_return_type method_decl = + let open Clang_ast_t in let par_to_ms_par par = match par with - | Clang_ast_t.ParmVarDecl (_, name_info, qt, var_decl_info) -> + | ParmVarDecl (_, name_info, qt, var_decl_info) -> let method_decl_info = Clang_ast_proj.get_decl_tuple method_decl in let _, name = CGeneral_utils.get_var_name_mangled method_decl_info name_info var_decl_info in - let param_typ = qual_type_to_sil_type tenv qt in let typ = - match param_typ.Typ.desc with - | Tstruct _ when is_cpp -> - qual_type_to_sil_type tenv (Ast_expressions.create_reference_qual_type qt) + ( match CAst_utils.get_decl_from_typ_ptr qt.qt_type_ptr with + | Some (CXXRecordDecl _) | Some (ClassTemplateSpecializationDecl _) -> + Ast_expressions.create_reference_qual_type qt | _ -> - param_typ + qt ) + |> qual_type_to_sil_type tenv in let is_pointer_to_const = CType.is_pointer_to_const qt in let is_value = CType.is_value qt in @@ -126,8 +127,7 @@ module BuildMethodSignature = struct else (return_typ, None, return_typ_annot) - let method_signature_of_decl qual_type_to_sil_type ~is_cpp tenv method_decl ?block_return_type - procname = + let method_signature_of_decl qual_type_to_sil_type tenv method_decl ?block_return_type procname = let decl_info = Clang_ast_proj.get_decl_tuple method_decl in let loc = decl_info.Clang_ast_t.di_source_range in let ret_type, return_param_typ, ret_typ_annot = @@ -136,9 +136,7 @@ module BuildMethodSignature = struct let method_kind = CMethodProperties.get_method_kind method_decl in let pointer_to_parent = decl_info.di_parent_pointer in let class_param = get_class_param qual_type_to_sil_type tenv method_decl in - let params = - get_parameters qual_type_to_sil_type ~is_cpp tenv ~block_return_type method_decl - in + let params = get_parameters qual_type_to_sil_type tenv ~block_return_type method_decl in let attributes = decl_info.Clang_ast_t.di_attributes in let is_cpp_virtual = CMethodProperties.is_cpp_virtual method_decl in let is_cpp_nothrow = CMethodProperties.is_cpp_nothrow method_decl in @@ -159,13 +157,12 @@ module BuildMethodSignature = struct ; return_param_typ } - let method_signature_body_of_decl qual_type_to_sil_type ~is_cpp tenv method_decl - ?block_return_type procname = + let method_signature_body_of_decl qual_type_to_sil_type tenv method_decl ?block_return_type + procname = let body = CMethodProperties.get_method_body method_decl in let init_list_instrs = CMethodProperties.get_init_list_instrs method_decl in let ms = - method_signature_of_decl qual_type_to_sil_type ~is_cpp tenv method_decl ?block_return_type - procname + method_signature_of_decl qual_type_to_sil_type tenv method_decl ?block_return_type procname in (ms, body, init_list_instrs) end diff --git a/infer/src/clang/CType_decl.mli b/infer/src/clang/CType_decl.mli index 85eaa97af..4ee60ade6 100644 --- a/infer/src/clang/CType_decl.mli +++ b/infer/src/clang/CType_decl.mli @@ -46,12 +46,11 @@ val class_from_pointer_type : Tenv.t -> Clang_ast_t.qual_type -> Typ.Name.t val get_type_from_expr_info : Clang_ast_t.expr_info -> Tenv.t -> Typ.t val method_signature_of_decl : - is_cpp:bool -> Tenv.t -> Clang_ast_t.decl -> ?block_return_type:Clang_ast_t.qual_type - -> Typ.Procname.t -> CMethodSignature.t + Tenv.t -> Clang_ast_t.decl -> ?block_return_type:Clang_ast_t.qual_type -> Typ.Procname.t + -> CMethodSignature.t val method_signature_body_of_decl : - is_cpp:bool -> Tenv.t -> Clang_ast_t.decl -> ?block_return_type:Clang_ast_t.qual_type - -> Typ.Procname.t + Tenv.t -> Clang_ast_t.decl -> ?block_return_type:Clang_ast_t.qual_type -> Typ.Procname.t -> CMethodSignature.t * Clang_ast_t.stmt option * [> `CXXConstructorInit of Clang_ast_t.cxx_ctor_initializer] list diff --git a/infer/src/clang/cFrontend_decl.ml b/infer/src/clang/cFrontend_decl.ml index e39b9a243..02fc4cf0a 100644 --- a/infer/src/clang/cFrontend_decl.ml +++ b/infer/src/clang/cFrontend_decl.ml @@ -104,7 +104,6 @@ module CFrontend_decl_funct (T : CModule_type.CTranslation) : CModule_type.CFron | None -> ([], None) in - let is_cpp = CGeneral_utils.is_cpp_translation trans_unit_ctx in let procname, block_return_type = match block_data_opt with | Some (_, block_return_type, procname, _) -> @@ -113,7 +112,7 @@ module CFrontend_decl_funct (T : CModule_type.CTranslation) : CModule_type.CFron (CType_decl.CProcname.from_decl ~tenv func_decl, None) in let ms, body_opt, extra_instrs = - CType_decl.method_signature_body_of_decl ~is_cpp tenv func_decl ?block_return_type procname + CType_decl.method_signature_body_of_decl tenv func_decl ?block_return_type procname in match body_opt with | Some body -> @@ -132,11 +131,10 @@ module CFrontend_decl_funct (T : CModule_type.CTranslation) : CModule_type.CFron let process_method_decl ?(set_objc_accessor_attr= false) ?(is_destructor= false) trans_unit_ctx tenv cfg curr_class meth_decl ~is_objc = - let is_cpp = CGeneral_utils.is_cpp_translation trans_unit_ctx in try let ms, body_opt, extra_instrs = let procname = CType_decl.CProcname.from_decl ~tenv meth_decl in - CType_decl.method_signature_body_of_decl ~is_cpp tenv meth_decl procname + CType_decl.method_signature_body_of_decl tenv meth_decl procname in match body_opt with | Some body -> diff --git a/infer/src/clang/cMethod_trans.ml b/infer/src/clang/cMethod_trans.ml index 3ee309ecc..2d4683140 100644 --- a/infer/src/clang/cMethod_trans.ml +++ b/infer/src/clang/cMethod_trans.ml @@ -20,13 +20,12 @@ type method_call_type = MCVirtual | MCNoVirtual | MCStatic [@@deriving compare] let equal_method_call_type = [%compare.equal : method_call_type] -let method_signature_of_pointer trans_unit_ctx tenv pointer = - let is_cpp = CGeneral_utils.is_cpp_translation trans_unit_ctx in +let method_signature_of_pointer tenv pointer = try match CAst_utils.get_decl pointer with | Some meth_decl -> let procname = CType_decl.CProcname.from_decl ~tenv meth_decl in - let ms = CType_decl.method_signature_of_decl ~is_cpp tenv meth_decl procname in + let ms = CType_decl.method_signature_of_decl tenv meth_decl procname in Some ms | None -> None @@ -78,10 +77,10 @@ let get_superclass_curr_class_objc context = (* Gets the class name from a method signature found by clang, if search is successful *) -let get_class_name_method_call_from_clang trans_unit_ctx tenv obj_c_message_expr_info = +let get_class_name_method_call_from_clang tenv obj_c_message_expr_info = match obj_c_message_expr_info.Clang_ast_t.omei_decl_pointer with | Some pointer -> ( - match method_signature_of_pointer trans_unit_ctx tenv pointer with + match method_signature_of_pointer tenv pointer with | Some ms -> ( match ms.CMethodSignature.name with | Typ.Procname.ObjC_Cpp objc_cpp -> @@ -318,7 +317,7 @@ let create_external_procdesc cfg proc_name clang_method_kind type_opt = let create_procdesc_with_pointer context pointer class_name_opt name = let open CContext in - match method_signature_of_pointer context.translation_unit_context context.tenv pointer with + match method_signature_of_pointer context.tenv pointer with | Some callee_ms -> ignore (create_local_procdesc context.translation_unit_context context.cfg context.tenv callee_ms diff --git a/infer/src/clang/cMethod_trans.mli b/infer/src/clang/cMethod_trans.mli index d8737f810..20fe9f84c 100644 --- a/infer/src/clang/cMethod_trans.mli +++ b/infer/src/clang/cMethod_trans.mli @@ -33,12 +33,9 @@ val get_class_name_method_call_from_receiver_kind : CContext.t -> Clang_ast_t.obj_c_message_expr_info -> (Exp.t * Typ.t) list -> Typ.Name.t val get_class_name_method_call_from_clang : - CFrontend_config.translation_unit_context -> Tenv.t -> Clang_ast_t.obj_c_message_expr_info - -> Typ.Name.t option + Tenv.t -> Clang_ast_t.obj_c_message_expr_info -> Typ.Name.t option -val method_signature_of_pointer : - CFrontend_config.translation_unit_context -> Tenv.t -> Clang_ast_t.pointer - -> CMethodSignature.t option +val method_signature_of_pointer : Tenv.t -> Clang_ast_t.pointer -> CMethodSignature.t option val get_method_name_from_clang : Tenv.t -> CMethodSignature.t option -> Typ.Procname.t option diff --git a/infer/src/clang/cTrans.ml b/infer/src/clang/cTrans.ml index d9e37e05f..b8a44b7b7 100644 --- a/infer/src/clang/cTrans.ml +++ b/infer/src/clang/cTrans.ml @@ -33,8 +33,7 @@ module CTrans_funct (F : CModule_type.CFrontend) : CModule_type.CTranslation = s let ms_opt = match method_pointer_opt with | Some pointer -> - CMethod_trans.method_signature_of_pointer context.translation_unit_context context.tenv - pointer + CMethod_trans.method_signature_of_pointer context.tenv pointer | None -> None in @@ -585,10 +584,7 @@ module CTrans_funct (F : CModule_type.CFrontend) : CModule_type.CTranslation = s Option.iter ~f:(call_translation context) decl_opt ; let method_name = CAst_utils.get_unqualified_name name_info in L.(debug Capture Verbose) "!!!!! Dealing with method '%s' @." method_name ; - let ms_opt = - CMethod_trans.method_signature_of_pointer context.translation_unit_context context.tenv - decl_ptr - in + let ms_opt = CMethod_trans.method_signature_of_pointer context.tenv decl_ptr in let is_instance_method = match ms_opt with | Some {CMethodSignature.method_kind= CPP_INSTANCE | OBJC_INSTANCE} -> @@ -1217,8 +1213,8 @@ module CTrans_funct (F : CModule_type.CFrontend) : CModule_type.CTranslation = s match receiver_kind with | `Class qual_type -> let class_opt = - CMethod_trans.get_class_name_method_call_from_clang context.translation_unit_context - context.CContext.tenv obj_c_message_expr_info + CMethod_trans.get_class_name_method_call_from_clang context.CContext.tenv + obj_c_message_expr_info in Some (new_or_alloc_trans trans_state_pri sil_loc si qual_type class_opt selector) | _ ->