<commit_before>open Misc
open Asttypes
open Types
open Typedtree
open Mytools
open Longident
open Format
open Print_type

(** Printing facility for typed abstract syntax trees produced by the 
    type-checker*)

(*#########################################################################*)
(* ** Printing of base values *)

let string_of_ident s = 
   Ident.name s

let string_of_lident idt =
   let names = Longident.flatten idt in
   String.concat "." names

let string_of_constant = function
  | Const_int n -> string_of_int n
  (*| Const_char c -> String.make 1 c
  | Const_string (s, _) -> "\"" ^ s ^ "\"" *)
  | Const_float f -> f
  (*| Const_int32 _ -> unsupported "int32 type"
  | Const_int64 _ -> unsupported "int64 type"
  | Const_nativeint _ -> unsupported "native int type"*)
  | _ -> unsupported "constant"

(*
let string_of_recflag = function
  | Nonrecursive -> ""
  | Recursive -> " rec" 
*)


(*#########################################################################*)
(* ** Printing of items *)

(*
let string_of_typed_var s t =
   sprintf "(%s : %s)" s (string_of_type_exp t)
*)

(*
let string_of_path p = 
   Path.name p
*)

let show_string s = 
  s

(*#########################################################################*)
(* ** Some Contexts *)

let create_context l = l


(*#########################################################################*)
(* ** Printing of patterns *)

let string_of_pattern matchedexpr par p =
    (* It also returns a context of expressions to be substituted. *)
   let rec aux par p =
     match p.pat_desc with
     | Tpat_any -> "default",
        create_context []
     | Tpat_var (id,_) -> "default", 
         create_context [id, matchedexpr]
     (*
     | Tpat_alias (p, ak, _) -> unsupported "alias patterns"
       (* let sp = aux false p in
         begin match ak with 
         | TPat_alias id -> show_par par (sprintf "%s as %s" (string_of_typed_var (string_of_ident id) p.pat_type) sp) 
         | TPat_constraint _ -> sp
         | TPat_type pp -> sp (* ignore type *)
         end  *)
      *)
     | Tpat_constant c -> 
         sprintf "case %s" (string_of_constant c),
         create_context []
     | Tpat_tuple l -> 
         "default",
         let li = List.length l in
         create_context
            (List.flatten (List.mapi (fun i -> function
                | Tpat_any -> []
                | Tpat_var (id, _) ->
                    [id, "proj_" ^ string_of_int i ^ "_" ^ string_of_int li ^ "(" ^ matchedexpr ^ ")"]) l))
     | Tpat_construct (p,cd,ps) -> unsupported "construct patterns" 
        (*
         let c = string_of_path p in
         if ps = []
            then c
         else if List.length ps = 1 
            then show_par par (c ^ " " ^ aux true (List.hd ps))
         else
            show_par par (sprintf "%s (%s)" c (show_list (aux false) "," ps)) *)
     (*| Tpat_or (p1,p2,_) -> 
         show_par par (sprintf "%s | %s" (aux false p1) (aux false p2))
     | Tpat_lazy p1 -> 
        show_par par (sprintf "lazy %s" (aux true p1))
     | Tpat_variant (_,_,_) -> unsupported "variant patterns"
     | Tpat_record _ -> unsupported "record patterns"
     | Tpat_array pats -> unsupported "array patterns"*)
     | _ -> unsupported "pattern"
     in
  aux false p

let string_of_let_pattern par fvs p =
   let typ = p.pat_type in
   let styp = string_of_type_sch fvs typ in
   sprintf "%s : %s" (string_of_pattern par p) styp
   (* 
   match p.pat_desc with<commit_msg>Put back the old version of this file.<commit_after>open Misc
open Asttypes
open Types
open Typedtree
open Mytools
open Longident
open Format
open Print_type

(** Printing facility for typed abstract syntax trees produced by the 
    type-checker*)

(*#########################################################################*)
(* ** Printing of base values *)

let string_of_ident s = 
   Ident.name s

let string_of_lident idt =
   let names = Longident.flatten idt in
   String.concat "." names

let string_of_constant = function
  | Const_int n -> string_of_int n
  | Const_char c -> String.make 1 c
  | Const_string (s, _) -> s
  | Const_float f -> f
  | Const_int32 _ -> unsupported "int32 type"
  | Const_int64 _ -> unsupported "int64 type"
  | Const_nativeint _ -> unsupported "native int type"

let string_of_recflag = function
  | Nonrecursive -> ""
  | Recursive -> " rec" 



(*#########################################################################*)
(* ** Printing of items *)

let string_of_typed_var s t =
   sprintf "(%s : %s)" s (string_of_type_exp t)

let string_of_path p = 
   Path.name p

let show_string s = 
  s

(*#########################################################################*)
(* ** Printing of patterns *)

let string_of_pattern par p =
   let rec aux par p =
     match p.pat_desc with
     | Tpat_any -> "_"
     | Tpat_var (id,_) -> string_of_typed_var (string_of_ident id) p.pat_type
     | Tpat_alias (p, ak, _) -> unsupported "alias patterns"
       (* let sp = aux false p in
         begin match ak with 
         | TPat_alias id -> show_par par (sprintf "%s as %s" (string_of_typed_var (string_of_ident id) p.pat_type) sp) 
         | TPat_constraint _ -> sp
         | TPat_type pp -> sp (* ignore type *)
         end  *)
     | Tpat_constant c -> 
         sprintf "%s" (string_of_constant c)
     | Tpat_tuple l -> 
         show_par true (sprintf "%s" (show_list (aux false) "," l))
     | Tpat_construct (p,cd,ps) -> unsupported "construct patterns" 
        (*
         let c = string_of_path p in
         if ps = []
            then c
         else if List.length ps = 1 
            then show_par par (c ^ " " ^ aux true (List.hd ps))
         else
            show_par par (sprintf "%s (%s)" c (show_list (aux false) "," ps)) *)
     | Tpat_or (p1,p2,_) -> 
         show_par par (sprintf "%s | %s" (aux false p1) (aux false p2))
     | Tpat_lazy p1 -> 
        show_par par (sprintf "lazy %s" (aux true p1))
     | Tpat_variant (_,_,_) -> unsupported "variant patterns"
     | Tpat_record _ -> unsupported "record patterns"
     | Tpat_array pats -> unsupported "array patterns"
     in
  aux false p

let string_of_let_pattern par fvs p =
   let typ = p.pat_type in
   let styp = string_of_type_sch fvs typ in
   sprintf "%s : %s" (string_of_pattern par p) styp
   (* 
   match p.pat_desc with
{'fraction_non_alphanumeric': 0.18772677078403532, 'fraction_numerical': 0.005048114844612715, 'mean_word_length': 2.6753623188405795, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 54, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5413006', 'n_tokens_mistral': 2063, 'n_tokens_neox': 1991, 'n_words': 612}