[clang] make ast_node argument optional in Unimplemented and IncorrectAssumption exception raising functions

Summary:
- ast_node argument is now optional in functions `unimplemented` and `incorrect_assumption` in cFrontend_config
	- The argument type was already an option, and the majority of the calls were with 'None'. This makes the function more intuitive to use

Reviewed By: sblackshear

Differential Revision: D6846141

fbshipit-source-id: 13deb8f
master
Varun Arora 7 years ago committed by Facebook Github Bot
parent 80b3d080ce
commit 440040ada9

@ -178,7 +178,7 @@ let make_next_object_exp stmt_info item items =
let decl_ref_expr_info = make_decl_ref_expr_info decl_ref in let decl_ref_expr_info = make_decl_ref_expr_info decl_ref in
(Clang_ast_t.DeclRefExpr (stmt_info_var, [], expr_info, decl_ref_expr_info), var_qual_type) (Clang_ast_t.DeclRefExpr (stmt_info_var, [], expr_info, decl_ref_expr_info), var_qual_type)
| _ -> | _ ->
CFrontend_config.incorrect_assumption __POS__ stmt_info.Clang_ast_t.si_source_range None CFrontend_config.incorrect_assumption __POS__ stmt_info.Clang_ast_t.si_source_range
"unexpected item %a" "unexpected item %a"
(Pp.to_string ~f:Clang_ast_j.string_of_stmt) (Pp.to_string ~f:Clang_ast_j.string_of_stmt)
item item

@ -28,13 +28,13 @@ type exception_details =
exception Unimplemented of exception_details exception Unimplemented of exception_details
let unimplemented position source_range ast_node fmt = let unimplemented position source_range ?ast_node fmt =
F.kasprintf (fun msg -> raise (Unimplemented {msg; position; source_range; ast_node})) fmt F.kasprintf (fun msg -> raise (Unimplemented {msg; position; source_range; ast_node})) fmt
exception IncorrectAssumption of exception_details exception IncorrectAssumption of exception_details
let incorrect_assumption position source_range ast_node fmt = let incorrect_assumption position source_range ?ast_node fmt =
F.kasprintf (fun msg -> raise (IncorrectAssumption {msg; position; source_range; ast_node})) fmt F.kasprintf (fun msg -> raise (IncorrectAssumption {msg; position; source_range; ast_node})) fmt

