[clang] Do not raise an exception when type pointer not found

Reviewed By: da319

Differential Revision: D8567239

fbshipit-source-id: 6eed973
master
Dulma Churchill 7 years ago committed by Facebook Github Bot
parent 5156ff7f65
commit 4c726692a9

@ -126,25 +126,21 @@ let get_enum_constant_exp enum_constant_pointer =
ClangPointers.Map.find_exn !CFrontend_config.enum_map enum_constant_pointer ClangPointers.Map.find_exn !CFrontend_config.enum_map enum_constant_pointer
let get_type ?source_range type_ptr = let get_type type_ptr =
let source_range = match source_range with Some sr -> sr | None -> dummy_source_range () in
match type_ptr with match type_ptr with
(* 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 *)
| Clang_ast_types.TypePtr.Ptr raw_ptr -> | Clang_ast_types.TypePtr.Ptr raw_ptr ->
let typ = Int.Table.find ClangPointers.pointer_type_table raw_ptr in Int.Table.find ClangPointers.pointer_type_table raw_ptr
if Option.is_none typ then
CFrontend_config.incorrect_assumption __POS__ source_range
"type with pointer %d not found@\n" raw_ptr ;
typ
| _ -> | _ ->
(* TODO(T30739447): investigate why this happens *)
(* otherwise, function fails *) (* otherwise, function fails *)
let type_str = Clang_ast_extend.type_ptr_to_string type_ptr in let type_str = Clang_ast_extend.type_ptr_to_string type_ptr in
L.(debug Capture Medium) "type %s is not clang pointer@\n" type_str ; L.(debug Capture Medium) "type %s is not clang pointer@\n" type_str ;
None None
let get_desugared_type ?source_range type_ptr = let get_desugared_type type_ptr =
let typ_opt = get_type ?source_range type_ptr in let typ_opt = get_type type_ptr in
match typ_opt with match typ_opt with
| Some typ | Some typ
-> ( -> (

@ -45,12 +45,10 @@ val get_unqualified_name : Clang_ast_t.named_decl_info -> string
val get_class_name_from_member : Clang_ast_t.named_decl_info -> QualifiedCppName.t val get_class_name_from_member : Clang_ast_t.named_decl_info -> QualifiedCppName.t
(** returns qualified class name given member name info *) (** returns qualified class name given member name info *)
val get_type : val get_type : Clang_ast_t.type_ptr -> Clang_ast_t.c_type option
?source_range:Clang_ast_t.source_range -> Clang_ast_t.type_ptr -> Clang_ast_t.c_type option
(** looks up clang pointer to type and returns c_type. It requires type_ptr to be `TPtr. *) (** looks up clang pointer to type and returns c_type. It requires type_ptr to be `TPtr. *)
val get_desugared_type : val get_desugared_type : Clang_ast_t.type_ptr -> Clang_ast_t.c_type option
?source_range:Clang_ast_t.source_range -> Clang_ast_t.type_ptr -> Clang_ast_t.c_type option
(** looks up clang pointer to type and resolves any sugar around it. (** looks up clang pointer to type and resolves any sugar around it.
See get_type for more info and restrictions *) See get_type for more info and restrictions *)

@ -1074,11 +1074,7 @@ let has_type_const_ptr_to_objc_class node =
let open Clang_ast_t in let open Clang_ast_t in
match get_ast_node_type_ptr node with match get_ast_node_type_ptr node with
| Some type_ptr -> ( | Some type_ptr -> (
match match CAst_utils.get_desugared_type type_ptr with
CAst_utils.get_desugared_type
~source_range:(Ctl_parser_types.ast_node_source_range node)
type_ptr
with
| Some (ObjCObjectPointerType (_, qt)) -> | Some (ObjCObjectPointerType (_, qt)) ->
qt.qt_is_const qt.qt_is_const
| _ -> | _ ->

Loading…
Cancel
Save