From a18cf040df3535918648cca91b044f69410c4186 Mon Sep 17 00:00:00 2001 From: Jules Villard Date: Fri, 23 Aug 2019 01:23:23 -0700 Subject: [PATCH] [al] better distinction AL vs frontend in file names Summary: Rename some AL source files so they mention AL explicitly instead of "cFrontend" which could be confused with the clang frontend itself. Reviewed By: ezgicicek Differential Revision: D16962539 fbshipit-source-id: 29237cd1c --- .../al/{cFrontend_checkers_main.ml => AL.ml} | 39 +++++++++---------- .../{cFrontend_checkers_main.mli => AL.mli} | 0 .../al/{cFrontend_errors.ml => ALIssues.ml} | 18 ++++----- .../al/{cFrontend_errors.mli => ALIssues.mli} | 0 .../al/{cFrontend_checkers.ml => ALUtils.ml} | 1 + .../{cFrontend_checkers.mli => ALUtils.mli} | 0 infer/src/al/ComponentKit.ml | 14 +++---- infer/src/al/tableaux.ml | 12 +++--- infer/src/al/tableaux.mli | 9 ++--- infer/src/clang/Capture.ml | 2 +- ...ontend_errorsTests.ml => ALIssuesTests.ml} | 2 +- infer/src/unit/clang/ALIssuesTests.mli | 10 +++++ infer/src/unit/clang/ClangTests.ml | 3 +- 13 files changed, 58 insertions(+), 52 deletions(-) rename infer/src/al/{cFrontend_checkers_main.ml => AL.ml} (92%) rename infer/src/al/{cFrontend_checkers_main.mli => AL.mli} (100%) rename infer/src/al/{cFrontend_errors.ml => ALIssues.ml} (96%) rename infer/src/al/{cFrontend_errors.mli => ALIssues.mli} (100%) rename infer/src/al/{cFrontend_checkers.ml => ALUtils.ml} (99%) rename infer/src/al/{cFrontend_checkers.mli => ALUtils.mli} (100%) rename infer/src/unit/clang/{CFrontend_errorsTests.ml => ALIssuesTests.ml} (92%) create mode 100644 infer/src/unit/clang/ALIssuesTests.mli diff --git a/infer/src/al/cFrontend_checkers_main.ml b/infer/src/al/AL.ml similarity index 92% rename from infer/src/al/cFrontend_checkers_main.ml rename to infer/src/al/AL.ml index 7c5bc7f4b..cd5ac3d8d 100644 --- a/infer/src/al/cFrontend_checkers_main.ml +++ b/infer/src/al/AL.ml @@ -56,7 +56,7 @@ and parse_imports ~from_file imports_files = List.fold_right ~f:parse_one_import_file ~init:([], []) imports_files -let parse_ctl_file linters_def_file channel : CFrontend_errors.linter list = +let parse_ctl_file linters_def_file channel : ALIssues.linter list = match CTLParserHelper.parse_al_file linters_def_file channel with | Some { import_files= imports @@ -68,20 +68,20 @@ let parse_ctl_file linters_def_file channel : CFrontend_errors.linter list = collect_all_macros_and_paths ~from_file:linters_def_file imports curr_file_macros curr_file_paths in - let macros_map = CFrontend_errors.build_macros_map macros in - let paths_map = CFrontend_errors.build_paths_map paths in + let macros_map = ALIssues.build_macros_map macros in + let paths_map = ALIssues.build_paths_map paths in L.(debug Linters Medium) "#### Start Expanding checkers #####@\n" ; - let exp_checkers = CFrontend_errors.expand_checkers macros_map paths_map parsed_checkers in + let exp_checkers = ALIssues.expand_checkers macros_map paths_map parsed_checkers in L.(debug Linters Medium) "#### Checkers Expanded #####@\n" ; if Config.debug_mode then List.iter ~f:CTL.print_checker exp_checkers ; - CFrontend_errors.create_parsed_linters linters_def_file exp_checkers + ALIssues.create_parsed_linters linters_def_file exp_checkers | None -> L.(debug Linters Medium) "No linters found.@\n" ; [] (** Parse the files with linters definitions, and return a list of linters *) -let parse_ctl_files linters_def_files : CFrontend_errors.linter list = +let parse_ctl_files linters_def_files : ALIssues.linter list = let collect_parsed_linters linters_def_file linters = L.(debug Linters Medium) "Loading linters rules from %s@\n" linters_def_file ; let in_channel = In_channel.create linters_def_file in @@ -246,7 +246,7 @@ let rec do_frontend_checks_stmt linters (context : CLintersContext.context) () ) ; do_frontend_checks_stmt linters context map_active stmt in - CFrontend_errors.invoke_set_of_checkers_on_node linters context an ; + ALIssues.invoke_set_of_checkers_on_node linters context an ; (* The map should be visited when we enter the node before visiting children *) let map_active = Tableaux.update_linter_context_map linters an map_act in let stmt_context_list = @@ -328,7 +328,7 @@ and do_frontend_checks_decl linters (context : CLintersContext.context) | BlockDecl _ | ObjCMethodDecl _ -> let context' = CLintersContext.update_current_method context decl in - CFrontend_errors.invoke_set_of_checkers_on_node linters context' an ; + ALIssues.invoke_set_of_checkers_on_node linters context' an ; (* We need to visit explicitly nodes reachable via Parameters transitions because they won't be visited during the evaluation of the formula *) do_frontend_checks_via_transition linters context' map_active an CTL.Parameters ; @@ -339,22 +339,22 @@ and do_frontend_checks_decl linters (context : CLintersContext.context) () ) ; call_tableaux linters context' an map_active | ObjCImplementationDecl (_, _, decls, _, _) | ObjCInterfaceDecl (_, _, decls, _, _) -> - CFrontend_errors.invoke_set_of_checkers_on_node linters context an ; + ALIssues.invoke_set_of_checkers_on_node linters context an ; let context' = {context with current_objc_class= Some decl} in List.iter ~f:(do_frontend_checks_decl linters context' map_active) decls ; call_tableaux linters context' an map_active | ObjCCategoryImplDecl (_, _, decls, _, _) | ObjCCategoryDecl (_, _, decls, _, _) -> - CFrontend_errors.invoke_set_of_checkers_on_node linters context an ; + ALIssues.invoke_set_of_checkers_on_node linters context an ; let context' = {context with current_objc_category= Some decl} in List.iter ~f:(do_frontend_checks_decl linters context' map_active) decls ; call_tableaux linters context' an map_active | ObjCProtocolDecl (_, _, decls, _, _) -> - CFrontend_errors.invoke_set_of_checkers_on_node linters context an ; + ALIssues.invoke_set_of_checkers_on_node linters context an ; let context' = {context with current_objc_protocol= Some decl} in List.iter ~f:(do_frontend_checks_decl linters context' map_active) decls ; call_tableaux linters context' an map_active | _ -> - CFrontend_errors.invoke_set_of_checkers_on_node linters context an ; + ALIssues.invoke_set_of_checkers_on_node linters context an ; ( match Clang_ast_proj.get_decl_context_tuple decl with | Some (decls, _) -> List.iter ~f:(do_frontend_checks_decl linters context map_active) decls @@ -381,7 +381,7 @@ let linters_files = let do_frontend_checks (trans_unit_ctx : CFrontend_config.translation_unit_context) ast = - CFrontend_errors.issue_log := IssueLog.empty ; + ALIssues.issue_log := IssueLog.empty ; L.(debug Capture Quiet) "Loading the following linters files: %a@\n" (Pp.comma_seq Format.pp_print_string) @@ -389,15 +389,15 @@ let do_frontend_checks (trans_unit_ctx : CFrontend_config.translation_unit_conte CTL.create_ctl_evaluation_tracker trans_unit_ctx.source_file ; let parsed_linters = let parsed_linters = parse_ctl_files linters_files in - CFrontend_errors.filter_parsed_linters parsed_linters trans_unit_ctx.source_file + ALIssues.filter_parsed_linters parsed_linters trans_unit_ctx.source_file in let source_file = trans_unit_ctx.CFrontend_config.source_file in L.(debug Linters Medium) - "Start linting file %a with rules: @\n%a@\n" SourceFile.pp source_file - CFrontend_errors.pp_linters parsed_linters ; + "Start linting file %a with rules: @\n%a@\n" SourceFile.pp source_file ALIssues.pp_linters + parsed_linters ; if Config.print_active_checkers then L.progress "Linting file %a, active linters: @\n%a@\n" SourceFile.pp source_file - CFrontend_errors.pp_linters parsed_linters ; + ALIssues.pp_linters parsed_linters ; Tableaux.init_global_nodes_valuation () ; match ast with | Clang_ast_t.TranslationUnitDecl (_, decl_list, _, _) -> @@ -405,10 +405,9 @@ let do_frontend_checks (trans_unit_ctx : CFrontend_config.translation_unit_conte let allowed_decls = List.filter ~f:(Tableaux.is_decl_allowed context) decl_list in (* We analyze the top level and then all the allowed declarations *) let active_map : Tableaux.context_linter_map = Tableaux.init_active_map parsed_linters in - CFrontend_errors.invoke_set_of_checkers_on_node parsed_linters context - (Ctl_parser_types.Decl ast) ; + ALIssues.invoke_set_of_checkers_on_node parsed_linters context (Ctl_parser_types.Decl ast) ; List.iter ~f:(do_frontend_checks_decl parsed_linters context active_map) allowed_decls ; - IssueLog.store !CFrontend_errors.issue_log ~dir:Config.lint_issues_dir_name ~file:source_file ; + IssueLog.store !ALIssues.issue_log ~dir:Config.lint_issues_dir_name ~file:source_file ; L.(debug Linters Medium) "End linting file %a@\n" SourceFile.pp source_file ; CTL.save_dotty_when_in_debug_mode trans_unit_ctx.CFrontend_config.source_file (*if CFrontend_config.tableaux_evaluation then ( diff --git a/infer/src/al/cFrontend_checkers_main.mli b/infer/src/al/AL.mli similarity index 100% rename from infer/src/al/cFrontend_checkers_main.mli rename to infer/src/al/AL.mli diff --git a/infer/src/al/cFrontend_errors.ml b/infer/src/al/ALIssues.ml similarity index 96% rename from infer/src/al/cFrontend_errors.ml rename to infer/src/al/ALIssues.ml index f24be1546..ef4993b33 100644 --- a/infer/src/al/cFrontend_errors.ml +++ b/infer/src/al/ALIssues.ml @@ -104,25 +104,25 @@ let stmt_checkers_list = List.map ~f:single_to_multi stmt_single_checkers_list let evaluate_place_holder context ph an = match ph with | "%ivar_name%" -> - MF.monospaced_to_string (CFrontend_checkers.ivar_name an) + MF.monospaced_to_string (ALUtils.ivar_name an) | "%decl_name%" -> MF.monospaced_to_string (Ctl_parser_types.ast_node_name an) | "%cxx_ref_captured_in_block%" -> - MF.monospaced_to_string (CFrontend_checkers.cxx_ref_captured_in_block an) + MF.monospaced_to_string (ALUtils.cxx_ref_captured_in_block an) | "%decl_ref_or_selector_name%" -> - MF.monospaced_to_string (CFrontend_checkers.decl_ref_or_selector_name an) + MF.monospaced_to_string (ALUtils.decl_ref_or_selector_name an) | "%receiver_method_call%" -> - MF.monospaced_to_string (CFrontend_checkers.receiver_method_call an) + MF.monospaced_to_string (ALUtils.receiver_method_call an) | "%iphoneos_target_sdk_version%" -> - MF.monospaced_to_string (CFrontend_checkers.iphoneos_target_sdk_version context an) + MF.monospaced_to_string (ALUtils.iphoneos_target_sdk_version context an) | "%available_ios_sdk%" -> - MF.monospaced_to_string (CFrontend_checkers.available_ios_sdk an) + MF.monospaced_to_string (ALUtils.available_ios_sdk an) | "%class_available_ios_sdk%" -> - MF.monospaced_to_string (CFrontend_checkers.class_available_ios_sdk an) + MF.monospaced_to_string (ALUtils.class_available_ios_sdk an) | "%type%" -> MF.monospaced_to_string (Ctl_parser_types.ast_node_type an) | "%class_name%" -> - CFrontend_checkers.class_name an + ALUtils.class_name an | "%child_type%" -> MF.monospaced_to_string (Ctl_parser_types.stmt_node_child_type an) | "%name%" -> @@ -529,7 +529,7 @@ let invoke_set_of_parsed_checkers_an parsed_linters context (an : Ctl_parser_typ | None -> () | Some witness -> - let loc = CFrontend_checkers.location_from_an context witness in + let loc = ALUtils.location_from_an context witness in fill_issue_desc_info_and_log context ~witness ~current_node:an linter.issue_desc loc ) parsed_linters diff --git a/infer/src/al/cFrontend_errors.mli b/infer/src/al/ALIssues.mli similarity index 100% rename from infer/src/al/cFrontend_errors.mli rename to infer/src/al/ALIssues.mli diff --git a/infer/src/al/cFrontend_checkers.ml b/infer/src/al/ALUtils.ml similarity index 99% rename from infer/src/al/cFrontend_checkers.ml rename to infer/src/al/ALUtils.ml index fd348f441..f104d08c7 100644 --- a/infer/src/al/cFrontend_checkers.ml +++ b/infer/src/al/ALUtils.ml @@ -9,6 +9,7 @@ open! IStd module L = Logging (* Helper functions *) + let location_from_stmt lctx stmt = let info, _ = Clang_ast_proj.get_stmt_tuple stmt in CLocation.location_of_source_range lctx.CLintersContext.translation_unit_context.source_file diff --git a/infer/src/al/cFrontend_checkers.mli b/infer/src/al/ALUtils.mli similarity index 100% rename from infer/src/al/cFrontend_checkers.mli rename to infer/src/al/ALUtils.mli diff --git a/infer/src/al/ComponentKit.ml b/infer/src/al/ComponentKit.ml index 34c825a05..b6d400856 100644 --- a/infer/src/al/ComponentKit.ml +++ b/infer/src/al/ComponentKit.ml @@ -158,7 +158,7 @@ let mutable_local_vars_advice context an = ^ MF.monospaced_to_string named_decl_info.ni_name ^ " should be const to avoid reassignment" ; suggestion= Some "Add a const (after the asterisk for pointer types)." - ; loc= CFrontend_checkers.location_from_dinfo context decl_info } + ; loc= ALUtils.location_from_dinfo context decl_info } | _ -> None else None @@ -194,7 +194,7 @@ let component_factory_function_advice context an = Some "Prefer subclassing CKCompositeComponent to static helper functions that return \ a CKComponent subclass." - ; loc= CFrontend_checkers.location_from_dinfo context decl_info } + ; loc= ALUtils.location_from_dinfo context decl_info } else None | _ -> None @@ -248,7 +248,7 @@ let component_with_unconventional_superclass_advice context an = ; mode= CIssue.On ; description= "Never Subclass Components" ; suggestion= Some "Instead, create a new subclass of CKCompositeComponent." - ; loc= CFrontend_checkers.location_from_decl context if_decl } + ; loc= ALUtils.location_from_decl context if_decl } else None else None | _ -> @@ -307,7 +307,7 @@ let component_with_multiple_factory_methods_advice context an = Some "Instead, always expose all parameters in a single designated initializer and \ document which are optional." - ; loc= CFrontend_checkers.location_from_decl context meth_decl } ) + ; loc= ALUtils.location_from_decl context meth_decl } ) (IList.drop factory_methods 1) | _ -> assert false @@ -383,7 +383,7 @@ let rec component_initializer_with_side_effects_advice_ (context : CLintersConte ; description= "No Side-effects" ; suggestion= Some "Your +new method should not modify any global variables or global state." - ; loc= CFrontend_checkers.location_from_stmt context call_stmt } + ; loc= ALUtils.location_from_stmt context call_stmt } | _ -> None ) | _ -> @@ -452,10 +452,10 @@ let component_file_cyclomatic_complexity_info (context : CLintersContext.context match an with | Ctl_parser_types.Stmt stmt when Config.compute_analytics && is_cyclo_stmt stmt && is_ck_context context an -> - Some (CFrontend_checkers.location_from_stmt context stmt) + Some (ALUtils.location_from_stmt context stmt) | Ctl_parser_types.Decl (Clang_ast_t.TranslationUnitDecl _ as d) when Config.compute_analytics && context.is_ck_translation_unit -> - Some (CFrontend_checkers.location_from_decl context d) + Some (ALUtils.location_from_decl context d) | _ -> None in diff --git a/infer/src/al/tableaux.ml b/infer/src/al/tableaux.ml index 407558b74..8958b84a8 100644 --- a/infer/src/al/tableaux.ml +++ b/infer/src/al/tableaux.ml @@ -64,8 +64,8 @@ let is_in_formula phi = match phi with CTL.InNode _ -> true | _ -> false let init_active_map parsed_linters = List.fold ~f:(fun acc_map linter -> - let not_inf = not (is_in_formula linter.CFrontend_errors.condition) in - ClosureHashtbl.add linter.CFrontend_errors.condition not_inf acc_map ) + let not_inf = not (is_in_formula linter.ALIssues.condition) in + ClosureHashtbl.add linter.ALIssues.condition not_inf acc_map ) ~init:ClosureHashtbl.empty parsed_linters @@ -76,7 +76,7 @@ let init_active_map parsed_linters = its subformulae *) let update_linter_context_map parsed_linters an linter_context_map = let do_one_linter acc_map linter = - let phi = linter.CFrontend_errors.condition in + let phi = linter.ALIssues.condition in match phi with | CTL.InNode (tl, _) -> ( try @@ -292,13 +292,13 @@ let rec is_state_only_formula phi = (i.e., it's in the analized file )*) let report_issue an lcxt linter (*npo_condition*) = let open Ctl_parser_types in - let open CFrontend_errors in + let open ALIssues in (*let name = Ctl_parser_types.ast_node_kind an in let pointer = Ctl_parser_types.ast_node_pointer an in L.(debug Linters Medium) "@\n@\n@\n ***** In (%i, %s) Reporting because we found @\n%a@\n@\n@\n@\n" pointer name CTL.Debug.pp_formula linter.condition ;*) - let loc = CFrontend_checkers.location_from_an lcxt an in + let loc = ALUtils.location_from_an lcxt an in let should_report = match an with Decl dec -> is_decl_allowed lcxt dec | Stmt _ -> true in if should_report then fill_issue_desc_info_and_log lcxt ~witness:an ~current_node:an linter.issue_desc loc @@ -321,7 +321,7 @@ let skip_evaluation_InNode_formula an phi = (* Build valuation, i.e. set of valid subformula for a pair (node, checker) *) let build_valuation parsed_linters an lcxt linter_map_context = - let open CFrontend_errors in + let open ALIssues in let node_pointer = Ctl_parser_types.ast_node_pointer an in (*L.(debug Linters Medium) "@\n@\n ******** Tableaux called for node %i ******** @\n@\n" node_pointer ;*) diff --git a/infer/src/al/tableaux.mli b/infer/src/al/tableaux.mli index ea589e54a..35be2357e 100644 --- a/infer/src/al/tableaux.mli +++ b/infer/src/al/tableaux.mli @@ -13,16 +13,13 @@ type context_linter_map = bool ClosureHashtbl.t val init_global_nodes_valuation : unit -> unit -val init_active_map : CFrontend_errors.linter list -> bool ClosureHashtbl.t +val init_active_map : ALIssues.linter list -> bool ClosureHashtbl.t val update_linter_context_map : - CFrontend_errors.linter list - -> Ctl_parser_types.ast_node - -> context_linter_map - -> context_linter_map + ALIssues.linter list -> Ctl_parser_types.ast_node -> context_linter_map -> context_linter_map val build_valuation : - CFrontend_errors.linter list + ALIssues.linter list -> Ctl_parser_types.ast_node -> CLintersContext.context -> context_linter_map diff --git a/infer/src/clang/Capture.ml b/infer/src/clang/Capture.ml index ce24bb5bf..da8f783ad 100644 --- a/infer/src/clang/Capture.ml +++ b/infer/src/clang/Capture.ml @@ -98,7 +98,7 @@ let run_clang_frontend ast_source = L.(debug Capture Quiet) "Clang frontend action is %s@\n" Config.clang_frontend_action_string ; L.(debug Capture Medium) "Start %s of AST from %a@\n" Config.clang_frontend_action_string pp_ast_filename ast_source ; - if Config.linters then CFrontend_checkers_main.do_frontend_checks trans_unit_ctx ast_decl ; + if Config.linters then AL.do_frontend_checks trans_unit_ctx ast_decl ; if Config.export_changed_functions then ( let source_file = trans_unit_ctx.CFrontend_config.source_file in let process_fn = AstToRangeMap.process_ast ast_decl (Tenv.create ()) source_file in diff --git a/infer/src/unit/clang/CFrontend_errorsTests.ml b/infer/src/unit/clang/ALIssuesTests.ml similarity index 92% rename from infer/src/unit/clang/CFrontend_errorsTests.ml rename to infer/src/unit/clang/ALIssuesTests.ml index 9eed3f73f..727f71dac 100644 --- a/infer/src/unit/clang/CFrontend_errorsTests.ml +++ b/infer/src/unit/clang/ALIssuesTests.ml @@ -13,7 +13,7 @@ let test_correct_removing_new_lines = Format.fprintf fmt "Expected: [%s] Found: [%s]" expected actual in let create_test (desc : string) (expected_desc : string) _ = - let output = CFrontend_errors.remove_new_lines_and_whitespace desc in + let output = ALIssues.remove_new_lines_and_whitespace desc in let cmp s1 s2 = String.equal s1 s2 in assert_equal ~pp_diff:pp_diff_of_desc ~cmp expected_desc output in diff --git a/infer/src/unit/clang/ALIssuesTests.mli b/infer/src/unit/clang/ALIssuesTests.mli new file mode 100644 index 000000000..73bb61726 --- /dev/null +++ b/infer/src/unit/clang/ALIssuesTests.mli @@ -0,0 +1,10 @@ +(* + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + *) + +open! IStd + +val tests : OUnit2.test diff --git a/infer/src/unit/clang/ClangTests.ml b/infer/src/unit/clang/ClangTests.ml index 8a1a9e2e9..bb2b5ddf0 100644 --- a/infer/src/unit/clang/ClangTests.ml +++ b/infer/src/unit/clang/ClangTests.ml @@ -6,5 +6,4 @@ *) open! IStd -let tests = - [CiOSVersionNumbersTests.tests; QualifiedCppNameTests.tests; CFrontend_errorsTests.tests] +let tests = [CiOSVersionNumbersTests.tests; QualifiedCppNameTests.tests; ALIssuesTests.tests]