diff --git a/infer/src/IR/AccessPath.ml b/infer/src/IR/AccessPath.ml index 3b6af7622..098b43b78 100644 --- a/infer/src/IR/AccessPath.ml +++ b/infer/src/IR/AccessPath.ml @@ -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 diff --git a/infer/src/IR/Mangled.ml b/infer/src/IR/Mangled.ml index 397fe3308..27363b24d 100644 --- a/infer/src/IR/Mangled.ml +++ b/infer/src/IR/Mangled.ml @@ -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 diff --git a/infer/src/IR/Mangled.mli b/infer/src/IR/Mangled.mli index 9e33b782c..1d7289134 100644 --- a/infer/src/IR/Mangled.mli +++ b/infer/src/IR/Mangled.mli @@ -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 diff --git a/infer/src/IR/Pvar.ml b/infer/src/IR/Pvar.ml index 2b8c35840..1e0f29411 100644 --- a/infer/src/IR/Pvar.ml +++ b/infer/src/IR/Pvar.ml @@ -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") diff --git a/infer/src/eradicate/AnnotatedSignature.ml b/infer/src/eradicate/AnnotatedSignature.ml index 18504ced1..f4e89ef8d 100644 --- a/infer/src/eradicate/AnnotatedSignature.ml +++ b/infer/src/eradicate/AnnotatedSignature.ml @@ -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' diff --git a/infer/src/eradicate/eradicateChecks.ml b/infer/src/eradicate/eradicateChecks.ml index a11702160..1c17885bd 100644 --- a/infer/src/eradicate/eradicateChecks.ml +++ b/infer/src/eradicate/eradicateChecks.ml @@ -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 diff --git a/infer/src/eradicate/typeCheck.ml b/infer/src/eradicate/typeCheck.ml index 1a8d1b25e..2918b82c4 100644 --- a/infer/src/eradicate/typeCheck.ml +++ b/infer/src/eradicate/typeCheck.ml @@ -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) diff --git a/infer/src/eradicate/typeErr.ml b/infer/src/eradicate/typeErr.ml index 054f0427f..6d9fa8fbf 100644 --- a/infer/src/eradicate/typeErr.ml +++ b/infer/src/eradicate/typeErr.ml @@ -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 diff --git a/infer/src/java/jConfig.ml b/infer/src/java/jConfig.ml index 8d439903c..8d8cb553d 100644 --- a/infer/src/java/jConfig.ml +++ b/infer/src/java/jConfig.ml @@ -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 = "" diff --git a/infer/src/quandary/JavaTrace.ml b/infer/src/quandary/JavaTrace.ml index c6facdabc..62ce62fd9 100644 --- a/infer/src/quandary/JavaTrace.ml +++ b/infer/src/quandary/JavaTrace.ml @@ -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)