Skip to content

Commit e76fb73

Browse files
committed
Changes to the cases in switch were not committed.
1 parent c0e67e9 commit e76fb73

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+7474
-7413
lines changed

jscomp/core/j.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,7 @@ and 'a case_clause = {
329329
switch_case : 'a ;
330330
switch_body : block ;
331331
should_break : bool ; (* true means break *)
332+
comment : string option ;
332333
}
333334

334335
(* TODO: For efficency: block should not be a list, it should be able to

jscomp/core/js_dump.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,12 +499,13 @@ and pp_function is_method
499499
and pp_one_case_clause : 'a .
500500
_ -> P.t -> (P.t -> 'a -> unit) -> 'a J.case_clause -> _
501501
= fun cxt f pp_cond
502-
({switch_case; switch_body ; should_break } : _ J.case_clause) ->
502+
({switch_case; switch_body ; should_break; comment; } : _ J.case_clause) ->
503503
let cxt =
504504
P.group f 1 (fun _ ->
505505
P.group f 1 (fun _ ->
506506
P.string f L.case;
507507
P.space f ;
508+
pp_comment_option f comment;
508509
pp_cond f switch_case; (* could be integer or string *)
509510
P.space f ;
510511
P.string f L.colon );

jscomp/core/js_map.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -444,12 +444,12 @@ class virtual map =
444444
*)
445445
'a 'a_out.
446446
('self_type -> 'a -> 'a_out) -> 'a case_clause -> 'a_out case_clause =
447-
fun _f_a { switch_case = _x; switch_body = _x_i1; should_break = _x_i2
447+
fun _f_a { switch_case = _x; switch_body = _x_i1; should_break = _x_i2; comment
448448
} ->
449449
let _x = _f_a o _x in
450450
let _x_i1 = o#block _x_i1 in
451451
let _x_i2 = o#bool _x_i2
452-
in { switch_case = _x; switch_body = _x_i1; should_break = _x_i2; }
452+
in { switch_case = _x; switch_body = _x_i1; should_break = _x_i2; comment }
453453
method block : block -> block = (* true means break *)
454454
(* TODO: For efficency: block should not be a list, it should be able to
455455
be concatenated in both ways

jscomp/core/js_of_lam_variant.ml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ let eval (arg : J.expression) (dispatches : (int * string) list ) : E.t =
4242
(Ext_list.map dispatches (fun (i,r) ->
4343
{J.switch_case = i ;
4444
switch_body = [S.return_stmt (E.str r)];
45-
should_break = false (* FIXME: if true, still print break*)
45+
should_break = false; (* FIXME: if true, still print break*)
46+
comment = None;
4647
})))]
4748

4849
(** invariant: optional is not allowed in this case *)
@@ -61,7 +62,8 @@ let eval_as_event (arg : J.expression) (dispatches : (int * string) list ) =
6162
(Ext_list.map dispatches (fun (i,r) ->
6263
{J.switch_case = i ;
6364
switch_body = [S.return_stmt (E.str r)];
64-
should_break = false (* FIXME: if true, still print break*)
65+
should_break = false; (* FIXME: if true, still print break*)
66+
comment = None;
6567
}) ))]
6668
, (* TODO: improve, one dispatch later,
6769
the problem is that we can not create bindings
@@ -89,7 +91,8 @@ let eval_as_int (arg : J.expression) (dispatches : (int * int) list ) : E.t =
8991
(Ext_list.map dispatches (fun (i,r) ->
9092
{J.switch_case = i ;
9193
switch_body = [S.return_stmt (E.int (Int32.of_int r))];
92-
should_break = false (* FIXME: if true, still print break*)
94+
should_break = false; (* FIXME: if true, still print break*)
95+
comment = None;
9396
}) ))]
9497

9598
let eval_as_unwrap (arg : J.expression) : E.t =

