1997-03-24 12:11:22 -08:00
|
|
|
(***********************************************************************)
|
|
|
|
(* *)
|
2011-07-27 07:17:02 -07:00
|
|
|
(* OCaml *)
|
1997-03-24 12:11:22 -08:00
|
|
|
(* *)
|
|
|
|
(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)
|
|
|
|
(* *)
|
|
|
|
(* Copyright 1996 Institut National de Recherche en Informatique et *)
|
1999-11-17 10:59:06 -08:00
|
|
|
(* en Automatique. All rights reserved. This file is distributed *)
|
|
|
|
(* under the terms of the Q Public License version 1.0. *)
|
1997-03-24 12:11:22 -08:00
|
|
|
(* *)
|
|
|
|
(***********************************************************************)
|
|
|
|
|
|
|
|
(* Basic operations on core types *)
|
|
|
|
|
1999-11-30 08:07:38 -08:00
|
|
|
open Asttypes
|
1997-03-24 12:11:22 -08:00
|
|
|
open Types
|
|
|
|
|
2011-11-24 01:02:48 -08:00
|
|
|
(**** Sets, maps and hashtables of types ****)
|
|
|
|
|
|
|
|
module TypeSet : Set.S with type elt = type_expr
|
|
|
|
module TypeMap : Map.S with type key = type_expr
|
|
|
|
module TypeHash : Hashtbl.S with type key = type_expr
|
|
|
|
|
|
|
|
(**** Levels ****)
|
|
|
|
|
1997-03-24 12:11:22 -08:00
|
|
|
val generic_level: int
|
|
|
|
|
1998-07-03 10:40:39 -07:00
|
|
|
val newty2: int -> type_desc -> type_expr
|
|
|
|
(* Create a type *)
|
1997-03-24 12:11:22 -08:00
|
|
|
val newgenty: type_desc -> type_expr
|
|
|
|
(* Create a generic type *)
|
2011-09-22 02:05:42 -07:00
|
|
|
val newgenvar: ?name:string -> unit -> type_expr
|
1997-03-24 12:11:22 -08:00
|
|
|
(* Return a fresh generic variable *)
|
1999-11-30 08:07:38 -08:00
|
|
|
|
|
|
|
(* Use Tsubst instead
|
1998-07-03 10:40:39 -07:00
|
|
|
val newmarkedvar: int -> type_expr
|
|
|
|
(* Return a fresh marked variable *)
|
1997-03-24 12:11:22 -08:00
|
|
|
val newmarkedgenvar: unit -> type_expr
|
|
|
|
(* Return a fresh marked generic variable *)
|
1999-11-30 08:07:38 -08:00
|
|
|
*)
|
1997-03-24 12:11:22 -08:00
|
|
|
|
2011-09-22 02:05:42 -07:00
|
|
|
val is_Tvar: type_expr -> bool
|
|
|
|
val is_Tunivar: type_expr -> bool
|
2012-05-24 22:11:55 -07:00
|
|
|
val dummy_method: label
|
2011-09-22 02:05:42 -07:00
|
|
|
|
1997-03-24 12:11:22 -08:00
|
|
|
val repr: type_expr -> type_expr
|
|
|
|
(* Return the canonical representative of a type. *)
|
|
|
|
|
1997-05-11 14:48:21 -07:00
|
|
|
val field_kind_repr: field_kind -> field_kind
|
|
|
|
(* Return the canonical representative of an object field
|
|
|
|
kind. *)
|
|
|
|
|
2001-04-19 01:34:21 -07:00
|
|
|
val commu_repr: commutable -> commutable
|
|
|
|
(* Return the canonical representative of a commutation lock *)
|
|
|
|
|
2011-11-24 01:02:48 -08:00
|
|
|
(**** polymorphic variants ****)
|
|
|
|
|
1999-11-30 08:07:38 -08:00
|
|
|
val row_repr: row_desc -> row_desc
|
|
|
|
(* Return the canonical representative of a row description *)
|
|
|
|
val row_field_repr: row_field -> row_field
|
2004-01-06 05:41:40 -08:00
|
|
|
val row_field: label -> row_desc -> row_field
|
1999-11-30 08:07:38 -08:00
|
|
|
(* Return the canonical representative of a row field *)
|
|
|
|
val row_more: row_desc -> type_expr
|
|
|
|
(* Return the extension variable of the row *)
|
2012-07-17 20:21:12 -07:00
|
|
|
val row_fixed: row_desc -> bool
|
|
|
|
(* Return whether the row should be treated as fixed or not *)
|
1999-11-30 08:07:38 -08:00
|
|
|
val static_row: row_desc -> bool
|
|
|
|
(* Return whether the row is static or not *)
|
|
|
|
val hash_variant: label -> int
|
|
|
|
(* Hash function for variant tags *)
|
|
|
|
|
2003-05-19 02:21:17 -07:00
|
|
|
val proxy: type_expr -> type_expr
|
|
|
|
(* Return the proxy representative of the type: either itself
|
|
|
|
or a row variable *)
|
|
|
|
|
2007-10-09 03:29:37 -07:00
|
|
|
(**** Utilities for private abbreviations with fixed rows ****)
|
2005-03-22 19:08:37 -08:00
|
|
|
val has_constr_row: type_expr -> bool
|
|
|
|
val is_row_name: string -> bool
|
2013-01-29 06:21:12 -08:00
|
|
|
val is_constr_row: type_expr -> bool
|
2005-03-22 19:08:37 -08:00
|
|
|
|
1997-03-24 12:11:22 -08:00
|
|
|
(**** Utilities for type traversal ****)
|
|
|
|
|
|
|
|
val iter_type_expr: (type_expr -> unit) -> type_expr -> unit
|
|
|
|
(* Iteration on types *)
|
1999-11-30 08:07:38 -08:00
|
|
|
val iter_row: (type_expr -> unit) -> row_desc -> unit
|
|
|
|
(* Iteration on types in a row *)
|
2002-04-18 00:27:47 -07:00
|
|
|
val iter_abbrev: (type_expr -> unit) -> abbrev_memo -> unit
|
|
|
|
(* Iteration on types in an abbreviation list *)
|
1997-03-24 12:11:22 -08:00
|
|
|
|
2012-05-31 22:12:44 -07:00
|
|
|
val copy_type_desc:
|
|
|
|
?keep_names:bool -> (type_expr -> type_expr) -> type_desc -> type_desc
|
2001-11-22 02:41:29 -08:00
|
|
|
(* Copy on types *)
|
2001-11-22 20:35:48 -08:00
|
|
|
val copy_row:
|
2002-04-18 00:27:47 -07:00
|
|
|
(type_expr -> type_expr) ->
|
|
|
|
bool -> row_desc -> bool -> type_expr -> row_desc
|
2001-11-22 02:41:29 -08:00
|
|
|
val copy_kind: field_kind -> field_kind
|
|
|
|
|
1997-03-24 12:11:22 -08:00
|
|
|
val save_desc: type_expr -> type_desc -> unit
|
|
|
|
(* Save a type description *)
|
2006-01-04 08:55:50 -08:00
|
|
|
val dup_kind: field_kind option ref -> unit
|
|
|
|
(* Save a None field_kind, and make it point to a fresh Fvar *)
|
1997-03-24 12:11:22 -08:00
|
|
|
val cleanup_types: unit -> unit
|
|
|
|
(* Restore type descriptions *)
|
|
|
|
|
|
|
|
val lowest_level: int
|
|
|
|
(* Marked type: ty.level < lowest_level *)
|
|
|
|
val pivot_level: int
|
|
|
|
(* Type marking: ty.level <- pivot_level - ty.level *)
|
1998-06-24 12:22:26 -07:00
|
|
|
val mark_type: type_expr -> unit
|
|
|
|
(* Mark a type *)
|
1998-10-16 04:51:18 -07:00
|
|
|
val mark_type_node: type_expr -> unit
|
|
|
|
(* Mark a type node (but not its sons) *)
|
|
|
|
val mark_type_params: type_expr -> unit
|
|
|
|
(* Mark the sons of a type node *)
|
1997-03-24 12:11:22 -08:00
|
|
|
val unmark_type: type_expr -> unit
|
1998-06-24 12:22:26 -07:00
|
|
|
val unmark_type_decl: type_declaration -> unit
|
|
|
|
val unmark_class_type: class_type -> unit
|
|
|
|
val unmark_class_signature: class_signature -> unit
|
1997-03-24 12:11:22 -08:00
|
|
|
(* Remove marks from a type *)
|
|
|
|
|
|
|
|
(**** Memorization of abbreviation expansion ****)
|
|
|
|
|
2008-07-18 19:13:09 -07:00
|
|
|
val find_expans: private_flag -> Path.t -> abbrev_memo -> type_expr option
|
2003-11-06 17:07:32 -08:00
|
|
|
(* Look up a memorized abbreviation *)
|
1997-03-24 12:11:22 -08:00
|
|
|
val cleanup_abbrev: unit -> unit
|
|
|
|
(* Flush the cache of abbreviation expansions.
|
|
|
|
When some types are saved (using [output_value]), this
|
|
|
|
function MUST be called just before. *)
|
|
|
|
val memorize_abbrev:
|
2008-07-18 19:13:09 -07:00
|
|
|
abbrev_memo ref ->
|
|
|
|
private_flag -> Path.t -> type_expr -> type_expr -> unit
|
1997-03-24 12:11:22 -08:00
|
|
|
(* Add an expansion in the cache *)
|
1998-06-24 12:22:26 -07:00
|
|
|
val forget_abbrev:
|
|
|
|
abbrev_memo ref -> Path.t -> unit
|
|
|
|
(* Remove an abbreviation from the cache *)
|
1999-11-30 08:07:38 -08:00
|
|
|
|
|
|
|
(**** Utilities for labels ****)
|
|
|
|
|
|
|
|
val is_optional : label -> bool
|
|
|
|
val label_name : label -> label
|
|
|
|
val extract_label :
|
|
|
|
label -> (label * 'a) list ->
|
|
|
|
label * 'a * (label * 'a) list * (label * 'a) list
|
|
|
|
(* actual label, value, before list, after list *)
|
2002-11-20 21:39:01 -08:00
|
|
|
|
|
|
|
(**** Utilities for backtracking ****)
|
|
|
|
|
|
|
|
type snapshot
|
|
|
|
(* A snapshot for backtracking *)
|
|
|
|
val snapshot: unit -> snapshot
|
|
|
|
(* Make a snapshot for later backtracking. Costs nothing *)
|
|
|
|
val backtrack: snapshot -> unit
|
2002-11-20 22:22:02 -08:00
|
|
|
(* Backtrack to a given snapshot. Only possible if you have
|
2002-11-20 21:39:01 -08:00
|
|
|
not already backtracked to a previous snapshot.
|
|
|
|
Calls [cleanup_abbrev] internally *)
|
|
|
|
|
|
|
|
(* Functions to use when modifying a type (only Ctype?) *)
|
|
|
|
val link_type: type_expr -> type_expr -> unit
|
2002-11-20 22:22:02 -08:00
|
|
|
(* Set the desc field of [t1] to [Tlink t2], logging the old
|
|
|
|
value if there is an active snapshot *)
|
2002-11-20 21:39:01 -08:00
|
|
|
val set_level: type_expr -> int -> unit
|
2002-11-20 22:22:02 -08:00
|
|
|
val set_name:
|
|
|
|
(Path.t * type_expr list) option ref ->
|
|
|
|
(Path.t * type_expr list) option -> unit
|
2002-11-20 21:39:01 -08:00
|
|
|
val set_row_field: row_field option ref -> row_field -> unit
|
|
|
|
val set_univar: type_expr option ref -> type_expr -> unit
|
|
|
|
val set_kind: field_kind option ref -> field_kind -> unit
|
|
|
|
val set_commu: commutable ref -> commutable -> unit
|
2011-11-24 01:02:48 -08:00
|
|
|
val set_typeset: TypeSet.t ref -> TypeSet.t -> unit
|
2002-11-20 22:22:02 -08:00
|
|
|
(* Set references, logging the old value *)
|
2002-11-20 21:39:01 -08:00
|
|
|
val log_type: type_expr -> unit
|
|
|
|
(* Log the old value of a type, before modifying it by hand *)
|
2011-07-28 18:39:09 -07:00
|
|
|
|
|
|
|
(**** Forward declarations ****)
|
|
|
|
val print_raw: (Format.formatter -> type_expr -> unit) ref
|