Distinguish between C++ and objc class types

Reviewed By: cristianoc

Differential Revision: D2885523

fb-gh-sync-id: 84f13a6
master
Andrzej Kotulski 9 years ago committed by facebook-github-bot-7
parent 9d7ab4b9c2
commit 262796d3bf

@ -97,7 +97,7 @@ let create_void_unsigned_long_type =
let create_void_void_type = let create_void_void_type =
new_constant_type_ptr () 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 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 = { let make_obj_c_message_expr_info_class selector tp pointer = {
Clang_ast_t.omei_selector = selector; 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_is_definition_found = false;
omei_decl_pointer = pointer 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 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) 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' *) (* Create expression PseudoObjectExpr for 'o.m' *)
let build_PseudoObjectExpr tp_m o_cast_decl_ref_exp mname = 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 *) (* NSArray *objects = a *)
let objects_array_DeclStmt init = let objects_array_DeclStmt init =
let di = { empty_decl_info with Clang_ast_t.di_pointer = Ast_utils.get_fresh_pointer () } in 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 *) (* init should be ImplicitCastExpr of array a *)
let vdi = { empty_var_decl_info with Clang_ast_t.vdi_init_expr = Some (init) } in 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 let objects_name = Ast_utils.make_name_decl CFrontend_config.objects in

@ -37,7 +37,7 @@ val create_void_unsigned_long_type : type_ptr
val create_void_void_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 val create_struct_type : string -> type_ptr

@ -52,10 +52,10 @@ let get_class_param function_method_decl_info =
if (is_instance_method function_method_decl_info) then if (is_instance_method function_method_decl_info) then
match function_method_decl_info with match function_method_decl_info with
| Cpp_Meth_decl_info (_, _, class_name, _) -> | 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)] [(CFrontend_config.this, class_type)]
| ObjC_Meth_decl_info (_, class_name) -> | 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)] [(CFrontend_config.self, class_type)]
| _ -> [] | _ -> []
else [] else []

@ -202,7 +202,7 @@ struct
try try
f trans_state stmt f trans_state stmt
with Self.SelfClassException class_name -> 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 let expanded_type = CTypes.expand_structured_type trans_state.context.CContext.tenv typ in
{ empty_res_trans with { empty_res_trans with
exps = [(Sil.Sizeof(expanded_type, Sil.Subtype.exact), Sil.Tint Sil.IULong)] } exps = [(Sil.Sizeof(expanded_type, Sil.Subtype.exact), Sil.Tint Sil.IULong)] }

