[clang] Remove dependency of mk_c_function from is_cpp

Reviewed By: mbouaziz

Differential Revision: D8188881

fbshipit-source-id: dd191dc
master
Dulma Churchill 7 years ago committed by Facebook Github Bot
parent d7d3e16d6f
commit 663a923ee1

@ -1 +1 @@
Subproject commit 74635a68ec1fee857cf1d3c3bfa7503f3a41491e Subproject commit f31f7c9c28d8fb9b59c0dacc74a24e4bfe90a904

@ -510,7 +510,7 @@ and get_template_info tenv (fdi: Clang_ast_t.function_decl_info) =
Typ.NoTemplate Typ.NoTemplate
and mk_c_function ?tenv ~is_cpp name function_decl_info_opt = and mk_c_function ?tenv name function_decl_info_opt =
let file = let file =
match function_decl_info_opt with match function_decl_info_opt with
| Some (decl_info, function_decl_info) -> ( | Some (decl_info, function_decl_info) -> (
@ -531,12 +531,12 @@ and mk_c_function ?tenv ~is_cpp name function_decl_info_opt =
| None -> | None ->
"" ""
in in
let mangled_opt = let mangled_opt, is_cpp =
match function_decl_info_opt with match function_decl_info_opt with
| Some (_, function_decl_info) -> | Some (_, function_decl_info) ->
function_decl_info.Clang_ast_t.fdi_mangled_name (function_decl_info.Clang_ast_t.fdi_mangled_name, function_decl_info.Clang_ast_t.fdi_is_cpp)
| _ -> | _ ->
None (None, false)
in in
let mangled_name = match mangled_opt with Some m when is_cpp -> m | _ -> "" in let mangled_name = match mangled_opt with Some m when is_cpp -> m | _ -> "" in
let template_info = let template_info =
@ -606,13 +606,12 @@ and objc_block_procname outer_proc_opt =
(* TODO: get the parameters from BuildMethodSignature.get_parameters and pass it to the method names *) (* TODO: get the parameters from BuildMethodSignature.get_parameters and pass it to the method names *)
and from_decl ?tenv ~is_cpp ?outer_proc meth_decl = and from_decl ?tenv ?outer_proc meth_decl =
let open Clang_ast_t in let open Clang_ast_t in
match meth_decl with match meth_decl with
| FunctionDecl (decl_info, name_info, _, fdi) -> | FunctionDecl (decl_info, name_info, _, fdi) ->
let name = CAst_utils.get_qualified_name name_info in let name = CAst_utils.get_qualified_name name_info in
let function_info = Some (decl_info, fdi) in mk_c_function ?tenv name (Some (decl_info, fdi))
mk_c_function ~is_cpp ?tenv name function_info
| CXXMethodDecl (decl_info, name_info, _, fdi, mdi) | CXXMethodDecl (decl_info, name_info, _, fdi, mdi)
| CXXConstructorDecl (decl_info, name_info, _, fdi, mdi) | CXXConstructorDecl (decl_info, name_info, _, fdi, mdi)
| CXXConversionDecl (decl_info, name_info, _, fdi, mdi) | CXXConversionDecl (decl_info, name_info, _, fdi, mdi)
@ -641,7 +640,7 @@ and get_struct_methods struct_decl tenv =
| CXXDestructorDecl _ | CXXDestructorDecl _
| ObjCMethodDecl _ | ObjCMethodDecl _
| BlockDecl _ -> | BlockDecl _ ->
Some (from_decl ~is_cpp:true ~tenv decl) Some (from_decl ~tenv decl)
| _ -> | _ ->
None ) None )
@ -700,9 +699,9 @@ module CProcname = struct
let from_decl = from_decl let from_decl = from_decl
module NoAstDecl = struct module NoAstDecl = struct
let c_function_of_string ~is_cpp tenv name = let c_function_of_string tenv name =
let qual_name = QualifiedCppName.of_qual_string name in let qual_name = QualifiedCppName.of_qual_string name in
mk_c_function ~is_cpp ~tenv qual_name None mk_c_function ~tenv qual_name None
let cpp_method_of_string tenv class_name method_name = let cpp_method_of_string tenv class_name method_name =
@ -713,7 +712,7 @@ module CProcname = struct
mk_objc_method class_name method_name method_kind mk_objc_method class_name method_name method_kind
end end
let from_decl_for_linters ~is_cpp method_decl = let from_decl_for_linters method_decl =
let open Clang_ast_t in let open Clang_ast_t in
match method_decl with match method_decl with
| ObjCMethodDecl (decl_info, name_info, mdi) -> | ObjCMethodDecl (decl_info, name_info, mdi) ->
@ -726,7 +725,7 @@ module CProcname = struct
in in
objc_method_procname decl_info method_name mdi objc_method_procname decl_info method_name mdi
| _ -> | _ ->
from_decl ~is_cpp method_decl from_decl method_decl
end end
let get_type_from_expr_info ei tenv = let get_type_from_expr_info ei tenv =

