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 :