[clang] Refactor annotation generation to a separate place

Reviewed By: akotulski

Differential Revision: D4642703

fbshipit-source-id: 57fde17
master
Dulma Churchill 8 years ago committed by Facebook Github Bot
parent 090ec908b8
commit 60f732bf7e

@ -232,11 +232,21 @@ let is_type_nonnull type_ptr =
| _ ->
false
let is_type_nullable type_ptr =
let open Clang_ast_t in
match get_type type_ptr with
| Some AttributedType (_, attr_info) -> attr_info.ati_attr_kind = `Nullable
| _ -> false
let sil_annot_of_type type_ptr =
let default_visibility = true in
let mk_annot annot_name_opt =
match annot_name_opt with
| Some annot_name ->
[{ Annot.class_name = annot_name; parameters = []; }, default_visibility]
| None -> Annot.Item.empty in
let annot_name_opt =
match get_type type_ptr with
| Some AttributedType (_, attr_info) ->
if attr_info.ati_attr_kind = `Nullable then Some Annotations.nullable
(* other annotations go here *)
else None
| _ -> None in
mk_annot annot_name_opt
let string_of_type_ptr type_ptr = Clang_ast_j.string_of_type_ptr type_ptr

@ -34,8 +34,6 @@ val is_copy : Clang_ast_t.property_attribute option -> bool
val is_type_nonnull : Clang_ast_t.type_ptr -> bool
val is_type_nullable : Clang_ast_t.type_ptr -> bool
val get_fresh_pointer : unit -> Clang_ast_t.pointer
val get_invalid_pointer : unit -> Clang_ast_t.pointer
@ -166,3 +164,5 @@ val type_ptr_is_typedef_named : Clang_ast_types.t_ptr -> string -> bool
val is_objc_factory_method : Clang_ast_t.decl -> Clang_ast_t.decl -> bool
val name_of_decl_ref_opt : Clang_ast_t.decl_ref option -> string option
val sil_annot_of_type : Clang_ast_types.t_ptr -> Annot.Item.t

@ -342,17 +342,9 @@ let should_create_procdesc cfg procname defined =
| None -> true
let sil_method_annotation_of_args args method_type : Annot.Method.t =
let default_visibility = true in
let mk_annot annot_name =
let annot = { Annot.class_name = annot_name; parameters = []; } in
annot, default_visibility in
let sil_annot_of_type type_ptr =
if CAst_utils.is_type_nullable type_ptr then
[mk_annot Annotations.nullable]
else Annot.Item.empty in
let args_types = List.map ~f:(fun (_, qt) -> qt.Clang_ast_t.qt_type_ptr) args in
let param_annots = List.map ~f:sil_annot_of_type args_types in
let retval_annot = sil_annot_of_type method_type in
let param_annots = List.map ~f:CAst_utils.sil_annot_of_type args_types in
let retval_annot = CAst_utils.sil_annot_of_type method_type in
retval_annot, param_annots
let is_pointer_to_const type_ptr = match CAst_utils.get_type type_ptr with

Loading…
Cancel
Save