[IR] More detailed type for Fieldname.t

Summary:
Split Fieldname.t into `Java` and `Clang`. Each of them have different naming conventions and this way it's easier to differentiate between them.
Make `Java` variant store string instead of mangled since mangled part was always empty
Changes to `Clang` variant are coming in the next diff

Reviewed By: jeremydubreil

Differential Revision: D4746708

fbshipit-source-id: c5858a8
master
Andrzej Kotulski 8 years ago committed by Facebook Github Bot
parent 68af2afb77
commit 71702a13dc

@ -10,7 +10,13 @@ open! IStd;
let module Hashtbl = Caml.Hashtbl; let module Hashtbl = Caml.Hashtbl;
type t = {fpos: int, fname: Mangled.t} [@@deriving compare]; type t =
| Hidden /* Backend relies that Hidden is the smallest (first) field in Abs.should_raise_objc_leak */
| Clang Mangled.t
| Java string
[@@deriving compare];
let hidden_str = ".hidden";
let equal = [%compare.equal : t]; let equal = [%compare.equal : t];
@ -24,22 +30,38 @@ let module Map = Caml.Map.Make {
let compare = compare; let compare = compare;
}; };
let module Clang = {
/** Create a field name with the given position (field number in the CSU) */
let create (n: Mangled.t) => Clang n;
};
let module Java = {
/** Create a field name with the given position (field number in the CSU) */ /** Create a field name with the given position (field number in the CSU) */
let create (n: Mangled.t) (position: int) => {fpos: position, fname: n}; let from_string n => Java n;
};
/** Convert a fieldname to a string. */ /** Convert a fieldname to a string. */
let to_string fn => Mangled.to_string fn.fname; let to_string =
fun
| Hidden => hidden_str
| Java fname => fname
| Clang fname => Mangled.to_string fname;
/** Convert a fieldname to a string, including the mangled part. */ /** Convert a fieldname to a string, including the mangled part. */
let to_complete_string fn => Mangled.to_string_full fn.fname; let to_complete_string =
fun
| Hidden => hidden_str
| Java fname => fname
| Clang fname => Mangled.to_string_full fname;
/** Convert a fieldname to a simplified string with at most one-level path. */ /** Convert a fieldname to a simplified string with at most one-level path. */
let to_simplified_string fn => { let to_simplified_string fn => {
let s = Mangled.to_string fn.fname; let s = to_string fn;
switch (String.rsplit2 s on::'.') { switch (String.rsplit2 s on::'.') {
| Some (s1, s2) => | Some (s1, s2) =>
switch (String.rsplit2 s1 on::'.') { switch (String.rsplit2 s1 on::'.') {
@ -53,18 +75,20 @@ let to_simplified_string fn => {
/** Convert a fieldname to a flat string without path. */ /** Convert a fieldname to a flat string without path. */
let to_flat_string fn => { let to_flat_string fn => {
let s = Mangled.to_string fn.fname; let s = to_string fn;
switch (String.rsplit2 s on::'.') { switch (String.rsplit2 s on::'.') {
| Some (_, s2) => s2 | Some (_, s2) => s2
| _ => s | _ => s
} }
}; };
let pp f fn => let pp f =>
/* only use for debug F.fprintf f "%a#%d" pp_name fn.fname fn.fpos */ fun
Mangled.pp f fn.fname; | Hidden => Format.fprintf f "%s" hidden_str
| Java fname => Format.fprintf f "%s" fname
| Clang fname => Mangled.pp f fname;
let pp_latex style f fn => Latex.pp_string style f (Mangled.to_string fn.fname); let pp_latex style f fn => Latex.pp_string style f (to_string fn);
/** Returns the class part of the fieldname */ /** Returns the class part of the fieldname */
@ -95,11 +119,9 @@ let java_is_outer_instance fn => {
} }
}; };
let fieldname_offset fn => fn.fpos;
/** hidded fieldname constant */ /** hidded fieldname constant */
let hidden = create (Mangled.from_string ".hidden") 0; let hidden = Hidden;
/** hidded fieldname constant */ /** hidded fieldname constant */

@ -24,9 +24,17 @@ let module Set: Caml.Set.S with type elt = t;
/** Map for fieldnames */ /** Map for fieldnames */
let module Map: Caml.Map.S with type key = t; let module Map: Caml.Map.S with type key = t;
let module Clang: {
/** Create a field name at the given position */ /** Create a clang field name */
let create: Mangled.t => int => t; let create: Mangled.t => t;
};
let module Java: {
/** Create a java field name */
let from_string: string => t;
};
/** Convert a field name to a string. */ /** Convert a field name to a string. */

@ -1972,7 +1972,7 @@ and sigma_imply tenv calc_index_frame calc_missing subs prop1 sigma2 : (subst2 *
(Exp.int len, [(index, Sil.Eexp (Exp.zero, Sil.inst_none))], Sil.inst_none) (Exp.int len, [(index, Sil.Eexp (Exp.zero, Sil.inst_none))], Sil.inst_none)
| Config.Java -> | Config.Java ->
let mk_fld_sexp s = let mk_fld_sexp s =
let fld = Fieldname.create (Mangled.from_string s) 0 in let fld = Fieldname.Java.from_string s in
let se = Sil.Eexp (Exp.Var (Ident.create_fresh Ident.kprimed), Sil.Inone) in let se = Sil.Eexp (Exp.Var (Ident.create_fresh Ident.kprimed), Sil.Inone) in
(fld, se) in (fld, se) in
let fields = ["java.lang.String.count"; "java.lang.String.hash"; "java.lang.String.offset"; "java.lang.String.value"] in let fields = ["java.lang.String.count"; "java.lang.String.hash"; "java.lang.String.offset"; "java.lang.String.value"] in
@ -1989,7 +1989,7 @@ and sigma_imply tenv calc_index_frame calc_missing subs prop1 sigma2 : (subst2 *
let root = Exp.Const (Const.Cclass (Ident.string_to_name s)) in let root = Exp.Const (Const.Cclass (Ident.string_to_name s)) in
let sexp = (* TODO: add appropriate fields *) let sexp = (* TODO: add appropriate fields *)
Sil.Estruct Sil.Estruct
([(Fieldname.create (Mangled.from_string "java.lang.Class.name") 0, ([(Fieldname.Java.from_string "java.lang.Class.name",
Sil.Eexp ((Exp.Const (Const.Cstr s), Sil.Inone)))], Sil.inst_none) in Sil.Eexp ((Exp.Const (Const.Cstr s), Sil.Inone)))], Sil.inst_none) in
let class_texp = let class_texp =
let class_type = Typ.Name.Java.from_string "java.lang.Class" in let class_type = Typ.Name.Java.from_string "java.lang.Class" in

@ -324,9 +324,8 @@ module TransferFunctions (CFG : ProcCfg.S) = struct
(* create a dummy write that represents mutating the contents of the container *) (* create a dummy write that represents mutating the contents of the container *)
let open Domain in let open Domain in
let dummy_fieldname = let dummy_fieldname =
Fieldname.create Fieldname.Java.from_string
(Mangled.from_string (container_write_string ^ (Typ.Procname.get_method callee_pname)) in
(container_write_string ^ (Typ.Procname.get_method callee_pname))) 0 in
let dummy_access_exp = Exp.Lfield (receiver_exp, dummy_fieldname, receiver_typ) in let dummy_access_exp = Exp.Lfield (receiver_exp, dummy_fieldname, receiver_typ) in
let callee_accesses = let callee_accesses =
match AccessPath.of_lhs_exp dummy_access_exp receiver_typ ~f_resolve_id with match AccessPath.of_lhs_exp dummy_access_exp receiver_typ ~f_resolve_id with

@ -102,7 +102,7 @@ let replicate n el = List.map ~f:(fun _ -> el) (list_range 0 (n -1))
let mk_class_field_name field_qual_name = let mk_class_field_name field_qual_name =
let field_name = field_qual_name.Clang_ast_t.ni_name in let field_name = field_qual_name.Clang_ast_t.ni_name in
let class_name = CAst_utils.get_class_name_from_member field_qual_name in let class_name = CAst_utils.get_class_name_from_member field_qual_name in
Fieldname.create (Mangled.mangled field_name class_name) 0 Fieldname.Clang.create (Mangled.mangled field_name class_name)
let is_cpp_translation translation_unit_context = let is_cpp_translation translation_unit_context =
let lang = translation_unit_context.CFrontend_config.lang in let lang = translation_unit_context.CFrontend_config.lang in

@ -221,9 +221,7 @@ let rec typecheck_expr
match EradicateChecks.explain_expr tenv node index_exp with match EradicateChecks.explain_expr tenv node index_exp with
| Some s -> s | Some s -> s
| None -> "?" in | None -> "?" in
let fname = Fieldname.create let fname = Fieldname.Java.from_string index in
(Mangled.from_string index)
0 in
if checks.eradicate then if checks.eradicate then
EradicateChecks.check_array_access tenv EradicateChecks.check_array_access tenv
find_canonical_duplicate find_canonical_duplicate
@ -560,7 +558,7 @@ let typecheck_instr
node node
instr_ref instr_ref
array_exp array_exp
(Fieldname.create (Mangled.from_string "length") 0) (Fieldname.Java.from_string "length")
ta ta
loc loc
false; false;

@ -205,11 +205,9 @@ let translate_method_name m =
let fieldname_create cn fs = let fieldname_create cn fs =
let fieldname cn fs =
let fieldname = (JBasics.fs_name fs) in let fieldname = (JBasics.fs_name fs) in
let classname = (JBasics.cn_name cn) in let classname = (JBasics.cn_name cn) in
Mangled.from_string (classname^"."^fieldname) in Fieldname.Java.from_string (classname^"."^fieldname)
Fieldname.create (fieldname cn fs) 0
let create_sil_class_field cn cf = let create_sil_class_field cn cf =
let fs = cf.Javalib.cf_signature in let fs = cf.Javalib.cf_signature in

@ -15,8 +15,7 @@ let make_var var_str =
let make_base ?(typ=Typ.Tvoid) base_str = let make_base ?(typ=Typ.Tvoid) base_str =
AccessPath.base_of_pvar (make_var base_str) typ AccessPath.base_of_pvar (make_var base_str) typ
let make_fieldname fld_str = let make_fieldname = Fieldname.Java.from_string
Fieldname.create (Mangled.from_string fld_str) 0
let make_field_access access_str = let make_field_access access_str =
AccessPath.FieldAccess (make_fieldname access_str) AccessPath.FieldAccess (make_fieldname access_str)

Loading…
Cancel
Save