[clang] Refactor computing procnames for blocks

Reviewed By: mbouaziz

Differential Revision: D8148085

fbshipit-source-id: 8217d57
master
Dulma Churchill 7 years ago committed by Facebook Github Bot
parent bfcc88a5e2
commit 7a68dde647

@ -182,14 +182,6 @@ let get_record_definition decl =
decl decl
(** Global counter for anonymous block*)
let block_counter = ref 0
let get_fresh_block_index () =
block_counter := !block_counter + 1 ;
!block_counter
let mk_objc_method class_typename method_name method_kind = let mk_objc_method class_typename method_name method_kind =
Typ.Procname.ObjC_Cpp Typ.Procname.ObjC_Cpp
(Typ.Procname.ObjC_Cpp.make class_typename method_name method_kind Typ.NoTemplate) (Typ.Procname.ObjC_Cpp.make class_typename method_name method_kind Typ.NoTemplate)
@ -442,7 +434,17 @@ and objc_method_procname ?tenv decl_info method_name mdi =
mk_objc_method class_typename method_name method_kind mk_objc_method class_typename method_name method_kind
and from_decl ?tenv ~is_cpp meth_decl = and objc_block_procname outer_proc_opt =
let outer_proc_string = Option.value_map ~f:Typ.Procname.to_string outer_proc_opt ~default:"" in
let block_procname_with_index i =
Printf.sprintf "%s%s%s%d" Config.anonymous_block_prefix outer_proc_string
Config.anonymous_block_num_sep i
in
let name = block_procname_with_index (CFrontend_config.get_fresh_block_index ()) in
Typ.Procname.mangled_objc_block name
and from_decl ?tenv ~is_cpp ?outer_proc meth_decl =
let open Clang_ast_t in let open Clang_ast_t in
match meth_decl with match meth_decl with
| FunctionDecl (decl_info, name_info, _, fdi) -> | FunctionDecl (decl_info, name_info, _, fdi) ->
@ -460,11 +462,7 @@ and from_decl ?tenv ~is_cpp meth_decl =
| ObjCMethodDecl (decl_info, name_info, mdi) -> | ObjCMethodDecl (decl_info, name_info, mdi) ->
objc_method_procname ?tenv decl_info name_info.Clang_ast_t.ni_name mdi objc_method_procname ?tenv decl_info name_info.Clang_ast_t.ni_name mdi
| BlockDecl _ -> | BlockDecl _ ->
let name = objc_block_procname outer_proc
Config.anonymous_block_prefix ^ Config.anonymous_block_num_sep
^ string_of_int (get_fresh_block_index ())
in
Typ.Procname.mangled_objc_block name
| _ -> | _ ->
Logging.die InternalError "Expected method decl, but got %s." Logging.die InternalError "Expected method decl, but got %s."
(Clang_ast_proj.get_decl_kind_string meth_decl) (Clang_ast_proj.get_decl_kind_string meth_decl)
@ -531,20 +529,6 @@ and get_record_struct_type tenv definition_decl : Typ.desc =
module CProcname = struct module CProcname = struct
let from_decl = from_decl let from_decl = from_decl
(* silly, but required to avoid circular dependencies *)
let reset_block_counter () = block_counter := 0
let block_procname_with_index defining_proc i =
Config.anonymous_block_prefix ^ Typ.Procname.to_string defining_proc
^ Config.anonymous_block_num_sep ^ string_of_int i
let mk_fresh_block_procname defining_proc =
let name = block_procname_with_index defining_proc (get_fresh_block_index ()) in
Typ.Procname.mangled_objc_block name
module NoAstDecl = struct module NoAstDecl = struct
let c_function_of_string ~is_cpp tenv name = let c_function_of_string ~is_cpp tenv name =
let qual_name = QualifiedCppName.of_qual_string name in let qual_name = QualifiedCppName.of_qual_string name in

