Skip to content

Commit

Permalink
[Handler] raise exception instead of using L.error
Browse files Browse the repository at this point in the history
  • Loading branch information
oojahooo committed Apr 25, 2024
1 parent 3648789 commit 3d5d697
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 21 deletions.
3 changes: 1 addition & 2 deletions src/doEdit.ml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
open Core
module S = AbsDiff
module D = Diff
module EF = EditFunction
module H = Utils
Expand Down Expand Up @@ -264,7 +263,7 @@ let apply_action donee = function
apply_update_exp func_name s e1 e2 donee
| D.UpdateCallExp (func_name, s, s2) ->
apply_update_callexp func_name s s2 donee
| _ -> L.error "apply_action - Not implemented"
| _ -> failwith "apply_action - Not implemented"

let write_out path ast =
let out_chan_orig = Core.Out_channel.create path in
Expand Down
23 changes: 12 additions & 11 deletions src/editFunction.ml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ let fst_of_branch b s =
| Cil.If (_, tb, fb, _) ->
if b then List.hd tb.bstmts |> Option.value ~default:s
else List.hd fb.bstmts |> Option.value ~default:s
| _ -> L.error "fst_of_branch - wrong stmt"
| _ -> failwith "fst_of_branch - wrong stmt"

let ids2asts maps ids =
StrSet.fold
Expand Down Expand Up @@ -53,23 +53,23 @@ let rec translate_offset maps sol_map abs_offset offset =
let new_e = translate_exp maps sol_map e.ast in
let new_o = translate_offset maps sol_map o o' in
Cil.Index (new_e, new_o)
| _ -> L.error "translate_offset - concrete and abstract offset not matched"
| _ -> failwith "translate_offset - concrete and abstract offset not matched"

and translate_lhost maps sol_map abs_lhost lhost =
match (abs_lhost, lhost) with
| A.SMem e, Cil.Mem _ -> Cil.Mem (translate_exp maps sol_map e.ast)
| A.SVar _, Cil.Var _ -> lhost
| _ -> L.error "translate_lhost - concrete and abstract lhost not matched"
| _ -> failwith "translate_lhost - concrete and abstract lhost not matched"

and break_down_translate_lval maps sol_map lval =
match lval with
| A.AbsLval (sym, cil) -> (
match (sym, cil) with
| A.SLNull, _ -> L.error "translate_lval - Lval is null"
| A.SLNull, _ -> failwith "translate_lval - Lval is null"
| A.Lval (abs_lhost, abs_offset), (lhost, offset) ->
( translate_lhost maps sol_map abs_lhost lhost,
translate_offset maps sol_map abs_offset offset ))
| _ -> L.error "translate_lval - translation target is not an lvalue"
| _ -> failwith "translate_lval - translation target is not an lvalue"

and translate_lval maps sol_map slval =
let new_lvs = translate_ids sol_map slval.A.ids |> ids2asts maps in
Expand Down Expand Up @@ -111,8 +111,8 @@ and translate_exp maps sol_map = function
| A.SSizeOf _, e -> e
| A.SSizeOfStr _, Cil.SizeOfStr _ | _ ->
Utils.print_ekind cil;
L.error "translate_exp - not implemented")
| _ -> L.error "translate_exp - translation target is not an expression"
failwith "translate_exp - not implemented")
| _ -> failwith "translate_exp - translation target is not an expression"

let rec translate_if_stmt maps sol_map scond sthen_block selse_block =
let cond = translate_exp maps sol_map scond.A.ast in
Expand Down Expand Up @@ -153,11 +153,12 @@ and translate_instr maps sol_map abs_instr i =
in
Cil.mkStmt (Cil.Instr [ Cil.Call (None, fun_exp, args, Cil.locUnknown) ])
| a, i ->
L.error
F.asprintf
"translate_stmt - translation target is not an instruction type:\n\
%a\n\
%s"
AbsDiff.pp_absstmt a (Ast.s_instr i)
|> failwith

