fixing tenv_add to add only struct_typ's

Reviewed By: akotulski

Differential Revision: D2988324

fb-gh-sync-id: b6093d1
shipit-source-id: b6093d1
master
Sam Blackshear 9 years ago committed by Facebook Github Bot 4
parent 749a649138
commit 337d2cc537

@ -3774,10 +3774,8 @@ let tenv_lookup tenv name =
with Not_found -> None with Not_found -> None
(** Add a (name,type) pair to the global type environment. *) (** Add a (name,type) pair to the global type environment. *)
let tenv_add tenv name typ = let tenv_add tenv name struct_typ =
match typ with TypenameHash.replace tenv name struct_typ
| Tstruct struct_typ -> TypenameHash.replace tenv name struct_typ
| _ -> assert false
(** expand a type if it is a typename by looking it up in the type environment *) (** expand a type if it is a typename by looking it up in the type environment *)
let expand_type tenv typ = let expand_type tenv typ =

@ -525,7 +525,7 @@ val tenv_mem : tenv -> Typename.t -> bool
val tenv_lookup : tenv -> Typename.t -> typ option val tenv_lookup : tenv -> Typename.t -> typ option
(** Add a (name,typ) pair to the global type environment. *) (** Add a (name,typ) pair to the global type environment. *)
val tenv_add : tenv -> Typename.t -> typ -> unit val tenv_add : tenv -> Typename.t -> struct_typ -> unit
(** expand a type if it is a typename by looking it up in the type environment *) (** expand a type if it is a typename by looking it up in the type environment *)
val expand_type : tenv -> typ -> typ val expand_type : tenv -> typ -> typ

