Cleanup handling of namespaces from ocaml code

Summary: public Plugin already exports fully qualified name, we don't need
to reconstruct it in ocaml again.
It wasn't used anywhere so this diff shouldn't change any behavior

Reviewed By: dulmarod

Differential Revision: D2668588

fb-gh-sync-id: 1ed1d61
master
Andrzej Kotulski 9 years ago committed by facebook-github-bot-1
parent 66777d5f07
commit c2aaf867cd

@ -31,12 +31,11 @@ type t =
is_objc_method : bool; is_objc_method : bool;
curr_class: curr_class; curr_class: curr_class;
is_callee_expression : bool; is_callee_expression : bool;
namespace: string option; (* contains the name of the namespace if we are in the scope of one*)
outer_context : t option; (* in case of objc blocks, the context of the method containing the block *) outer_context : t option; (* in case of objc blocks, the context of the method containing the block *)
mutable blocks_static_vars : ((Sil.pvar * Sil.typ) list) Procname.Map.t; mutable blocks_static_vars : ((Sil.pvar * Sil.typ) list) Procname.Map.t;
} }
let create_context tenv cg cfg procdesc ns curr_class is_objc_method context_opt = let create_context tenv cg cfg procdesc curr_class is_objc_method context_opt =
{ tenv = tenv; { tenv = tenv;
cg = cg; cg = cg;
cfg = cfg; cfg = cfg;
@ -44,7 +43,6 @@ let create_context tenv cg cfg procdesc ns curr_class is_objc_method context_opt
curr_class = curr_class; curr_class = curr_class;
is_callee_expression = false; is_callee_expression = false;
is_objc_method = is_objc_method; is_objc_method = is_objc_method;
namespace = ns;
outer_context = context_opt; outer_context = context_opt;
blocks_static_vars = Procname.Map.empty blocks_static_vars = Procname.Map.empty
} }

@ -26,7 +26,6 @@ type t =
is_objc_method : bool; is_objc_method : bool;
curr_class: curr_class; curr_class: curr_class;
is_callee_expression : bool; is_callee_expression : bool;
namespace: string option; (* contains the name of the namespace if we are in the scope of one*)
outer_context : t option; (* in case of objc blocks, the context of the method containing the block *) outer_context : t option; (* in case of objc blocks, the context of the method containing the block *)
mutable blocks_static_vars : ((Sil.pvar * Sil.typ) list) Procname.Map.t; mutable blocks_static_vars : ((Sil.pvar * Sil.typ) list) Procname.Map.t;
} }
@ -54,7 +53,7 @@ val is_objc_method : t -> bool
val get_tenv : t -> Sil.tenv val get_tenv : t -> Sil.tenv
val create_context : Sil.tenv -> Cg.t -> Cfg.cfg -> Cfg.Procdesc.t -> val create_context : Sil.tenv -> Cg.t -> Cfg.cfg -> Cfg.Procdesc.t ->
string option -> curr_class -> bool -> t option -> t curr_class -> bool -> t option -> t
val create_curr_class : Sil.tenv -> string -> curr_class val create_curr_class : Sil.tenv -> string -> curr_class