jscomp/core/lam_compile.ml

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,7 @@ and compile_recursive_lets cxt id_args : Js_output.t =
412412
and compile_general_cases
413413
:
414414
'a .
415+
('a -> string option) ->
415416
('a -> J.expression) ->
416417
(J.expression -> J.expression -> J.expression) ->
417418
Lam_compile_context.t ->
@@ -421,6 +422,7 @@ and compile_general_cases
421422
_ ->
422423
('a * Lam.t) list -> default_case -> J.block
423424
= fun
425+
(make_comment : _ -> string option)
424426
(make_exp : _ -> J.expression)
425427
(eq_exp : J.expression -> J.expression -> J.expression)
426428
(cxt : Lam_compile_context.t)
@@ -499,10 +501,11 @@ and compile_general_cases
499501
should_break && Lam_exit_code.has_exit lam in
500502
{J.switch_case ;
501503
switch_body;
502-
should_break
504+
should_break;
505+
comment = make_comment switch_case;
503506
}
504507
else
505-
{ switch_case; switch_body = []; should_break = false }
508+
{ switch_case; switch_body = []; should_break = false; comment = make_comment switch_case; }
506509
)
507510

508511
(* TODO: we should also group default *)
@@ -514,6 +517,11 @@ and compile_general_cases
514517

515518
and compile_cases ~is_tag cxt switch_exp table default names =
516519
compile_general_cases
520+
(fun i ->
521+
if names.Lam.consts = [| "Constant" |] then None else
522+
match (if is_tag then names.Lam.blocks.(i) else names.consts.(i)) with
523+
| s -> Some s
524+
| exception Invalid_argument _ -> Some "NotFound")
517525
(fun i ->
518526
let comment = match (if is_tag then names.Lam.blocks.(i) else names.consts.(i)) with
519527
| s -> Some s
@@ -601,6 +609,7 @@ and compile_switch switch_arg sw (lambda_cxt : Lam_compile_context.t) names =
601609

602610
and compile_string_cases cxt switch_exp table default =
603611
compile_general_cases
612+
(fun s -> None)
604613
E.str
605614
E.string_equal
606615
cxt
@@ -756,15 +765,15 @@ and compile_staticcatch (lam : Lam.t) (lambda_cxt : Lam_compile_context.t)=
756765
Js_output.append_output
757766
(Js_output.make (S.declare_variable ~kind:Variable v :: declares) )
758767
(Js_output.append_output lbody (Js_output.make (
759-
compile_cases ~is_tag:false new_cxt exit_expr handlers NonComplete {consts=[||]; blocks=[||]}) ~value:(E.var v )))
768+
compile_cases ~is_tag:false new_cxt exit_expr handlers NonComplete {consts=[| "Constant" |]; blocks=[||]}) ~value:(E.var v )))
760769
| Declare (kind, id)
761770
(* declare first this we will do branching*) ->
762771
let declares = S.declare_variable ~kind id :: declares in
763772
let new_cxt = {lambda_cxt with jmp_table = jmp_table; continuation = Assign id } in
764773
let lbody = compile_lambda new_cxt body in
765774
Js_output.append_output (Js_output.make declares)
766775
(Js_output.append_output lbody
767-
(Js_output.make (compile_cases ~is_tag:false new_cxt exit_expr handlers NonComplete {consts=[||]; blocks=[||]})))
776+
(Js_output.make (compile_cases ~is_tag:false new_cxt exit_expr handlers NonComplete {consts=[|"Constant"|]; blocks=[||]})))
768777
(* place holder -- tell the compiler that
769778
we don't know if it's complete
770779
*)
@@ -773,13 +782,13 @@ and compile_staticcatch (lam : Lam.t) (lambda_cxt : Lam_compile_context.t)=
773782
let lbody = compile_lambda new_cxt body in
774783
Js_output.append_output (Js_output.make declares)
775784
(Js_output.append_output lbody
776-
(Js_output.make (compile_cases ~is_tag:false new_cxt exit_expr handlers NonComplete {consts=[||]; blocks=[||]})))
785+
(Js_output.make (compile_cases ~is_tag:false new_cxt exit_expr handlers NonComplete {consts=[|"Constant"|]; blocks=[||]})))
777786
| Assign _ ->
778787
let new_cxt = {lambda_cxt with jmp_table = jmp_table } in
779788
let lbody = compile_lambda new_cxt body in
780789
Js_output.append_output (Js_output.make declares)
781790
(Js_output.append_output lbody
782-
(Js_output.make (compile_cases ~is_tag:false new_cxt exit_expr handlers NonComplete {consts=[||]; blocks=[||]})))
791+
(Js_output.make (compile_cases ~is_tag:false new_cxt exit_expr handlers NonComplete {consts=[|"Constant"|]; blocks=[||]})))
783792

