[IR] Add Typ.TVar variant to Typ.desc

Summary: Allow type variables in `Typ.desc`. It will be used to store template type arguments.

Reviewed By: jberdine

Differential Revision: D5154757

fbshipit-source-id: 55b8e81
master
Andrzej Kotulski 8 years ago committed by Facebook Github Bot
parent 2d73c71845
commit 5522365479

@ -117,6 +117,7 @@ module T = {
| Tfun bool /** function type with noreturn attribute */
| Tptr t ptr_kind /** pointer type */
| Tstruct name /** structured value type name */
| TVar string /** type variable (ie. C++ template variables) */
| Tarray t (option IntLit.t) (option IntLit.t) /** array type with statically fixed length and stride */
[@@deriving compare]
and name =
@ -190,6 +191,7 @@ let rec pp_full pe f typ => {
let pp_desc f {desc} =>
switch desc {
| Tstruct tname => F.fprintf f "%a" (pp_name_c_syntax pe) tname
| TVar name => F.fprintf f "%s" name
| Tint ik => F.fprintf f "%s" (ikind_to_string ik)
| Tfloat fk => F.fprintf f "%s" (fkind_to_string fk)
| Tvoid => F.fprintf f "void"

@ -91,6 +91,7 @@ and desc =
| Tfun bool /** function type with noreturn attribute */
| Tptr t ptr_kind /** pointer type */
| Tstruct name /** structured value type name */
| TVar string /** type variable (ie. C++ template variables) */
| Tarray t (option IntLit.t) (option IntLit.t) /** array type with statically fixed stride and length */
[@@deriving compare]
and name =

@ -408,7 +408,7 @@ let mk_rules_for_dll tenv (para : Sil.hpara_dll) : rule list =
let typ_get_recursive_flds tenv typ_exp =
let filter typ (_, (t: Typ.t), _) =
match t.desc with
| Tstruct _ | Tint _ | Tfloat _ | Tvoid | Tfun _ ->
| Tstruct _ | Tint _ | Tfloat _ | Tvoid | Tfun _ | TVar _ ->
false
| Tptr ({desc=Tstruct _} as typ', _) ->
Typ.equal typ' typ
@ -425,7 +425,7 @@ let typ_get_recursive_flds tenv typ_exp =
L.out "@.typ_get_recursive: unexpected type expr: %a@." Exp.pp typ_exp;
[] (* ToDo: assert false *)
)
| Tint _ | Tvoid | Tfun _ | Tptr _ | Tfloat _ | Tarray _ -> []
| Tint _ | Tvoid | Tfun _ | Tptr _ | Tfloat _ | Tarray _ | TVar _ -> []
)
| Exp.Var _ -> [] (* type of |-> not known yet *)
| Exp.Const _ -> []

@ -472,7 +472,7 @@ let rec create_strexp_of_type tenv struct_init_mode (typ : Typ.t) len inst : Sil
else
create_fresh_var () in
match typ.desc, len with
| (Tint _ | Tfloat _ | Tvoid | Tfun _ | Tptr _), None ->
| (Tint _ | Tfloat _ | Tvoid | Tfun _ | Tptr _ | TVar _), None ->
Eexp (init_value (), inst)
| Tstruct name, _ -> (
match struct_init_mode, Tenv.lookup tenv name with
@ -496,7 +496,7 @@ let rec create_strexp_of_type tenv struct_init_mode (typ : Typ.t) len inst : Sil
Earray (len, [], inst)
| Tarray _, Some len ->
Earray (len, [], inst)
| (Tint _ | Tfloat _ | Tvoid | Tfun _ | Tptr _), Some _ ->
| (Tint _ | Tfloat _ | Tvoid | Tfun _ | Tptr _ | TVar _), Some _ ->
assert false
let replace_array_contents (hpred : Sil.hpred) esel : Sil.hpred = match hpred with

@ -154,10 +154,10 @@ let rec create_struct_values pname tenv orig_prop footprint_part kind max_stamp
| (Sil.Off_fld _) :: _ ->
assert false
)
| Tint _, [] | Tfloat _, [] | Tvoid, [] | Tfun _, [] | Tptr _, [] ->
| Tint _, [] | Tfloat _, [] | Tvoid, [] | Tfun _, [] | Tptr _, [] | TVar _, [] ->
let id = new_id () in
([], Sil.Eexp (Exp.Var id, inst), t)
| (Tint _ | Tfloat _ | Tvoid | Tfun _ | Tptr _), (Off_index e) :: off' ->
| (Tint _ | Tfloat _ | Tvoid | Tfun _ | Tptr _ | TVar _), (Off_index e) :: off' ->
(* In this case, we lift t to the t array. *)
let t', mk_typ_f = match t.Typ.desc with
| Typ.Tptr(t', _) -> t', (function desc -> Typ.mk ~default:t desc)
@ -170,7 +170,7 @@ let rec create_struct_values pname tenv orig_prop footprint_part kind max_stamp
let se = Sil.Earray (len, [(e', se')], inst) in
let res_t = mk_typ_f (Tarray (res_t', None, None)) in
(Sil.Aeq(e, e') :: atoms', se, res_t)
| Tint _, _ | Tfloat _, _ | Tvoid, _ | Tfun _, _ | Tptr _, _ ->
| Tint _, _ | Tfloat _, _ | Tvoid, _ | Tfun _, _ | Tptr _, _ | TVar _, _ ->
fail t off __POS__
in
if Config.trace_rearrange then

@ -49,7 +49,7 @@ struct
| Typ.Tfloat fkind -> sizeof_fkind fkind
| Typ.Tvoid -> 1
| Typ.Tptr (_, _) -> 4
| Typ.Tstruct _ -> 4 (* TODO *)
| Typ.Tstruct _ | Typ.TVar _ -> 4 (* TODO *)
| Typ.Tarray (_, Some length, Some stride) -> IntLit.to_int stride * IntLit.to_int length
| Typ.Tarray (typ, Some length, None) -> sizeof typ * IntLit.to_int length
| _ -> 4

@ -741,7 +741,7 @@ let var_or_zero_in_init_list tenv e typ ~return_zero:return_zero =
| Tint _ | Tfloat _ | Tptr _ ->
let exp = if return_zero then Sil.zero_value_of_numerical_type typ else e in
[ [(exp, typ)] ]
| Tfun _ | Tvoid | Tarray _ -> assert false in
| Tfun _ | Tvoid | Tarray _ | TVar _ -> assert false in
List.concat (var_or_zero_in_init_list' e typ String.Set.empty)
(*

Loading…
Cancel
Save