[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
master
Nikos Gorogiannis 4 years ago committed by Facebook GitHub Bot
parent 3ddf77f0f1
commit d718c04816

@ -34,7 +34,13 @@ module Java = struct
; kind: kind } ; kind: kind }
[@@deriving compare] [@@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 () = 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} {class_name; return_type; method_name; parameters; kind}

@ -631,3 +631,28 @@ let rec pp_java ~verbose f {desc} =
F.fprintf f "%a[]" (pp_java ~verbose) elt F.fprintf f "%a[]" (pp_java ~verbose) elt
| _ -> | _ ->
L.die InternalError "pp_java rec" 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

@ -338,6 +338,9 @@ val is_unsigned_int : t -> bool
val is_char : 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 has_block_prefix : string -> bool
val unsome : string -> t option -> t val unsome : string -> t option -> t

Loading…
Cancel
Save