@ -20,12 +20,10 @@ open CFrontend_utils
open CGen_trans open CGen_trans
(* Translate one global declaration *) (* Translate one global declaration *)
let rec translate_one_declaration tenv cg cfg namespace parent_dec dec = let rec translate_one_declaration tenv cg cfg parent_dec dec =
let open Clang_ast_t in let open Clang_ast_t in
(* each procedure has different scope: start names from id 0 *) (* each procedure has different scope: start names from id 0 *)
Ident.NameGenerator.reset (); Ident.NameGenerator.reset ();
let ns_suffix = Ast_utils.namespace_to_string namespace in
let info = Clang_ast_proj.get_decl_tuple dec in let info = Clang_ast_proj.get_decl_tuple dec in
CLocation.update_curr_file info; CLocation.update_curr_file info;
let source_range = info.Clang_ast_t.di_source_range in let source_range = info.Clang_ast_t.di_source_range in
@ -33,14 +31,14 @@ let rec translate_one_declaration tenv cg cfg namespace parent_dec dec =
(if should_translate_decl then (if should_translate_decl then
match dec with match dec with
| FunctionDecl(di, name_info, tp, fdecl_info) -> | FunctionDecl(di, name_info, tp, fdecl_info) ->
CMethod_declImpl.function_decl tenv cfg cg namespace dec None CMethod_declImpl.function_decl tenv cfg cg dec None
(* Currently C/C++ record decl treated in the same way *) (* Currently C/C++ record decl treated in the same way *)
| CXXRecordDecl (_, _, _, _, decl_list, _, _, _) | RecordDecl (_, _, _, _, decl_list, _, _) -> | CXXRecordDecl (_, _, _, _, decl_list, _, _, _) | RecordDecl (_, _, _, _, decl_list, _, _) ->
ignore (CTypes_decl.add_types_from_decl_to_tenv tenv namespace dec); ignore (CTypes_decl.add_types_from_decl_to_tenv tenv dec);
let method_decls = CTypes_decl.get_method_decls dec decl_list in let method_decls = CTypes_decl.get_method_decls dec decl_list in
let tranlate_method (parent, decl) = let tranlate_method (parent, decl) =
translate_one_declaration tenv cg cfg namespace parent decl in translate_one_declaration tenv cg cfg parent decl in
IList.iter tranlate_method method_decls IList.iter tranlate_method method_decls
| ObjCInterfaceDecl(decl_info, name_info, decl_list, decl_context_info, oi_decl_info) -> | ObjCInterfaceDecl(decl_info, name_info, decl_list, decl_context_info, oi_decl_info) ->
@ -48,31 +46,31 @@ let rec translate_one_declaration tenv cg cfg namespace parent_dec dec =
let curr_class = ObjcInterface_decl.get_curr_class name oi_decl_info in let curr_class = ObjcInterface_decl.get_curr_class name oi_decl_info in
ignore ignore
(ObjcInterface_decl.interface_declaration CTypes_decl.type_ptr_to_sil_type tenv dec); (ObjcInterface_decl.interface_declaration CTypes_decl.type_ptr_to_sil_type tenv dec);
CMethod_declImpl.process_methods tenv cg cfg curr_class namespace decl_list CMethod_declImpl.process_methods tenv cg cfg curr_class decl_list
| ObjCProtocolDecl(decl_info, name_info, decl_list, decl_context_info, _) -> | ObjCProtocolDecl(decl_info, name_info, decl_list, decl_context_info, _) ->
let name = Ast_utils.get_qualified_name name_info in let name = Ast_utils.get_qualified_name name_info in
let curr_class = CContext.ContextProtocol name in let curr_class = CContext.ContextProtocol name in
ignore (ObjcProtocol_decl.protocol_decl CTypes_decl.type_ptr_to_sil_type tenv dec); ignore (ObjcProtocol_decl.protocol_decl CTypes_decl.type_ptr_to_sil_type tenv dec);
CMethod_declImpl.process_methods tenv cg cfg curr_class namespace decl_list CMethod_declImpl.process_methods tenv cg cfg curr_class decl_list
| ObjCCategoryDecl(decl_info, name_info, decl_list, decl_context_info, ocdi) -> | ObjCCategoryDecl(decl_info, name_info, decl_list, decl_context_info, ocdi) ->
let name = Ast_utils.get_qualified_name name_info in let name = Ast_utils.get_qualified_name name_info in
let curr_class = ObjcCategory_decl.get_curr_class_from_category_decl name ocdi in let curr_class = ObjcCategory_decl.get_curr_class_from_category_decl name ocdi in
ignore (ObjcCategory_decl.category_decl CTypes_decl.type_ptr_to_sil_type tenv dec); ignore (ObjcCategory_decl.category_decl CTypes_decl.type_ptr_to_sil_type tenv dec);
CMethod_declImpl.process_methods tenv cg cfg curr_class namespace decl_list CMethod_declImpl.process_methods tenv cg cfg curr_class decl_list
| ObjCCategoryImplDecl(decl_info, name_info, decl_list, decl_context_info, ocidi) -> | ObjCCategoryImplDecl(decl_info, name_info, decl_list, decl_context_info, ocidi) ->
let name = Ast_utils.get_qualified_name name_info in let name = Ast_utils.get_qualified_name name_info in
let curr_class = ObjcCategory_decl.get_curr_class_from_category_impl name ocidi in let curr_class = ObjcCategory_decl.get_curr_class_from_category_impl name ocidi in
ignore (ObjcCategory_decl.category_impl_decl CTypes_decl.type_ptr_to_sil_type tenv dec); ignore (ObjcCategory_decl.category_impl_decl CTypes_decl.type_ptr_to_sil_type tenv dec);
CMethod_declImpl.process_methods tenv cg cfg curr_class namespace decl_list CMethod_declImpl.process_methods tenv cg cfg curr_class decl_list
| ObjCImplementationDecl(decl_info, name_info, decl_list, decl_context_info, idi) -> | ObjCImplementationDecl(decl_info, name_info, decl_list, decl_context_info, idi) ->
let curr_class = ObjcInterface_decl.get_curr_class_impl idi in let curr_class = ObjcInterface_decl.get_curr_class_impl idi in
let type_ptr_to_sil_type = CTypes_decl.type_ptr_to_sil_type in let type_ptr_to_sil_type = CTypes_decl.type_ptr_to_sil_type in
ignore (ObjcInterface_decl.interface_impl_declaration type_ptr_to_sil_type tenv dec); ignore (ObjcInterface_decl.interface_impl_declaration type_ptr_to_sil_type tenv dec);
CMethod_declImpl.process_methods tenv cg cfg curr_class namespace decl_list; CMethod_declImpl.process_methods tenv cg cfg curr_class decl_list;
CFrontend_errors.check_for_property_errors cfg curr_class CFrontend_errors.check_for_property_errors cfg curr_class
| CXXMethodDecl (decl_info, name_info, type_ptr, function_decl_info, _) | CXXMethodDecl (decl_info, name_info, type_ptr, function_decl_info, _)
@ -87,19 +85,17 @@ let rec translate_one_declaration tenv cg cfg namespace parent_dec dec =
let class_name = CTypes_decl.get_record_name d in let class_name = CTypes_decl.get_record_name d in
let curr_class = CContext.ContextCls(class_name, None, []) in let curr_class = CContext.ContextCls(class_name, None, []) in
if !CFrontend_config.testing_mode then if !CFrontend_config.testing_mode then
CMethod_declImpl.process_methods tenv cg cfg curr_class namespace [dec] CMethod_declImpl.process_methods tenv cg cfg curr_class [dec]
| Some dec -> Printing.log_stats "Methods of %s skipped\n" (Ast_utils.string_of_decl dec) | Some dec -> Printing.log_stats "Methods of %s skipped\n" (Ast_utils.string_of_decl dec)
| None -> ()) | None -> ())
| dec -> ()); | dec -> ());
match dec with match dec with
| EnumDecl _ -> ignore (CEnum_decl.enum_decl dec) | EnumDecl _ -> ignore (CEnum_decl.enum_decl dec)
| LinkageSpecDecl (decl_info, decl_list, decl_context_info) -> | LinkageSpecDecl (decl_info, decl_list, decl_context_info) ->
Printing.log_out "ADDING: LinkageSpecDecl decl list\n"; Printing.log_out "ADDING: LinkageSpecDecl decl list\n";
IList.iter (translate_one_declaration tenv cg cfg namespace dec) decl_list IList.iter (translate_one_declaration tenv cg cfg dec) decl_list
| NamespaceDecl (decl_info, name_info, decl_list, decl_context_info, _) -> | NamespaceDecl (decl_info, name_info, decl_list, decl_context_info, _) ->
let name = ns_suffix^name_info.Clang_ast_t.ni_name in IList.iter (translate_one_declaration tenv cg cfg dec) decl_list
IList.iter (translate_one_declaration tenv cg cfg (Some name) dec) decl_list
| dec -> () | dec -> ()
(* Translates a file by translating the ast into a cfg. *) (* Translates a file by translating the ast into a cfg. *)
@ -110,7 +106,7 @@ let compute_icfg tenv source_file ast =
Printing.log_out "\n Start creating icfg\n"; Printing.log_out "\n Start creating icfg\n";
let cg = Cg.create () in let cg = Cg.create () in
let cfg = Cfg.Node.create_cfg () in let cfg = Cfg.Node.create_cfg () in
IList.iter (translate_one_declaration tenv cg cfg None ast) decl_list; IList.iter (translate_one_declaration tenv cg cfg ast) decl_list;
Printing.log_out "\n Finished creating icfg\n"; Printing.log_out "\n Finished creating icfg\n";
(cg, cfg) (cg, cfg)
| _ -> assert false (* NOTE: Assumes that an AST alsways starts with a TranslationUnitDecl *) | _ -> assert false (* NOTE: Assumes that an AST alsways starts with a TranslationUnitDecl *)