784793
and compile_sequand
785794
(l : Lam.t) (r : Lam.t) (lambda_cxt : Lam_compile_context.t) =

jscomp/test/adt_optimize_test.js

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,20 @@ function f4(param) {
2929
function f5(param) {
3030
if (typeof param === "number") {
3131
switch (param) {
32-
case 0 :
32+
case /* A */0 :
3333
return 1;
34-
case 1 :
34+
case /* B */1 :
3535
return 3;
36-
case 2 :
36+
case /* F */2 :
3737
return 4;
3838

3939
}
4040
} else {
4141
switch (param.tag | 0) {
42-
case 0 :
43-
case 1 :
42+
case /* C */0 :
43+
case /* D */1 :
4444
return 1;
45-
case 2 :
45+
case /* E */2 :
4646
return 2;
4747

4848
}
@@ -64,21 +64,21 @@ function f6(param) {
6464
function f7(param) {
6565
if (typeof param === "number") {
6666
switch (param) {
67-
case 0 :
67+
case /* A */0 :
6868
return 1;
69-
case 1 :
69+
case /* B */1 :
7070
return 2;
71-
case 2 :
71+
case /* F */2 :
7272
return -1;
7373

7474
}
7575
} else {
7676
switch (param.tag | 0) {
77-
case 0 :
77+
case /* C */0 :
7878
return 3;
79-
case 1 :
79+
case /* D */1 :
8080
return 4;
81-
case 2 :
81+
case /* E */2 :
8282
return -1;
8383

8484
}
@@ -88,16 +88,16 @@ function f7(param) {
8888
function f8(param) {
8989
if (typeof param === "number") {
9090
switch (param) {
91-
case 0 :
92-
case 1 :
91+
case /* T60 */0 :
92+
case /* T61 */1 :
9393
return 1;
9494
default:
9595
return 3;
9696
}
9797
} else {
9898
switch (param.tag | 0) {
99-
case 0 :
100-
case 1 :
99+
case /* T64 */0 :
100+
case /* T65 */1 :
101101
return 2;
102102
default:
103103
return 3;
@@ -108,17 +108,17 @@ function f8(param) {
108108
function f9(param) {
109109
if (typeof param === "number") {
110110
switch (param) {
111-
case 0 :
112-
case 1 :
113-
case 2 :
111+
case /* T60 */0 :
112+
case /* T61 */1 :
113+
case /* T62 */2 :
114114
return 1;
115115
default:
116116
return 3;
117117
}
118118
} else {
119119
switch (param.tag | 0) {
120-
case 0 :
121-
case 1 :
120+
case /* T64 */0 :
121+
case /* T65 */1 :
122122
return 2;
123123
default:
124124
return 3;
@@ -129,23 +129,23 @@ function f9(param) {
129129
function f10(param) {
130130
if (typeof param === "number") {
131131
switch (param) {
132-
case 0 :
132+
case /* T60 */0 :
133133
return 0;
134-
case 1 :
134+
case /* T61 */1 :
135135
return 2;
136-
case 2 :
136+
case /* T62 */2 :
137137
return 4;
138-
case 3 :
138+
case /* T63 */3 :
139139
return 1;
140140

141141
}
142142
} else {
143143
switch (param.tag | 0) {
144-
case 0 :
145-
case 1 :
144+
case /* T64 */0 :
145+
case /* T65 */1 :
146146
return 2;
147-
case 2 :
148-
case 3 :
147+
case /* T66 */2 :
148+
case /* T68 */3 :
149149
return 3;
150150

151151
}

jscomp/test/arith_lexer.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,26 +25,26 @@ function __ocaml_lex_lexeme_rec(lexbuf, ___ocaml_lex_state) {
2525
var __ocaml_lex_state = ___ocaml_lex_state;
2626
var __ocaml_lex_state$1 = Lexing.engine(__ocaml_lex_tables, __ocaml_lex_state, lexbuf);
2727
switch (__ocaml_lex_state$1) {
28-
case 0 :
28+
case /* NotFound */0 :
2929
___ocaml_lex_state = 0;
3030
continue ;
31-
case 1 :
31+
case /* NotFound */1 :
3232
return /* NUMERAL */Block.__(0, [Caml_format.caml_int_of_string(Lexing.lexeme(lexbuf))]);
33-
case 2 :
33+
case /* NotFound */2 :
3434
return /* IDENT */Block.__(1, [Lexing.lexeme(lexbuf)]);
35-
case 3 :
35+
case /* NotFound */3 :
3636
return /* PLUS */0;
37-
case 4 :
37+
case /* NotFound */4 :
3838
return /* MINUS */1;
39-
case 5 :
39+
case /* NotFound */5 :
4040
return /* TIMES */2;
41-
case 6 :
41+
case /* NotFound */6 :
4242
return /* DIVIDE */3;
43-
case 7 :
43+
case /* NotFound */7 :
4444
return /* LPAREN */5;
45-
case 8 :
45+
case /* NotFound */8 :
4646
return /* RPAREN */6;
47-
case 9 :
47+
case /* NotFound */9 :
4848
return /* EOF */7;
4949
default:
5050
Curry._1(lexbuf[/* refill_buff */0], lexbuf);
@@ -60,19 +60,19 @@ function lexeme(lexbuf) {
6060

6161
function str(e) {
6262
switch (e.tag | 0) {
63-
case 0 :
63+
case /* Numeral */0 :
6464
return Pervasives.string_of_float(e[0]);
65-
case 1 :
65+
case /* Plus */1 :
6666
return str(e[0]) + ("+" + str(e[1]));
67-
case 2 :
67+
case /* Minus */2 :
6868
return str(e[0]) + ("-" + str(e[1]));
69-
case 3 :
69+
case /* Times */3 :
7070
return str(e[0]) + ("*" + str(e[1]));
71-
case 4 :
71+
case /* Divide */4 :
7272
return str(e[0]) + ("/" + str(e[1]));
73-
case 5 :
73+
case /* Negate */5 :
7474
return "-" + str(e[0]);
75-
case 6 :
75+
case /* Variable */6 :
7676
return e[0];
7777

7878
}

jscomp/test/arith_syntax.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@ var Pervasives = require("../../lib/js/pervasives.js");
44

55
function str(e) {
66
switch (e.tag | 0) {
7-
case 0 :
7+
case /* Numeral */0 :
88
return Pervasives.string_of_float(e[0]);
9-
case 1 :
9+
case /* Plus */1 :
1010
return str(e[0]) + ("+" + str(e[1]));
11-
case 2 :
11+
case /* Minus */2 :
1212
return str(e[0]) + ("-" + str(e[1]));
13-
case 3 :
13+
case /* Times */3 :
1414
return str(e[0]) + ("*" + str(e[1]));
15-
case 4 :
15+
case /* Divide */4 :
1616
return str(e[0]) + ("/" + str(e[1]));
17-
case 5 :
17+
case /* Negate */5 :
1818
return "-" + str(e[0]);
19-
case 6 :
19+
case /* Variable */6 :
2020
return e[0];
2121

2222
}

0 commit comments

Comments
 (0)