diff --git a/infer/src/clang/cFrontend_checkers.ml b/infer/src/clang/cFrontend_checkers.ml index 616049580..b9e5bfaf2 100644 --- a/infer/src/clang/cFrontend_checkers.ml +++ b/infer/src/clang/cFrontend_checkers.ml @@ -40,14 +40,6 @@ let location_from_an lcxt an = | Ctl_parser_types.Stmt st -> location_from_stmt lcxt st | Ctl_parser_types.Decl d -> location_from_decl lcxt d -let decl_name an = - match an with - | Ctl_parser_types.Decl dec -> - (match Clang_ast_proj.get_named_decl_tuple dec with - | Some (_, n) -> n.Clang_ast_t.ni_name - | None -> "") - | _ -> "" - let tag_name_of_node an = match an with | Ctl_parser_types.Stmt stmt -> Clang_ast_proj.get_stmt_kind_string stmt @@ -56,9 +48,9 @@ let tag_name_of_node an = let decl_ref_or_selector_name an = match CTL.next_state_via_transition an (Some CTL.PointerToDecl) with | Some (Ctl_parser_types.Decl ObjCMethodDecl _ as decl_an) -> - "The selector " ^ (decl_name decl_an) + "The selector " ^ (Ctl_parser_types.ast_node_name decl_an) | Some (Ctl_parser_types.Decl _ as decl_an) -> - "The reference " ^ (decl_name decl_an) + "The reference " ^ (Ctl_parser_types.ast_node_name decl_an) | _ -> failwith("decl_ref_or_selector_name must be called with a DeclRefExpr \ or an ObjCMessageExpr, but got " ^ (tag_name_of_node an)) diff --git a/infer/src/clang/cFrontend_checkers.mli b/infer/src/clang/cFrontend_checkers.mli index efb81d1fd..7e53a19fa 100644 --- a/infer/src/clang/cFrontend_checkers.mli +++ b/infer/src/clang/cFrontend_checkers.mli @@ -21,8 +21,6 @@ val location_from_an : val location_from_decl : CLintersContext.context -> Clang_ast_t.decl -> Location.t -val decl_name : Ctl_parser_types.ast_node -> string - val ivar_name : Ctl_parser_types.ast_node -> string val cxx_ref_captured_in_block : Ctl_parser_types.ast_node -> string diff --git a/infer/src/clang/cFrontend_errors.ml b/infer/src/clang/cFrontend_errors.ml index 7da579f82..e6735a13a 100644 --- a/infer/src/clang/cFrontend_errors.ml +++ b/infer/src/clang/cFrontend_errors.ml @@ -74,7 +74,7 @@ let parsed_linters = ref [] let evaluate_place_holder ph an = match ph with | "%ivar_name%" -> MF.monospaced_to_string (CFrontend_checkers.ivar_name an) - | "%decl_name%" -> MF.monospaced_to_string (CFrontend_checkers.decl_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) | "%decl_ref_or_selector_name%" -> diff --git a/infer/src/clang/cTL.ml b/infer/src/clang/cTL.ml index 39866572b..09e192e8f 100644 --- a/infer/src/clang/cTL.ml +++ b/infer/src/clang/cTL.ml @@ -150,10 +150,10 @@ module Debug = struct pp_formula phi let pp_ast ~ast_node_to_highlight ?(prettifier=Fn.id) fmt root = - let pp_node_info fmt an = match an with - | Stmt (ObjCMessageExpr (_, _, _, {omei_selector})) -> - Format.fprintf fmt "selector: \"%s\"" omei_selector - | _ -> Format.ifprintf fmt "" in + let pp_node_info fmt an = + let name = Ctl_parser_types.ast_node_name an in + let typ = Ctl_parser_types.ast_node_type an in + Format.fprintf fmt " %s %s" name typ in let rec pp_children pp_node wrapper fmt level nodes = match nodes with | [] -> () diff --git a/infer/src/clang/ctl_parser_types.ml b/infer/src/clang/ctl_parser_types.ml index b5a128824..f098b62a7 100644 --- a/infer/src/clang/ctl_parser_types.ml +++ b/infer/src/clang/ctl_parser_types.ml @@ -17,6 +17,25 @@ type ast_node = | Stmt of Clang_ast_t.stmt | Decl of Clang_ast_t.decl +let ast_node_name an = + let open Clang_ast_t in + match an with + | Decl dec -> + (match Clang_ast_proj.get_named_decl_tuple dec with + | Some (_, n) -> n.Clang_ast_t.ni_name + | None -> "") + | Stmt (DeclRefExpr (_, _, _, drti)) -> + (match drti.drti_decl_ref with + | Some dr -> + let ndi, _, _ = CAst_utils.get_info_from_decl_ref dr in + ndi.ni_name + | _ -> "") + | Stmt (ObjCIvarRefExpr(_, _, _, obj_c_ivar_ref_expr_info)) -> + let ndi, _, _ = CAst_utils.get_info_from_decl_ref obj_c_ivar_ref_expr_info.ovrei_decl_ref in + ndi.ni_name + | Stmt (ObjCMessageExpr (_, _, _, {omei_selector})) -> + omei_selector + | _ -> "" let infer_prefix = "__infer_ctl_" let report_when_const = "report_when" @@ -27,7 +46,6 @@ let mode_const = "mode" exception ALParsingException of string - (* Data structures for type parser. Correspondence with clang types inferred from StringRef BuiltinType::getName in @@ -95,7 +113,6 @@ let builtin_kind_to_string t = | ObjCClass -> "Class" | ObjCSel -> "SEL" - type abs_ctype = | BuiltIn of builtin_kind @@ -149,3 +166,23 @@ let tmp_c_type_equal ?name_c_type c_type abs_ctype = Type compared: c_type = `%s` abs_ctype =`%s`\n" name (abs_ctype_to_string abs_ctype); false + +(* to be extended with more types *) +let typ_string_of_type_ptr type_ptr = + match CAst_utils.get_type type_ptr with + | Some Clang_ast_t.BuiltinType (_, bt) -> + Clang_ast_j.string_of_builtin_type_kind bt + | _ -> "" + +let ast_node_type an = + match an with + | Stmt stmt -> + (match Clang_ast_proj.get_expr_tuple stmt with + | Some (_, _, expr_info) -> + typ_string_of_type_ptr expr_info.ei_qual_type.qt_type_ptr + | _ -> "") + | Decl decl -> + (match CAst_utils.type_of_decl decl with + | Some type_ptr -> + typ_string_of_type_ptr type_ptr + | _ -> "") diff --git a/infer/src/ctl_parser_types.mli b/infer/src/ctl_parser_types.mli new file mode 100644 index 000000000..af63a17a1 --- /dev/null +++ b/infer/src/ctl_parser_types.mli @@ -0,0 +1,32 @@ +(* + * Copyright (c) 2017 - present Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + *) + +(* Types used by the ctl parser *) + +(** the kind of AST nodes where formulas are evaluated *) +type ast_node = + | Stmt of Clang_ast_t.stmt + | Decl of Clang_ast_t.decl + +val ast_node_name : ast_node -> string + +val ast_node_type : ast_node -> string + +exception ALParsingException of string + +val infer_prefix : string +val report_when_const : string +val message_const : string +val suggestion_const : string +val severity_const : string +val mode_const : string + +type abs_ctype + +val tmp_c_type_equal : ?name_c_type : string -> Clang_ast_t.c_type -> abs_ctype -> bool