@ -142,12 +142,6 @@ struct
[] []
| _ -> snd (Clang_ast_proj.get_stmt_tuple stmt) | _ -> snd (Clang_ast_proj.get_stmt_tuple stmt)
let namespace_to_string namespace =
match namespace with
| None -> ""
| Some ns when ns ="" -> ""
| Some ns -> ns^"::"
let fold_qual_name qual_name_list = let fold_qual_name qual_name_list =
match qual_name_list with match qual_name_list with
| [] -> "" | [] -> ""

@ -34,8 +34,6 @@ end
module Ast_utils : module Ast_utils :
sig sig
val namespace_to_string : string option -> string
val string_of_stmt : Clang_ast_t.stmt -> string val string_of_stmt : Clang_ast_t.stmt -> string
val get_stmts_from_stmt : Clang_ast_t.stmt -> Clang_ast_t.stmt list val get_stmts_from_stmt : Clang_ast_t.stmt -> Clang_ast_t.stmt list

@ -15,10 +15,10 @@ open CFrontend_utils
module L = Logging module L = Logging
module type CMethod_decl = sig module type CMethod_decl = sig
val process_methods : Sil.tenv -> Cg.t -> Cfg.cfg -> CContext.curr_class -> string option -> val process_methods : Sil.tenv -> Cg.t -> Cfg.cfg -> CContext.curr_class ->
Clang_ast_t.decl list -> unit Clang_ast_t.decl list -> unit
val function_decl : Sil.tenv -> Cfg.cfg -> Cg.t -> string option -> Clang_ast_t.decl -> val function_decl : Sil.tenv -> Cfg.cfg -> Cg.t -> Clang_ast_t.decl ->
CModule_type.block_data option -> unit CModule_type.block_data option -> unit
val process_getter_setter : CContext.t -> Procname.t -> bool val process_getter_setter : CContext.t -> Procname.t -> bool
@ -31,7 +31,7 @@ struct
Specs.summary_exists_in_models procname && not !CFrontend_config.models_mode Specs.summary_exists_in_models procname && not !CFrontend_config.models_mode
(* Translates the method/function's body into nodes of the cfg. *) (* Translates the method/function's body into nodes of the cfg. *)
let add_method tenv cg cfg class_decl_opt procname namespace instrs is_objc_method let add_method tenv cg cfg class_decl_opt procname instrs is_objc_method
captured_vars outer_context_opt extra_instrs = captured_vars outer_context_opt extra_instrs =
Printing.log_out Printing.log_out
@ -41,7 +41,7 @@ struct
| Some procdesc -> | Some procdesc ->
if (Cfg.Procdesc.is_defined procdesc && not (model_exists procname)) then if (Cfg.Procdesc.is_defined procdesc && not (model_exists procname)) then
(let context = (let context =
CContext.create_context tenv cg cfg procdesc namespace class_decl_opt CContext.create_context tenv cg cfg procdesc class_decl_opt
is_objc_method outer_context_opt in is_objc_method outer_context_opt in
let start_node = Cfg.Procdesc.get_start_node procdesc in let start_node = Cfg.Procdesc.get_start_node procdesc in
let exit_node = Cfg.Procdesc.get_exit_node procdesc in let exit_node = Cfg.Procdesc.get_exit_node procdesc in
@ -64,7 +64,7 @@ struct
CMethod_trans.create_external_procdesc cfg procname is_objc_method None; CMethod_trans.create_external_procdesc cfg procname is_objc_method None;
() ()
let function_decl tenv cfg cg namespace func_decl block_data_opt = let function_decl tenv cfg cg func_decl block_data_opt =
Printing.log_out "\nResetting the goto_labels hashmap...\n"; Printing.log_out "\nResetting the goto_labels hashmap...\n";
CTrans_utils.GotoLabel.reset_all_labels (); (* C Language Std 6.8.6.1-1 *) CTrans_utils.GotoLabel.reset_all_labels (); (* C Language Std 6.8.6.1-1 *)
let captured_vars, outer_context_opt = let captured_vars, outer_context_opt =
@ -77,11 +77,11 @@ struct
| Some body -> (* Only in the case the function declaration has a defined body we create a procdesc *) | Some body -> (* Only in the case the function declaration has a defined body we create a procdesc *)
let procname = CMethod_signature.ms_get_name ms in let procname = CMethod_signature.ms_get_name ms in
if CMethod_trans.create_local_procdesc cfg tenv ms [body] captured_vars false then if CMethod_trans.create_local_procdesc cfg tenv ms [body] captured_vars false then
add_method tenv cg cfg CContext.ContextNoCls procname namespace [body] false add_method tenv cg cfg CContext.ContextNoCls procname [body] false
captured_vars outer_context_opt extra_instrs captured_vars outer_context_opt extra_instrs
| None -> () | None -> ()
let process_method_decl tenv cg cfg namespace curr_class meth_decl ~is_objc = let process_method_decl tenv cg cfg curr_class meth_decl ~is_objc =
let ms, body_opt, extra_instrs = let ms, body_opt, extra_instrs =
CMethod_trans.method_signature_of_decl meth_decl None in CMethod_trans.method_signature_of_decl meth_decl None in
match body_opt with match body_opt with
@ -89,30 +89,30 @@ struct
let is_instance = CMethod_signature.ms_is_instance ms in let is_instance = CMethod_signature.ms_is_instance ms in
let procname = CMethod_signature.ms_get_name ms in let procname = CMethod_signature.ms_get_name ms in
if CMethod_trans.create_local_procdesc cfg tenv ms [body] [] is_instance then if CMethod_trans.create_local_procdesc cfg tenv ms [body] [] is_instance then
add_method tenv cg cfg curr_class procname namespace [body] is_objc [] None extra_instrs add_method tenv cg cfg curr_class procname [body] is_objc [] None extra_instrs
| None -> () | None -> ()
let rec process_one_method_decl tenv cg cfg curr_class namespace dec = let rec process_one_method_decl tenv cg cfg curr_class dec =
let open Clang_ast_t in let open Clang_ast_t in
match dec with match dec with
| CXXMethodDecl _ | CXXConstructorDecl _ -> | CXXMethodDecl _ | CXXConstructorDecl _ ->
process_method_decl tenv cg cfg namespace curr_class dec ~is_objc:false process_method_decl tenv cg cfg curr_class dec ~is_objc:false
| ObjCMethodDecl _ -> | ObjCMethodDecl _ ->
process_method_decl tenv cg cfg namespace curr_class dec ~is_objc:true process_method_decl tenv cg cfg curr_class dec ~is_objc:true
| ObjCPropertyImplDecl (decl_info, property_impl_decl_info) -> | ObjCPropertyImplDecl (decl_info, property_impl_decl_info) ->
let pname = Ast_utils.property_name property_impl_decl_info in let pname = Ast_utils.property_name property_impl_decl_info in
Printing.log_out "ADDING: ObjCPropertyImplDecl for property '%s' " Printing.log_out "ADDING: ObjCPropertyImplDecl for property '%s' "
pname.Clang_ast_t.ni_name; pname.Clang_ast_t.ni_name;
let getter_setter = ObjcProperty_decl.make_getter_setter curr_class decl_info pname in let getter_setter = ObjcProperty_decl.make_getter_setter curr_class decl_info pname in
IList.iter (process_one_method_decl tenv cg cfg curr_class namespace) getter_setter IList.iter (process_one_method_decl tenv cg cfg curr_class) getter_setter
| EmptyDecl _ | ObjCIvarDecl _ | ObjCPropertyDecl _ -> () | EmptyDecl _ | ObjCIvarDecl _ | ObjCPropertyDecl _ -> ()
| _ -> | _ ->
Printing.log_stats Printing.log_stats
"\nWARNING: found Method Declaration '%s' skipped. NEED TO BE FIXED\n\n" (Ast_utils.string_of_decl dec); "\nWARNING: found Method Declaration '%s' skipped. NEED TO BE FIXED\n\n" (Ast_utils.string_of_decl dec);
() ()
let process_methods tenv cg cfg curr_class namespace decl_list = let process_methods tenv cg cfg curr_class decl_list =
IList.iter (process_one_method_decl tenv cg cfg curr_class namespace) decl_list IList.iter (process_one_method_decl tenv cg cfg curr_class) decl_list
let process_getter_setter context procname = let process_getter_setter context procname =
(*If there is already a spec for the method we want to generate (in incremental analysis) *) (*If there is already a spec for the method we want to generate (in incremental analysis) *)
@ -123,7 +123,6 @@ struct
let tenv = context.CContext.tenv in let tenv = context.CContext.tenv in
let cg = context.CContext.cg in let cg = context.CContext.cg in
let cfg = context.CContext.cfg in let cfg = context.CContext.cfg in
let namespace = context.CContext.namespace in
let cls = CContext.create_curr_class tenv class_name in let cls = CContext.create_curr_class tenv class_name in
let method_name = Procname.c_get_method procname in let method_name = Procname.c_get_method procname in
match ObjcProperty_decl.method_is_property_accesor cls method_name with match ObjcProperty_decl.method_is_property_accesor cls method_name with
@ -143,7 +142,7 @@ struct
| [accessor] -> | [accessor] ->
let decl_info = Clang_ast_proj.get_decl_tuple accessor in let decl_info = Clang_ast_proj.get_decl_tuple accessor in
if CLocation.should_translate_lib decl_info.Clang_ast_t.di_source_range then if CLocation.should_translate_lib decl_info.Clang_ast_t.di_source_range then
(process_one_method_decl tenv cg cfg cls namespace accessor; (process_one_method_decl tenv cg cfg cls accessor;
true) true)
else false else false
| _ -> false) | _ -> false)

