Skip to content

Commit db907f6

Browse files
committed
Don't use _ as a variable name when decompiling
Even if annotations say so (they can be spurious).
1 parent a58ab9a commit db907f6

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

tools/liquidity/liquidInterp.ml

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,17 @@ let unsanitize_gen_name s =
8383
let unsanitize_name s =
8484
let s = unsanitize_gen_name s in
8585
if List.mem s reserved_keywords || has_reserved_prefix s then
86-
s ^ "_"
86+
Some (s ^ "_")
8787
else if String.length s > 0 then
8888
match s.[0] with
89-
| 'A' .. 'Z' | '0' .. '9' -> "_" ^ s
90-
| _ -> s
91-
else s
89+
| 'A' .. 'Z' | '0' .. '9' -> Some ("_" ^ s)
90+
| '_' ->
91+
if String.length s > 1 then
92+
if s.[1] = '/' then None
93+
else Some s
94+
else None
95+
| _ -> Some s
96+
else Some s
9297

9398
let fprint_stack msg fmt stack =
9499
Format.fprintf fmt "Stack %s:\n" msg;
@@ -198,19 +203,19 @@ let add_name stack seq name =
198203
match stack with
199204
| x :: _ ->
200205
let name = unsanitize_name name in
201-
if x.node_name = None then x.node_name <- Some name;
206+
if x.node_name = None then x.node_name <- name;
202207
begin match x.kind, seq.kind with
203208
| N_IF_END_RESULT _, N_IF _
204209
| N_LOOP_RESULT _, N_LOOP _
205210
| N_LOOP_LEFT_RESULT _, N_LOOP_LEFT _
206211
| N_FOLD_RESULT _, N_FOLD _ ->
207-
if seq.node_name = None then seq.node_name <- Some name;
212+
if seq.node_name = None then seq.node_name <- name;
208213
| _ -> ()
209214
end;
210215
begin match x with
211216
(* recover closures names *)
212217
| { kind = N_PRIM "PAIR"; args = [ { kind = N_LAMBDA _ } as x; _] } ->
213-
if x.node_name = None then x.node_name <- Some name;
218+
if x.node_name = None then x.node_name <- name;
214219
| _ -> ()
215220
end;
216221
| [] -> ()

tools/liquidity/liquidMain.ml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,10 @@ let compile_tezos_file filename =
214214
LiquidEncode.encode_contract ~decompiling:true typed_ast in
215215
let live_ast = LiquidSimplify.simplify_contract
216216
~decompile_annoted:annoted_tz encode_ast to_inline in
217+
if !LiquidOptions.verbosity>0 then
218+
FileString.write_file (filename ^ ".simple")
219+
(DebugPrint.string_of_contract
220+
live_ast);
217221
let multi_ast = LiquidDecode.decode_contract live_ast in
218222
let untyped_ast = LiquidUntype.untype_contract multi_ast in
219223
(* let untyped_ast = c in *)

0 commit comments

Comments
 (0)