Make all internal pointers convertible to ints

Summary:
public Prepare to use integers as pointers (as opposed to strings right now).
This should speed decl/type map lookup and there are no real downsides.

In order to preserve all knowledge we have right now, use following semantics for pointer values
clang pointer - its value is greater than 0
invalid pointer - its value is 0
internal pointer - its value is smaller than 0

Reviewed By: jvillard

Differential Revision: D2739419

fb-gh-sync-id: d264c28
master
Andrzej Kotulski 9 years ago committed by facebook-github-bot-7
parent a54b2d03f6
commit 5b4df5566c

@ -61,41 +61,41 @@ let stmt_info_with_fresh_pointer stmt_info = {
si_source_range = stmt_info.Clang_ast_t.si_source_range; si_source_range = stmt_info.Clang_ast_t.si_source_range;
} }
let get_constant_type_ptr s = let new_constant_type_ptr () =
let pointer = CFrontend_config.type_pointer_prefix ^ s in let pointer = Ast_utils.get_fresh_pointer () in
`Prebuilt pointer `Prebuilt pointer
(* Whenever new type are added manually to the translation here, *) (* Whenever new type are added manually to the translation here, *)
(* they should be added to the map in cTypes_decl too!! *) (* they should be added to the map in cTypes_decl too!! *)
let create_int_type = let create_int_type =
get_constant_type_ptr "int" new_constant_type_ptr ()
let create_void_type = let create_void_type =
get_constant_type_ptr "void" new_constant_type_ptr ()
let create_void_star_type = let create_void_star_type =
get_constant_type_ptr "void *" new_constant_type_ptr ()
let create_id_type = let create_id_type =
get_constant_type_ptr CFrontend_config.id_cl new_constant_type_ptr ()
let create_nsarray_star_type = let create_nsarray_star_type =
get_constant_type_ptr (CFrontend_config.nsarray_cl ^ " *") new_constant_type_ptr ()
let create_char_star_type = let create_char_star_type =
get_constant_type_ptr "char *" new_constant_type_ptr ()
let create_BOOL_type = let create_BOOL_type =
get_constant_type_ptr "signed char" new_constant_type_ptr ()
let create_unsigned_long_type = let create_unsigned_long_type =
get_constant_type_ptr "unsigned long" new_constant_type_ptr ()
let create_void_unsigned_long_type = let create_void_unsigned_long_type =
get_constant_type_ptr "void *(unsigned long)" new_constant_type_ptr ()
let create_void_void_type = let create_void_void_type =
get_constant_type_ptr "void (void *)" new_constant_type_ptr ()
let create_class_type class_name = `ClassType class_name let create_class_type class_name = `ClassType class_name

@ -107,7 +107,7 @@ let init = "init"
let temp_var = "infer" let temp_var = "infer"
let pointer_prefix = "internal" let invalid_pointer = 0
let void = "void" let void = "void"
@ -157,8 +157,6 @@ let sil_types_map = ref Clang_ast_types.TypePointerMap.empty
(* Map from enum constants pointers to their predecesor and their sil value *) (* Map from enum constants pointers to their predecesor and their sil value *)
let enum_map = ref Clang_ast_main.PointerMap.empty let enum_map = ref Clang_ast_main.PointerMap.empty
let type_pointer_prefix = "internal_type"
let nsarray_cl = "NSArray" let nsarray_cl = "NSArray"
let infer = "infer" let infer = "infer"

@ -99,7 +99,7 @@ val init : string
val temp_var : string val temp_var : string
val pointer_prefix : string val invalid_pointer : int
val void : string val void : string
@ -152,8 +152,6 @@ val sil_types_map : (Sil.typ Clang_ast_types.TypePointerMap.t) ref
(** Map from enum constants pointers to their predecesor and their sil value *) (** Map from enum constants pointers to their predecesor and their sil value *)
val enum_map : (Clang_ast_t.pointer option * Sil.exp option) Clang_ast_main.PointerMap.t ref val enum_map : (Clang_ast_t.pointer option * Sil.exp option) Clang_ast_main.PointerMap.t ref
val type_pointer_prefix : string
val nsarray_cl : string val nsarray_cl : string
val infer : string val infer : string

@ -267,10 +267,11 @@ struct
let get_fresh_pointer () = let get_fresh_pointer () =
pointer_counter := !pointer_counter + 1; pointer_counter := !pointer_counter + 1;
CFrontend_config.pointer_prefix^(string_of_int (!pointer_counter)) let internal_pointer = -(!pointer_counter) in
string_of_int internal_pointer
let get_invalid_pointer () = let get_invalid_pointer () =
CFrontend_config.pointer_prefix^("INVALID") string_of_int CFrontend_config.invalid_pointer
let type_from_unary_expr_or_type_trait_expr_info info = let type_from_unary_expr_or_type_trait_expr_info info =
match info.Clang_ast_t.uttei_type_ptr with match info.Clang_ast_t.uttei_type_ptr with

@ -16,7 +16,8 @@ open CFrontend_utils
module L = Logging module L = Logging
let is_custom_var_pointer pointer = let is_custom_var_pointer pointer =
Utils.string_is_prefix CFrontend_config.pointer_prefix pointer let pointer_int = int_of_string pointer in
pointer_int <= 0
let is_captured procdesc vname = let is_captured procdesc vname =
IList.exists IList.exists

Loading…
Cancel
Save