From d718c04816c0f294ac3c84d9fdc11ae18e1251e9 Mon Sep 17 00:00:00 2001 From: Nikos Gorogiannis Date: Fri, 7 Aug 2020 04:19:23 -0700 Subject: [PATCH] [java][procname] enforce types for java Summary: Since types from the java frontend are a subtype of `Typ.t` provide the means to check and enforce that for return types in procnames. Reviewed By: ezgicicek Differential Revision: D20495527 fbshipit-source-id: b99c784af --- infer/src/IR/Procname.ml | 6 ++++++ infer/src/IR/Typ.ml | 25 +++++++++++++++++++++++++ infer/src/IR/Typ.mli | 3 +++ 3 files changed, 34 insertions(+) diff --git a/infer/src/IR/Procname.ml b/infer/src/IR/Procname.ml index 80d1f2b7e..99ae69a44 100644 --- a/infer/src/IR/Procname.ml +++ b/infer/src/IR/Procname.ml @@ -34,7 +34,13 @@ module Java = struct ; kind: kind } [@@deriving compare] + let ensure_java_type t = + if not (Typ.is_java_type t) then + L.die InternalError "Expected java type but got %a@." (Typ.pp_full Pp.text) t + + let make ~class_name ~return_type ~method_name ~parameters ~kind () = + Option.iter return_type ~f:ensure_java_type ; {class_name; return_type; method_name; parameters; kind} diff --git a/infer/src/IR/Typ.ml b/infer/src/IR/Typ.ml index 747457af4..1d66d81b6 100644 --- a/infer/src/IR/Typ.ml +++ b/infer/src/IR/Typ.ml @@ -631,3 +631,28 @@ let rec pp_java ~verbose f {desc} = F.fprintf f "%a[]" (pp_java ~verbose) elt | _ -> L.die InternalError "pp_java rec" + + +let is_java_primitive_type {desc} = + let is_java_int = function + | IInt | IBool | ISChar | IUShort | ILong | IShort -> + true + | _ -> + false + in + let is_java_float = function FFloat | FDouble -> true | _ -> false in + match desc with Tint ik -> is_java_int ik | Tfloat fk -> is_java_float fk | _ -> false + + +let rec is_java_type t = + match t.desc with + | Tvoid -> + true + | Tint _ | Tfloat _ -> + is_java_primitive_type t + | Tptr ({desc= Tstruct (JavaClass _)}, Pk_pointer) -> + true + | Tptr ({desc= Tarray {elt}}, Pk_pointer) -> + is_java_type elt + | _ -> + false diff --git a/infer/src/IR/Typ.mli b/infer/src/IR/Typ.mli index 8a8e4b32c..2f56c31d6 100644 --- a/infer/src/IR/Typ.mli +++ b/infer/src/IR/Typ.mli @@ -338,6 +338,9 @@ val is_unsigned_int : t -> bool val is_char : t -> bool +val is_java_type : t -> bool +(** is [t] a type produced by the Java frontend? *) + val has_block_prefix : string -> bool val unsome : string -> t option -> t