File tree Expand file tree Collapse file tree 11 files changed +1538
-1594
lines changed Expand file tree Collapse file tree 11 files changed +1538
-1594
lines changed Original file line number Diff line number Diff line change @@ -305,8 +305,8 @@ and statement_desc =
305
305
{[ goto : label option ; ]}
306
306
*)
307
307
308
- | Int_switch of expression * int case_clause list * block option
309
- | String_switch of expression * string case_clause list * block option
308
+ | Int_switch of expression * int_clause list * block option
309
+ | String_switch of expression * string_clause list * block option
310
310
| Throw of expression
311
311
| Try of block * (exception_ident * block) option * block option
312
312
| Debugger
@@ -329,9 +329,9 @@ and variable_declaration = {
329
329
property : property ;
330
330
ident_info : ident_info ;
331
331
}
332
-
333
- and 'a case_clause = {
334
- switch_case : 'a ;
332
+ and string_clause = string * case_clause
333
+ and int_clause = int * case_clause
334
+ and case_clause = {
335
335
switch_body : block ;
336
336
should_break : bool ; (* true means break *)
337
337
comment : string option ;
Original file line number Diff line number Diff line change @@ -488,9 +488,9 @@ and pp_function ~is_method
488
488
since it can be either [int] or [string]
489
489
*)
490
490
and pp_one_case_clause : 'a .
491
- _ -> P. t -> (P. t -> 'a -> unit ) -> 'a J. case_clause -> _
491
+ _ -> P. t -> (P. t -> 'a -> unit ) -> ( 'a * J. case_clause ) -> _
492
492
= fun cxt f pp_cond
493
- ({ switch_case; switch_body ; should_break; comment; } : _ J.case_clause ) ->
493
+ (switch_case , ( { switch_body ; should_break; comment; } : J.case_clause ) ) ->
494
494
let cxt =
495
495
P. group f 1 (fun _ ->
496
496
P. group f 1 (fun _ ->
@@ -520,7 +520,7 @@ and pp_one_case_clause : 'a .
520
520
cxt
521
521
522
522
and loop_case_clauses : 'a . cxt ->
523
- P. t -> (P. t -> 'a -> unit ) -> 'a J. case_clause list -> cxt
523
+ P. t -> (P. t -> 'a -> unit ) -> ( 'a * J. case_clause ) list -> cxt
524
524
= fun cxt f pp_cond cases ->
525
525
Ext_list. fold_left cases cxt (fun acc x -> pp_one_case_clause acc f pp_cond x)
526
526
Load Diff Large diffs are not rendered by default.
Load Diff Large diffs are not rendered by default.
Original file line number Diff line number Diff line change @@ -43,7 +43,7 @@ let eval (arg : J.expression) (dispatches : (string * string) list ) : E.t =
43
43
E. of_block
44
44
[(S. string_switch arg
45
45
(Ext_list. map dispatches (fun (i ,r ) ->
46
- { J. switch_case = i ;
46
+ i, J. {
47
47
switch_body = [S. return_stmt (E. str r)];
48
48
should_break = false ; (* FIXME: if true, still print break*)
49
49
comment = None ;
@@ -71,7 +71,7 @@ let eval_as_event (arg : J.expression) (dispatches : (string * string) list opti
71
71
72
72
(S. string_switch (E. poly_var_tag_access arg)
73
73
(Ext_list. map dispatches (fun (i ,r ) ->
74
- { J. switch_case = i ;
74
+ i, J. {
75
75
switch_body = [S. return_stmt (E. str r)];
76
76
should_break = false ; (* FIXME: if true, still print break*)
77
77
comment = None ;
@@ -103,7 +103,7 @@ let eval_as_int (arg : J.expression) (dispatches : (string * int) list ) : E.t
103
103
E. of_block
104
104
[(S. string_switch arg
105
105
(Ext_list. map dispatches (fun (i ,r ) ->
106
- { J. switch_case = i ;
106
+ i, J. {
107
107
switch_body = [S. return_stmt (E. int (Int32. of_int r))];
108
108
should_break = false ; (* FIXME: if true, still print break*)
109
109
comment = None ;
Original file line number Diff line number Diff line change @@ -98,13 +98,13 @@ let int_switch
98
98
?(declaration : (J.property * Ident.t) option )
99
99
?(default : J.block option )
100
100
(e : J.expression )
101
- (clauses : int J.case_clause list ): t =
101
+ (clauses : ( int * J.case_clause) list ): t =
102
102
match e.expression_desc with
103
103
| Number (Int {i; _} ) ->
104
104
let continuation =
105
105
match Ext_list. find_opt clauses
106
- (fun x ->
107
- if x. switch_case = Int32. to_int i then
106
+ (fun ( switch_case , x ) ->
107
+ if switch_case = Int32. to_int i then
108
108
Some x.switch_body else None )
109
109
with
110
110
| Some case -> case
@@ -137,12 +137,12 @@ let string_switch
137
137
?(declaration : (J.property * Ident.t) option )
138
138
?(default : J.block option )
139
139
(e : J.expression )
140
- (clauses : string J.case_clause list ): t =
140
+ (clauses : ( string * J.case_clause) list ): t =
141
141
match e.expression_desc with
142
142
| Str (_ ,s ) ->
143
143
let continuation =
144
- match Ext_list. find_opt clauses (fun x ->
145
- if x. switch_case = s then
144
+ match Ext_list. find_opt clauses (fun ( switch_case , x ) ->
145
+ if switch_case = s then
146
146
Some x.switch_body
147
147
else None
148
148
) with
Original file line number Diff line number Diff line change @@ -84,15 +84,15 @@ val int_switch :
84
84
?declaration : Lam_compat .let_kind * Ident .t ->
85
85
?default : J .block ->
86
86
J .expression ->
87
- int J .case_clause list ->
87
+ ( int * J .case_clause ) list ->
88
88
t
89
89
90
90
val string_switch :
91
91
?comment : string ->
92
92
?declaration : Lam_compat .let_kind * Ident .t ->
93
93
?default : J .block ->
94
94
J .expression ->
95
- string J .case_clause list ->
95
+ ( string * J .case_clause ) list ->
96
96
t
97
97
98
98
(* * Just declaration without initialization *)
Original file line number Diff line number Diff line change @@ -490,7 +490,7 @@ and compile_general_cases
490
490
Lam_compile_context. t ->
491
491
(?default :J.block ->
492
492
?declaration:Lam_compat.let_kind * Ident.t ->
493
- _ -> 'a J.case_clause list -> J.statement ) ->
493
+ _ -> ( 'a * J.case_clause) list -> J.statement ) ->
494
494
_ ->
495
495
('a * Lam. t ) list -> default_case -> J. block
496
496
= fun
@@ -501,7 +501,7 @@ and compile_general_cases
501
501
(switch :
502
502
?default:J.block ->
503
503
?declaration:Lam_compat.let_kind * Ident.t ->
504
- _ -> _ J.case_clause list -> J.statement
504
+ _ -> (_ * J.case_clause) list -> J.statement
505
505
)
506
506
(switch_exp : J.expression )
507
507
(cases : (_ * Lam.t) list )
@@ -571,13 +571,13 @@ and compile_general_cases
571
571
should_break
572
572
else
573
573
should_break && Lam_exit_code. has_exit lam in
574
- { J. switch_case ;
574
+ switch_case , J. {
575
575
switch_body;
576
576
should_break;
577
577
comment = make_comment switch_case;
578
578
}
579
579
else
580
- { switch_case; switch_body = [] ; should_break = false ; comment = make_comment switch_case; }
580
+ switch_case, { switch_body = [] ; should_break = false ; comment = make_comment switch_case; }
581
581
)
582
582
583
583
(* TODO: we should also group default *)
You can’t perform that action at this time.
0 commit comments