@ -81,8 +81,8 @@ let add_missing_fields tenv class_name ck fields =
| Some Sil.Tstruct ({ Sil.instance_fields } as struct_typ) -> | Some Sil.Tstruct ({ Sil.instance_fields } as struct_typ) ->
let new_fields = General_utils.append_no_duplicates_fields instance_fields fields in let new_fields = General_utils.append_no_duplicates_fields instance_fields fields in
let class_type_info = let class_type_info =
Sil.Tstruct {
{ struct_typ with struct_typ with
Sil.instance_fields = new_fields; Sil.instance_fields = new_fields;
static_fields = []; static_fields = [];
csu = Csu.Class ck; csu = Csu.Class ck;

@ -462,7 +462,7 @@ struct
let sort_fields_tenv tenv = let sort_fields_tenv tenv =
let sort_fields_struct typname st = let sort_fields_struct typname st =
let st' = { st with Sil.instance_fields = (sort_fields st.Sil.instance_fields) } in let st' = { st with Sil.instance_fields = (sort_fields st.Sil.instance_fields) } in
Sil.tenv_add tenv typname (Sil.Tstruct st') in Sil.tenv_add tenv typname st' in
Sil.tenv_iter sort_fields_struct tenv Sil.tenv_iter sort_fields_struct tenv
let rec collect_list_tuples l (a, a1, b, c, d) = let rec collect_list_tuples l (a, a1, b, c, d) =

@ -116,8 +116,9 @@ struct
IList.iter (fun (fn, _, _) -> IList.iter (fun (fn, _, _) ->
Printing.log_out "-----> field: '%s'\n" (Ident.fieldname_to_string fn)) fields; Printing.log_out "-----> field: '%s'\n" (Ident.fieldname_to_string fn)) fields;
let mblock = Mangled.from_string block_name in let mblock = Mangled.from_string block_name in
let block_type = Sil.Tstruct let block_struct_typ =
{ Sil.instance_fields = fields; {
Sil.instance_fields = fields;
static_fields = []; static_fields = [];
csu = Csu.Class Csu.Objc; csu = Csu.Class Csu.Objc;
struct_name = Some mblock; struct_name = Some mblock;
@ -125,8 +126,9 @@ struct
def_methods = []; def_methods = [];
struct_annotations = []; struct_annotations = [];
} in } in
let block_type = Sil.Tstruct block_struct_typ in
let block_name = Typename.TN_csu (Csu.Class Csu.Objc, mblock) in let block_name = Typename.TN_csu (Csu.Class Csu.Objc, mblock) in
Sil.tenv_add tenv block_name block_type; Sil.tenv_add tenv block_name block_struct_typ;
let trans_res = CTrans_utils.alloc_trans trans_state loc (Ast_expressions.dummy_stmt_info ()) block_type true in let trans_res = CTrans_utils.alloc_trans trans_state loc (Ast_expressions.dummy_stmt_info ()) block_type true in
let id_block = match trans_res.exps with let id_block = match trans_res.exps with
| [(Sil.Var id, _)] -> id | [(Sil.Var id, _)] -> id

@ -16,7 +16,7 @@ module L = Logging
let add_predefined_objc_types tenv = let add_predefined_objc_types tenv =
let class_typename = CType_to_sil_type.get_builtin_objc_typename `ObjCClass in let class_typename = CType_to_sil_type.get_builtin_objc_typename `ObjCClass in
let objc_class_type_info = let objc_class_type_info =
Sil.Tstruct { {
Sil.instance_fields = []; Sil.instance_fields = [];
static_fields = []; static_fields = [];
csu = Csu.Struct; csu = Csu.Struct;
@ -28,7 +28,7 @@ let add_predefined_objc_types tenv =
Sil.tenv_add tenv class_typename objc_class_type_info; Sil.tenv_add tenv class_typename objc_class_type_info;
let id_typename = CType_to_sil_type.get_builtin_objc_typename `ObjCId in let id_typename = CType_to_sil_type.get_builtin_objc_typename `ObjCId in
let objc_object_type_info = let objc_object_type_info =
Sil.Tstruct { {
Sil.instance_fields = []; Sil.instance_fields = [];
static_fields = []; static_fields = [];
csu = Csu.Struct; csu = Csu.Struct;
@ -137,12 +137,12 @@ let get_superclass_list_cpp decl =
IList.map get_super_field base_decls IList.map get_super_field base_decls
let add_struct_to_tenv tenv typ = let add_struct_to_tenv tenv typ =
let csu = match typ with let csu, struct_typ = match typ with
| Sil.Tstruct { Sil.csu } -> csu | Sil.Tstruct ({ Sil.csu } as struct_typ) -> csu, struct_typ
| _ -> assert false in | _ -> assert false in
let mangled = CTypes.get_name_from_struct typ in let mangled = CTypes.get_name_from_struct typ in
let typename = Typename.TN_csu(csu, mangled) in let typename = Typename.TN_csu(csu, mangled) in
Sil.tenv_add tenv typename typ Sil.tenv_add tenv typename struct_typ
let rec get_struct_fields tenv decl = let rec get_struct_fields tenv decl =
let open Clang_ast_t in let open Clang_ast_t in

@ -82,7 +82,8 @@ let process_category type_ptr_to_sil_type tenv curr_class decl_info decl_list =
let new_fields = General_utils.append_no_duplicates_fields fields instance_fields in let new_fields = General_utils.append_no_duplicates_fields fields instance_fields in
let new_methods = General_utils.append_no_duplicates_methods methods def_methods in let new_methods = General_utils.append_no_duplicates_methods methods def_methods in
let class_type_info = let class_type_info =
Sil.Tstruct { struct_typ with {
struct_typ with
Sil.instance_fields = new_fields; Sil.instance_fields = new_fields;
static_fields = []; static_fields = [];
csu = Csu.Class Csu.Objc; csu = Csu.Class Csu.Objc;

@ -125,7 +125,7 @@ let add_class_to_tenv type_ptr_to_sil_type tenv curr_class decl_info class_name
IList.iter (fun (fn, _, _) -> IList.iter (fun (fn, _, _) ->
Printing.log_out "-----> field: '%s'\n" (Ident.fieldname_to_string fn)) fields; Printing.log_out "-----> field: '%s'\n" (Ident.fieldname_to_string fn)) fields;
let interface_type_info = let interface_type_info =
Sil.Tstruct { {
Sil.instance_fields = fields; Sil.instance_fields = fields;
static_fields = []; static_fields = [];
csu = Csu.Class Csu.Objc; csu = Csu.Class Csu.Objc;
@ -155,11 +155,8 @@ let add_missing_methods tenv class_name ck decl_info decl_list curr_class =
def_methods; def_methods;
} as struct_typ) -> } as struct_typ) ->
let methods = General_utils.append_no_duplicates_methods def_methods methods in let methods = General_utils.append_no_duplicates_methods def_methods methods in
let typ = let struct_typ' = { struct_typ with Sil.def_methods = methods; } in
Sil.Tstruct Sil.tenv_add tenv class_tn_name struct_typ'
{ struct_typ with
Sil.def_methods = methods; } in
Sil.tenv_add tenv class_tn_name typ
| _ -> ()); | _ -> ());
Sil.Tvar class_tn_name Sil.Tvar class_tn_name

@ -32,7 +32,7 @@ let protocol_decl type_ptr_to_sil_type tenv decl =
Ast_utils.update_sil_types_map decl_key (Sil.Tvar protocol_name); Ast_utils.update_sil_types_map decl_key (Sil.Tvar protocol_name);
let def_methods = ObjcProperty_decl.get_methods curr_class decl_list in let def_methods = ObjcProperty_decl.get_methods curr_class decl_list in
let protocol_type_info = let protocol_type_info =
Sil.Tstruct { {
Sil.instance_fields = []; Sil.instance_fields = [];
static_fields = []; static_fields = [];
csu = Csu.Protocol; csu = Csu.Protocol;

@ -140,8 +140,8 @@ let extract_callbacks lifecycle_trace harness_procname proc_file_map tenv =
find_registered_callbacks lifecycle_trace harness_name proc_file_map tenv in find_registered_callbacks lifecycle_trace harness_name proc_file_map tenv in
let fields = IList.map (fun (fld, typ, _) -> (fld, typ, [])) registered_cbs in let fields = IList.map (fun (fld, typ, _) -> (fld, typ, [])) registered_cbs in
(* create a new typ for the harness containing all of the cb extraction vars as static fields *) (* create a new typ for the harness containing all of the cb extraction vars as static fields *)
let harness_typ = let harness_struct_typ =
Sil.Tstruct { {
Sil.instance_fields = fields; Sil.instance_fields = fields;
static_fields = []; static_fields = [];
csu = Csu.Class Csu.Java; csu = Csu.Class Csu.Java;
@ -150,10 +150,11 @@ let extract_callbacks lifecycle_trace harness_procname proc_file_map tenv =
def_methods = [harness_procname]; def_methods = [harness_procname];
struct_annotations = []; struct_annotations = [];
} in } in
let harness_typ = Sil.Tstruct harness_struct_typ in
(* update the tenv with our created harness typ. we don't have to save the tenv to disk here (* update the tenv with our created harness typ. we don't have to save the tenv to disk here
* because this is done immediately after harness generation runs in jMain.ml *) * because this is done immediately after harness generation runs in jMain.ml *)
let harness_class = Typename.TN_csu (Csu.Class Csu.Java, harness_name) in let harness_class = Typename.TN_csu (Csu.Class Csu.Java, harness_name) in
Sil.tenv_add tenv harness_class harness_typ; Sil.tenv_add tenv harness_class harness_struct_typ;
let cfgs_to_save = let cfgs_to_save =
IList.fold_left (fun cfgs_to_save (_, _, instrument_sil_f) -> IList.fold_left (fun cfgs_to_save (_, _, instrument_sil_f) ->
(* instrument the cfg's with callback extraction code *) (* instrument the cfg's with callback extraction code *)

@ -356,9 +356,11 @@ and get_class_type_no_pointer program tenv cn =
match Sil.tenv_lookup tenv named_type with match Sil.tenv_lookup tenv named_type with
| None -> create_sil_type program tenv cn | None -> create_sil_type program tenv cn
| Some t -> t in | Some t -> t in
Sil.tenv_add tenv named_type class_type_np; match class_type_np with
| Sil.Tstruct struct_typ ->
Sil.tenv_add tenv named_type struct_typ;
class_type_np class_type_np
| _ -> assert false
let get_class_type program tenv cn = let get_class_type program tenv cn =
let t = get_class_type_no_pointer program tenv cn in let t = get_class_type_no_pointer program tenv cn in
@ -467,7 +469,7 @@ let return_type program tenv ms meth_kind =
let add_models_types tenv = let add_models_types tenv =
let add_type t typename struct_typ = let add_type t typename struct_typ =
if not (Sil.tenv_mem t typename) then if not (Sil.tenv_mem t typename) then
Sil.tenv_add tenv typename (Sil.Tstruct struct_typ) in Sil.tenv_add tenv typename struct_typ in
Sil.tenv_iter (add_type tenv) !JClasspath.models_tenv Sil.tenv_iter (add_type tenv) !JClasspath.models_tenv

Loading…
Cancel
Save