@ -110,6 +110,8 @@ let create_struct_type struct_name = `StructType struct_name
let create_pointer_type typ = ` PointerOf typ
let create_qual_type ? ( is_const = false ) type_ptr = { Clang_ast_t . type_ptr ; is_const }
let create_reference_type typ = ` ReferenceOf typ
let create_integer_literal n =
@ -237,7 +239,8 @@ let make_objc_ivar_decl decl_info tp ivar_name =
Clang_ast_t . ovdi_is_synthesize = true ; (* NOTE: We set true here because we use this definition to synthesize the getter/setter *)
ovdi_access_control = ` Private ;
} in
Clang_ast_t . ObjCIvarDecl ( decl_info , ivar_name , tp , field_decl_info , obj_c_ivar_decl_info )
let qt = create_qual_type tp in
Clang_ast_t . ObjCIvarDecl ( decl_info , ivar_name , qt , field_decl_info , obj_c_ivar_decl_info )
let make_expr_info tp = {
Clang_ast_t . ei_type_ptr = tp ;
@ -273,7 +276,8 @@ let make_binary_stmt stmt1 stmt2 stmt_info expr_info boi =
let make_next_object_exp stmt_info item items =
let var_decl_ref , var_type =
match item with
| Clang_ast_t . DeclStmt ( _ , _ , [ Clang_ast_t . VarDecl ( di , name_info , var_type , _ ) ] ) ->
| Clang_ast_t . DeclStmt ( _ , _ , [ Clang_ast_t . VarDecl ( di , name_info , var_qual_type , _ ) ] ) ->
let var_type = var_qual_type . Clang_ast_t . type_ptr in
let decl_ptr = di . Clang_ast_t . di_pointer in
let decl_ref = make_decl_ref_tp ` Var decl_ptr name_info false var_type in
let stmt_info_var = {
@ -316,7 +320,8 @@ let make_DeclStmt stmt_info di tp vname old_vdi iexp =
| None -> None , [] in
let var_decl_info = { old_vdi with Clang_ast_t . vdi_init_expr = init_expr_opt } in
let di = fresh_decl_info di in
let var_decl = Clang_ast_t . VarDecl ( di , vname , tp , var_decl_info ) in
let qt = create_qual_type tp in
let var_decl = Clang_ast_t . VarDecl ( di , vname , qt , var_decl_info ) in
Clang_ast_t . DeclStmt ( stmt_info , init_expr_l , [ var_decl ] )
let build_OpaqueValueExpr si source_expr ei =
@ -393,9 +398,10 @@ let translate_block_enumerate block_name stmt_info stmt_list ei =
let build_idx_decl pidx =
match pidx with
| Clang_ast_t . ParmVarDecl ( di_idx , name_idx , tp _idx, vdi ) ->
| Clang_ast_t . ParmVarDecl ( di_idx , name_idx , q t_idx, vdi ) ->
let zero = create_integer_literal " 0 " in
(* tp_idx idx = 0; *)
(* qt_idx idx = 0; *)
let tp_idx = qt_idx . Clang_ast_t . type_ptr in
let idx_decl_stmt = make_DeclStmt ( fresh_stmt_info stmt_info ) di_idx tp_idx
name_idx vdi ( Some zero ) in
let idx_ei = make_expr_info tp_idx in
@ -417,7 +423,7 @@ let translate_block_enumerate block_name stmt_info stmt_list ei =
(* build statement BOOL * stop = malloc ( sizeof ( BOOL ) ) ; *)
let build_stop pstop =
match pstop with
| Clang_ast_t . ParmVarDecl ( di , name , tp , vdi ) ->
| Clang_ast_t . ParmVarDecl ( di , name , q t, vdi ) ->
let tp_fun = create_void_unsigned_long_type in
let type_opt = Some create_BOOL_type in
let parameter = Clang_ast_t . UnaryExprOrTypeTraitExpr
@ -428,6 +434,7 @@ let translate_block_enumerate block_name stmt_info stmt_list ei =
let stmt_info = fresh_stmt_info stmt_info in
let malloc_name = Ast_utils . make_name_decl CFrontend_config . malloc in
let malloc = create_call stmt_info pointer malloc_name tp_fun [ parameter ] in
let tp = qt . Clang_ast_t . type_ptr in
let init_exp = create_implicit_cast_expr ( fresh_stmt_info stmt_info ) [ malloc ] tp ` BitCast in
make_DeclStmt ( fresh_stmt_info stmt_info ) di tp name vdi ( Some init_exp )
| _ -> assert false in
@ -435,7 +442,8 @@ let translate_block_enumerate block_name stmt_info stmt_list ei =
(* BOOL * stop =NO; *)
let stop_equal_no pstop =
match pstop with
| Clang_ast_t . ParmVarDecl ( di , name , tp , _ ) ->
| Clang_ast_t . ParmVarDecl ( di , name , qt , _ ) ->
let tp = qt . Clang_ast_t . type_ptr in
let decl_ref = make_decl_ref_tp ` Var di . Clang_ast_t . di_pointer name false tp in
let cast = cast_expr decl_ref tp in
let postfix_deref = { Clang_ast_t . uoi_kind = ` Deref ; uoi_is_postfix = true } in
@ -448,7 +456,8 @@ let translate_block_enumerate block_name stmt_info stmt_list ei =
(* build statement free ( stop ) ; *)
let free_stop pstop =
match pstop with
| Clang_ast_t . ParmVarDecl ( di , name , tp , _ ) ->
| Clang_ast_t . ParmVarDecl ( di , name , qt , _ ) ->
let tp = qt . Clang_ast_t . type_ptr in
let tp_fun = create_void_void_type in
let decl_ref = make_decl_ref_tp ` Var di . Clang_ast_t . di_pointer name false tp in
let cast = cast_expr decl_ref tp in
@ -482,7 +491,8 @@ let translate_block_enumerate block_name stmt_info stmt_list ei =
let build_object_DeclStmt pobj decl_ref_expr_array decl_ref_expr_idx =
let open Clang_ast_t in
match pobj with
| ParmVarDecl ( di_obj , name_obj , tp_obj , _ ) ->
| ParmVarDecl ( di_obj , name_obj , qt_obj , _ ) ->
let tp_obj = qt_obj . Clang_ast_t . type_ptr in
let poe_ei = make_general_expr_info tp_obj ` RValue ` Ordinary in
let ei_array = get_ei_from_cast decl_ref_expr_array in
let ove_array = build_OpaqueValueExpr ( fresh_stmt_info stmt_info ) decl_ref_expr_array ei_array in
@ -495,14 +505,15 @@ let translate_block_enumerate block_name stmt_info stmt_list ei =
let ome = ObjCMessageExpr ( fresh_stmt_info stmt_info , [ ove_array ; ove_idx ] , poe_ei , obj_c_message_expr_info ) in
let pseudo_obj_expr = PseudoObjectExpr ( fresh_stmt_info stmt_info , [ objc_sre ; ove_array ; ove_idx ; ome ] , poe_ei ) in
let vdi = { empty_var_decl_info with vdi_init_expr = Some ( pseudo_obj_expr ) } in
let var_decl = VarDecl ( di_obj , name_obj , tp _obj, vdi ) in
let var_decl = VarDecl ( di_obj , name_obj , q t_obj, vdi ) in
DeclStmt ( fresh_stmt_info stmt_info , [ pseudo_obj_expr ] , [ var_decl ] )
| _ -> assert false in
(* 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 , ` OBJC ) ) in
let tp = create_qual_type @@ 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
@ -511,14 +522,16 @@ let translate_block_enumerate block_name stmt_info stmt_list ei =
let make_object_cast_decl_ref_expr objects =
match objects with
| Clang_ast_t . DeclStmt ( si , _ , [ Clang_ast_t . VarDecl ( _ , name , tp , _ ) ] ) ->
| Clang_ast_t . DeclStmt ( si , _ , [ Clang_ast_t . VarDecl ( _ , name , qt , _ ) ] ) ->
let tp = qt . Clang_ast_t . type_ptr in
let decl_ref = make_decl_ref_tp ` Var si . Clang_ast_t . si_pointer name false tp in
cast_expr decl_ref tp
| _ -> assert false in
let build_cast_decl_ref_expr_from_parm p =
match p with
| Clang_ast_t . ParmVarDecl ( di , name , tp , _ ) ->
| Clang_ast_t . ParmVarDecl ( di , name , qt , _ ) ->
let tp = qt . Clang_ast_t . type_ptr in
let decl_ref = make_decl_ref_tp ` Var di . Clang_ast_t . di_pointer name false tp in
cast_expr decl_ref tp
| _ -> assert false in
@ -530,9 +543,9 @@ let translate_block_enumerate block_name stmt_info stmt_list ei =
| Clang_ast_t . BlockExpr ( bsi , _ , bei , _ ) ->
let di = { empty_decl_info with Clang_ast_t . di_pointer = Ast_utils . get_fresh_pointer () } in
let vdi = { empty_var_decl_info with Clang_ast_t . vdi_init_expr = Some ( be ) } in
let tp = bei . Clang_ast_t . ei_type_ptr in
let var_decl = Clang_ast_t . VarDecl ( di , qual_block_name , tp , vdi ) in
Clang_ast_t . DeclStmt ( bsi , [ be ] , [ var_decl ] ) , [ ( block_name , di . Clang_ast_t . di_pointer , bei. Clang_ast_t . ei_type_ptr ) ]
let q t = create_qual_type bei . Clang_ast_t . ei_type_ptr in
let var_decl = Clang_ast_t . VarDecl ( di , qual_block_name , q t, vdi ) in
Clang_ast_t . DeclStmt ( bsi , [ be ] , [ var_decl ] ) , [ ( block_name , di . Clang_ast_t . di_pointer , qt ) ]
| _ -> assert false in
let make_block_call block_tp object_cast idx_cast stop_cast =