[typ][javaclass] abstract typename

Summary: The type-name definition for Java can be potentially improved (eg increase sharing, or comparison speed, much like `QualifiedCppName`) by switching away from `Mangled.t` which is essentially a string.  First step is to abstract the type.

Reviewed By: jberdine

Differential Revision: D19087508

fbshipit-source-id: 91a81f63b
master
Nikos Gorogiannis 5 years ago committed by Facebook Github Bot
parent 87b29a2d72
commit a79a819679

@ -410,7 +410,9 @@ let rec get_java_class_initializer tenv = function
| Lfield (Lvar pvar, fn, typ) when Pvar.is_global pvar -> ( | Lfield (Lvar pvar, fn, typ) when Pvar.is_global pvar -> (
match Struct.get_field_type_and_annotation ~lookup:(Tenv.lookup tenv) fn typ with match Struct.get_field_type_and_annotation ~lookup:(Tenv.lookup tenv) fn typ with
| Some (field_typ, annot) when Annot.Item.is_final annot -> | Some (field_typ, annot) when Annot.Item.is_final annot ->
let java_class = Typ.JavaClass (Pvar.get_name pvar) in let java_class =
Typ.JavaClass (JavaClassName.from_string (Mangled.to_string_full (Pvar.get_name pvar)))
in
Some (Procname.Java (Procname.Java.get_class_initializer java_class), pvar, fn, field_typ) Some (Procname.Java (Procname.Java.get_class_initializer java_class), pvar, fn, field_typ)
| _ -> | _ ->
None ) None )

@ -0,0 +1,9 @@
(*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*)
open! IStd
include Mangled

@ -0,0 +1,16 @@
(*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*)
open! IStd
type t [@@deriving compare]
val from_string : string -> t
val to_string : t -> string
val pp : Format.formatter -> t -> unit

@ -48,7 +48,7 @@ let templated_name_of_class_name class_name =
| CppClass (qual_name, template_spec_info) -> | CppClass (qual_name, template_spec_info) ->
(qual_name, template_args_of_template_spec_info template_spec_info) (qual_name, template_args_of_template_spec_info template_spec_info)
| JavaClass mangled_name -> | JavaClass mangled_name ->
(QualifiedCppName.of_list [Mangled.to_string mangled_name], []) (QualifiedCppName.of_list [JavaClassName.to_string mangled_name], [])
let templated_name_of_java java = let templated_name_of_java java =

@ -191,7 +191,7 @@ module T = struct
| CStruct of QualifiedCppName.t | CStruct of QualifiedCppName.t
| CUnion of QualifiedCppName.t | CUnion of QualifiedCppName.t
| CppClass of QualifiedCppName.t * template_spec_info | CppClass of QualifiedCppName.t * template_spec_info
| JavaClass of Mangled.t | JavaClass of JavaClassName.t
| ObjcClass of QualifiedCppName.t | ObjcClass of QualifiedCppName.t
| ObjcProtocol of QualifiedCppName.t | ObjcProtocol of QualifiedCppName.t
[@@deriving compare] [@@deriving compare]
@ -333,7 +333,7 @@ and pp_name_c_syntax pe f = function
| CppClass (name, template_spec) -> | CppClass (name, template_spec) ->
F.fprintf f "%a%a" QualifiedCppName.pp name (pp_template_spec_info pe) template_spec F.fprintf f "%a%a" QualifiedCppName.pp name (pp_template_spec_info pe) template_spec
| JavaClass name -> | JavaClass name ->
Mangled.pp f name JavaClassName.pp f name
and pp_template_spec_info pe f = function and pp_template_spec_info pe f = function
@ -396,7 +396,7 @@ module Name = struct
| CStruct _ | CUnion _ | CppClass _ | ObjcClass _ | ObjcProtocol _ -> | CStruct _ | CUnion _ | CppClass _ | ObjcClass _ | ObjcProtocol _ ->
qual_name n |> QualifiedCppName.to_qual_string qual_name n |> QualifiedCppName.to_qual_string
| JavaClass name -> | JavaClass name ->
Mangled.to_string name JavaClassName.to_string name
let pp fmt tname = let pp fmt tname =
@ -478,7 +478,7 @@ module Name = struct
F.pp_print_string fmt type_name F.pp_print_string fmt type_name
end end
let from_string name_str = JavaClass (Mangled.from_string name_str) let from_string name_str = JavaClass (JavaClassName.from_string name_str)
let from_package_class package_name class_name = let from_package_class package_name class_name =
if String.equal package_name "" then from_string class_name if String.equal package_name "" then from_string class_name

