From 88897addfab18cd3e28623ba67401bf37149d373 Mon Sep 17 00:00:00 2001 From: Ryan Rhee Date: Thu, 11 Aug 2016 14:21:36 -0700 Subject: [PATCH] Add in_main_file to context Reviewed By: jvillard Differential Revision: D3705270 fbshipit-source-id: dd693ad --- infer/src/clang/cFrontend_utils.ml | 5 +++++ infer/src/clang/cFrontend_utils.mli | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/infer/src/clang/cFrontend_utils.ml b/infer/src/clang/cFrontend_utils.ml index 364c73d57..ed3efae39 100644 --- a/infer/src/clang/cFrontend_utils.ml +++ b/infer/src/clang/cFrontend_utils.ml @@ -499,6 +499,11 @@ struct Some (decl_list, impl_decl_info) | _ -> None + let is_in_main_file decl = + let decl_info = Clang_ast_proj.get_decl_tuple decl in + let file_opt = (fst decl_info.Clang_ast_t.di_source_range).Clang_ast_t.sl_file in + opt_equal string_equal file_opt Config.source_file && Option.is_some file_opt + (* let rec getter_attribute_opt attributes = match attributes with diff --git a/infer/src/clang/cFrontend_utils.mli b/infer/src/clang/cFrontend_utils.mli index 1a9fe6c1b..a0c504bbd 100644 --- a/infer/src/clang/cFrontend_utils.mli +++ b/infer/src/clang/cFrontend_utils.mli @@ -171,6 +171,11 @@ sig Clang_ast_t.obj_c_implementation_decl_info) option + (** Returns true if the declaration or statement is inside the main source + file, as opposed to an imported header file. For statements, this refers + to the parent decl. *) + val is_in_main_file : Clang_ast_t.decl -> bool + end module General_utils :