@ -10,10 +10,10 @@
(** Process methods or functions declarations by adding them to the cfg. *) (** Process methods or functions declarations by adding them to the cfg. *)
module CMethod_decl_funct(T: CModule_type.CTranslation) : sig module CMethod_decl_funct(T: CModule_type.CTranslation) : sig
val process_methods : Sil.tenv -> Cg.t -> Cfg.cfg -> CContext.curr_class -> string option -> val process_methods : Sil.tenv -> Cg.t -> Cfg.cfg -> CContext.curr_class ->
Clang_ast_t.decl list -> unit Clang_ast_t.decl list -> unit
val function_decl : Sil.tenv -> Cfg.cfg -> Cg.t -> string option -> Clang_ast_t.decl -> val function_decl : Sil.tenv -> Cfg.cfg -> Cg.t -> Clang_ast_t.decl ->
CModule_type.block_data option -> unit CModule_type.block_data option -> unit
val process_getter_setter : CContext.t -> Procname.t -> bool val process_getter_setter : CContext.t -> Procname.t -> bool
@ -21,10 +21,10 @@ module CMethod_decl_funct(T: CModule_type.CTranslation) : sig
end end
module type CMethod_decl = sig module type CMethod_decl = sig
val process_methods : Sil.tenv -> Cg.t -> Cfg.cfg -> CContext.curr_class -> string option -> val process_methods : Sil.tenv -> Cg.t -> Cfg.cfg -> CContext.curr_class ->
Clang_ast_t.decl list -> unit Clang_ast_t.decl list -> unit
val function_decl : Sil.tenv -> Cfg.cfg -> Cg.t -> string option -> Clang_ast_t.decl -> val function_decl : Sil.tenv -> Cfg.cfg -> Cg.t -> Clang_ast_t.decl ->
CModule_type.block_data option -> unit CModule_type.block_data option -> unit
val process_getter_setter : CContext.t -> Procname.t -> bool val process_getter_setter : CContext.t -> Procname.t -> bool

