Remove custom Clang_ast_types module, extend types instead

Summary:
update-submodule: facebook-clang-plugins

Don't replace `clang_ast_types.ml` from fcp. Instead, one can now extend `Clang_ast_t.type_ptr` type!

Reviewed By: jberdine

Differential Revision: D4922249

fbshipit-source-id: 53b22b0
master
Andrzej Kotulski 8 years ago committed by Facebook Github Bot
parent a42302bd38
commit a81f4e7bf9

1
.gitignore vendored

@ -128,6 +128,7 @@ buck-out/
/infer/src/clang/clang_ast_v.mli /infer/src/clang/clang_ast_v.mli
/infer/src/clang/clang_ast_visit.ml /infer/src/clang/clang_ast_visit.ml
/infer/src/clang/clang_ast_main.ml /infer/src/clang/clang_ast_main.ml
/infer/src/clang/clang_ast_types.ml
/infer/annotations/annot_classes/ /infer/annotations/annot_classes/
/infer/annotations/annotations.jar /infer/annotations/annotations.jar

@ -1 +1 @@
Subproject commit c61920129b7b519a420e8dc648d1319391aaaf73 Subproject commit ee26293dd046acc5c2dd862d3201aa9f7dace96a

@ -110,7 +110,7 @@ CLANG_ATDGEN_STUBS = $(addprefix $(CLANG_ATDGEN_STUB_BASE), $(CLANG_ATDGEN_SUFFI
FCP_CLANG_AST_PROJ = $(addprefix $(FCP_CLANG_OCAML_BUILD_DIR)/, \ FCP_CLANG_AST_PROJ = $(addprefix $(FCP_CLANG_OCAML_BUILD_DIR)/, \
clang_ast_proj.ml clang_ast_proj.mli) clang_ast_proj.ml clang_ast_proj.mli)
FCP_CLANG_AST_MAIN = $(addprefix $(FCP_CLANG_OCAML_DIR)/, \ FCP_CLANG_AST_MAIN = $(addprefix $(FCP_CLANG_OCAML_DIR)/, \
clang_ast_visit.ml clang_ast_main.ml) clang_ast_visit.ml clang_ast_main.ml clang_ast_types.ml)
FCP_FILES_TO_MIRROR = $(FCP_CLANG_AST_PROJ) $(FCP_CLANG_AST_MAIN) FCP_FILES_TO_MIRROR = $(FCP_CLANG_AST_PROJ) $(FCP_CLANG_AST_MAIN)
INFER_CLANG_FCP_MIRRORED_FILES = $(addprefix $(CLANG_SOURCES)/, $(notdir $(FCP_FILES_TO_MIRROR))) INFER_CLANG_FCP_MIRRORED_FILES = $(addprefix $(CLANG_SOURCES)/, $(notdir $(FCP_FILES_TO_MIRROR)))

@ -51,7 +51,7 @@ let mk_c_function translation_unit_context ?tenv name function_decl_info_opt =
| Some (decl_info, function_decl_info) -> | Some (decl_info, function_decl_info) ->
(match function_decl_info.Clang_ast_t.fdi_storage_class with (match function_decl_info.Clang_ast_t.fdi_storage_class with
| Some "static" -> | Some "static" ->
let file_opt = (fst decl_info.Clang_ast_t.di_source_range).Clang_ast_t.sl_file in let file_opt = (fst decl_info.Clang_ast_t.di_source_range).Clang_ast_t.sl_file |> Option.map ~f:SourceFile.from_abs_path in
let file_to_hex src = SourceFile.to_string src |> Utils.string_crc_hex32 in let file_to_hex src = SourceFile.to_string src |> Utils.string_crc_hex32 in
Option.value_map ~f:file_to_hex ~default:"" file_opt Option.value_map ~f:file_to_hex ~default:"" file_opt
| _ -> "") | _ -> "")

@ -46,12 +46,12 @@ let rec return_type_of_function_type_ptr type_ptr =
return_type_of_function_type_ptr in_type_ptr return_type_of_function_type_ptr in_type_ptr
| Some _ -> | Some _ ->
Logging.err_debug "Warning: Type pointer %s is not a function type." Logging.err_debug "Warning: Type pointer %s is not a function type."
(Clang_ast_types.type_ptr_to_string type_ptr); (Clang_ast_extend.type_ptr_to_string type_ptr);
`ErrorType Clang_ast_extend.ErrorType
| None -> | None ->
Logging.err_debug "Warning: Type pointer %s not found." Logging.err_debug "Warning: Type pointer %s not found."
(Clang_ast_types.type_ptr_to_string type_ptr); (Clang_ast_extend.type_ptr_to_string type_ptr);
`ErrorType Clang_ast_extend.ErrorType
let return_type_of_function_type tp = let return_type_of_function_type tp =
return_type_of_function_type_ptr tp return_type_of_function_type_ptr tp

@ -72,7 +72,7 @@ let run_clang_frontend ast_source => {
switch ast_decl { switch ast_decl {
| Clang_ast_t.TranslationUnitDecl (_, _, _, info) => | Clang_ast_t.TranslationUnitDecl (_, _, _, info) =>
Config.arc_mode := info.Clang_ast_t.tudi_arc_enabled; Config.arc_mode := info.Clang_ast_t.tudi_arc_enabled;
let source_file = info.Clang_ast_t.tudi_input_path; let source_file = SourceFile.from_abs_path info.Clang_ast_t.tudi_input_path;
init_global_state_for_capture_and_linters source_file; init_global_state_for_capture_and_linters source_file;
let lang = let lang =
switch info.Clang_ast_t.tudi_input_kind { switch info.Clang_ast_t.tudi_input_kind {

@ -27,7 +27,8 @@ let is_in_main_file translation_unit_context an =
| None -> | None ->
false false
| Some source_file -> | Some source_file ->
SourceFile.equal source_file translation_unit_context.CFrontend_config.source_file SourceFile.equal (SourceFile.from_abs_path source_file)
translation_unit_context.CFrontend_config.source_file
let is_ck_context (context: CLintersContext.context) an = let is_ck_context (context: CLintersContext.context) an =
context.is_ck_translation_unit context.is_ck_translation_unit

@ -68,7 +68,7 @@ let create_qual_type ?(is_const=false) qt_type_ptr =
let new_constant_type_ptr () = let new_constant_type_ptr () =
let pointer = CAst_utils.get_fresh_pointer () in let pointer = CAst_utils.get_fresh_pointer () in
`Prebuilt pointer Clang_ast_extend.Prebuilt pointer
(* Whenever new type are added manually to the translation here, *) (* Whenever new type are added manually to the translation here, *)
(* they should be added to the map in cTypes_decl too!! *) (* they should be added to the map in cTypes_decl too!! *)
@ -106,19 +106,17 @@ let create_void_unsigned_long_type =
let create_void_void_type = let create_void_void_type =
new_constant_type_ptr () new_constant_type_ptr ()
let create_class_type typename = `ClassType typename let create_class_type typename = Clang_ast_extend.ClassType typename
let create_class_qual_type ?(is_const=false) typename = let create_class_qual_type ?(is_const=false) typename =
create_qual_type ~is_const @@ create_class_type typename create_qual_type ~is_const @@ create_class_type typename
let make_objc_class_type class_name = let make_objc_class_type class_name =
create_class_type (Typ.Name.Objc.from_string class_name) create_class_type (Typ.Name.Objc.from_string class_name)
let create_struct_type struct_name = `StructType struct_name let create_pointer_type typ = Clang_ast_extend.PointerOf typ
let create_pointer_type typ = `PointerOf typ
let create_pointer_qual_type ~is_const typ = create_qual_type ~is_const @@ create_pointer_type typ let create_pointer_qual_type ~is_const typ = create_qual_type ~is_const @@ create_pointer_type typ
let create_reference_type typ = `ReferenceOf typ let create_reference_type typ = Clang_ast_extend.ReferenceOf typ
let create_integer_literal n = let create_integer_literal n =
let stmt_info = dummy_stmt_info () in let stmt_info = dummy_stmt_info () in

@ -47,8 +47,6 @@ val create_void_void_type : type_ptr
val create_class_type : Typ.Name.t -> type_ptr val create_class_type : Typ.Name.t -> type_ptr
val create_class_qual_type : ?is_const:bool -> Typ.Name.t -> qual_type val create_class_qual_type : ?is_const:bool -> Typ.Name.t -> qual_type
val create_struct_type : Typ.Name.t -> type_ptr
val create_pointer_type : type_ptr -> type_ptr val create_pointer_type : type_ptr -> type_ptr
val create_pointer_qual_type : is_const:bool -> type_ptr -> qual_type val create_pointer_qual_type : is_const:bool -> type_ptr -> qual_type

@ -92,7 +92,7 @@ let get_property_of_ivar decl_ptr =
let update_sil_types_map type_ptr sil_type = let update_sil_types_map type_ptr sil_type =
CFrontend_config.sil_types_map := CFrontend_config.sil_types_map :=
Clang_ast_types.TypePointerMap.add type_ptr sil_type !CFrontend_config.sil_types_map Clang_ast_extend.TypePointerMap.add type_ptr sil_type !CFrontend_config.sil_types_map
let update_enum_map enum_constant_pointer sil_exp = let update_enum_map enum_constant_pointer sil_exp =
let open Clang_ast_main in let open Clang_ast_main in
@ -112,15 +112,18 @@ let get_enum_constant_exp enum_constant_pointer =
Clang_ast_main.PointerMap.find enum_constant_pointer !CFrontend_config.enum_map Clang_ast_main.PointerMap.find enum_constant_pointer !CFrontend_config.enum_map
let get_type type_ptr = let get_type type_ptr =
try
(* There is chance for success only if type_ptr is in fact clang pointer *) (* There is chance for success only if type_ptr is in fact clang pointer *)
(let raw_ptr = Clang_ast_types.type_ptr_to_clang_pointer type_ptr in match type_ptr with
try | Clang_ast_types.TypePtr.Ptr raw_ptr ->
(try
Some (Clang_ast_main.PointerMap.find raw_ptr !CFrontend_config.pointer_type_index) Some (Clang_ast_main.PointerMap.find raw_ptr !CFrontend_config.pointer_type_index)
with Not_found -> Logging.out "type with pointer %d not found\n" raw_ptr; None) with Not_found ->
with Clang_ast_types.Not_Clang_Pointer -> Logging.out "type with pointer %d not found\n" raw_ptr;
None
)
| _ ->
(* otherwise, function fails *) (* otherwise, function fails *)
let type_str = Clang_ast_types.type_ptr_to_string type_ptr in let type_str = Clang_ast_extend.type_ptr_to_string type_ptr in
Logging.out "type %s is not clang pointer\n" type_str; Logging.out "type %s is not clang pointer\n" type_str;
None None
@ -168,8 +171,6 @@ let sil_annot_of_type type_ptr =
| _ -> None in | _ -> None in
mk_annot annot_name_opt mk_annot annot_name_opt
let string_of_type_ptr type_ptr = Clang_ast_j.string_of_type_ptr type_ptr
let name_of_typedef_type_info {Clang_ast_t.tti_decl_ptr} = let name_of_typedef_type_info {Clang_ast_t.tti_decl_ptr} =
match get_decl tti_decl_ptr with match get_decl tti_decl_ptr with
| Some TypedefDecl (_, name_decl_info, _, _, _) -> | Some TypedefDecl (_, name_decl_info, _, _, _) ->
@ -183,17 +184,19 @@ let name_opt_of_typedef_type_ptr type_ptr =
| _ -> None | _ -> None
let string_of_qual_type {Clang_ast_t.qt_type_ptr; qt_is_const} = let string_of_qual_type {Clang_ast_t.qt_type_ptr; qt_is_const} =
Printf.sprintf "%s%s" (if qt_is_const then "is_const " else "") (string_of_type_ptr qt_type_ptr) Printf.sprintf "%s%s"
(if qt_is_const then "is_const " else "")
(Clang_ast_extend.type_ptr_to_string qt_type_ptr)
let add_type_from_decl_ref type_ptr_to_sil_type tenv decl_ref_opt fail_if_not_found = let add_type_from_decl_ref type_ptr_to_sil_type tenv decl_ref_opt fail_if_not_found =
match decl_ref_opt with (* translate interface first if found *) match decl_ref_opt with (* translate interface first if found *)
| Some dr -> | Some dr ->
ignore (type_ptr_to_sil_type tenv (`DeclPtr dr.Clang_ast_t.dr_decl_pointer)); ignore (type_ptr_to_sil_type tenv (Clang_ast_extend.DeclPtr dr.Clang_ast_t.dr_decl_pointer));
| _ -> if fail_if_not_found then assert false else () | _ -> if fail_if_not_found then assert false else ()
let add_type_from_decl_ref_list type_ptr_to_sil_type tenv decl_ref_list = let add_type_from_decl_ref_list type_ptr_to_sil_type tenv decl_ref_list =
let add_elem dr = let add_elem dr =
ignore (type_ptr_to_sil_type tenv (`DeclPtr dr.Clang_ast_t.dr_decl_pointer)) in ignore (type_ptr_to_sil_type tenv (Clang_ast_extend.DeclPtr dr.Clang_ast_t.dr_decl_pointer)) in
List.iter ~f:add_elem decl_ref_list List.iter ~f:add_elem decl_ref_list
let get_function_decl_with_body decl_ptr = let get_function_decl_with_body decl_ptr =

@ -60,10 +60,6 @@ val get_desugared_type : Clang_ast_t.type_ptr -> Clang_ast_t.c_type option
(RecordType, ObjCInterfaceType and None for others *) (RecordType, ObjCInterfaceType and None for others *)
val get_decl_from_typ_ptr : Clang_ast_t.type_ptr -> Clang_ast_t.decl option val get_decl_from_typ_ptr : Clang_ast_t.type_ptr -> Clang_ast_t.decl option
(** returns string representation of type_ptr
NOTE: this doesn't expand type, it only converts type_ptr to string *)
val string_of_type_ptr : Clang_ast_t.type_ptr -> string
val name_of_typedef_type_info : Clang_ast_t.typedef_type_info -> QualifiedCppName.t val name_of_typedef_type_info : Clang_ast_t.typedef_type_info -> QualifiedCppName.t
(** returns name of typedef if type_ptr points to Typedef, None otherwise *) (** returns name of typedef if type_ptr points to Typedef, None otherwise *)
@ -135,13 +131,13 @@ val get_super_ObjCImplementationDecl :
val is_objc_if_descendant : val is_objc_if_descendant :
?blacklist:string list -> Clang_ast_t.decl option -> string list -> bool ?blacklist:string list -> Clang_ast_t.decl option -> string list -> bool
val type_ptr_to_objc_interface : Clang_ast_types.t_ptr -> Clang_ast_t.decl option val type_ptr_to_objc_interface : Clang_ast_t.type_ptr -> Clang_ast_t.decl option
val type_ptr_is_typedef_named : Clang_ast_types.t_ptr -> string -> bool val type_ptr_is_typedef_named : Clang_ast_t.type_ptr -> string -> bool
(** A class method that returns an instance of the class is a factory method. *) (** A class method that returns an instance of the class is a factory method. *)
val is_objc_factory_method : Clang_ast_t.decl -> Clang_ast_t.decl -> 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 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 val sil_annot_of_type : Clang_ast_t.type_ptr -> Annot.Item.t

@ -100,7 +100,7 @@ let log_out = ref Format.std_formatter
let pointer_decl_index = ref Clang_ast_main.PointerMap.empty let pointer_decl_index = ref Clang_ast_main.PointerMap.empty
let pointer_stmt_index = ref Clang_ast_main.PointerMap.empty let pointer_stmt_index = ref Clang_ast_main.PointerMap.empty
let pointer_type_index = ref Clang_ast_main.PointerMap.empty let pointer_type_index = ref Clang_ast_main.PointerMap.empty
let sil_types_map = ref Clang_ast_types.TypePointerMap.empty let sil_types_map = ref Clang_ast_extend.TypePointerMap.empty
let reset_global_state () = let reset_global_state () =
enum_map := Clang_ast_main.PointerMap.empty; enum_map := Clang_ast_main.PointerMap.empty;
@ -110,4 +110,4 @@ let reset_global_state () =
pointer_decl_index := Clang_ast_main.PointerMap.empty; pointer_decl_index := Clang_ast_main.PointerMap.empty;
pointer_stmt_index := Clang_ast_main.PointerMap.empty; pointer_stmt_index := Clang_ast_main.PointerMap.empty;
pointer_type_index := Clang_ast_main.PointerMap.empty; pointer_type_index := Clang_ast_main.PointerMap.empty;
sil_types_map := Clang_ast_types.TypePointerMap.empty; sil_types_map := Clang_ast_extend.TypePointerMap.empty;

@ -106,6 +106,6 @@ val pointer_type_index : Clang_ast_t.c_type Clang_ast_main.PointerMap.t ref
(** Map from type pointers (clang pointers and types created later by frontend) to sil types (** Map from type pointers (clang pointers and types created later by frontend) to sil types
Populated during frontend execution when new type is found *) Populated during frontend execution when new type is found *)
val sil_types_map : (Typ.t Clang_ast_types.TypePointerMap.t) ref val sil_types_map : (Typ.t Clang_ast_extend.TypePointerMap.t) ref
val reset_global_state : unit -> unit val reset_global_state : unit -> unit

@ -16,8 +16,8 @@ let clang_to_sil_location trans_unit_ctx clang_loc =
let line = Option.value ~default:(-1) clang_loc.Clang_ast_t.sl_line in let line = Option.value ~default:(-1) clang_loc.Clang_ast_t.sl_line in
let col = Option.value ~default:(-1) clang_loc.Clang_ast_t.sl_column in let col = Option.value ~default:(-1) clang_loc.Clang_ast_t.sl_column in
let file = let file =
Option.value ~default:trans_unit_ctx.CFrontend_config.source_file Option.value_map ~default:trans_unit_ctx.CFrontend_config.source_file
clang_loc.Clang_ast_t.sl_file in ~f:SourceFile.from_abs_path clang_loc.Clang_ast_t.sl_file in
Location.{line; col; file} Location.{line; col; file}
let source_file_in_project source_file = let source_file_in_project source_file =
@ -30,7 +30,7 @@ let source_file_in_project source_file =
file_in_project && not (file_should_be_skipped) file_in_project && not (file_should_be_skipped)
let should_do_frontend_check trans_unit_ctx (loc_start, _) = let should_do_frontend_check trans_unit_ctx (loc_start, _) =
match loc_start.Clang_ast_t.sl_file with match Option.map ~f:SourceFile.from_abs_path loc_start.Clang_ast_t.sl_file with
| Some source_file -> | Some source_file ->
SourceFile.equal source_file trans_unit_ctx.CFrontend_config.source_file || SourceFile.equal source_file trans_unit_ctx.CFrontend_config.source_file ||
(source_file_in_project source_file && not Config.testing_mode) (source_file_in_project source_file && not Config.testing_mode)
@ -42,7 +42,7 @@ let should_do_frontend_check trans_unit_ctx (loc_start, _) =
than the source file to avoid conflicts between different versions of the libraries. *) than the source file to avoid conflicts between different versions of the libraries. *)
let should_translate trans_unit_ctx (loc_start, loc_end) decl_trans_context ~translate_when_used = let should_translate trans_unit_ctx (loc_start, loc_end) decl_trans_context ~translate_when_used =
let map_file_of pred loc = let map_file_of pred loc =
match loc.Clang_ast_t.sl_file with match Option.map ~f:SourceFile.from_abs_path loc.Clang_ast_t.sl_file with
| Some f -> pred f | Some f -> pred f
| None -> false | None -> false
in in

@ -101,5 +101,5 @@ let ms_to_string ms =
IList.to_string IList.to_string
(fun (s1, s2) -> (Mangled.to_string s1) ^ ", " ^ (CAst_utils.string_of_qual_type s2)) (fun (s1, s2) -> (Mangled.to_string s1) ^ ", " ^ (CAst_utils.string_of_qual_type s2))
ms.args ms.args
^ "->" ^ (CAst_utils.string_of_type_ptr ms.ret_type) ^ " " ^ ^ "->" ^ (Clang_ast_extend.type_ptr_to_string ms.ret_type) ^ " " ^
Clang_ast_j.string_of_source_range ms.loc Clang_ast_j.string_of_source_range ms.loc

@ -52,10 +52,10 @@ let get_class_param function_method_decl_info =
if (is_instance_method function_method_decl_info) then if (is_instance_method function_method_decl_info) then
match function_method_decl_info with match function_method_decl_info with
| Cpp_Meth_decl_info (_, _, class_decl_ptr, _) -> | Cpp_Meth_decl_info (_, _, class_decl_ptr, _) ->
let class_type = Ast_expressions.create_qual_type (`DeclPtr class_decl_ptr) in let class_type = Ast_expressions.create_qual_type (Clang_ast_extend.DeclPtr class_decl_ptr) in
[(Mangled.from_string CFrontend_config.this, class_type)] [(Mangled.from_string CFrontend_config.this, class_type)]
| ObjC_Meth_decl_info (_, class_decl_ptr) -> | ObjC_Meth_decl_info (_, class_decl_ptr) ->
let class_type = Ast_expressions.create_qual_type (`DeclPtr class_decl_ptr) in let class_type = Ast_expressions.create_qual_type (Clang_ast_extend.DeclPtr class_decl_ptr) in
[(Mangled.from_string CFrontend_config.self, class_type)] [(Mangled.from_string CFrontend_config.self, class_type)]
| _ -> [] | _ -> []
else [] else []

@ -2675,7 +2675,7 @@ struct
let child_stmt_info = let child_stmt_info =
{ (Ast_expressions.dummy_stmt_info ()) with Clang_ast_t.si_source_range = source_range } in { (Ast_expressions.dummy_stmt_info ()) with Clang_ast_t.si_source_range = source_range } in
let trans_state' = PriorityNode.try_claim_priority_node trans_state this_stmt_info in let trans_state' = PriorityNode.try_claim_priority_node trans_state this_stmt_info in
let class_type_ptr = Ast_expressions.create_pointer_type (`DeclPtr class_ptr) in let class_type_ptr = Ast_expressions.create_pointer_type (Clang_ast_extend.DeclPtr class_ptr) in
let this_res_trans = this_expr_trans trans_state' sil_loc class_type_ptr in let this_res_trans = this_expr_trans trans_state' sil_loc class_type_ptr in
let var_res_trans = match ctor_init.Clang_ast_t.xci_subject with let var_res_trans = match ctor_init.Clang_ast_t.xci_subject with
| `Delegating _ | `BaseClass _ -> | `Delegating _ | `BaseClass _ ->

@ -127,8 +127,8 @@ and sil_type_of_c_type translate_decl tenv c_type =
and decl_ptr_to_sil_type translate_decl tenv decl_ptr = and decl_ptr_to_sil_type translate_decl tenv decl_ptr =
let open Clang_ast_t in let open Clang_ast_t in
let typ = `DeclPtr decl_ptr in let typ = Clang_ast_extend.DeclPtr decl_ptr in
try Clang_ast_types.TypePointerMap.find typ !CFrontend_config.sil_types_map try Clang_ast_extend.TypePointerMap.find typ !CFrontend_config.sil_types_map
with Not_found -> with Not_found ->
match CAst_utils.get_decl decl_ptr with match CAst_utils.get_decl decl_ptr with
| Some (CXXRecordDecl _ as d) | Some (CXXRecordDecl _ as d)
@ -151,7 +151,7 @@ and decl_ptr_to_sil_type translate_decl tenv decl_ptr =
and clang_type_ptr_to_sil_type translate_decl tenv type_ptr = and clang_type_ptr_to_sil_type translate_decl tenv type_ptr =
try try
Clang_ast_types.TypePointerMap.find type_ptr !CFrontend_config.sil_types_map Clang_ast_extend.TypePointerMap.find type_ptr !CFrontend_config.sil_types_map
with Not_found -> with Not_found ->
(match CAst_utils.get_type type_ptr with (match CAst_utils.get_type type_ptr with
| Some c_type -> | Some c_type ->
@ -162,24 +162,24 @@ and clang_type_ptr_to_sil_type translate_decl tenv type_ptr =
and prebuilt_type_to_sil_type type_ptr = and prebuilt_type_to_sil_type type_ptr =
try try
Clang_ast_types.TypePointerMap.find type_ptr !CFrontend_config.sil_types_map Clang_ast_extend.TypePointerMap.find type_ptr !CFrontend_config.sil_types_map
with Not_found -> with Not_found ->
Logging.out "Prebuilt type %s not found\n" Logging.out "Prebuilt type %s not found\n"
(Clang_ast_types.type_ptr_to_string type_ptr); (Clang_ast_extend.type_ptr_to_string type_ptr);
assert false assert false
and type_ptr_to_sil_type translate_decl tenv type_ptr = and type_ptr_to_sil_type translate_decl tenv type_ptr =
match type_ptr with match type_ptr with
| `TPtr _ -> clang_type_ptr_to_sil_type translate_decl tenv type_ptr | Clang_ast_types.TypePtr.Ptr _ -> clang_type_ptr_to_sil_type translate_decl tenv type_ptr
| `Prebuilt _ -> prebuilt_type_to_sil_type type_ptr | Clang_ast_extend.Prebuilt _ -> prebuilt_type_to_sil_type type_ptr
| `PointerOf typ -> | Clang_ast_extend.PointerOf typ ->
let sil_typ = type_ptr_to_sil_type translate_decl tenv typ in let sil_typ = type_ptr_to_sil_type translate_decl tenv typ in
Typ.Tptr (sil_typ, Typ.Pk_pointer) Typ.Tptr (sil_typ, Typ.Pk_pointer)
| `ReferenceOf typ -> | Clang_ast_extend.ReferenceOf typ ->
let sil_typ = type_ptr_to_sil_type translate_decl tenv typ in let sil_typ = type_ptr_to_sil_type translate_decl tenv typ in
Typ.Tptr (sil_typ, Typ.Pk_reference) Typ.Tptr (sil_typ, Typ.Pk_reference)
| `ClassType typename -> | Clang_ast_extend.ClassType typename ->
Typ.Tstruct typename Typ.Tstruct typename
| `StructType typename -> Typ.Tstruct typename | Clang_ast_extend.DeclPtr ptr -> decl_ptr_to_sil_type translate_decl tenv ptr
| `DeclPtr ptr -> decl_ptr_to_sil_type translate_decl tenv ptr | Clang_ast_extend.ErrorType -> Typ.Tvoid
| `ErrorType -> Typ.Tvoid | _ -> raise (invalid_arg "unknown variant for type_ptr")

@ -0,0 +1,63 @@
(*
* Copyright (c) 2015 - present Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*)
open! IStd
(* This module adds more variants to some types in AST *)
(* The implementation extends default one from *)
(* facebook-clang-plugins repository *)
(* Type pointers *)
type Clang_ast_types.TypePtr.t +=
| Prebuilt of int
| PointerOf of Clang_ast_types.TypePtr.t
| ReferenceOf of Clang_ast_types.TypePtr.t
| ClassType of Typ.Name.t
| DeclPtr of int
| ErrorType
module TypePointerOrd = struct
type t = Clang_ast_types.TypePtr.t
let rec compare a1 a2 = match a1, a2 with
| _ when phys_equal a1 a2 -> 0
| Clang_ast_types.TypePtr.Ptr a, Clang_ast_types.TypePtr.Ptr b -> Int.compare a b
| Clang_ast_types.TypePtr.Ptr _, _ -> 1
| _, Clang_ast_types.TypePtr.Ptr _ -> -1
| Prebuilt a, Prebuilt b -> Int.compare a b
| Prebuilt _, _ -> 1
| _, Prebuilt _ -> -1
| PointerOf a, PointerOf b -> compare a b
| PointerOf _, _ -> 1
| _, PointerOf _ -> -1
| ReferenceOf a, ReferenceOf b -> compare a b
| ReferenceOf _, _ -> 1
| _, ReferenceOf _ -> -1
| ClassType a, ClassType b -> Typ.Name.compare a b
| ClassType _, _ -> 1
| _, ClassType _ -> -1
| DeclPtr a, DeclPtr b -> Int.compare a b
| DeclPtr _, _ -> 1
| _, DeclPtr _ -> -1
| ErrorType, ErrorType -> 0
| _ -> raise (invalid_arg ("unexpected type_ptr variants: "))
end
module TypePointerMap = Caml.Map.Make(TypePointerOrd)
let rec type_ptr_to_string = function
| Clang_ast_types.TypePtr.Ptr raw -> "clang_ptr_" ^ (string_of_int raw)
| Prebuilt raw -> "prebuilt_" ^ (string_of_int raw)
| PointerOf typ -> "pointer_of_" ^ type_ptr_to_string typ
| ReferenceOf typ -> "reference_of_" ^ type_ptr_to_string typ
| ClassType name -> "class_name_" ^ Typ.Name.name name
| DeclPtr raw -> "decl_ptr_" ^ (string_of_int raw)
| ErrorType -> "error_type"
| _ -> "unknown"

@ -1,65 +0,0 @@
(*
* Copyright (c) 2015 - present Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*)
open! IStd
(* This module adds more structure to some fields in AST *)
(* The implementation is replacement of default one from *)
(* facebook-clang-plugins repository *)
(* Type pointers *)
exception Not_Clang_Pointer
type t_ptr = [
| `TPtr of int
| `Prebuilt of int
| `PointerOf of t_ptr
| `ReferenceOf of t_ptr
| `ClassType of Typ.Name.t
| `StructType of Typ.Name.t
| `DeclPtr of int
| `ErrorType
] [@@deriving compare]
module TypePointerOrd = struct
type t = t_ptr [@@deriving compare]
end
module TypePointerMap = Caml.Map.Make(TypePointerOrd)
let rec type_ptr_to_string type_ptr = match type_ptr with
| `TPtr raw -> "clang_ptr_" ^ (string_of_int raw)
| `Prebuilt raw -> "prebuilt_" ^ (string_of_int raw)
| `PointerOf typ -> "pointer_of_" ^ type_ptr_to_string typ
| `ReferenceOf typ -> "reference_of_" ^ type_ptr_to_string typ
| `ClassType name -> "class_name_" ^ Typ.Name.name name
| `StructType name -> "struct_name_" ^ Typ.Name.name name
| `DeclPtr raw -> "decl_ptr_" ^ (string_of_int raw)
| `ErrorType -> "error_type"
let type_ptr_to_clang_pointer type_ptr = match type_ptr with
| `TPtr raw -> raw
| _ -> raise Not_Clang_Pointer
let pointer_to_type_ptr raw = `TPtr raw
let type_ptr_to_pointer type_ptr = match type_ptr with
| `TPtr raw -> raw
| _ -> 0 (* invalid pointer *)
(* Source files *)
type src_file = SourceFile.t
let source_file_of_string = SourceFile.from_abs_path
let string_of_source_file = SourceFile.to_abs_path

@ -68,7 +68,7 @@ let get_base_class_name_from_category decl =
let process_category type_ptr_to_sil_type tenv class_name decl_info decl_list = let process_category type_ptr_to_sil_type tenv class_name decl_info decl_list =
let decl_fields = CField_decl.get_fields type_ptr_to_sil_type tenv decl_list in let decl_fields = CField_decl.get_fields type_ptr_to_sil_type tenv decl_list in
let class_tn_name = Typ.Name.Objc.from_qual_name class_name in let class_tn_name = Typ.Name.Objc.from_qual_name class_name in
let decl_key = `DeclPtr decl_info.Clang_ast_t.di_pointer in let decl_key = Clang_ast_extend.DeclPtr decl_info.Clang_ast_t.di_pointer in
CAst_utils.update_sil_types_map decl_key (Typ.Tstruct class_tn_name); CAst_utils.update_sil_types_map decl_key (Typ.Tstruct class_tn_name);
(match Tenv.lookup tenv class_tn_name with (match Tenv.lookup tenv class_tn_name with
| Some ({ fields } as struct_typ) -> | Some ({ fields } as struct_typ) ->

@ -78,7 +78,7 @@ let add_class_to_tenv type_ptr_to_sil_type tenv decl_info name_info decl_list oc
let class_name = CAst_utils.get_qualified_name name_info in let class_name = CAst_utils.get_qualified_name name_info in
Logging.out_debug "ADDING: ObjCInterfaceDecl for '%a'\n" QualifiedCppName.pp class_name; Logging.out_debug "ADDING: ObjCInterfaceDecl for '%a'\n" QualifiedCppName.pp class_name;
let interface_name = Typ.Name.Objc.from_qual_name class_name in let interface_name = Typ.Name.Objc.from_qual_name class_name in
let decl_key = `DeclPtr decl_info.Clang_ast_t.di_pointer in let decl_key = Clang_ast_extend.DeclPtr decl_info.Clang_ast_t.di_pointer in
CAst_utils.update_sil_types_map decl_key (Typ.Tstruct interface_name); CAst_utils.update_sil_types_map decl_key (Typ.Tstruct interface_name);
let decl_supers, decl_fields = let decl_supers, decl_fields =
create_supers_fields type_ptr_to_sil_type tenv decl_list create_supers_fields type_ptr_to_sil_type tenv decl_list
@ -142,7 +142,7 @@ let interface_impl_declaration type_ptr_to_sil_type tenv decl =
let fields = CField_decl.get_fields type_ptr_to_sil_type tenv decl_list in let fields = CField_decl.get_fields type_ptr_to_sil_type tenv decl_list in
CField_decl.add_missing_fields tenv class_name fields; CField_decl.add_missing_fields tenv class_name fields;
let class_tn_name = Typ.Name.Objc.from_qual_name class_name in let class_tn_name = Typ.Name.Objc.from_qual_name class_name in
let decl_key = `DeclPtr decl_info.Clang_ast_t.di_pointer in let decl_key = Clang_ast_extend.DeclPtr decl_info.Clang_ast_t.di_pointer in
let class_typ = Typ.Tstruct class_tn_name in let class_typ = Typ.Tstruct class_tn_name in
CAst_utils.update_sil_types_map decl_key class_typ; CAst_utils.update_sil_types_map decl_key class_typ;
class_typ class_typ

@ -26,7 +26,7 @@ let protocol_decl type_ptr_to_sil_type tenv decl =
(* It may turn out that we need a more specific treatment for protocols*) (* It may turn out that we need a more specific treatment for protocols*)
Logging.out_debug "ADDING: ObjCProtocolDecl for '%a'\n" QualifiedCppName.pp name; Logging.out_debug "ADDING: ObjCProtocolDecl for '%a'\n" QualifiedCppName.pp name;
let protocol_name = Typ.Name.Objc.protocol_from_qual_name name in let protocol_name = Typ.Name.Objc.protocol_from_qual_name name in
let decl_key = `DeclPtr decl_info.Clang_ast_t.di_pointer in let decl_key = Clang_ast_extend.DeclPtr decl_info.Clang_ast_t.di_pointer in
CAst_utils.update_sil_types_map decl_key (Typ.Tstruct protocol_name); CAst_utils.update_sil_types_map decl_key (Typ.Tstruct protocol_name);
ignore( Tenv.mk_struct tenv ~methods:[] protocol_name ); ignore( Tenv.mk_struct tenv ~methods:[] protocol_name );
add_protocol_super type_ptr_to_sil_type tenv obj_c_protocol_decl_info; add_protocol_super type_ptr_to_sil_type tenv obj_c_protocol_decl_info;

Loading…
Cancel
Save