make get_decl_from_typ_ptr return optional type instead of crashing

Summary:
public
Make Ast_utils.get_decl_from_typ_ptr function more forgiving.
It will return None instead of crashing when there is no decl for a given type.
This is done in prepratation to try to get destructor function of any type without crashing.

Reviewed By: dulmarod

Differential Revision: D2769302

fb-gh-sync-id: 7a9fcfe
master
Andrzej Kotulski 9 years ago committed by facebook-github-bot-1
parent 7960798ca8
commit cc4d3f3cd0

@ -350,13 +350,10 @@ struct
let get_decl_from_typ_ptr typ_ptr =
let typ_opt = get_desugared_type typ_ptr in
let typ = match typ_opt with Some t -> t | _ -> assert false in
let get_decl_or_fail decl_ptr = match get_decl decl_ptr with
| Some d -> d
| None -> assert false in
(* it needs extending to handle objC types *)
match typ with
| Clang_ast_t.RecordType (ti, decl_ptr) -> get_decl_or_fail decl_ptr
| _ -> assert false
| Clang_ast_t.RecordType (ti, decl_ptr) -> get_decl decl_ptr
| _ -> None
(*TODO take the attributes into account too. To be done after we get the attribute's arguments. *)
let is_type_nonnull type_ptr =

@ -103,7 +103,7 @@ sig
(** returns declaration of the type for certain types and crashes for others
NOTE: this function needs extending to handle objC types *)
val get_decl_from_typ_ptr : Clang_ast_t.type_ptr -> Clang_ast_t.decl
val get_decl_from_typ_ptr : Clang_ast_t.type_ptr -> Clang_ast_t.decl option
val string_of_type_ptr : Clang_ast_t.type_ptr -> string

@ -133,7 +133,10 @@ let get_superclass_decls decl =
| ClassTemplateSpecializationDecl (_, _, _, _, _, _, _, cxx_rec_info) ->
(* there is no concept of virtual inheritance in the backend right now *)
let base_ptr = cxx_rec_info.Clang_ast_t.xrdi_bases @ cxx_rec_info.Clang_ast_t.xrdi_vbases in
IList.map Ast_utils.get_decl_from_typ_ptr base_ptr
let get_decl_or_fail typ_ptr = match Ast_utils.get_decl_from_typ_ptr typ_ptr with
| Some decl -> decl
| None -> assert false in
IList.map get_decl_or_fail base_ptr
| _ -> []
(** fetches list of superclasses for C++ classes *)

Loading…
Cancel
Save