@ -22,7 +22,7 @@ end
module type CMethod_declaration = module type CMethod_declaration =
sig sig
val function_decl : Sil.tenv -> Cfg.cfg -> Cg.t -> string option -> Clang_ast_t.decl -> val function_decl : Sil.tenv -> Cfg.cfg -> Cg.t -> Clang_ast_t.decl ->
block_data option -> unit block_data option -> unit
val process_getter_setter : CContext.t -> Procname.t -> bool val process_getter_setter : CContext.t -> Procname.t -> bool

@ -1895,7 +1895,7 @@ struct
let ids_instrs = IList.map assign_captured_var captured_vars in let ids_instrs = IList.map assign_captured_var captured_vars in
let ids, instrs = IList.split ids_instrs in let ids, instrs = IList.split ids_instrs in
let block_data = (context, type_ptr, block_pname, captured_vars) in let block_data = (context, type_ptr, block_pname, captured_vars) in
M.function_decl context.tenv context.cfg context.cg context.namespace decl (Some block_data); M.function_decl context.tenv context.cfg context.cg decl (Some block_data);
Cfg.set_procname_priority context.cfg block_pname; Cfg.set_procname_priority context.cfg block_pname;
let captured_exps = IList.map (fun id -> Sil.Var id) ids in let captured_exps = IList.map (fun id -> Sil.Var id) ids in
let tu = Sil.Ctuple ((Sil.Const (Sil.Cfun block_pname)) :: captured_exps) in let tu = Sil.Ctuple ((Sil.Const (Sil.Cfun block_pname)) :: captured_exps) in