@ -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 if is_retain_method method_name || is_autorelease_method method_name
then Ast_expressions.create_id_type else Ast_expressions.create_void_type in then Ast_expressions.create_id_type else Ast_expressions.create_void_type in
let class_name = CFrontend_config.nsobject_cl 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 let args = [(CFrontend_config.self, class_type)] in
get_predefined_ms_method condition class_name method_name Procname.Instance_objc_method get_predefined_ms_method condition class_name method_name Procname.Instance_objc_method
mk_procname lang args return_type [] (get_builtinname method_name) 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 = let condition =
method_name = CFrontend_config.init method_name = CFrontend_config.init
&& class_name = CFrontend_config.nsautorelease_pool_cl in && 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 get_predefined_ms_method condition class_name method_name Procname.Instance_objc_method
mk_procname lang [(CFrontend_config.self, class_type)] mk_procname lang [(CFrontend_config.self, class_type)]
Ast_expressions.create_void_type [] None Ast_expressions.create_void_type [] None
@ -163,7 +163,7 @@ let get_predefined_ms_nsautoreleasepool_release class_name method_name mk_procna
let condition = let condition =
(method_name = CFrontend_config.release || method_name = CFrontend_config.drain) (method_name = CFrontend_config.release || method_name = CFrontend_config.drain)
&& class_name = CFrontend_config.nsautorelease_pool_cl in && 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 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 mk_procname lang [(CFrontend_config.self, class_type)] Ast_expressions.create_void_type
[] (Some SymExec.ModelBuiltins.__objc_release_autorelease_pool) [] (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 match get_predefined_ms_nsautoreleasepool_release class_name method_name mk_procname lang with
| Some ms -> Some ms | Some ms -> Some ms
| None -> | 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 match get_predefined_ms_retain_release class_type method_name mk_procname lang with
| Some ms -> Some ms | Some ms -> Some ms
| None -> | None ->

@ -174,9 +174,9 @@ and type_ptr_to_sil_type translate_decl tenv type_ptr =
| `PointerOf typ -> | `PointerOf typ ->
let sil_typ = type_ptr_to_sil_type translate_decl tenv typ in let sil_typ = type_ptr_to_sil_type translate_decl tenv typ in
Sil.Tptr (sil_typ, Sil.Pk_pointer) Sil.Tptr (sil_typ, Sil.Pk_pointer)
| `ClassType name -> | `ClassType (name, lang) ->
(* TODO: make the class kind a parameter of the function, instead of a constant Csu.Objc *) let kind = match lang with `OBJC -> Csu.Objc | `CPP -> Csu.CPP in
Sil.Tvar (CTypes.mk_classname name Csu.Objc) Sil.Tvar (CTypes.mk_classname name kind)
| `StructType name -> Sil.Tvar (CTypes.mk_structname name) | `StructType name -> Sil.Tvar (CTypes.mk_structname name)
| `DeclPtr ptr -> decl_ptr_to_sil_type translate_decl tenv ptr | `DeclPtr ptr -> decl_ptr_to_sil_type translate_decl tenv ptr
| `ErrorType -> Sil.Tvoid | `ErrorType -> Sil.Tvoid

@ -231,9 +231,8 @@ and add_types_from_decl_to_tenv tenv decl =
and type_ptr_to_sil_type tenv tp = 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 CType_to_sil_type.type_ptr_to_sil_type add_types_from_decl_to_tenv tenv tp
let objc_class_name_to_sil_type tenv name =
let type_name_to_sil_type tenv name = type_ptr_to_sil_type tenv (Ast_expressions.create_class_type (name, `OBJC))
type_ptr_to_sil_type tenv (Ast_expressions.create_class_type name)
let get_type_from_expr_info ei tenv = let get_type_from_expr_info ei tenv =
let tp = ei.Clang_ast_t.ei_type_ptr in let tp = ei.Clang_ast_t.ei_type_ptr in

@ -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 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

@ -15,12 +15,13 @@
(* Type pointers *) (* Type pointers *)
exception Not_Clang_Pointer exception Not_Clang_Pointer
type class_info = string * [`CPP | `OBJC]
type t_ptr = [ type t_ptr = [
| `TPtr of int | `TPtr of int
| `Prebuilt of int | `Prebuilt of int
| `PointerOf of t_ptr | `PointerOf of t_ptr
| `ClassType of string | `ClassType of class_info
| `StructType of string | `StructType of string
| `DeclPtr of int | `DeclPtr of int
| `ErrorType] | `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) | `TPtr raw -> "clang_ptr_" ^ (string_of_int raw)
| `Prebuilt raw -> "prebuilt_" ^ (string_of_int raw) | `Prebuilt raw -> "prebuilt_" ^ (string_of_int raw)
| `PointerOf typ -> "pointer_of_" ^ type_ptr_to_string typ | `PointerOf typ -> "pointer_of_" ^ type_ptr_to_string typ
| `ClassType name -> "class_name_" ^ name | `ClassType (name, _) -> "class_name_" ^ name
| `StructType name -> "struct_name_" ^ name | `StructType name -> "struct_name_" ^ name
| `DeclPtr raw -> "decl_ptr_" ^ (string_of_int raw) | `DeclPtr raw -> "decl_ptr_" ^ (string_of_int raw)
| `ErrorType -> "error_type" | `ErrorType -> "error_type"

Loading…
Cancel
Save