Mangled.this/is_this

Reviewed By: ngorogiannis, jvillard

Differential Revision: D10483968

fbshipit-source-id: c9204af40
master
Mehdi Bouaziz 6 years ago committed by Facebook Github Bot
parent e72cd6c00f
commit 2d4e58f57f

@ -302,8 +302,7 @@ let inner_class_normalize p =
(* this$n.f ... -> this.f . ... *)
(* happens in ctrs only *)
| Some ((Var.ProgramVar pvar, typ), all_accesses) when is_synthetic_this pvar ->
let varname = Mangled.from_string "this" in
mk_pvar_as varname pvar
mk_pvar_as Mangled.this pvar
|> Option.map ~f:(fun new_pvar -> (base_of_pvar new_pvar typ, all_accesses))
| _ ->
None

@ -34,6 +34,10 @@ let to_string_full (pn : t) =
(** Pretty print a mangled name *)
let pp f pn = F.pp_print_string f (to_string pn)
let this = from_string "this"
let is_this = function {plain= "this"} -> true | _ -> false
module Set = Caml.Set.Make (struct
type nonrec t = t

@ -31,6 +31,10 @@ val to_string_full : t -> string
val pp : Format.formatter -> t -> unit
(** Pretty print a mangled name *)
val this : t
val is_this : t -> bool
(** Set of Mangled. *)
module Set : Caml.Set.S with type elt = t

@ -47,7 +47,7 @@ let compare_modulo_this x y =
else
let cmp = Mangled.compare x.pv_name y.pv_name in
if not (Int.equal 0 cmp) then cmp
else if String.equal "this" (Mangled.to_string x.pv_name) then 0
else if Mangled.is_this x.pv_name then 0
else compare_pvar_kind x.pv_kind y.pv_kind
@ -131,7 +131,7 @@ let is_global pv = match pv.pv_kind with Global_var _ -> true | _ -> false
let is_static_local pv = match pv.pv_kind with Global_var (_, _, _, true, _) -> true | _ -> false
(** Check if a pvar is the special "this" var *)
let is_this pvar = Mangled.equal (get_name pvar) (Mangled.from_string "this")
let is_this pvar = Mangled.is_this (get_name pvar)
(** Check if a pvar is the special "self" var *)
let is_self pvar = Mangled.equal (get_name pvar) (Mangled.from_string "self")

@ -91,7 +91,7 @@ let mark proc_name ann asig (b, bs) =
in
let rec combine l1 l2 =
match (l1, l2) with
| (p, ia, t) :: l1', l2' when String.equal (Mangled.to_string p) "this" ->
| (p, ia, t) :: l1', l2' when Mangled.is_this p ->
(p, ia, t) :: combine l1' l2'
| (s, ia, t) :: l1', x :: l2' ->
mark_param (s, ia, t) x :: combine l1' l2'

@ -51,12 +51,7 @@ let classify_procedure proc_attributes =
classification
let is_virtual = function
| (p, _, _) :: _ when String.equal (Mangled.to_string p) "this" ->
true
| _ ->
false
let is_virtual = function (p, _, _) :: _ when Mangled.is_this p -> true | _ -> false
(** Check an access (read or write) to a field. *)
let check_field_access tenv find_canonical_duplicate curr_pname node instr_ref exp fname ta loc :
@ -259,7 +254,7 @@ let check_constructor_initialization tenv find_canonical_duplicate curr_pname cu
| TypeOrigin.Undef ->
false
| TypeOrigin.Field (TypeOrigin.Formal name, _, _) ->
let circular = String.equal (Mangled.to_string name) "this" in
let circular = Mangled.is_this name in
not circular
| _ ->
true

@ -350,8 +350,8 @@ let typecheck_instr tenv calls_this checks (node : Procdesc.Node.t) idenv curr_p
constructor_check_calls_this calls_this pname ;
(* Drop reference parameters to this and outer objects. *)
let is_hidden_parameter (n, _) =
let n_str = Mangled.to_string n in
String.equal n_str "this" || Str.string_match (Str.regexp "$bcvar[0-9]+") n_str 0
Mangled.is_this n
|| Str.string_match (Str.regexp "$bcvar[0-9]+") (Mangled.to_string n) 0
in
let rec drop_n_args ntl =
match ntl with
@ -502,10 +502,10 @@ let typecheck_instr tenv calls_this checks (node : Procdesc.Node.t) idenv curr_p
~f:(fun i (_, typ) ->
let arg =
if Int.equal i 0 && not (Typ.Procname.Java.is_static callee_pname_java) then
"this"
else Printf.sprintf "arg%d" i
Mangled.this
else Printf.sprintf "arg%d" i |> Mangled.from_string
in
(Mangled.from_string arg, typ) )
(arg, typ) )
etl_
in
let ret_type = Typ.Procname.Java.get_return_typ callee_pname_java in
@ -774,8 +774,7 @@ let typecheck_instr tenv calls_this checks (node : Procdesc.Node.t) idenv curr_p
~f:(fun (sparam, _) ->
let s, _, _ = sparam in
let param_is_this =
String.equal (Mangled.to_string s) "this"
|| String.is_prefix ~prefix:"this$" (Mangled.to_string s)
Mangled.is_this s || String.is_prefix ~prefix:"this$" (Mangled.to_string s)
in
not param_is_this )
(List.zip_exn sig_slice call_slice)

@ -219,7 +219,7 @@ module Severity = struct
let this_type_get_severity tenv (signature : AnnotatedSignature.t) =
match signature.params with
| (p, _, this_type) :: _ when String.equal (Mangled.to_string p) "this" ->
| (p, _, this_type) :: _ when Mangled.is_this p ->
Option.bind ~f:get_severity (PatternMatch.type_get_annotation tenv this_type)
| _ ->
None

@ -29,7 +29,7 @@ let out_of_bound_cl = "java.lang.ArrayIndexOutOfBoundsException"
(** {2 Names of special variables, constants and method names} *)
let this = Mangled.from_string "this"
let this = Mangled.this
let constructor_name = "<init>"

@ -158,11 +158,7 @@ module SourceKind = struct
List.map
~f:(fun (name, typ) ->
let taint =
match Mangled.to_string name with
| "this" ->
None
| _ ->
Some (make_source name typ.Typ.desc)
if Mangled.is_this name then None else Some (make_source name typ.Typ.desc)
in
(name, typ, taint) )
(Procdesc.get_formals pdesc)

Loading…
Cancel
Save