From 70d5b604bf65421a4f8218d00892d65c54205fcd Mon Sep 17 00:00:00 2001 From: Ryan Rhee Date: Wed, 10 Aug 2016 12:24:29 -0700 Subject: [PATCH] Split get_super into get_super_impl and get_super_if Reviewed By: jvillard Differential Revision: D3693879 fbshipit-source-id: b18f930 --- infer/src/clang/cFrontend_checkers.ml | 2 +- infer/src/clang/cFrontend_utils.ml | 22 ++++++++++++++++------ infer/src/clang/cFrontend_utils.mli | 6 +++++- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/infer/src/clang/cFrontend_checkers.ml b/infer/src/clang/cFrontend_checkers.ml index cac023817..3101e7406 100644 --- a/infer/src/clang/cFrontend_checkers.ml +++ b/infer/src/clang/cFrontend_checkers.ml @@ -334,7 +334,7 @@ let checker_NSNotificationCenter _ decl_info impl_decl_info decls = match super with | Some (decl_list, impl_decl_info) -> (f decl_list - || exists_on_hierarchy f (Ast_utils.get_super impl_decl_info)) + || exists_on_hierarchy f (Ast_utils.get_super_impl impl_decl_info)) | None -> false in let eventually_removeObserver_in_whole_hierarchy decls impl_decl_info = diff --git a/infer/src/clang/cFrontend_utils.ml b/infer/src/clang/cFrontend_utils.ml index e051d06ad..364c73d57 100644 --- a/infer/src/clang/cFrontend_utils.ml +++ b/infer/src/clang/cFrontend_utils.ml @@ -469,15 +469,25 @@ struct Buffer.add_string buffer name; Buffer.contents buffer - let get_super impl_decl_info = + let rec get_super_if decl = + match decl with + | Some Clang_ast_t.ObjCImplementationDecl(_, _, _, _, impl_decl_info) -> + (* Try getting the super ref through the impl info, and fall back to + getting the if decl first and getting the super ref through it. *) + let super_ref = get_decl_opt_with_decl_ref impl_decl_info.oidi_super in + if Option.is_some super_ref then + super_ref + else + get_super_if (get_decl_opt_with_decl_ref impl_decl_info.oidi_class_interface) + | Some Clang_ast_t.ObjCInterfaceDecl(_, _, _, _, interface_decl_info) -> + get_decl_opt_with_decl_ref interface_decl_info.otdi_super + | _ -> None + + let get_super_impl impl_decl_info = let objc_interface_decl_current = get_decl_opt_with_decl_ref impl_decl_info.Clang_ast_t.oidi_class_interface in - let objc_interface_decl_super = - match objc_interface_decl_current with - | Some Clang_ast_t.ObjCInterfaceDecl(_, _, _, _, interface_decl_info) -> - get_decl_opt_with_decl_ref interface_decl_info.otdi_super - | _ -> None in + let objc_interface_decl_super = get_super_if objc_interface_decl_current in let objc_implementation_decl_super = match objc_interface_decl_super with | Some ObjCInterfaceDecl(_, _, _, _, interface_decl_info) -> diff --git a/infer/src/clang/cFrontend_utils.mli b/infer/src/clang/cFrontend_utils.mli index afb469f59..d85785722 100644 --- a/infer/src/clang/cFrontend_utils.mli +++ b/infer/src/clang/cFrontend_utils.mli @@ -159,11 +159,15 @@ sig (* Generates a key for a declaration based on its name and the declaration tag. *) val generate_key_decl : Clang_ast_t.decl -> string + (* Given an objc impl or interface decl, returns the objc interface decl of + the superclass, if any. *) + val get_super_if : Clang_ast_t.decl option -> Clang_ast_t.decl option + (* * Given an objc impl decl info, return the super class's list of decls and * its objc impl decl info. *) - val get_super : + val get_super_impl : Clang_ast_t.obj_c_implementation_decl_info -> (Clang_ast_t.decl list * Clang_ast_t.obj_c_implementation_decl_info)