@ -109,7 +109,7 @@ and name =
args of its parent classes, for example: MyClass<int>::InnerClass<int> will store args of its parent classes, for example: MyClass<int>::InnerClass<int> will store
"MyClass<int>", "InnerClass" *) "MyClass<int>", "InnerClass" *)
| CppClass of QualifiedCppName.t * template_spec_info | CppClass of QualifiedCppName.t * template_spec_info
| JavaClass of Mangled.t | JavaClass of JavaClassName.t
| ObjcClass of QualifiedCppName.t | ObjcClass of QualifiedCppName.t
| ObjcProtocol of QualifiedCppName.t | ObjcProtocol of QualifiedCppName.t
[@@deriving compare] [@@deriving compare]

@ -208,7 +208,11 @@ module TransferFunctions = struct
let assign_java_enum_values id callee_pname mem = let assign_java_enum_values id callee_pname mem =
match Procname.get_class_type_name callee_pname with match Procname.get_class_type_name callee_pname with
| Some (JavaClass class_name as typename) -> | Some (JavaClass class_name as typename) ->
let class_var = Loc.of_var (Var.of_pvar (Pvar.mk_global class_name)) in let class_var =
Loc.of_var
(Var.of_pvar
(Pvar.mk_global (Mangled.from_string (JavaClassName.to_string class_name))))
in
let fn = Fieldname.make typename "$VALUES" in let fn = Fieldname.make typename "$VALUES" in
let v = Dom.Mem.find (Loc.append_field class_var ~fn) mem in let v = Dom.Mem.find (Loc.append_field class_var ~fn) mem in
Dom.Mem.add_stack (Loc.of_id id) v mem Dom.Mem.add_stack (Loc.of_id id) v mem

@ -66,7 +66,7 @@ let rec add_loads_of_exp summary tenv loc (exp : Exp.t) astate =
match exp with match exp with
| Const (Cclass class_ident) -> | Const (Cclass class_ident) ->
(* [X.class] expressions *) (* [X.class] expressions *)
let class_str = Ident.name_to_string class_ident |> Mangled.from_string in let class_str = Ident.name_to_string class_ident |> JavaClassName.from_string in
let class_name = Typ.JavaClass class_str in let class_name = Typ.JavaClass class_str in
load_class summary tenv loc astate class_name load_class summary tenv loc astate class_name
| Sizeof {typ= {desc= Tarray {elt}}} -> | Sizeof {typ= {desc= Tarray {elt}}} ->

@ -80,7 +80,7 @@ include TaintAnalysis.Make (struct
let is_taintable_type typ = let is_taintable_type typ =
match typ.Typ.desc with match typ.Typ.desc with
| Typ.Tptr ({desc= Tstruct (JavaClass typename)}, _) | Tstruct (JavaClass typename) -> ( | Typ.Tptr ({desc= Tstruct (JavaClass typename)}, _) | Tstruct (JavaClass typename) -> (
match Mangled.to_string_full typename with match JavaClassName.to_string typename with
| "android.content.Intent" | "android.net.Uri" | "java.lang.String" | "java.net.URI" -> | "android.content.Intent" | "android.net.Uri" | "java.lang.String" | "java.net.URI" ->
true true
| _ -> | _ ->

Loading…
Cancel
Save