From a44109b2b284bfb92d15a7d33a922f97d31546d1 Mon Sep 17 00:00:00 2001 From: Dulma Churchill Date: Thu, 29 Sep 2016 04:07:33 -0700 Subject: [PATCH] [linters] Pass the current method in the context to the checks about the methods or functions declarations Reviewed By: ddino Differential Revision: D3937070 fbshipit-source-id: da7b4a6 --- infer/src/clang/cFrontend_checkers_main.ml | 58 ++++++++++++---------- 1 file changed, 32 insertions(+), 26 deletions(-) diff --git a/infer/src/clang/cFrontend_checkers_main.ml b/infer/src/clang/cFrontend_checkers_main.ml index 9d17b435f..453768466 100644 --- a/infer/src/clang/cFrontend_checkers_main.ml +++ b/infer/src/clang/cFrontend_checkers_main.ml @@ -28,33 +28,39 @@ and do_frontend_checks_decl context decl = let open Clang_ast_t in let info = Clang_ast_proj.get_decl_tuple decl in CLocation.update_curr_file info; - (match decl with - | FunctionDecl(_, _, _, fdi) - | CXXMethodDecl (_, _, _, fdi, _) - | CXXConstructorDecl (_, _, _, fdi, _) - | CXXConversionDecl (_, _, _, fdi, _) - | CXXDestructorDecl (_, _, _, fdi, _) -> - (match fdi.Clang_ast_t.fdi_body with - | Some stmt -> - let context = {context with CLintersContext.current_method = Some decl } in - do_frontend_checks_stmt context stmt - | None -> ()) - | ObjCMethodDecl (_, _, mdi) -> - (match mdi.Clang_ast_t.omdi_body with - | Some stmt -> - let context = {context with CLintersContext.current_method = Some decl } in - do_frontend_checks_stmt context stmt - | None -> ()) - | BlockDecl (_, block_decl_info) -> - (match block_decl_info.Clang_ast_t.bdi_body with - | Some stmt -> - let context = {context with CLintersContext.current_method = Some decl } in - do_frontend_checks_stmt context stmt - | None -> ()) - | _ -> ()); - let context' = CFrontend_errors.run_frontend_checkers_on_decl context decl in + let context' = + (match decl with + | FunctionDecl(_, _, _, fdi) + | CXXMethodDecl (_, _, _, fdi, _) + | CXXConstructorDecl (_, _, _, fdi, _) + | CXXConversionDecl (_, _, _, fdi, _) + | CXXDestructorDecl (_, _, _, fdi, _) -> + let context' = {context with CLintersContext.current_method = Some decl } in + (match fdi.Clang_ast_t.fdi_body with + | Some stmt -> + do_frontend_checks_stmt context' stmt + | None -> ()); + context' + | ObjCMethodDecl (_, _, mdi) -> + let context' = {context with CLintersContext.current_method = Some decl } in + (match mdi.Clang_ast_t.omdi_body with + | Some stmt -> + do_frontend_checks_stmt context' stmt + | None -> ()); + context' + | BlockDecl (_, block_decl_info) -> + let context' = {context with CLintersContext.current_method = Some decl } in + (match block_decl_info.Clang_ast_t.bdi_body with + | Some stmt -> + do_frontend_checks_stmt context' stmt + | None -> ()); + context' + | _ -> context) in + let context'' = CFrontend_errors.run_frontend_checkers_on_decl context' decl in + let context_with_orig_current_method = + {context'' with CLintersContext.current_method = context.CLintersContext.current_method } in match Clang_ast_proj.get_decl_context_tuple decl with - | Some (decls, _) -> IList.iter (do_frontend_checks_decl context') decls + | Some (decls, _) -> IList.iter (do_frontend_checks_decl context_with_orig_current_method) decls | None -> () let context_with_ck_set context decl_list =