@ -32,7 +32,7 @@ let add_predefined_basic_types () =
CAst_utils . update_sil_types_map tp return_type in
let sil_void_type = CType_to_sil_type . sil_type_of_builtin_type_kind ` Void in
let sil_char_type = CType_to_sil_type . sil_type_of_builtin_type_kind ` Char_S in
let sil_nsarray_type = Typ . Tstruct ( CType. mk_classname CFrontend_config . nsarray_cl Csu . Objc ) in
let sil_nsarray_type = Typ . Tstruct ( Typename. Objc . from_string CFrontend_config . nsarray_cl ) in
let sil_id_type = CType_to_sil_type . get_builtin_objc_type ` ObjCId in
add_basic_type create_int_type ` Int ;
add_basic_type create_void_type ` Void ;
@ -50,44 +50,37 @@ let add_predefined_types tenv =
add_predefined_objc_types tenv ;
add_predefined_basic_types ()
let create_c su opt_type =
let create_c _record_typename opt_type =
match opt_type with
| ` Type s ->
( let buf = Str . split ( Str . regexp " [ \t ]+ " ) s in
match buf with
| " struct " :: _ -> Csu . Struct
| " class " :: _ -> Csu. Class Csu . CPP
| " union " :: _ -> Csu. Union
| _ -> Csu. Struct )
| " struct " :: _ -> Typename . C . from_string
| " class " :: _ -> Typename. Cpp . from_string
| " union " :: _ -> Typename. C . union_from_string
| _ -> Typename. C . from_string )
| _ -> assert false
(* We need to take the name out of the type as the struct can be anonymous *)
let get_record_ name_csu decl =
let get_record_ type name decl =
let open Clang_ast_t in
let name_info , csu = match decl with
| RecordDecl ( _ , name_info , opt_type , _ , _ , _ , _ ) ->
name_info , create_csu opt_type
| CXXRecordDecl ( _ , name_info , _ , _ , _ , _ , _ , _ )
| ClassTemplateSpecializationDecl ( _ , name_info , _ , _ , _ , _ , _ , _ , _ ) ->
(* we use Csu.Class for C++ because we expect Csu.Class csu from *)
(* types that have methods. And in C++ struct/class/union can have methods *)
name_info , Csu . Class Csu . CPP
| ObjCInterfaceDecl ( _ , name_info , _ , _ , _ )
| ObjCImplementationDecl ( _ , name_info , _ , _ , _ )
| ObjCProtocolDecl ( _ , name_info , _ , _ , _ )
| ObjCCategoryDecl ( _ , name_info , _ , _ , _ )
| ObjCCategoryImplDecl ( _ , name_info , _ , _ , _ ) ->
name_info , Csu . Class Csu . Objc
| _ -> assert false in
let name = CAst_utils . get_qualified_name name_info in
csu , name
let get_record_name decl = snd ( get_record_name_csu decl )
match decl with
| RecordDecl ( _ , name_info , opt_type , _ , _ , _ , _ ) ->
CAst_utils . get_qualified_name name_info | > create_c_record_typename opt_type
| CXXRecordDecl ( _ , name_info , _ , _ , _ , _ , _ , _ )
| ClassTemplateSpecializationDecl ( _ , name_info , _ , _ , _ , _ , _ , _ , _ ) ->
(* we use Csu.Class for C++ because we expect Csu.Class csu from *)
(* types that have methods. And in C++ struct/class/union can have methods *)
CAst_utils . get_qualified_name name_info | > Typename . Cpp . from_string
| ObjCInterfaceDecl ( _ , name_info , _ , _ , _ )
| ObjCImplementationDecl ( _ , name_info , _ , _ , _ )
| ObjCProtocolDecl ( _ , name_info , _ , _ , _ )
| ObjCCategoryDecl ( _ , name_info , _ , _ , _ )
| ObjCCategoryImplDecl ( _ , name_info , _ , _ , _ ) ->
CAst_utils . get_qualified_name name_info | > Typename . Objc . from_string
| _ -> assert false
let get_record_typename decl =
let csu , name = get_record_name_csu decl in
let mangled_name = Mangled . from_string name in
Typename . TN_csu ( csu , mangled_name )
let get_record_name decl = get_record_typename decl | > Typename . name
let get_class_template_name = function
| Clang_ast_t . ClassTemplateDecl ( _ , name_info , _ ) -> CAst_utils . get_qualified_name name_info
@ -109,9 +102,7 @@ let get_superclass_decls decl =
(* * fetches list of superclasses for C++ classes *)
let get_superclass_list_cpp decl =
let base_decls = get_superclass_decls decl in
let decl_to_mangled_name decl = Mangled . from_string ( get_record_name decl ) in
let get_super_field super_decl =
Typename . TN_csu ( Csu . Class Csu . CPP , decl_to_mangled_name super_decl ) in
let get_super_field super_decl = Typename . Cpp . from_string ( get_record_name super_decl ) in
List . map ~ f : get_super_field base_decls
let get_translate_as_friend_decl decl_list =
@ -197,16 +188,16 @@ and get_record_struct_type tenv definition_decl =
| CXXRecordDecl ( _ , _ , _ , type_ptr , _ , _ , record_decl_info , _ )
| RecordDecl ( _ , _ , _ , type_ptr , _ , _ , record_decl_info ) ->
let sil_typename = get_record_typename definition_decl in
let csu , name = get_record_name_csu definition_decl in
( match Tenv . lookup tenv sil_typename with
| Some _ -> Typ . Tstruct sil_typename (* just reuse what is already in tenv *)
| None ->
let is_complete_definition = record_decl_info . Clang_ast_t . rdi_is_complete_definition in
let extra_fields = if CTrans_models . is_objc_memory_model_controlled name then
let extra_fields =
if CTrans_models . is_objc_memory_model_controlled ( Typename . name sil_typename ) then
[ Typ . Struct . objc_ref_counter_field ]
else [] in
let annots =
if Csu. equal csu ( Csu . Class Csu . CPP ) then Annot . Class . cpp
if Typename. Cpp . is_class sil_typename then Annot . Class . cpp
else Annot . Item . empty (* No annotations for structs *) in
if is_complete_definition then (
CAst_utils . update_sil_types_map type_ptr ( Typ . Tstruct sil_typename ) ;