From 262796d3bfff748cf209790dd66182de1f0d9561 Mon Sep 17 00:00:00 2001 From: Andrzej Kotulski Date: Mon, 1 Feb 2016 07:25:43 -0800 Subject: [PATCH] Distinguish between C++ and objc class types Reviewed By: cristianoc Differential Revision: D2885523 fb-gh-sync-id: 84f13a6 --- infer/src/clang/ast_expressions.ml | 8 ++++---- infer/src/clang/ast_expressions.mli | 2 +- infer/src/clang/cMethod_trans.ml | 4 ++-- infer/src/clang/cTrans.ml | 2 +- infer/src/clang/cTrans_models.ml | 8 ++++---- infer/src/clang/cType_to_sil_type.ml | 6 +++--- infer/src/clang/cTypes_decl.ml | 5 ++--- infer/src/clang/cTypes_decl.mli | 2 +- infer/src/clang/clang_ast_types.ml | 5 +++-- 9 files changed, 21 insertions(+), 21 deletions(-) diff --git a/infer/src/clang/ast_expressions.ml b/infer/src/clang/ast_expressions.ml index 8c0b4ff1e..5d57d5341 100644 --- a/infer/src/clang/ast_expressions.ml +++ b/infer/src/clang/ast_expressions.ml @@ -97,7 +97,7 @@ let create_void_unsigned_long_type = let create_void_void_type = new_constant_type_ptr () -let create_class_type class_name = `ClassType class_name +let create_class_type class_info = `ClassType class_info let create_struct_type struct_name = `StructType struct_name @@ -190,7 +190,7 @@ let make_obj_c_message_expr_info_instance sel = { let make_obj_c_message_expr_info_class selector tp pointer = { Clang_ast_t.omei_selector = selector; - omei_receiver_kind = `Class (create_class_type tp); + omei_receiver_kind = `Class (create_class_type (tp, `OBJC)); omei_is_definition_found = false; omei_decl_pointer = pointer } @@ -338,7 +338,7 @@ let build_OpaqueValueExpr si source_expr ei = let opaque_value_expr_info = { Clang_ast_t.ovei_source_expr = Some source_expr } in Clang_ast_t.OpaqueValueExpr (si, [], ei, opaque_value_expr_info) -let pseudo_object_tp () = create_class_type CFrontend_config.pseudo_object_type +let pseudo_object_tp () = create_class_type (CFrontend_config.pseudo_object_type, `OBJC) (* Create expression PseudoObjectExpr for 'o.m' *) let build_PseudoObjectExpr tp_m o_cast_decl_ref_exp mname = @@ -515,7 +515,7 @@ let translate_block_enumerate block_name stmt_info stmt_list ei = (* NSArray *objects = a *) let objects_array_DeclStmt init = let di = { empty_decl_info with Clang_ast_t.di_pointer = Ast_utils.get_fresh_pointer () } in - let tp = create_pointer_type (create_class_type CFrontend_config.nsarray_cl) in + let tp = create_pointer_type (create_class_type (CFrontend_config.nsarray_cl, `OBJC)) in (* init should be ImplicitCastExpr of array a *) let vdi = { empty_var_decl_info with Clang_ast_t.vdi_init_expr = Some (init) } in let objects_name = Ast_utils.make_name_decl CFrontend_config.objects in diff --git a/infer/src/clang/ast_expressions.mli b/infer/src/clang/ast_expressions.mli index 91ab7db41..c7891ac54 100644 --- a/infer/src/clang/ast_expressions.mli +++ b/infer/src/clang/ast_expressions.mli @@ -37,7 +37,7 @@ val create_void_unsigned_long_type : type_ptr val create_void_void_type : type_ptr -val create_class_type : string -> type_ptr +val create_class_type : Clang_ast_types.class_info -> type_ptr val create_struct_type : string -> type_ptr diff --git a/infer/src/clang/cMethod_trans.ml b/infer/src/clang/cMethod_trans.ml index 46a33cbfc..aafb1bc6b 100644 --- a/infer/src/clang/cMethod_trans.ml +++ b/infer/src/clang/cMethod_trans.ml @@ -52,10 +52,10 @@ let get_class_param function_method_decl_info = 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 + let class_type = Ast_expressions.create_class_type (class_name, `CPP) in [(CFrontend_config.this, class_type)] | ObjC_Meth_decl_info (_, class_name) -> - let class_type = Ast_expressions.create_class_type class_name in + let class_type = Ast_expressions.create_class_type (class_name, `OBJC) in [(CFrontend_config.self, class_type)] | _ -> [] else [] diff --git a/infer/src/clang/cTrans.ml b/infer/src/clang/cTrans.ml index 02da656d1..142dfc781 100644 --- a/infer/src/clang/cTrans.ml +++ b/infer/src/clang/cTrans.ml @@ -202,7 +202,7 @@ struct try f trans_state stmt with Self.SelfClassException class_name -> - let typ = CTypes_decl.type_name_to_sil_type trans_state.context.CContext.tenv class_name in + let typ = CTypes_decl.objc_class_name_to_sil_type trans_state.context.CContext.tenv class_name in let expanded_type = CTypes.expand_structured_type trans_state.context.CContext.tenv typ in { empty_res_trans with exps = [(Sil.Sizeof(expanded_type, Sil.Subtype.exact), Sil.Tint Sil.IULong)] } diff --git a/infer/src/clang/cTrans_models.ml b/infer/src/clang/cTrans_models.ml index d00fba525..01fb51c77 100644 --- a/infer/src/clang/cTrans_models.ml +++ b/infer/src/clang/cTrans_models.ml @@ -145,7 +145,7 @@ let get_predefined_ms_retain_release class_name method_name mk_procname lang = if is_retain_method method_name || is_autorelease_method method_name then Ast_expressions.create_id_type else Ast_expressions.create_void_type in let class_name = CFrontend_config.nsobject_cl in - let class_type = Ast_expressions.create_class_type class_name in + let class_type = Ast_expressions.create_class_type (class_name, `OBJC) in let args = [(CFrontend_config.self, class_type)] in get_predefined_ms_method condition class_name method_name Procname.Instance_objc_method mk_procname lang args return_type [] (get_builtinname method_name) @@ -154,7 +154,7 @@ let get_predefined_ms_autoreleasepool_init class_name method_name mk_procname la let condition = method_name = CFrontend_config.init && class_name = CFrontend_config.nsautorelease_pool_cl in - let class_type = Ast_expressions.create_class_type class_name in + let class_type = Ast_expressions.create_class_type (class_name, `OBJC) in get_predefined_ms_method condition class_name method_name Procname.Instance_objc_method mk_procname lang [(CFrontend_config.self, class_type)] Ast_expressions.create_void_type [] None @@ -163,7 +163,7 @@ let get_predefined_ms_nsautoreleasepool_release class_name method_name mk_procna let condition = (method_name = CFrontend_config.release || method_name = CFrontend_config.drain) && class_name = CFrontend_config.nsautorelease_pool_cl in - let class_type = Ast_expressions.create_class_type class_name in + let class_type = Ast_expressions.create_class_type (class_name, `OBJC) in get_predefined_ms_method condition class_name method_name Procname.Instance_objc_method mk_procname lang [(CFrontend_config.self, class_type)] Ast_expressions.create_void_type [] (Some SymExec.ModelBuiltins.__objc_release_autorelease_pool) @@ -172,7 +172,7 @@ let get_predefined_model_method_signature class_name method_name mk_procname lan match get_predefined_ms_nsautoreleasepool_release class_name method_name mk_procname lang with | Some ms -> Some ms | None -> - let class_type = Ast_expressions.create_class_type class_name in + let class_type = Ast_expressions.create_class_type (class_name, `OBJC) in match get_predefined_ms_retain_release class_type method_name mk_procname lang with | Some ms -> Some ms | None -> diff --git a/infer/src/clang/cType_to_sil_type.ml b/infer/src/clang/cType_to_sil_type.ml index aeabc168b..68442cea0 100644 --- a/infer/src/clang/cType_to_sil_type.ml +++ b/infer/src/clang/cType_to_sil_type.ml @@ -174,9 +174,9 @@ and type_ptr_to_sil_type translate_decl tenv type_ptr = | `PointerOf typ -> let sil_typ = type_ptr_to_sil_type translate_decl tenv typ in Sil.Tptr (sil_typ, Sil.Pk_pointer) - | `ClassType name -> - (* TODO: make the class kind a parameter of the function, instead of a constant Csu.Objc *) - Sil.Tvar (CTypes.mk_classname name Csu.Objc) + | `ClassType (name, lang) -> + let kind = match lang with `OBJC -> Csu.Objc | `CPP -> Csu.CPP in + Sil.Tvar (CTypes.mk_classname name kind) | `StructType name -> Sil.Tvar (CTypes.mk_structname name) | `DeclPtr ptr -> decl_ptr_to_sil_type translate_decl tenv ptr | `ErrorType -> Sil.Tvoid diff --git a/infer/src/clang/cTypes_decl.ml b/infer/src/clang/cTypes_decl.ml index a5c26e063..a727ce1e5 100644 --- a/infer/src/clang/cTypes_decl.ml +++ b/infer/src/clang/cTypes_decl.ml @@ -231,9 +231,8 @@ and add_types_from_decl_to_tenv tenv decl = and type_ptr_to_sil_type tenv tp = CType_to_sil_type.type_ptr_to_sil_type add_types_from_decl_to_tenv tenv tp - -let type_name_to_sil_type tenv name = - type_ptr_to_sil_type tenv (Ast_expressions.create_class_type name) +let objc_class_name_to_sil_type tenv name = + type_ptr_to_sil_type tenv (Ast_expressions.create_class_type (name, `OBJC)) let get_type_from_expr_info ei tenv = let tp = ei.Clang_ast_t.ei_type_ptr in diff --git a/infer/src/clang/cTypes_decl.mli b/infer/src/clang/cTypes_decl.mli index a20dd0bf2..2c25e9029 100644 --- a/infer/src/clang/cTypes_decl.mli +++ b/infer/src/clang/cTypes_decl.mli @@ -30,4 +30,4 @@ val get_type_curr_class_objc : Sil.tenv -> CContext.curr_class -> Sil.typ val get_type_from_expr_info : Clang_ast_t.expr_info -> Sil.tenv -> Sil.typ -val type_name_to_sil_type : Sil.tenv -> string -> Sil.typ +val objc_class_name_to_sil_type : Sil.tenv -> string -> Sil.typ diff --git a/infer/src/clang/clang_ast_types.ml b/infer/src/clang/clang_ast_types.ml index 97f82c616..0521439cf 100644 --- a/infer/src/clang/clang_ast_types.ml +++ b/infer/src/clang/clang_ast_types.ml @@ -15,12 +15,13 @@ (* Type pointers *) exception Not_Clang_Pointer +type class_info = string * [`CPP | `OBJC] type t_ptr = [ | `TPtr of int | `Prebuilt of int | `PointerOf of t_ptr - | `ClassType of string + | `ClassType of class_info | `StructType of string | `DeclPtr of int | `ErrorType] @@ -36,7 +37,7 @@ let rec type_ptr_to_string type_ptr = match type_ptr with | `TPtr raw -> "clang_ptr_" ^ (string_of_int raw) | `Prebuilt raw -> "prebuilt_" ^ (string_of_int raw) | `PointerOf typ -> "pointer_of_" ^ type_ptr_to_string typ - | `ClassType name -> "class_name_" ^ name + | `ClassType (name, _) -> "class_name_" ^ name | `StructType name -> "struct_name_" ^ name | `DeclPtr raw -> "decl_ptr_" ^ (string_of_int raw) | `ErrorType -> "error_type"