[clang] make it easier to call CProcname.from_decl

Summary:
This required a translation unit context, but really all it needs is a bool specifying whether the procname is a cpp name.
Makes it easier to call this function from a place where I'll need it in the near future.

Reviewed By: jvillard

Differential Revision: D7812835

fbshipit-source-id: 7900893
master
Sam Blackshear 7 years ago committed by Facebook Github Bot
parent ce0ffaf877
commit 9b2ac3de6e

@ -52,7 +52,7 @@ let is_decl_info_generic_model {Clang_ast_t.di_attributes} =
List.exists ~f di_attributes
let mk_c_function translation_unit_context ?tenv name function_decl_info_opt =
let mk_c_function ?tenv ~is_cpp name function_decl_info_opt =
let file =
match function_decl_info_opt with
| Some (decl_info, function_decl_info) -> (
@ -80,13 +80,7 @@ let mk_c_function translation_unit_context ?tenv name function_decl_info_opt =
| _ ->
None
in
let mangled_name =
match mangled_opt with
| Some m when CGeneral_utils.is_cpp_translation translation_unit_context ->
m
| _ ->
""
in
let mangled_name = match mangled_opt with Some m when is_cpp -> m | _ -> "" in
let template_info, is_generic_model =
match (function_decl_info_opt, tenv) with
| Some (decl_info, function_decl_info), Some t ->
@ -172,9 +166,9 @@ let get_class_typename ?tenv method_decl_info =
module NoAstDecl = struct
let c_function_of_string translation_unit_context tenv name =
let c_function_of_string ~is_cpp tenv name =
let qual_name = QualifiedCppName.of_qual_string name in
mk_c_function translation_unit_context ~tenv qual_name None
mk_c_function ~is_cpp ~tenv qual_name None
let cpp_method_of_string tenv class_name method_name =
@ -192,13 +186,13 @@ let objc_method_procname ?tenv decl_info method_name mdi =
mk_objc_method class_typename method_name method_kind
let from_decl translation_unit_context ?tenv meth_decl =
let from_decl ?tenv ~is_cpp meth_decl =
let open Clang_ast_t in
match meth_decl with
| FunctionDecl (decl_info, name_info, _, fdi) ->
let name = CAst_utils.get_qualified_name name_info in
let function_info = Some (decl_info, fdi) in
mk_c_function translation_unit_context ?tenv name function_info
mk_c_function ~is_cpp ?tenv name function_info
| CXXMethodDecl (decl_info, name_info, _, fdi, mdi)
| CXXConstructorDecl (decl_info, name_info, _, fdi, mdi)
| CXXConversionDecl (decl_info, name_info, _, fdi, mdi)
@ -220,7 +214,7 @@ let from_decl translation_unit_context ?tenv meth_decl =
(Clang_ast_proj.get_decl_kind_string meth_decl)
let from_decl_for_linters translation_unit_context method_decl =
let from_decl_for_linters ~is_cpp method_decl =
let open Clang_ast_t in
match method_decl with
| ObjCMethodDecl (decl_info, name_info, mdi) ->
@ -233,4 +227,4 @@ let from_decl_for_linters translation_unit_context method_decl =
in
objc_method_procname decl_info method_name mdi
| _ ->
from_decl translation_unit_context method_decl
from_decl ~is_cpp method_decl

@ -9,13 +9,11 @@
open! IStd
val from_decl :
CFrontend_config.translation_unit_context -> ?tenv:Tenv.t -> Clang_ast_t.decl -> Typ.Procname.t
val from_decl : ?tenv:Tenv.t -> is_cpp:bool -> Clang_ast_t.decl -> Typ.Procname.t
(** Given decl, return its procname. This function should be used for all procedures
present in original AST *)
val from_decl_for_linters :
CFrontend_config.translation_unit_context -> Clang_ast_t.decl -> Typ.Procname.t
val from_decl_for_linters : is_cpp:bool -> Clang_ast_t.decl -> Typ.Procname.t
(** This is used for bug hashing for linters. In ObjC the method names contain the parameter names,
thus if people add new parameters, any bug about the method will be considered different which means
reporting on unchanged code. So, in the ObjC method case, we create the method name only based on the
@ -23,8 +21,7 @@ val from_decl_for_linters :
(** WARNING: functions from this module should not be used if full decl is available in AST *)
module NoAstDecl : sig
val c_function_of_string :
CFrontend_config.translation_unit_context -> Tenv.t -> string -> Typ.Procname.t
val c_function_of_string : is_cpp:bool -> Tenv.t -> string -> Typ.Procname.t
val cpp_method_of_string : Tenv.t -> Typ.Name.t -> string -> Typ.Procname.t

@ -436,12 +436,12 @@ let expand_checkers macro_map path_map checkers =
(** Add a frontend warning with a description desc at location loc to the errlog of a proc desc *)
let log_frontend_issue translation_unit_context method_decl_opt (node: Ctl_parser_types.ast_node)
let log_frontend_issue ~is_cpp method_decl_opt (node: Ctl_parser_types.ast_node)
(issue_desc: CIssue.issue_desc) linters_def_file =
let procname =
match method_decl_opt with
| Some method_decl ->
CProcname.from_decl_for_linters translation_unit_context method_decl
CProcname.from_decl_for_linters ~is_cpp method_decl
| None ->
Typ.Procname.Linters_dummy_method
in
@ -471,9 +471,12 @@ let fill_issue_desc_info_and_log context an (issue_desc: CIssue.issue_desc) lint
let description = process_message issue_desc.description in
let suggestion = Option.map ~f:process_message issue_desc.suggestion in
let issue_desc' = {issue_desc with description; loc; suggestion} in
let is_cpp =
CGeneral_utils.is_cpp_translation context.CLintersContext.translation_unit_context
in
try
log_frontend_issue context.CLintersContext.translation_unit_context
context.CLintersContext.current_method an issue_desc' linters_def_file
log_frontend_issue ~is_cpp context.CLintersContext.current_method an issue_desc'
linters_def_file
with CFrontend_config.IncorrectAssumption e ->
let trans_unit_ctx = context.CLintersContext.translation_unit_context in
ClangLogging.log_caught_exception trans_unit_ctx "IncorrectAssumption" e.position

@ -186,17 +186,18 @@ let get_init_list_instrs method_decl_info =
let method_signature_of_decl trans_unit_ctx tenv meth_decl block_data_opt =
let open Clang_ast_t in
let is_cpp = CGeneral_utils.is_cpp_translation trans_unit_ctx in
match (meth_decl, block_data_opt) with
| FunctionDecl (decl_info, _, qt, fdi), _ ->
let func_decl = Func_decl_info (fdi, qt) in
let procname = CProcname.from_decl trans_unit_ctx ~tenv meth_decl in
let procname = CProcname.from_decl ~is_cpp ~tenv meth_decl in
let ms = build_method_signature trans_unit_ctx tenv decl_info procname func_decl None None in
(ms, fdi.Clang_ast_t.fdi_body, [])
| CXXMethodDecl (decl_info, _, qt, fdi, mdi), _
| CXXConstructorDecl (decl_info, _, qt, fdi, mdi), _
| CXXConversionDecl (decl_info, _, qt, fdi, mdi), _
| CXXDestructorDecl (decl_info, _, qt, fdi, mdi), _ ->
let procname = CProcname.from_decl trans_unit_ctx ~tenv meth_decl in
let procname = CProcname.from_decl ~is_cpp ~tenv meth_decl in
let parent_ptr = Option.value_exn decl_info.di_parent_pointer in
let method_decl = Cpp_Meth_decl_info (fdi, mdi, parent_ptr, qt) in
let parent_pointer = decl_info.Clang_ast_t.di_parent_pointer in
@ -208,7 +209,7 @@ let method_signature_of_decl trans_unit_ctx tenv meth_decl block_data_opt =
(* it will be empty for methods *)
(ms, fdi.Clang_ast_t.fdi_body, init_list_instrs)
| ObjCMethodDecl (decl_info, _, mdi), _ ->
let procname = CProcname.from_decl trans_unit_ctx ~tenv meth_decl in
let procname = CProcname.from_decl ~is_cpp ~tenv meth_decl in
let parent_ptr = Option.value_exn decl_info.di_parent_pointer in
let method_decl = ObjC_Meth_decl_info (mdi, parent_ptr) in
let parent_pointer = decl_info.Clang_ast_t.di_parent_pointer in
@ -658,8 +659,8 @@ let create_procdesc_with_pointer context pointer class_name_opt name =
( CProcname.NoAstDecl.cpp_method_of_string context.tenv class_name name
, ProcAttributes.CPP_INSTANCE )
| None ->
( CProcname.NoAstDecl.c_function_of_string context.translation_unit_context
context.tenv name
let is_cpp = CGeneral_utils.is_cpp_translation context.translation_unit_context in
( CProcname.NoAstDecl.c_function_of_string ~is_cpp context.tenv name
, ProcAttributes.C_FUNCTION )
in
create_external_procdesc context.cfg callee_name method_kind None ;

Loading…
Cancel
Save