[IR] Track objC protocols in each class

Summary: This will be needed in the next diff so that we can find all classes that conform to `NSCopying` protocol.

Reviewed By: skcho

Differential Revision: D24216549

fbshipit-source-id: 297b527a6
master
Ezgi Çiçek 4 years ago committed by Facebook GitHub Bot
parent 8da46d0f0d
commit ebee6fd7ba

@ -43,6 +43,7 @@ type t =
{ fields: fields (** non-static fields *) { fields: fields (** non-static fields *)
; statics: fields (** static fields *) ; statics: fields (** static fields *)
; supers: Typ.Name.t list (** superclasses *) ; supers: Typ.Name.t list (** superclasses *)
; objc_protocols: Typ.Name.t list (** ObjC protocols *)
; methods: Procname.t list (** methods defined *) ; methods: Procname.t list (** methods defined *)
; exported_objc_methods: Procname.t list (** methods in ObjC interface, subset of [methods] *) ; exported_objc_methods: Procname.t list (** methods in ObjC interface, subset of [methods] *)
; annots: Annot.Item.t (** annotations *) ; annots: Annot.Item.t (** annotations *)
@ -57,9 +58,15 @@ let pp_field pe f (field_name, typ, ann) =
let pp pe name f let pp pe name f
({fields; statics; supers; methods; exported_objc_methods; annots; java_class_info; dummy}[@warning ({ fields
"+9"]) ; statics
= ; supers
; objc_protocols
; methods
; exported_objc_methods
; annots
; java_class_info
; dummy }[@warning "+9"]) =
let pp_field pe f (field_name, typ, ann) = let pp_field pe f (field_name, typ, ann) =
F.fprintf f "@;<0 2>%a %a %a" (Typ.pp_full pe) typ Fieldname.pp field_name Annot.Item.pp ann F.fprintf f "@;<0 2>%a %a %a" (Typ.pp_full pe) typ Fieldname.pp field_name Annot.Item.pp ann
in in
@ -75,6 +82,7 @@ let pp pe name f
@[<v>fields: {@[<v>%a@]}@,\ @[<v>fields: {@[<v>%a@]}@,\
statics: {@[<v>%a@]}@,\ statics: {@[<v>%a@]}@,\
supers: {@[<v>%a@]}@,\ supers: {@[<v>%a@]}@,\
objc_protocols: {@[<v>%a@]}@,\
methods: {@[<v>%a@]}@,\ methods: {@[<v>%a@]}@,\
exported_obj_methods: {@[<v>%a@]}@,\ exported_obj_methods: {@[<v>%a@]}@,\
annots: {@[<v>%a@]}@,\ annots: {@[<v>%a@]}@,\
@ -87,30 +95,43 @@ let pp pe name f
statics statics
(seq (fun f n -> F.fprintf f "@;<0 2>%a" Typ.Name.pp n)) (seq (fun f n -> F.fprintf f "@;<0 2>%a" Typ.Name.pp n))
supers supers
(seq (fun f n -> F.fprintf f "@;<0 2>%a" Typ.Name.pp n))
objc_protocols
(seq (fun f m -> F.fprintf f "@;<0 2>%a" Procname.pp m)) (seq (fun f m -> F.fprintf f "@;<0 2>%a" Procname.pp m))
methods methods
(seq (fun f m -> F.fprintf f "@;<0 2>%a" Procname.pp m)) (seq (fun f m -> F.fprintf f "@;<0 2>%a" Procname.pp m))
exported_objc_methods Annot.Item.pp annots pp_java_class_info_opt java_class_info dummy exported_objc_methods Annot.Item.pp annots pp_java_class_info_opt java_class_info dummy
let internal_mk_struct ?default ?fields ?statics ?methods ?exported_objc_methods ?supers ?annots let internal_mk_struct ?default ?fields ?statics ?methods ?exported_objc_methods ?supers
?java_class_info ?dummy () = ?objc_protocols ?annots ?java_class_info ?dummy () =
let default_ = let default_ =
{ fields= [] { fields= []
; statics= [] ; statics= []
; methods= [] ; methods= []
; exported_objc_methods= [] ; exported_objc_methods= []
; supers= [] ; supers= []
; objc_protocols= []
; annots= Annot.Item.empty ; annots= Annot.Item.empty
; java_class_info= None ; java_class_info= None
; dummy= false } ; dummy= false }
in in
let mk_struct_ ?(default = default_) ?(fields = default.fields) ?(statics = default.statics) let mk_struct_ ?(default = default_) ?(fields = default.fields) ?(statics = default.statics)
?(methods = default.methods) ?(exported_objc_methods = default.exported_objc_methods) ?(methods = default.methods) ?(exported_objc_methods = default.exported_objc_methods)
?(supers = default.supers) ?(annots = default.annots) ?(dummy = default.dummy) () = ?(supers = default.supers) ?(objc_protocols = default.objc_protocols)
{fields; statics; methods; exported_objc_methods; supers; annots; java_class_info; dummy} ?(annots = default.annots) ?(dummy = default.dummy) () =
{ fields
; statics
; methods
; exported_objc_methods
; supers
; objc_protocols
; annots
; java_class_info
; dummy }
in in
mk_struct_ ?default ?fields ?statics ?methods ?exported_objc_methods ?supers ?annots ?dummy () mk_struct_ ?default ?fields ?statics ?methods ?exported_objc_methods ?supers ?objc_protocols
?annots ?dummy ()
(** the element typ of the final extensible array in the given typ, if any *) (** the element typ of the final extensible array in the given typ, if any *)

@ -26,6 +26,7 @@ type t =
{ fields: fields (** non-static fields *) { fields: fields (** non-static fields *)
; statics: fields (** static fields *) ; statics: fields (** static fields *)
; supers: Typ.Name.t list (** superclasses *) ; supers: Typ.Name.t list (** superclasses *)
; objc_protocols: Typ.Name.t list (** ObjC protocols *)
; methods: Procname.t list (** methods defined *) ; methods: Procname.t list (** methods defined *)
; exported_objc_methods: Procname.t list (** methods in ObjC interface, subset of [methods] *) ; exported_objc_methods: Procname.t list (** methods in ObjC interface, subset of [methods] *)
; annots: Annot.Item.t (** annotations *) ; annots: Annot.Item.t (** annotations *)
@ -46,6 +47,7 @@ val internal_mk_struct :
-> ?methods:Procname.t list -> ?methods:Procname.t list
-> ?exported_objc_methods:Procname.t list -> ?exported_objc_methods:Procname.t list
-> ?supers:Typ.Name.t list -> ?supers:Typ.Name.t list
-> ?objc_protocols:Typ.Name.t list
-> ?annots:Annot.Item.t -> ?annots:Annot.Item.t
-> ?java_class_info:java_class_info -> ?java_class_info:java_class_info
-> ?dummy:bool -> ?dummy:bool

@ -25,11 +25,11 @@ let pp fmt (tenv : t) =
let create () = TypenameHash.create 1000 let create () = TypenameHash.create 1000
(** Construct a struct type in a type environment *) (** Construct a struct type in a type environment *)
let mk_struct tenv ?default ?fields ?statics ?methods ?exported_objc_methods ?supers ?annots let mk_struct tenv ?default ?fields ?statics ?methods ?exported_objc_methods ?supers ?objc_protocols
?java_class_info ?dummy name = ?annots ?java_class_info ?dummy name =
let struct_typ = let struct_typ =
Struct.internal_mk_struct ?default ?fields ?statics ?methods ?exported_objc_methods ?supers Struct.internal_mk_struct ?default ?fields ?statics ?methods ?exported_objc_methods ?supers
?annots ?java_class_info ?dummy () ?objc_protocols ?annots ?java_class_info ?dummy ()
in in
TypenameHash.replace tenv name struct_typ ; TypenameHash.replace tenv name struct_typ ;
struct_typ struct_typ

@ -40,6 +40,7 @@ val mk_struct :
-> ?methods:Procname.t list -> ?methods:Procname.t list
-> ?exported_objc_methods:Procname.t list -> ?exported_objc_methods:Procname.t list
-> ?supers:Typ.Name.t list -> ?supers:Typ.Name.t list
-> ?objc_protocols:Typ.Name.t list
-> ?annots:Annot.Item.t -> ?annots:Annot.Item.t
-> ?java_class_info:Struct.java_class_info -> ?java_class_info:Struct.java_class_info
-> ?dummy:bool -> ?dummy:bool

@ -75,6 +75,13 @@ let add_class_to_tenv qual_type_to_sil_type procname_from_decl tenv decl_info na
create_supers_fields qual_type_to_sil_type tenv interface_name decl_list create_supers_fields qual_type_to_sil_type tenv interface_name decl_list
ocidi.Clang_ast_t.otdi_super ocidi.Clang_ast_t.otdi_super
in in
let objc_protocols =
List.filter_map
~f:(fun dr ->
Option.map dr.Clang_ast_t.dr_name ~f:(fun x ->
CAst_utils.get_qualified_name x |> Typ.Name.Objc.from_qual_name ) )
ocidi.Clang_ast_t.otdi_protocols
in
let fields_sc = CField_decl.fields_superclass tenv ocidi in let fields_sc = CField_decl.fields_superclass tenv ocidi in
(*In case we found categories, or partial definition of this class earlier and they are already in the tenv *) (*In case we found categories, or partial definition of this class earlier and they are already in the tenv *)
let fields, (supers : Typ.Name.t list), methods = let fields, (supers : Typ.Name.t list), methods =
@ -95,8 +102,8 @@ let add_class_to_tenv qual_type_to_sil_type procname_from_decl tenv decl_info na
methods methods
in in
ignore ignore
(Tenv.mk_struct tenv ~fields:all_fields ~supers ~methods ~annots:Annot.Class.objc (Tenv.mk_struct tenv ~fields:all_fields ~supers ~objc_protocols ~methods
~exported_objc_methods:methods interface_name) ; ~annots:Annot.Class.objc ~exported_objc_methods:methods interface_name) ;
interface_desc interface_desc

Loading…
Cancel
Save