@ -129,23 +129,23 @@ and decl_ptr_to_sil_type translate_decl tenv decl_ptr =
let typ = `DeclPtr decl_ptr in let typ = `DeclPtr decl_ptr in
try Clang_ast_types.TypePointerMap.find typ !CFrontend_config.sil_types_map try Clang_ast_types.TypePointerMap.find typ !CFrontend_config.sil_types_map
with Not_found -> with Not_found ->
match Ast_utils.get_decl decl_ptr with match Ast_utils.get_decl decl_ptr with
| Some (CXXRecordDecl _ as d) | Some (CXXRecordDecl _ as d)
| Some (RecordDecl _ as d) | Some (RecordDecl _ as d)
| Some (ObjCInterfaceDecl _ as d) | Some (ObjCInterfaceDecl _ as d)
| Some (ObjCImplementationDecl _ as d) | Some (ObjCImplementationDecl _ as d)
| Some (ObjCProtocolDecl _ as d) | Some (ObjCProtocolDecl _ as d)
| Some (ObjCCategoryDecl _ as d) | Some (ObjCCategoryDecl _ as d)
| Some (ObjCCategoryImplDecl _ as d) | Some (ObjCCategoryImplDecl _ as d)
| Some (EnumDecl _ as d) -> translate_decl tenv None d | Some (EnumDecl _ as d) -> translate_decl tenv d
| Some _ -> | Some _ ->
Printing.log_err "Warning: Wrong decl found for pointer %s " Printing.log_err "Warning: Wrong decl found for pointer %s "
(Clang_ast_j.string_of_pointer decl_ptr); (Clang_ast_j.string_of_pointer decl_ptr);
Sil.Tvoid Sil.Tvoid
| None -> | None ->
Printing.log_err "Warning: Decl pointer %s not found." Printing.log_err "Warning: Decl pointer %s not found."
(Clang_ast_j.string_of_pointer decl_ptr); (Clang_ast_j.string_of_pointer decl_ptr);
Sil.Tvoid Sil.Tvoid
and clang_type_ptr_to_sil_type translate_decl tenv type_ptr = and clang_type_ptr_to_sil_type translate_decl tenv type_ptr =
try try