@ -10,12 +10,11 @@
open! IStd open! IStd
module CProcname : sig module CProcname : sig
val from_decl : val from_decl : ?tenv:Tenv.t -> ?outer_proc:Typ.Procname.t -> Clang_ast_t.decl -> Typ.Procname.t
?tenv:Tenv.t -> is_cpp:bool -> ?outer_proc:Typ.Procname.t -> Clang_ast_t.decl -> Typ.Procname.t
(** Given decl, return its procname. This function should be used for all procedures (** Given decl, return its procname. This function should be used for all procedures
present in original AST *) present in original AST *)
val from_decl_for_linters : is_cpp:bool -> Clang_ast_t.decl -> Typ.Procname.t val from_decl_for_linters : Clang_ast_t.decl -> Typ.Procname.t
(** This is used for bug hashing for linters. In ObjC the method names contain the parameter names, (** 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 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 reporting on unchanged code. So, in the ObjC method case, we create the method name only based on the
@ -23,7 +22,7 @@ module CProcname : sig
(** WARNING: functions from this module should not be used if full decl is available in AST *) (** WARNING: functions from this module should not be used if full decl is available in AST *)
module NoAstDecl : sig module NoAstDecl : sig
val c_function_of_string : is_cpp:bool -> Tenv.t -> string -> Typ.Procname.t val c_function_of_string : Tenv.t -> string -> Typ.Procname.t
val cpp_method_of_string : Tenv.t -> Typ.Name.t -> string -> Typ.Procname.t val cpp_method_of_string : Tenv.t -> Typ.Name.t -> string -> Typ.Procname.t

@ -112,7 +112,7 @@ module CFrontend_decl_funct (T : CModule_type.CTranslation) : CModule_type.CFron
| Some (_, block_return_type, procname, _) -> | Some (_, block_return_type, procname, _) ->
(procname, Some block_return_type) (procname, Some block_return_type)
| _ -> | _ ->
(CType_decl.CProcname.from_decl ~is_cpp ~tenv func_decl, None) (CType_decl.CProcname.from_decl ~tenv func_decl, None)
in in
let ms, body_opt, extra_instrs = let ms, body_opt, extra_instrs =
CType_decl.method_signature_body_of_decl ~is_cpp tenv func_decl ?block_return_type procname CType_decl.method_signature_body_of_decl ~is_cpp tenv func_decl ?block_return_type procname
@ -137,7 +137,7 @@ module CFrontend_decl_funct (T : CModule_type.CTranslation) : CModule_type.CFron
let is_cpp = CGeneral_utils.is_cpp_translation trans_unit_ctx in let is_cpp = CGeneral_utils.is_cpp_translation trans_unit_ctx in
try try
let ms, body_opt, extra_instrs = let ms, body_opt, extra_instrs =
let procname = CType_decl.CProcname.from_decl ~is_cpp ~tenv meth_decl in let procname = CType_decl.CProcname.from_decl ~tenv meth_decl in
CType_decl.method_signature_body_of_decl ~is_cpp tenv meth_decl procname CType_decl.method_signature_body_of_decl ~is_cpp tenv meth_decl procname
in in
match body_opt with match body_opt with

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

@ -27,7 +27,7 @@ let method_signature_of_pointer trans_unit_ctx tenv pointer =
try try
match CAst_utils.get_decl pointer with match CAst_utils.get_decl pointer with
| Some meth_decl -> | Some meth_decl ->
let procname = CType_decl.CProcname.from_decl ~is_cpp ~tenv meth_decl in let procname = CType_decl.CProcname.from_decl ~tenv meth_decl in
let ms = CType_decl.method_signature_of_decl ~is_cpp tenv meth_decl procname in let ms = CType_decl.method_signature_of_decl ~is_cpp tenv meth_decl procname in
Some ms Some ms
| None -> | None ->
@ -333,8 +333,7 @@ let create_procdesc_with_pointer context pointer class_name_opt name =
( CType_decl.CProcname.NoAstDecl.cpp_method_of_string context.tenv class_name name ( CType_decl.CProcname.NoAstDecl.cpp_method_of_string context.tenv class_name name
, ProcAttributes.CPP_INSTANCE ) , ProcAttributes.CPP_INSTANCE )
| None -> | None ->
let is_cpp = CGeneral_utils.is_cpp_translation context.translation_unit_context in ( CType_decl.CProcname.NoAstDecl.c_function_of_string context.tenv name
( CType_decl.CProcname.NoAstDecl.c_function_of_string ~is_cpp context.tenv name
, ProcAttributes.C_FUNCTION ) , ProcAttributes.C_FUNCTION )
in in
create_external_procdesc context.cfg callee_name method_kind None ; create_external_procdesc context.cfg callee_name method_kind None ;

@ -2637,13 +2637,10 @@ module CTrans_funct (F : CModule_type.CFrontend) : CModule_type.CTranslation = s
and blockExpr_trans trans_state stmt_info expr_info decl = and blockExpr_trans trans_state stmt_info expr_info decl =
let context = trans_state.context in let context = trans_state.context in
let outer_proc = Procdesc.get_proc_name context.CContext.procdesc in let outer_proc = Procdesc.get_proc_name context.CContext.procdesc in
let is_cpp = CGeneral_utils.is_cpp_translation context.translation_unit_context in
match decl with match decl with
| Clang_ast_t.BlockDecl (_, block_decl_info) -> | Clang_ast_t.BlockDecl (_, block_decl_info) ->
let open CContext in let open CContext in
let block_pname = let block_pname = CType_decl.CProcname.from_decl decl ~tenv:context.tenv ~outer_proc in
CType_decl.CProcname.from_decl decl ~tenv:context.tenv ~is_cpp ~outer_proc
in
let captured_pvars = let captured_pvars =
CVar_decl.captured_vars_from_block_info context stmt_info.Clang_ast_t.si_source_range CVar_decl.captured_vars_from_block_info context stmt_info.Clang_ast_t.si_source_range
block_decl_info.Clang_ast_t.bdi_captured_variables block_decl_info.Clang_ast_t.bdi_captured_variables

Loading…
Cancel
Save