@ -10,7 +10,8 @@
open! IStd open! IStd
module CProcname : sig module CProcname : sig
val from_decl : ?tenv:Tenv.t -> is_cpp:bool -> Clang_ast_t.decl -> Typ.Procname.t val from_decl :
?tenv:Tenv.t -> is_cpp:bool -> ?outer_proc:Typ.Procname.t -> Clang_ast_t.decl -> Typ.Procname.t
(** Given decl, return its procname. This function should be used for all procedures (** Given decl, return its procname. This function should be used for all procedures
present in original AST *) present in original AST *)
@ -29,12 +30,6 @@ module CProcname : sig
val objc_method_of_string_kind : val objc_method_of_string_kind :
Typ.Name.t -> string -> Typ.Procname.ObjC_Cpp.kind -> Typ.Procname.t Typ.Name.t -> string -> Typ.Procname.ObjC_Cpp.kind -> Typ.Procname.t
end end
val mk_fresh_block_procname : Typ.Procname.t -> Typ.Procname.t
(** Makes a fresh name for a block defined inside the defining procedure.
It updates the global block_counter *)
val reset_block_counter : unit -> unit
end end
(** Processes types and record declarations by adding them to the tenv *) (** Processes types and record declarations by adding them to the tenv *)

@ -41,7 +41,7 @@ let compute_icfg trans_unit_ctx tenv ast =
let init_global_state_capture () = let init_global_state_capture () =
Ident.NameGenerator.reset () ; Ident.NameGenerator.reset () ;
CFrontend_config.global_translation_unit_decls := [] ; CFrontend_config.global_translation_unit_decls := [] ;
CType_decl.CProcname.reset_block_counter () CFrontend_config.reset_block_counter ()
let do_source_file (translation_unit_context: CFrontend_config.translation_unit_context) ast = let do_source_file (translation_unit_context: CFrontend_config.translation_unit_context) ast =

@ -141,6 +141,16 @@ let procedures_attempted = ref 0
let procedures_failed = ref 0 let procedures_failed = ref 0
(** Global counter for anonymous block*)
let block_counter = ref 0
let get_fresh_block_index () =
block_counter := !block_counter + 1 ;
!block_counter
let reset_block_counter () = block_counter := 0
let reset_global_state () = let reset_global_state () =
enum_map := ClangPointers.Map.empty ; enum_map := ClangPointers.Map.empty ;
global_translation_unit_decls := [] ; global_translation_unit_decls := [] ;

@ -137,6 +137,10 @@ val procedures_attempted : int ref
val procedures_failed : int ref val procedures_failed : int ref
val get_fresh_block_index : unit -> int
val reset_block_counter : unit -> unit
val reset_global_state : unit -> unit val reset_global_state : unit -> unit
val tableaux_evaluation : bool val tableaux_evaluation : bool

@ -2639,11 +2639,14 @@ module CTrans_funct (F : CModule_type.CFrontend) : CModule_type.CTranslation = s
and blockExpr_trans trans_state stmt_info expr_info decl = and blockExpr_trans trans_state stmt_info expr_info decl =
let context = trans_state.context in let context = trans_state.context in
let procname = Procdesc.get_proc_name context.CContext.procdesc in let outer_proc = Procdesc.get_proc_name context.CContext.procdesc in
let is_cpp = CGeneral_utils.is_cpp_translation context.translation_unit_context in
match decl with match decl with
| Clang_ast_t.BlockDecl (_, block_decl_info) -> | Clang_ast_t.BlockDecl (_, block_decl_info) ->
let open CContext in let open CContext in
let block_pname = CType_decl.CProcname.mk_fresh_block_procname procname in let block_pname =
CType_decl.CProcname.from_decl decl ~tenv:context.tenv ~is_cpp ~outer_proc
in
let captured_pvars = let captured_pvars =
CVar_decl.captured_vars_from_block_info context stmt_info.Clang_ast_t.si_source_range CVar_decl.captured_vars_from_block_info context stmt_info.Clang_ast_t.si_source_range
block_decl_info.Clang_ast_t.bdi_captured_variables block_decl_info.Clang_ast_t.bdi_captured_variables

Loading…
Cancel
Save