@ -26,7 +26,7 @@ type exception_details =
exception Unimplemented of exception_details exception Unimplemented of exception_details
val unimplemented : val unimplemented :
string * int * int * int -> Clang_ast_t.source_range -> string option string * int * int * int -> Clang_ast_t.source_range -> ?ast_node:string
-> ('a, Format.formatter, unit, _) format4 -> 'a -> ('a, Format.formatter, unit, _) format4 -> 'a
(** Raise Unimplemented. This is caught at the level of translating a method and makes the frontend (** Raise Unimplemented. This is caught at the level of translating a method and makes the frontend
give up on that method. *) give up on that method. *)
@ -34,7 +34,7 @@ val unimplemented :
exception IncorrectAssumption of exception_details exception IncorrectAssumption of exception_details
val incorrect_assumption : val incorrect_assumption :
string * int * int * int -> Clang_ast_t.source_range -> string option string * int * int * int -> Clang_ast_t.source_range -> ?ast_node:string
-> ('a, Format.formatter, unit, _) format4 -> 'a -> ('a, Format.formatter, unit, _) format4 -> 'a
(** Used to mark places in the frontend that incorrectly assume something to be (** Used to mark places in the frontend that incorrectly assume something to be
impossible. TODO(t21762295) get rid of all instances of this. *) impossible. TODO(t21762295) get rid of all instances of this. *)

@ -87,7 +87,7 @@ let get_var_name_mangled decl_info name_info var_decl_info =
| "", Some index -> | "", Some index ->
"__param_" ^ string_of_int index "__param_" ^ string_of_int index
| "", None -> | "", None ->
CFrontend_config.incorrect_assumption __POS__ decl_info.Clang_ast_t.di_source_range None CFrontend_config.incorrect_assumption __POS__ decl_info.Clang_ast_t.di_source_range
"Got both empty clang_name and None for param_idx in get_var_name_mangled (%a) (%a)" "Got both empty clang_name and None for param_idx in get_var_name_mangled (%a) (%a)"
(Pp.to_string ~f:Clang_ast_j.string_of_named_decl_info) (Pp.to_string ~f:Clang_ast_j.string_of_named_decl_info)
name_info name_info

@ -393,13 +393,13 @@ module CTrans_funct (F : CModule_type.CFrontend) : CModule_type.CTranslation = s
let exps = [(exp, typ)] in let exps = [(exp, typ)] in
{empty_res_trans with exps; instrs} {empty_res_trans with exps; instrs}
| Tfun _ | Tvoid | Tarray _ | TVar _ -> | Tfun _ | Tvoid | Tarray _ | TVar _ ->
CFrontend_config.unimplemented __POS__ stmt_info.Clang_ast_t.si_source_range None CFrontend_config.unimplemented __POS__ stmt_info.Clang_ast_t.si_source_range
"fill_typ_with_zero on type %a" (Typ.pp Pp.text) typ "fill_typ_with_zero on type %a" (Typ.pp Pp.text) typ
in in
let res_trans = fill_typ_with_zero var_exp_typ in let res_trans = fill_typ_with_zero var_exp_typ in
{res_trans with initd_exps= [fst var_exp_typ]} {res_trans with initd_exps= [fst var_exp_typ]}
| None -> | None ->
CFrontend_config.unimplemented __POS__ stmt_info.Clang_ast_t.si_source_range None CFrontend_config.unimplemented __POS__ stmt_info.Clang_ast_t.si_source_range
"Retrieving var from non-InitListExpr parent" "Retrieving var from non-InitListExpr parent"
@ -516,7 +516,7 @@ module CTrans_funct (F : CModule_type.CFrontend) : CModule_type.CTranslation = s
assert false ) assert false )
| _ as decl -> | _ as decl ->
(* FIXME(t21762295): we do not expect this to happen but it does *) (* FIXME(t21762295): we do not expect this to happen but it does *)
CFrontend_config.incorrect_assumption __POS__ stmt_info.Clang_ast_t.si_source_range None CFrontend_config.incorrect_assumption __POS__ stmt_info.Clang_ast_t.si_source_range
"di_parent_pointer should be always set for fields/ivars, but got %a" "di_parent_pointer should be always set for fields/ivars, but got %a"
(Pp.option (Pp.to_string ~f:Clang_ast_j.string_of_decl)) (Pp.option (Pp.to_string ~f:Clang_ast_j.string_of_decl))
decl decl
@ -753,7 +753,7 @@ module CTrans_funct (F : CModule_type.CFrontend) : CModule_type.CTranslation = s
| `CXXMethod | `CXXConversion | `CXXConstructor | `CXXDestructor -> | `CXXMethod | `CXXConversion | `CXXConstructor | `CXXDestructor ->
method_deref_trans trans_state pre_trans_result decl_ref stmt_info decl_kind method_deref_trans trans_state pre_trans_result decl_ref stmt_info decl_kind
| _ -> | _ ->
CFrontend_config.unimplemented __POS__ stmt_info.Clang_ast_t.si_source_range None CFrontend_config.unimplemented __POS__ stmt_info.Clang_ast_t.si_source_range
"Decl ref expression %a with pointer %d still needs to be translated" "Decl ref expression %a with pointer %d still needs to be translated"
(Pp.to_string ~f:Clang_ast_j.string_of_decl_kind) (Pp.to_string ~f:Clang_ast_j.string_of_decl_kind)
decl_kind decl_ref.Clang_ast_t.dr_decl_pointer decl_kind decl_ref.Clang_ast_t.dr_decl_pointer
@ -991,7 +991,7 @@ module CTrans_funct (F : CModule_type.CFrontend) : CModule_type.CTranslation = s
if Int.equal (List.length params) (List.length params_stmt) then params if Int.equal (List.length params) (List.length params_stmt) then params
else else
(* FIXME(t21762295) this is reachable *) (* FIXME(t21762295) this is reachable *)
CFrontend_config.incorrect_assumption __POS__ si.Clang_ast_t.si_source_range None CFrontend_config.incorrect_assumption __POS__ si.Clang_ast_t.si_source_range
"In call to %a: stmt_list and res_trans_par.exps must have same size but they don't:@\nstmt_list(%d)=[%a]@\nres_trans_par.exps(%d)=[%a]@\n" "In call to %a: stmt_list and res_trans_par.exps must have same size but they don't:@\nstmt_list(%d)=[%a]@\nres_trans_par.exps(%d)=[%a]@\n"
Typ.Procname.pp procname (List.length params) (Pp.seq Exp.pp) Typ.Procname.pp procname (List.length params) (Pp.seq Exp.pp)
(List.map ~f:fst params) (List.length params_stmt) (List.map ~f:fst params) (List.length params_stmt)
@ -1025,7 +1025,7 @@ module CTrans_funct (F : CModule_type.CFrontend) : CModule_type.CTranslation = s
pn pn
| _ -> | _ ->
(* method pointer not implemented, this shouldn't happen but it does (t21762295) *) (* method pointer not implemented, this shouldn't happen but it does (t21762295) *)
CFrontend_config.incorrect_assumption __POS__ si.Clang_ast_t.si_source_range None CFrontend_config.incorrect_assumption __POS__ si.Clang_ast_t.si_source_range
"Could not resolve CXX method call %a" Exp.pp sil_method "Could not resolve CXX method call %a" Exp.pp sil_method
in in
(* As we may have nodes coming from different parameters we need to call instruction for each (* As we may have nodes coming from different parameters we need to call instruction for each
@ -1521,7 +1521,7 @@ module CTrans_funct (F : CModule_type.CFrontend) : CModule_type.CTranslation = s
let root_nodes' = if root_nodes <> [] then root_nodes else op_res_trans.root_nodes in let root_nodes' = if root_nodes <> [] then root_nodes else op_res_trans.root_nodes in
{op_res_trans with root_nodes= root_nodes'} {op_res_trans with root_nodes= root_nodes'}
| _ -> | _ ->
CFrontend_config.unimplemented __POS__ stmt_info.Clang_ast_t.si_source_range None CFrontend_config.unimplemented __POS__ stmt_info.Clang_ast_t.si_source_range
"BinaryConditionalOperator not translated" "BinaryConditionalOperator not translated"
@ -1853,7 +1853,7 @@ module CTrans_funct (F : CModule_type.CFrontend) : CModule_type.CTranslation = s
{empty_res_trans with root_nodes= top_nodes; leaf_nodes= succ_nodes} {empty_res_trans with root_nodes= top_nodes; leaf_nodes= succ_nodes}
| _ -> | _ ->
(* TODO(t21762295) this raises sometimes *) (* TODO(t21762295) this raises sometimes *)
CFrontend_config.incorrect_assumption __POS__ stmt_info.Clang_ast_t.si_source_range None CFrontend_config.incorrect_assumption __POS__ stmt_info.Clang_ast_t.si_source_range
"Unexpected Switch Statement sub-expression list: [%a]" "Unexpected Switch Statement sub-expression list: [%a]"
(Pp.semicolon_seq (Pp.to_string ~f:Clang_ast_j.string_of_stmt)) (Pp.semicolon_seq (Pp.to_string ~f:Clang_ast_j.string_of_stmt))
switch_stmt_list switch_stmt_list
@ -2073,7 +2073,7 @@ module CTrans_funct (F : CModule_type.CFrontend) : CModule_type.CTranslation = s
| [stmt] -> | [stmt] ->
[init_expr_trans trans_state (var_exp, var_typ) stmt_info (Some stmt)] [init_expr_trans trans_state (var_exp, var_typ) stmt_info (Some stmt)]
| _ -> | _ ->
CFrontend_config.unimplemented __POS__ stmt_info.Clang_ast_t.si_source_range None CFrontend_config.unimplemented __POS__ stmt_info.Clang_ast_t.si_source_range
"InitListExpression for var %a type %a with multiple init statements" Exp.pp var_exp "InitListExpression for var %a type %a with multiple init statements" Exp.pp var_exp
(Typ.pp_full Pp.text) var_typ (Typ.pp_full Pp.text) var_typ
@ -2119,7 +2119,7 @@ module CTrans_funct (F : CModule_type.CFrontend) : CModule_type.CTranslation = s
| Tint _ | Tfloat _ | Tptr _ -> | Tint _ | Tfloat _ | Tptr _ ->
initListExpr_builtin_trans trans_state_pri init_stmt_info stmts var_exp var_typ initListExpr_builtin_trans trans_state_pri init_stmt_info stmts var_exp var_typ
| _ -> | _ ->
CFrontend_config.unimplemented __POS__ stmt_info.Clang_ast_t.si_source_range None CFrontend_config.unimplemented __POS__ stmt_info.Clang_ast_t.si_source_range
"InitListExp for var %a of type %a" Exp.pp var_exp (Typ.pp Pp.text) var_typ "InitListExp for var %a of type %a" Exp.pp var_exp (Typ.pp Pp.text) var_typ
in in
let nname = "InitListExp" in let nname = "InitListExp" in
@ -2238,7 +2238,7 @@ module CTrans_funct (F : CModule_type.CFrontend) : CModule_type.CTranslation = s
(* Record declaration is done in the beginning when procdesc is defined.*) (* Record declaration is done in the beginning when procdesc is defined.*)
collect_all_decl trans_state var_decls' next_nodes stmt_info collect_all_decl trans_state var_decls' next_nodes stmt_info
| decl :: _ -> | decl :: _ ->
CFrontend_config.incorrect_assumption __POS__ stmt_info.Clang_ast_t.si_source_range None CFrontend_config.incorrect_assumption __POS__ stmt_info.Clang_ast_t.si_source_range
"unexpected decl type %s in collect_all_decl: %a" "unexpected decl type %s in collect_all_decl: %a"
(Clang_ast_proj.get_decl_kind_string decl) (Clang_ast_proj.get_decl_kind_string decl)
(Pp.to_string ~f:Clang_ast_j.string_of_decl) (Pp.to_string ~f:Clang_ast_j.string_of_decl)
@ -2262,7 +2262,7 @@ module CTrans_funct (F : CModule_type.CFrontend) : CModule_type.CTranslation = s
| (TypedefDecl _ | TypeAliasDecl _ | UsingDecl _ | UsingDirectiveDecl _) :: _ -> | (TypedefDecl _ | TypeAliasDecl _ | UsingDecl _ | UsingDirectiveDecl _) :: _ ->
empty_res_trans empty_res_trans
| decl :: _ -> | decl :: _ ->
CFrontend_config.unimplemented __POS__ stmt_info.Clang_ast_t.si_source_range None CFrontend_config.unimplemented __POS__ stmt_info.Clang_ast_t.si_source_range
"In DeclStmt found an unknown declaration type %s" (Clang_ast_j.string_of_decl decl) "In DeclStmt found an unknown declaration type %s" (Clang_ast_j.string_of_decl decl)
| [] -> | [] ->
assert false assert false
@ -2965,12 +2965,12 @@ module CTrans_funct (F : CModule_type.CFrontend) : CModule_type.CTranslation = s
| NullStmt _, FallThroughAttr _ -> | NullStmt _, FallThroughAttr _ ->
no_op_trans trans_state.succ_nodes no_op_trans trans_state.succ_nodes
| _ -> | _ ->
CFrontend_config.unimplemented __POS__ stmt_info.Clang_ast_t.si_source_range None CFrontend_config.unimplemented __POS__ stmt_info.Clang_ast_t.si_source_range
"attributedStmt [stmt] [attr] with:@\nstmt=%s@\nattr=%s@\n" "attributedStmt [stmt] [attr] with:@\nstmt=%s@\nattr=%s@\n"
(Clang_ast_j.string_of_stmt stmt) (Clang_ast_j.string_of_stmt stmt)
(Clang_ast_j.string_of_attribute attr) ) (Clang_ast_j.string_of_attribute attr) )
| _ -> | _ ->
CFrontend_config.unimplemented __POS__ stmt_info.Clang_ast_t.si_source_range None CFrontend_config.unimplemented __POS__ stmt_info.Clang_ast_t.si_source_range
"attributedStmt with:@\nstmts=[%a]@\nattrs=[%a]@\n" "attributedStmt with:@\nstmts=[%a]@\nattrs=[%a]@\n"
(Pp.semicolon_seq (Pp.to_string ~f:Clang_ast_j.string_of_stmt)) (Pp.semicolon_seq (Pp.to_string ~f:Clang_ast_j.string_of_stmt))
stmts stmts
@ -2986,7 +2986,7 @@ module CTrans_funct (F : CModule_type.CFrontend) : CModule_type.CTranslation = s
if destr_trans_result.root_nodes <> [] then destr_trans_result if destr_trans_result.root_nodes <> [] then destr_trans_result
else {empty_res_trans with root_nodes= bn.break} else {empty_res_trans with root_nodes= bn.break}
| _ (* t21762295 *) -> | _ (* t21762295 *) ->
CFrontend_config.incorrect_assumption __POS__ stmt_info.Clang_ast_t.si_source_range None CFrontend_config.incorrect_assumption __POS__ stmt_info.Clang_ast_t.si_source_range
"Break stmt without continuation: %a" "Break stmt without continuation: %a"
(Pp.to_string ~f:Clang_ast_j.string_of_stmt_info) (Pp.to_string ~f:Clang_ast_j.string_of_stmt_info)
stmt_info stmt_info
@ -3000,7 +3000,7 @@ module CTrans_funct (F : CModule_type.CFrontend) : CModule_type.CTranslation = s
if destr_trans_result.root_nodes <> [] then destr_trans_result if destr_trans_result.root_nodes <> [] then destr_trans_result
else {empty_res_trans with root_nodes= bn.continue} else {empty_res_trans with root_nodes= bn.continue}
| _ (* t21762295 *) -> | _ (* t21762295 *) ->
CFrontend_config.incorrect_assumption __POS__ stmt_info.Clang_ast_t.si_source_range None CFrontend_config.incorrect_assumption __POS__ stmt_info.Clang_ast_t.si_source_range
"Continue stmt without continuation: %a" "Continue stmt without continuation: %a"
(Pp.to_string ~f:Clang_ast_j.string_of_stmt_info) (Pp.to_string ~f:Clang_ast_j.string_of_stmt_info)
stmt_info stmt_info
@ -3057,7 +3057,7 @@ module CTrans_funct (F : CModule_type.CFrontend) : CModule_type.CTranslation = s
switchStmt_trans trans_state stmt_info switch_stmt_list switchStmt_trans trans_state stmt_info switch_stmt_list
| CaseStmt _ -> | CaseStmt _ ->
(* where do we even get case stmts outside of the switch stmt? (t21762295) *) (* where do we even get case stmts outside of the switch stmt? (t21762295) *)
CFrontend_config.incorrect_assumption __POS__ stmt_info.Clang_ast_t.si_source_range None CFrontend_config.incorrect_assumption __POS__ stmt_info.Clang_ast_t.si_source_range
"Case statement outside of switch statement: %a" "Case statement outside of switch statement: %a"
(Pp.to_string ~f:Clang_ast_j.string_of_stmt) (Pp.to_string ~f:Clang_ast_j.string_of_stmt)
instr instr
@ -3241,12 +3241,12 @@ module CTrans_funct (F : CModule_type.CFrontend) : CModule_type.CTranslation = s
| SubstNonTypeTemplateParmPackExpr _ | SubstNonTypeTemplateParmPackExpr _
| CXXDependentScopeMemberExpr _ -> | CXXDependentScopeMemberExpr _ ->
CFrontend_config.unimplemented __POS__ stmt_info.Clang_ast_t.si_source_range CFrontend_config.unimplemented __POS__ stmt_info.Clang_ast_t.si_source_range
(Some (Clang_ast_proj.get_stmt_kind_string instr)) ~ast_node:(Clang_ast_proj.get_stmt_kind_string instr)
"Translation of templated code is unsupported: %a" "Translation of templated code is unsupported: %a"
(Pp.to_string ~f:Clang_ast_j.string_of_stmt) (Pp.to_string ~f:Clang_ast_j.string_of_stmt)
instr instr
| ForStmt (_, _) | WhileStmt (_, _) | DoStmt (_, _) | ObjCForCollectionStmt (_, _) -> | ForStmt (_, _) | WhileStmt (_, _) | DoStmt (_, _) | ObjCForCollectionStmt (_, _) ->
CFrontend_config.incorrect_assumption __POS__ stmt_info.Clang_ast_t.si_source_range None CFrontend_config.incorrect_assumption __POS__ stmt_info.Clang_ast_t.si_source_range
"Unexpected shape for %a: %a" "Unexpected shape for %a: %a"
(Pp.to_string ~f:Clang_ast_proj.get_stmt_kind_string) (Pp.to_string ~f:Clang_ast_proj.get_stmt_kind_string)
instr instr
@ -3342,7 +3342,7 @@ module CTrans_funct (F : CModule_type.CFrontend) : CModule_type.CTranslation = s
| SEHTryStmt _ | SEHTryStmt _
| DefaultStmt _ -> | DefaultStmt _ ->
CFrontend_config.unimplemented __POS__ stmt_info.Clang_ast_t.si_source_range CFrontend_config.unimplemented __POS__ stmt_info.Clang_ast_t.si_source_range
(Some (Clang_ast_proj.get_stmt_kind_string instr)) ~ast_node:(Clang_ast_proj.get_stmt_kind_string instr)
"Statement translation for kind %s: %a" "Statement translation for kind %s: %a"
(Clang_ast_proj.get_stmt_kind_string instr) (Clang_ast_proj.get_stmt_kind_string instr)
(Pp.to_string ~f:Clang_ast_j.string_of_stmt) (Pp.to_string ~f:Clang_ast_j.string_of_stmt)

@ -53,7 +53,7 @@ let sil_var_of_decl_ref context source_range decl_ref procname =
sil_var_of_decl context var_decl procname sil_var_of_decl context var_decl procname
| None -> | None ->
(* FIXME(t21762295) *) (* FIXME(t21762295) *)
CFrontend_config.incorrect_assumption __POS__ source_range None CFrontend_config.incorrect_assumption __POS__ source_range
"pointer '%d' for var decl not found. The var decl was: %a" pointer "pointer '%d' for var decl not found. The var decl was: %a" pointer
(Pp.to_string ~f:Clang_ast_j.string_of_decl_ref) (Pp.to_string ~f:Clang_ast_j.string_of_decl_ref)
decl_ref decl_ref

Loading…
Cancel
Save