and translate_loop maps sol_map sb =
let block =
Expand All @@ -178,8 +179,8 @@ and translate_new_stmt maps sol_map = function
Cil.mkStmt (Cil.Return (None, Cil.locUnknown))
| A.SGoto _, Cil.Goto _ -> cil
| abs_instr, Cil.Instr i -> translate_instr maps sol_map abs_instr i
| _ -> L.error "translate_stmt - not implemented")
| _ -> L.error "translate_stmt - translation target is not a statement type"
| _ -> failwith "translate_stmt - not implemented")
| _ -> failwith "translate_stmt - translation target is not a statement type"

let translate_new_stmts maps sol_map =
List.map ~f:(fun abs_node -> translate_new_stmt maps sol_map abs_node.A.ast)
Expand Down Expand Up @@ -258,5 +259,5 @@ let translate cand_donor maps out_dir target_alarm abs_diff =
translate_update_stmt maps sol_map before after ss
| A.SUpdateExp (s, e1, e2) -> translate_update_exp maps sol_map s e1 e2
| A.SUpdateCallExp (s, s2) -> translate_update_callexp maps sol_map s s2
| _ -> L.error "translate - not implemented")
| _ -> failwith "translate - not implemented")
abs_diff
4 changes: 2 additions & 2 deletions src/modeling.ml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ let match_facts =
List.fold2_exn
~f:(fun ps a1 a2 -> PairSet.add (a1, a2) ps)
~init:pairs args1 args2
| _ -> L.error "match_facts - invalid format")
| _ -> failwith "match_facts - invalid format")
~init:PairSet.empty

let dump_sol_map target_alarm buggy_maps target_maps cand_donor out_dir pairs =
Expand Down Expand Up @@ -59,7 +59,7 @@ let parse_dl_fact rel =
|> List.map ~f:(fun s -> int_of_string s)
in
(func_name, args)
| _ -> L.error "parse_dl_fact - invalid format"
| _ -> failwith "parse_dl_fact - invalid format"

let is_dl_fact s =
String.is_suffix s ~suffix:"." && not (String.is_substring ~substring:":-" s)
Expand Down
2 changes: 1 addition & 1 deletion src/parser.ml
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ let get_alarm work_dir =
|> read_and_split |> List.hd_exn
with
| [ src; snk; alarm_id ] -> (src, snk, alarm_id)
| _ -> L.error ~to_console:true "get_alarm: invalid format"
| _ -> failwith "get_alarm: invalid format"
in
let alarm_exp_files =
Sys.readdir work_dir
Expand Down
11 changes: 6 additions & 5 deletions src/z3utils.ml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
open Core
module F = Format
module L = Logger
module Hashtbl = Stdlib.Hashtbl

Expand Down Expand Up @@ -44,7 +45,7 @@ let match_func z3env f =
| "DZError" -> z3env.dzerror
| "ErrTrace" -> z3env.errtrace
| "Bug" -> z3env.bug
| s -> L.error "match_func: invalid function - %s" s
| s -> F.sprintf "match_func: invalid function - %s" s |> failwith

let is_binop = function
| "PlusA" | "PlusPI" | "IndexPI" | "MinusA" | "MinusPI" | "MinusPP" | "Mult"
Expand Down Expand Up @@ -76,7 +77,7 @@ let int_of_binop = function
| "bvor" -> 19
| "and" -> 20
| "or" -> 21
| _ -> L.error "int_of_binop: invalid symbol"
| _ -> failwith "int_of_binop: invalid symbol"

let binop_of_int = function
| 0 -> "PlusA"
Expand All @@ -101,21 +102,21 @@ let binop_of_int = function
| 19 -> "bvor"
| 20 -> "and"
| 21 -> "or"
| _ -> L.error "binop_of_int: invalid int"
| _ -> failwith "binop_of_int: invalid int"

let is_unop = function "BNot" | "LNot" | "Neg" -> true | _ -> false

let int_of_unop = function
| "BNot" -> 22
| "LNot" -> 23
| "Neg" -> 24
| _ -> L.error "int_of_unop: invalid symbol"
| _ -> failwith "int_of_unop: invalid symbol"

let unop_of_int = function
| 22 -> "BNot"
| 23 -> "LNot"
| 24 -> "Neg"
| _ -> L.error "unop_of_int: invalid symbol"
| _ -> failwith "unop_of_int: invalid symbol"

let match_sort z3env s =
let sort_id = String.split ~on:'-' s in
Expand Down

0 comments on commit 3d5d697

Please sign in to comment.