@@ -336,22 +336,6 @@ let zero_float_lit : t =
336
336
let float_mod ?comment e1 e2 : J.expression =
337
337
{ comment; expression_desc = Bin (Mod , e1, e2) }
338
338
339
- let literal = function
340
- | Ast_untagged_variants. String s -> str s ~delim: DStarJ
341
- | Int i -> small_int i
342
- | Float f -> float f
343
- | Bool b -> bool b
344
- | Null -> nil
345
- | Undefined -> undefined
346
- | Block IntType -> str " number"
347
- | Block FloatType -> str " number"
348
- | Block StringType -> str " string"
349
- | Block Array -> str " Array" ~delim: DNoQuotes
350
- | Block Object -> str " object"
351
- | Block Unknown ->
352
- (* TODO: clean up pattern mathing algo whih confuses literal with blocks *)
353
- assert false
354
-
355
339
let array_index ?comment (e0 : t ) (e1 : t ) : t =
356
340
match (e0.expression_desc, e1.expression_desc) with
357
341
| Array (l, _), Number (Int { i; _ })
@@ -776,7 +760,23 @@ let string_equal ?comment (e0 : t) (e1 : t) : t =
776
760
let is_type_number ?comment (e : t ) : t =
777
761
string_equal ?comment (typeof e) (str " number" )
778
762
779
- let rec is_a_literal_case ~(literal_cases : Ast_untagged_variants.literal_type list ) ~block_cases (e :t ) : t =
763
+ let tag_type = function
764
+ | Ast_untagged_variants. String s -> str s ~delim: DStarJ
765
+ | Int i -> small_int i
766
+ | Float f -> float f
767
+ | Bool b -> bool b
768
+ | Null -> nil
769
+ | Undefined -> undefined
770
+ | Untagged IntType -> str " number"
771
+ | Untagged FloatType -> str " number"
772
+ | Untagged StringType -> str " string"
773
+ | Untagged ArrayType -> str " Array" ~delim: DNoQuotes
774
+ | Untagged ObjectType -> str " object"
775
+ | Untagged UnknownType ->
776
+ (* TODO: this should not happen *)
777
+ assert false
778
+
779
+ let rec is_a_literal_case ~(literal_cases : Ast_untagged_variants.tag_type list ) ~block_cases (e :t ) : t =
780
780
let literals_overlaps_with_string () =
781
781
Ext_list. exists literal_cases (function
782
782
| String _ -> true
@@ -793,24 +793,24 @@ let rec is_a_literal_case ~(literal_cases : Ast_untagged_variants.literal_type l
793
793
let (!=) x y = bin NotEqEq x y in
794
794
let (||) x y = bin Or x y in
795
795
let (&&) x y = bin And x y in
796
- let is_literal_case (l : Ast_untagged_variants.literal_type ) : t = e == (literal l ) in
797
- let is_not_block_case (c :Ast_untagged_variants.block_type ) : t = match c with
796
+ let is_literal_case (t : Ast_untagged_variants.tag_type ) : t = e == (tag_type t ) in
797
+ let is_not_block_case (c : Ast_untagged_variants.block_type ) : t = match c with
798
798
| StringType when literals_overlaps_with_string () = false (* No overlap *) ->
799
799
(typeof e) != (str " string" )
800
800
| IntType when literals_overlaps_with_number () = false ->
801
801
(typeof e) != (str " number" )
802
802
| FloatType when literals_overlaps_with_number () = false ->
803
803
(typeof e) != (str " number" )
804
- | Array ->
804
+ | ArrayType ->
805
805
not (is_array e)
806
- | Object when literals_overlaps_with_object () = false ->
806
+ | ObjectType when literals_overlaps_with_object () = false ->
807
807
(typeof e) != (str " object" )
808
- | Object (* overlap *) ->
808
+ | ObjectType (* overlap *) ->
809
809
e == nil || (typeof e) != (str " object" )
810
810
| StringType (* overlap *)
811
811
| IntType (* overlap *)
812
812
| FloatType (* overlap *)
813
- | Unknown ->
813
+ | UnknownType ->
814
814
(* We don't know the type of unknown, so we need to express:
815
815
this is not one of the literals *)
816
816
(match literal_cases with
0 commit comments