added Tenv.get_overriden_method

Summary:
As suggested in the discussion https://github.com/facebook/infer/issues/326 this pull request implements

```ocaml
get_overriden_method : Tenv.t -> Procname.java -> Procname.t
```

to get the method of a superclass that is being overridden by a specific java pname.

I thought of unit test this, but unfortunately I wasn't able to figure out how to create the proper context with OUnit2. Perhaps the easiest way to test this will be integration tests.
Feel free to reject the pull request if unit tests are mandatory (or for any other reason, of course).
Closes https://github.com/facebook/infer/pull/341

Reviewed By: jeremydubreil

Differential Revision: D3221254

Pulled By: sblackshear

fb-gh-sync-id: 9c26258
fbshipit-source-id: 9c26258
master
Luis Cruz 9 years ago committed by Facebook Github Bot 0
parent 3a856aa6f0
commit 51f4dc7a9a

@ -92,6 +92,37 @@ let proc_extract_declaring_class_typ tenv pname_java =
let proc_extract_return_typ tenv pname_java = let proc_extract_return_typ tenv pname_java =
lookup_java_typ_from_string tenv (Procname.java_get_return_type pname_java) lookup_java_typ_from_string tenv (Procname.java_get_return_type pname_java)
(** Get method that is being overriden by java_pname (if any) **)
let get_overriden_method tenv pname_java =
let struct_typ_get_def_method_by_name struct_typ method_name =
IList.find
(fun def_method -> method_name = Procname.get_method def_method)
struct_typ.Sil.def_methods in
let rec get_overriden_method_in_superclasses pname_java superclasses=
match superclasses with
| superclass :: superclasses_tail ->
begin
match lookup tenv superclass with
| Some struct_typ ->
begin
try
Some (struct_typ_get_def_method_by_name
struct_typ
(Procname.java_get_method pname_java))
with Not_found ->
get_overriden_method_in_superclasses
pname_java
(superclasses_tail @ struct_typ.Sil.superclasses)
end
| None -> get_overriden_method_in_superclasses pname_java superclasses_tail
end
| [] -> None in
match proc_extract_declaring_class_typ tenv pname_java with
| Some proc_struct_typ ->
get_overriden_method_in_superclasses pname_java proc_struct_typ.superclasses
| _ -> None
(** expand a type if it is a typename by looking it up in the type environment *) (** expand a type if it is a typename by looking it up in the type environment *)
let expand_type tenv typ = let expand_type tenv typ =
match typ with match typ with

@ -55,3 +55,6 @@ val pp : Format.formatter -> t -> unit
(** Save a type environment into a file *) (** Save a type environment into a file *)
val store_to_file : DB.filename -> t -> unit val store_to_file : DB.filename -> t -> unit
(** Get method that is being overriden by java_pname (if any) **)
val get_overriden_method : t -> Procname.java -> Procname.t option

Loading…
Cancel
Save