[clang] Replace Prebuilt type_ptr with Typ.t

Summary: There was unncecessary abstraction here - instead of looking up sil type in the map, simply store it as part of variant payload

Reviewed By: jberdine

Differential Revision: D4938114

fbshipit-source-id: 9fb8dd4
master
Andrzej Kotulski 8 years ago committed by Facebook Github Bot
parent d20d71da50
commit e742d5bb7b

@ -17,38 +17,8 @@ let add_predefined_objc_types tenv =
ignore (Tenv.mk_struct tenv (CType_to_sil_type.get_builtin_objc_typename `ObjCClass));
ignore (Tenv.mk_struct tenv (CType_to_sil_type.get_builtin_objc_typename `ObjCId))
(* Whenever new type are added manually to the translation in ast_expressions, *)
(* they should be added here too!! *)
let add_predefined_basic_types () =
let open Ast_expressions in
let add_basic_type tp basic_type_kind =
let sil_type = CType_to_sil_type.sil_type_of_builtin_type_kind basic_type_kind in
CAst_utils.update_sil_types_map tp sil_type in
let add_pointer_type tp sil_type =
let pointer_type = CType.add_pointer_to_typ sil_type in
CAst_utils.update_sil_types_map tp pointer_type in
let add_function_type tp return_type =
(* We translate function types as the return type of the function *)
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 (Typ.Name.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;
add_basic_type create_char_type `Char_S;
add_basic_type create_BOOL_type `SChar;
add_basic_type create_unsigned_long_type `ULong;
add_pointer_type create_void_star_type sil_void_type;
add_pointer_type create_char_star_type sil_char_type;
add_pointer_type create_nsarray_star_type sil_nsarray_type;
add_pointer_type create_id_type sil_id_type;
add_function_type create_void_unsigned_long_type sil_void_type;
add_function_type create_void_void_type sil_void_type
let add_predefined_types tenv =
add_predefined_objc_types tenv;
add_predefined_basic_types ()
add_predefined_objc_types tenv
let create_c_record_typename opt_type =
match opt_type with

@ -66,45 +66,32 @@ let stmt_info_with_fresh_pointer stmt_info = {
let create_qual_type ?(is_const=false) qt_type_ptr =
{ Clang_ast_t.qt_type_ptr; qt_is_const=is_const }
let new_constant_type_ptr () =
let pointer = CAst_utils.get_fresh_pointer () in
Clang_ast_extend.Prebuilt pointer
let builtin_to_type_ptr kind = Clang_ast_extend.Builtin kind
(* Whenever new type are added manually to the translation here, *)
(* they should be added to the map in cTypes_decl too!! *)
let create_int_type =
new_constant_type_ptr ()
let pointerof_type_ptr type_ptr = Clang_ast_extend.PointerOf type_ptr
let create_void_type =
new_constant_type_ptr ()
(* We translate function types as the return type of the function *)
let function_type_ptr return_type = return_type
let create_void_star_type =
new_constant_type_ptr ()
let create_int_type = builtin_to_type_ptr `Int
let create_id_type =
new_constant_type_ptr ()
let create_void_type = builtin_to_type_ptr `Void
let create_nsarray_star_type =
new_constant_type_ptr ()
let create_void_star_type = pointerof_type_ptr create_void_type
let create_char_type =
new_constant_type_ptr ()
let create_id_type = pointerof_type_ptr (builtin_to_type_ptr `ObjCId)
let create_char_star_type =
new_constant_type_ptr ()
let create_char_type = builtin_to_type_ptr `Char_S
let create_char_star_type = pointerof_type_ptr create_char_type
let create_char_star_qual_type ~is_const = create_qual_type ~is_const create_char_star_type
let create_BOOL_type =
new_constant_type_ptr ()
let create_BOOL_type = builtin_to_type_ptr `SChar
let create_unsigned_long_type =
new_constant_type_ptr ()
let create_unsigned_long_type = builtin_to_type_ptr `ULong
let create_void_unsigned_long_type =
new_constant_type_ptr ()
let create_void_unsigned_long_type = function_type_ptr create_void_type
let create_void_void_type =
new_constant_type_ptr ()
let create_void_void_type = function_type_ptr create_void_type
let create_class_type typename = Clang_ast_extend.ClassType typename
let create_class_qual_type ?(is_const=false) typename =

@ -21,29 +21,17 @@ val dummy_stmt_info : unit -> stmt_info
val create_qual_type : ?is_const:bool -> type_ptr -> qual_type
val create_char_type : type_ptr
val create_char_star_type : type_ptr
val create_char_star_qual_type : is_const:bool -> qual_type
val create_id_type : type_ptr
val create_nsarray_star_type : type_ptr
val create_void_type : type_ptr
val create_int_type : type_ptr
val create_void_star_type : type_ptr
val create_BOOL_type : type_ptr
val create_unsigned_long_type : type_ptr
val create_void_unsigned_long_type : type_ptr
val create_void_void_type : type_ptr
val create_class_type : Typ.Name.t -> type_ptr
val create_class_qual_type : ?is_const:bool -> Typ.Name.t -> qual_type

@ -160,18 +160,10 @@ and clang_type_ptr_to_sil_type translate_decl tenv type_ptr =
sil_type
| _ -> Typ.Tvoid)
and prebuilt_type_to_sil_type type_ptr =
try
Clang_ast_extend.TypePointerMap.find type_ptr !CFrontend_config.sil_types_map
with Not_found ->
Logging.out "Prebuilt type %s not found\n"
(Clang_ast_extend.type_ptr_to_string type_ptr);
assert false
and type_ptr_to_sil_type translate_decl tenv type_ptr =
match type_ptr with
| Clang_ast_types.TypePtr.Ptr _ -> clang_type_ptr_to_sil_type translate_decl tenv type_ptr
| Clang_ast_extend.Prebuilt _ -> prebuilt_type_to_sil_type type_ptr
| Clang_ast_extend.Builtin kind -> sil_type_of_builtin_type_kind kind
| Clang_ast_extend.PointerOf typ ->
let sil_typ = type_ptr_to_sil_type translate_decl tenv typ in
Typ.Tptr (sil_typ, Typ.Pk_pointer)

@ -16,7 +16,7 @@ open! IStd
(* Type pointers *)
type Clang_ast_types.TypePtr.t +=
| Prebuilt of int
| Builtin of Clang_ast_t.builtin_type_kind
| PointerOf of Clang_ast_types.TypePtr.t
| ReferenceOf of Clang_ast_types.TypePtr.t
| ClassType of Typ.Name.t
@ -30,9 +30,9 @@ module TypePointerOrd = struct
| Clang_ast_types.TypePtr.Ptr a, Clang_ast_types.TypePtr.Ptr b -> Int.compare a b
| Clang_ast_types.TypePtr.Ptr _, _ -> 1
| _, Clang_ast_types.TypePtr.Ptr _ -> -1
| Prebuilt a, Prebuilt b -> Int.compare a b
| Prebuilt _, _ -> 1
| _, Prebuilt _ -> -1
| Builtin a, Builtin b -> Polymorphic_compare.compare a b
| Builtin _, _ -> 1
| _, Builtin _ -> -1
| PointerOf a, PointerOf b -> compare a b
| PointerOf _, _ -> 1
| _, PointerOf _ -> -1
@ -54,7 +54,7 @@ module TypePointerMap = Caml.Map.Make(TypePointerOrd)
let rec type_ptr_to_string = function
| Clang_ast_types.TypePtr.Ptr raw -> "clang_ptr_" ^ (string_of_int raw)
| Prebuilt raw -> "prebuilt_" ^ (string_of_int raw)
| Builtin t -> "sil_" ^ (Clang_ast_j.string_of_builtin_type_kind t)
| PointerOf typ -> "pointer_of_" ^ type_ptr_to_string typ
| ReferenceOf typ -> "reference_of_" ^ type_ptr_to_string typ
| ClassType name -> "class_name_" ^ Typ.Name.name name

Loading…
Cancel
Save