Remove redundant Typ.struct_typ.csu field

Summary:
The Typ.struct_typ.csu field is now redundant with the Csu.t in the
name: Typename.t field.

Reviewed By: cristianoc

Differential Revision: D3791861

fbshipit-source-id: 5370885
master
Josh Berdine 8 years ago committed by Facebook Github Bot 7
parent f0940f25d7
commit 2bebd94553

@ -286,7 +286,6 @@ and struct_typ = {
name: Typename.t, /** name */
instance_fields: struct_fields, /** non-static fields */
static_fields: struct_fields, /** static fields */
csu: Csu.t, /** class/struct/union */
superclasses: list Typename.t, /** list of superclasses */
def_methods: list Procname.t, /** methods defined */
struct_annotations: item_annotation /** annotations */
@ -306,18 +305,15 @@ let rec fld_typ_ann_compare fta1 fta2 =>
triple_compare Ident.fieldname_compare compare item_annotation_compare fta1 fta2
and fld_typ_ann_list_compare ftal1 ftal2 => IList.compare fld_typ_ann_compare ftal1 ftal2
and struct_typ_compare struct_typ1 struct_typ2 =>
if (struct_typ1.csu == Csu.Class Csu.Java && struct_typ2.csu == Csu.Class Csu.Java) {
switch (struct_typ1.name, struct_typ2.name) {
| (TN_csu (Class Java) _, TN_csu (Class Java) _) =>
Typename.compare struct_typ1.name struct_typ2.name
} else {
| _ =>
let n = fld_typ_ann_list_compare struct_typ1.instance_fields struct_typ2.instance_fields;
if (n != 0) {
n
} else {
let n = fld_typ_ann_list_compare struct_typ1.static_fields struct_typ2.static_fields;
if (n != 0) {
n
} else {
let n = Csu.compare struct_typ1.csu struct_typ2.csu;
if (n != 0) {
n
} else {
@ -325,7 +321,6 @@ and struct_typ_compare struct_typ1 struct_typ2 =>
}
}
}
}
/** Comparision for types. */
and compare t1 t2 =>
if (t1 === t2) {
@ -367,13 +362,12 @@ let struct_typ_equal struct_typ1 struct_typ2 => struct_typ_compare struct_typ1 s
let equal t1 t2 => compare t1 t2 == 0;
let rec pp_struct_typ pe pp_base f {csu, instance_fields, name} =>
let rec pp_struct_typ pe pp_base f {instance_fields, name} =>
if false {
/* change false to true to print the details of struct */
F.fprintf
f
"%s %a {%a} %a"
(Csu.name csu)
"%a {%a} %a"
Typename.pp
name
(pp_seq (fun f (fld, t, _) => F.fprintf f "%a %a" (pp_full pe) t Ident.pp_fieldname fld))
@ -534,8 +528,8 @@ let get_field_type_and_annotation fn =>
/** if [struct_typ] is a class, return its class kind (Java, CPP, or Obj-C) */
let struct_typ_get_class_kind struct_typ =>
switch struct_typ.csu {
| Csu.Class class_kind => Some class_kind
switch struct_typ.name {
| TN_csu (Class class_kind) _ => Some class_kind
| _ => None
};
@ -565,7 +559,7 @@ let struct_typ_is_objc_class struct_typ =>
let is_class_of_kind typ ck =>
switch typ {
| Tstruct {csu: Csu.Class ck'} => ck == ck'
| Tstruct {name: TN_csu (Class ck') _} => ck == ck'
| _ => false
};

@ -141,7 +141,6 @@ and struct_typ = {
name: Typename.t, /** name */
instance_fields: struct_fields, /** non-static fields */
static_fields: struct_fields, /** static fields */
csu: Csu.t, /** class/struct/union */
superclasses: list Typename.t, /** list of superclasses */
def_methods: list Procname.t, /** methods defined */
struct_annotations: item_annotation /** annotations */

@ -685,7 +685,7 @@ let desc_leak hpred_type_opt value_str_opt resource_opt resource_action_opt loc
s, " to ", " on " in
let typ_str =
match hpred_type_opt with
| Some (Exp.Sizeof (Tstruct { csu = Class _; name; }, _, _)) ->
| Some (Exp.Sizeof (Tstruct { name = TN_csu (Class _, _) as name; }, _, _)) ->
" of type " ^ Typename.name name ^ " "
| _ -> " " in
let desc_str =

@ -760,7 +760,7 @@ let execute_alloc mk can_return_null
evaluate_char_sizeof (Exp.Const (Const.Cint len))
| Exp.Sizeof _ -> e in
let size_exp, procname = match args with
| [(Exp.Sizeof (Tstruct { csu = Class Objc; name } as s, len, subt), _)] ->
| [(Exp.Sizeof (Tstruct { name = TN_csu (Class Objc, _) as name } as s, len, subt), _)] ->
let struct_type =
match AttributesTable.get_correct_type_from_objc_class_name name with
| Some struct_type -> struct_type

@ -1476,7 +1476,6 @@ let expand_hpred_pointer calc_index_frame hpred : bool * bool * Sil.hpred =
(Tstruct
{ instance_fields = [(fld, cnt_typ, Typ.item_annotation_empty)];
static_fields = [];
csu = Struct;
name = TN_csu (Struct, Mangled.from_string "counterfeit");
superclasses = [];
def_methods = [];
@ -1516,7 +1515,7 @@ struct
let is_interface tenv class_name =
match Tenv.lookup tenv class_name with
| Some ({ csu = Class Java } as struct_typ) ->
| Some ({ name = TN_csu (Class Java, _) } as struct_typ) ->
(IList.length struct_typ.Typ.instance_fields = 0) &&
(IList.length struct_typ.Typ.def_methods = 0)
| _ -> false
@ -1534,7 +1533,7 @@ struct
let rec check cn =
Typename.equal cn c2 || is_root_class c2 ||
match Tenv.lookup tenv cn with
| Some ({ csu = Class _; superclasses }) ->
| Some ({ name = TN_csu (Class _, _); superclasses }) ->
IList.exists check superclasses
| _ -> false in
check c1
@ -1555,7 +1554,8 @@ struct
(** check if t1 is a subtype of t2, in Java *)
let rec check_subtype_java tenv t1 t2 =
match t1, t2 with
| Typ.Tstruct { csu = Class Java; name = cn1 }, Typ.Tstruct { csu = Class Java; name = cn2 } ->
| Typ.Tstruct { name = TN_csu (Class Java, _) as cn1 },
Typ.Tstruct { name = TN_csu (Class Java, _) as cn2 } ->
check_subclass tenv cn1 cn2
| Typ.Tarray (dom_type1, _), Typ.Tarray (dom_type2, _) ->
@ -1564,7 +1564,7 @@ struct
| Typ.Tptr (dom_type1, _), Typ.Tptr (dom_type2, _) ->
check_subtype_java tenv dom_type1 dom_type2
| Typ.Tarray _, Typ.Tstruct { Typ.csu = Csu.Class Csu.Java; name = cn2 } ->
| Typ.Tarray _, Typ.Tstruct { name = TN_csu (Class Java, _) as cn2 } ->
Typename.equal cn2 serializable_type
|| Typename.equal cn2 cloneable_type
|| Typename.equal cn2 object_type
@ -1587,7 +1587,8 @@ struct
let rec case_analysis_type_java tenv (t1, st1) (t2, st2) =
match t1, t2 with
| Typ.Tstruct { csu = Class Java; name = cn1 }, Typ.Tstruct { csu = Class Java; name = cn2 } ->
| Typ.Tstruct { name = TN_csu (Class Java, _) as cn1 },
Typ.Tstruct { name = TN_csu (Class Java, _) as cn2 } ->
Subtype.case_analysis (cn1, st1) (cn2, st2)
(check_subclass tenv) (is_interface tenv)
@ -1597,7 +1598,7 @@ struct
| Typ.Tptr (dom_type1, _), Typ.Tptr (dom_type2, _) ->
case_analysis_type_java tenv (dom_type1, st1) (dom_type2, st2)
| Typ.Tstruct { Typ.csu = Csu.Class Csu.Java; name = cn1 }, Typ.Tarray _ ->
| Typ.Tstruct { name = TN_csu (Class Java, _) as cn1 }, Typ.Tarray _ ->
if (Typename.equal cn1 serializable_type
|| Typename.equal cn1 cloneable_type
|| Typename.equal cn1 object_type) &&

@ -506,7 +506,7 @@ let resolve_method tenv class_name proc_name =
let right_proc_name =
Procname.replace_class proc_name (Typename.name class_name) in
match Tenv.lookup tenv class_name with
| Some { Typ.csu = Csu.Class _; def_methods; superclasses } ->
| Some { name = TN_csu (Class _, _); def_methods; superclasses } ->
if method_exists right_proc_name def_methods then
Some right_proc_name
else

@ -467,8 +467,9 @@ let texp_star texp1 texp2 =
| 0 -> ftal_sub ftal1' ftal2'
| _ -> ftal_sub ftal1 ftal2' end in
let typ_star t1 t2 = match t1, t2 with
| Typ.Tstruct { Typ.instance_fields = instance_fields1; csu = csu1 },
Typ.Tstruct { Typ.instance_fields = instance_fields2; csu = csu2 } when csu1 = csu2 ->
| Typ.Tstruct { instance_fields = instance_fields1; name = TN_csu (csu1, _) },
Typ.Tstruct { instance_fields = instance_fields2; name = TN_csu (csu2, _) }
when csu1 = csu2 ->
if ftal_sub instance_fields1 instance_fields2 then t2 else t1
| _ -> t1 in
match texp1, texp2 with

@ -35,7 +35,7 @@ let java_proc_name_with_class_method pn_java class_with_path method_name =
with _ -> false)
let get_direct_supers tenv = function
| { Typ.csu = Csu.Class _; superclasses } ->
| { Typ.name = TN_csu (Class _, _); superclasses } ->
IList.map (Tenv.lookup tenv) superclasses
|> IList.flatten_options
| _ ->

@ -82,12 +82,10 @@ let add_missing_fields tenv class_name ck fields =
match Tenv.lookup tenv class_tn_name with
| Some ({ Typ.instance_fields } as struct_typ) ->
let new_fields = General_utils.append_no_duplicates_fields instance_fields fields in
let class_type_info =
{
let class_type_info = {
struct_typ with
Typ.instance_fields = new_fields;
instance_fields = new_fields;
static_fields = [];
csu = Csu.Class ck;
name = class_tn_name;
} in
Printing.log_out " Updating info for class '%s' in tenv\n" class_name;

@ -130,7 +130,6 @@ struct
{
Typ.instance_fields = fields;
static_fields = [];
csu = Csu.Class Csu.Objc;
name = block_name;
superclasses = [];
def_methods = [];

@ -21,7 +21,6 @@ let add_predefined_objc_types tenv =
{
Typ.instance_fields = [];
static_fields = [];
csu = Csu.Struct;
name = TN_csu (Struct, Mangled.from_string CFrontend_config.objc_class);
superclasses = [];
def_methods = [];
@ -33,7 +32,6 @@ let add_predefined_objc_types tenv =
{
Typ.instance_fields = [];
static_fields = [];
csu = Csu.Struct;
name = TN_csu (Struct, Mangled.from_string CFrontend_config.objc_object);
superclasses = [];
def_methods = [];
@ -223,7 +221,6 @@ and get_record_declaration_struct_type tenv decl =
let sil_type = Typ.Tstruct {
Typ.instance_fields = non_static_fields;
static_fields;
csu;
name = sil_typename;
superclasses;
def_methods;
@ -246,7 +243,6 @@ and get_record_declaration_struct_type tenv decl =
let empty_struct_type = Typ.Tstruct {
Typ.instance_fields = extra_fields;
static_fields = [];
csu;
name = sil_typename;
superclasses = [];
def_methods = [];

@ -81,12 +81,10 @@ let process_category type_ptr_to_sil_type tenv curr_class decl_info decl_list =
| Some ({ Typ.instance_fields; def_methods } as struct_typ) ->
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 class_type_info =
{
let class_type_info = {
struct_typ with
Typ.instance_fields = new_fields;
instance_fields = new_fields;
static_fields = [];
csu = Csu.Class Csu.Objc;
name = class_tn_name;
def_methods = new_methods;
} in

@ -128,15 +128,13 @@ let add_class_to_tenv type_ptr_to_sil_type tenv curr_class decl_info name_info d
Printing.log_out "Class %s field:\n" class_name;
IList.iter (fun (fn, _, _) ->
Printing.log_out "-----> field: '%s'\n" (Ident.fieldname_to_string fn)) all_fields;
let interface_type_info =
{
Typ.instance_fields = all_fields;
let interface_type_info = Typ.{
instance_fields = all_fields;
static_fields = [];
csu = Csu.Class Csu.Objc;
name = interface_name;
superclasses;
def_methods = methods;
struct_annotations = Typ.objc_class_annotation;
struct_annotations = objc_class_annotation;
} in
Tenv.add tenv interface_name interface_type_info;
Printing.log_out
@ -153,10 +151,7 @@ let add_missing_methods tenv class_name ck decl_info decl_list curr_class =
Ast_utils.update_sil_types_map decl_key (Typ.Tvar class_tn_name);
begin
match Tenv.lookup tenv class_tn_name with
| Some ({ Typ.static_fields = [];
csu = Csu.Class _;
def_methods;
} as struct_typ) ->
| Some ({ static_fields = []; name = TN_csu (Class _, _); def_methods; } as struct_typ) ->
let methods = General_utils.append_no_duplicates_methods def_methods methods in
let struct_typ' = { struct_typ with Typ.def_methods = methods; } in
Tenv.add tenv class_tn_name struct_typ'

@ -33,11 +33,9 @@ let protocol_decl type_ptr_to_sil_type tenv decl =
let decl_key = `DeclPtr decl_info.Clang_ast_t.di_pointer in
Ast_utils.update_sil_types_map decl_key (Typ.Tvar protocol_name);
let def_methods = ObjcProperty_decl.get_methods curr_class decl_list in
let protocol_type_info =
{
Typ.instance_fields = [];
let protocol_type_info = Typ.{
instance_fields = [];
static_fields = [];
csu = Csu.Protocol;
name = protocol_name;
superclasses = [];
def_methods;

@ -135,7 +135,7 @@ let check_condition case_zero find_canonical_duplicate curr_pname
let loc = Cfg.Node.get_loc node in
let throwable_found = ref false in
let typ_is_throwable = function
| Typ.Tstruct { csu = Class _; name } ->
| Typ.Tstruct { name = TN_csu (Class _, _) as name } ->
string_equal (Typename.name name) "java.lang.Throwable"
| _ -> false in
let do_instr = function

@ -87,7 +87,7 @@ let is_android_lib_class class_name =
a list of method names [lifecycle_procs_strs], get the appropriate typ and procnames *)
let get_lifecycle_for_framework_typ_opt tenv lifecycle_typ lifecycle_proc_strs =
match Tenv.lookup tenv (Typename.TN_csu (Csu.Class Csu.Java, lifecycle_typ)) with
| Some ({ Typ.csu = Csu.Class _; def_methods } as lifecycle_typ) ->
| Some ({ name = TN_csu (Class _, _); def_methods } as lifecycle_typ) ->
(* TODO (t4645631): collect the procedures for which is_java is returning false *)
let lookup_proc lifecycle_proc =
IList.find (fun decl_proc ->

@ -18,7 +18,7 @@ module F = Format
constituting a lifecycle trace *)
let try_create_lifecycle_trace struct_typ lifecycle_struct_typ lifecycle_procs tenv =
match struct_typ with
| { Typ.csu = Class Java; name } ->
| { Typ.name = TN_csu (Class Java, _) as name } ->
if PatternMatch.is_subtype tenv struct_typ lifecycle_struct_typ &&
not (AndroidFramework.is_android_lib_class name) then
let ptr_to_struct_typ = Some (Typ.Tptr (Tstruct struct_typ, Pk_pointer)) in

@ -95,7 +95,7 @@ let rec inhabit_typ typ cfg env =
(* select methods that are constructors and won't force us into infinite recursion because
* we are already inhabiting one of their argument types *)
let get_all_suitable_constructors typ = match typ with
| Typ.Tstruct { Typ.csu = Csu.Class _; def_methods } ->
| Typ.Tstruct { name = TN_csu (Class _, _); def_methods } ->
let is_suitable_constructor p =
let try_get_non_receiver_formals p =
get_non_receiver_formals (formals_from_name cfg p) in

@ -108,7 +108,7 @@ let retrieve_fieldname fieldname =
let get_field_name program static tenv cn fs =
match JTransType.get_class_type_no_pointer program tenv cn with
| Typ.Tstruct { Typ.instance_fields; static_fields; csu = Csu.Class _ } ->
| Typ.Tstruct { Typ.instance_fields; static_fields; name = TN_csu (Class _, _) } ->
let fieldname, _, _ =
try
IList.find

@ -88,7 +88,7 @@ let rec create_array_type typ dim =
let extract_cn_no_obj typ =
match typ with
| Typ.Tptr (Tstruct { csu = Class _; name }, Pk_pointer) ->
| Typ.Tptr (Tstruct { name = TN_csu (Class _, _) as name }, Pk_pointer) ->
let class_name = Typename.name name in
if class_name = JConfig.object_cl then None
else
@ -238,7 +238,6 @@ let dummy_type cn =
Typ.Tstruct {
Typ.instance_fields = [];
static_fields = [];
csu = Csu.Class Csu.Java;
name = Typename.Java.from_string (JBasics.cn_name cn);
superclasses = [];
def_methods = [];
@ -339,7 +338,6 @@ and create_sil_type program tenv cn =
Typ.Tstruct {
Typ.instance_fields;
static_fields;
csu = Csu.Class Csu.Java;
name = Typename.Java.from_string (JBasics.cn_name cn);
superclasses;
def_methods;

Loading…
Cancel
Save