@ -13,5 +13,5 @@ val get_builtin_objc_type : [< `ObjCClass | `ObjCId ] -> Sil.typ
val sil_type_of_builtin_type_kind : Clang_ast_t.builtin_type_kind -> Sil.typ val sil_type_of_builtin_type_kind : Clang_ast_t.builtin_type_kind -> Sil.typ
val type_ptr_to_sil_type : (Sil.tenv -> string option -> Clang_ast_t.decl -> Sil.typ) -> val type_ptr_to_sil_type : (Sil.tenv -> Clang_ast_t.decl -> Sil.typ) ->
Sil.tenv -> Clang_ast_t.type_ptr -> Sil.typ Sil.tenv -> Clang_ast_t.type_ptr -> Sil.typ

@ -108,7 +108,7 @@ let get_method_decls parent decl_list =
and traverse_decl_list parent decl_list = IList.flatten (IList.map (traverse_decl parent) decl_list) in and traverse_decl_list parent decl_list = IList.flatten (IList.map (traverse_decl parent) decl_list) in
traverse_decl_list parent decl_list traverse_decl_list parent decl_list
let get_class_methods tenv class_name namespace decl_list = let get_class_methods tenv class_name decl_list =
let process_method_decl = function let process_method_decl = function
| Clang_ast_t.CXXMethodDecl (decl_info, name_info, tp, function_decl_info, _) | Clang_ast_t.CXXMethodDecl (decl_info, name_info, tp, function_decl_info, _)
| Clang_ast_t.CXXConstructorDecl (decl_info, name_info, tp, function_decl_info, _) -> | Clang_ast_t.CXXConstructorDecl (decl_info, name_info, tp, function_decl_info, _) ->
@ -143,7 +143,7 @@ let add_struct_to_tenv tenv typ =
let typename = Sil.TN_csu(csu, mangled) in let typename = Sil.TN_csu(csu, mangled) in
Sil.tenv_add tenv typename typ Sil.tenv_add tenv typename typ
let rec get_struct_fields tenv namespace decl = let rec get_struct_fields tenv decl =
let open Clang_ast_t in let open Clang_ast_t in
let decl_list = match decl with let decl_list = match decl with
| CXXRecordDecl (_, _, _, _, decl_list, _, _, _) | CXXRecordDecl (_, _, _, _, decl_list, _, _, _)
@ -159,14 +159,14 @@ let rec get_struct_fields tenv namespace decl =
| RecordDecl (decl_info, _, _, _, _, _, _) -> | RecordDecl (decl_info, _, _, _, _, _, _) ->
(* C++/C Records treated in the same way*) (* C++/C Records treated in the same way*)
if not decl_info.Clang_ast_t.di_is_implicit then if not decl_info.Clang_ast_t.di_is_implicit then
ignore (add_types_from_decl_to_tenv tenv namespace decl); [] ignore (add_types_from_decl_to_tenv tenv decl); []
| _ -> [] in | _ -> [] in
let base_decls = get_superclass_decls decl in let base_decls = get_superclass_decls decl in
let base_class_fields = IList.map (get_struct_fields tenv namespace) base_decls in let base_class_fields = IList.map (get_struct_fields tenv) base_decls in
IList.flatten (base_class_fields @ (IList.map do_one_decl decl_list)) IList.flatten (base_class_fields @ (IList.map do_one_decl decl_list))
(* For a record declaration it returns/constructs the type *) (* For a record declaration it returns/constructs the type *)
and get_strct_cpp_class_declaration_type tenv namespace decl = and get_strct_cpp_class_declaration_type tenv decl =
let open Clang_ast_t in let open Clang_ast_t in
match decl with match decl with
| CXXRecordDecl (decl_info, name_info, opt_type, type_ptr, decl_list, _, record_decl_info, _) | CXXRecordDecl (decl_info, name_info, opt_type, type_ptr, decl_list, _, record_decl_info, _)
@ -179,13 +179,13 @@ and get_strct_cpp_class_declaration_type tenv namespace decl =
if not record_decl_info.Clang_ast_t.rdi_is_complete_definition then if not record_decl_info.Clang_ast_t.rdi_is_complete_definition then
Printing.log_err Printing.log_err
" ...Warning, definition incomplete. The full definition will probably be later \n@."; " ...Warning, definition incomplete. The full definition will probably be later \n@.";
let non_static_fields = get_struct_fields tenv namespace decl in let non_static_fields = get_struct_fields tenv decl in
let non_static_fields' = if CTrans_models.is_objc_memory_model_controlled name then let non_static_fields' = if CTrans_models.is_objc_memory_model_controlled name then
General_utils.append_no_duplicates_fields [Sil.objc_ref_counter_field] non_static_fields General_utils.append_no_duplicates_fields [Sil.objc_ref_counter_field] non_static_fields
else non_static_fields in else non_static_fields in
let sorted_non_static_fields = CFrontend_utils.General_utils.sort_fields non_static_fields' in let sorted_non_static_fields = CFrontend_utils.General_utils.sort_fields non_static_fields' in
let static_fields = [] in (* Warning for the moment we do not treat static field. *) let static_fields = [] in (* Warning for the moment we do not treat static field. *)
let methods = get_class_methods tenv name namespace decl_list in (* C++ methods only *) let methods = get_class_methods tenv name decl_list in (* C++ methods only *)
let superclasses = get_superclass_list decl in let superclasses = get_superclass_list decl in
let item_annotation = Sil.item_annotation_empty in (* No annotations for struts *) let item_annotation = Sil.item_annotation_empty in (* No annotations for struts *)
let sil_type = Sil.Tstruct (sorted_non_static_fields, static_fields, csu, Some mangled_name, let sil_type = Sil.Tstruct (sorted_non_static_fields, static_fields, csu, Some mangled_name,
@ -195,12 +195,12 @@ and get_strct_cpp_class_declaration_type tenv namespace decl =
sil_type sil_type
| _ -> assert false | _ -> assert false
and add_types_from_decl_to_tenv tenv namespace decl = and add_types_from_decl_to_tenv tenv decl =
let open Clang_ast_t in let open Clang_ast_t in
match decl with match decl with
| CXXRecordDecl (decl_info, name_info, opt_type, type_ptr, decl_list, _, record_decl_info, _) | CXXRecordDecl (decl_info, name_info, opt_type, type_ptr, decl_list, _, record_decl_info, _)
| RecordDecl (decl_info, name_info, opt_type, type_ptr, decl_list, _, record_decl_info) -> | RecordDecl (decl_info, name_info, opt_type, type_ptr, decl_list, _, record_decl_info) ->
get_strct_cpp_class_declaration_type tenv namespace decl get_strct_cpp_class_declaration_type tenv decl
| ObjCInterfaceDecl _ -> ObjcInterface_decl.interface_declaration type_ptr_to_sil_type tenv decl | ObjCInterfaceDecl _ -> ObjcInterface_decl.interface_declaration type_ptr_to_sil_type tenv decl
| ObjCImplementationDecl _ -> | ObjCImplementationDecl _ ->
ObjcInterface_decl.interface_impl_declaration type_ptr_to_sil_type tenv decl ObjcInterface_decl.interface_impl_declaration type_ptr_to_sil_type tenv decl

@ -15,7 +15,7 @@ val get_record_name : Clang_ast_t.decl -> string
val get_method_decls : Clang_ast_t.decl -> Clang_ast_t.decl list -> (Clang_ast_t.decl * Clang_ast_t.decl) list val get_method_decls : Clang_ast_t.decl -> Clang_ast_t.decl list -> (Clang_ast_t.decl * Clang_ast_t.decl) list
val add_types_from_decl_to_tenv : Sil.tenv -> string option -> Clang_ast_t.decl -> Sil.typ val add_types_from_decl_to_tenv : Sil.tenv -> Clang_ast_t.decl -> Sil.typ
(* Adds the predefined types objc_class which is a struct, *) (* Adds the predefined types objc_class which is a struct, *)
(* and Class, which is a pointer to objc_class. *) (* and Class, which is a pointer to objc_class. *)

Loading…
Cancel
Save