1996-09-23 04:33:27 -07:00
|
|
|
(***********************************************************************)
|
|
|
|
(* *)
|
|
|
|
(* Objective Caml *)
|
|
|
|
(* *)
|
|
|
|
(* 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. *)
|
1996-09-23 04:33:27 -07:00
|
|
|
(* *)
|
|
|
|
(***********************************************************************)
|
|
|
|
|
|
|
|
(* $Id$ *)
|
|
|
|
|
|
|
|
(* Representation of types and declarations *)
|
|
|
|
|
|
|
|
open Asttypes
|
|
|
|
|
|
|
|
(* Type expressions for the core language *)
|
|
|
|
|
|
|
|
type type_expr =
|
|
|
|
{ mutable desc: type_desc;
|
1998-07-03 10:40:39 -07:00
|
|
|
mutable level: int;
|
|
|
|
mutable id: int }
|
1996-09-23 04:33:27 -07:00
|
|
|
|
|
|
|
and type_desc =
|
|
|
|
Tvar
|
2001-04-19 01:34:21 -07:00
|
|
|
| Tarrow of label * type_expr * type_expr * commutable
|
1996-09-23 04:33:27 -07:00
|
|
|
| Ttuple of type_expr list
|
1997-01-21 09:43:53 -08:00
|
|
|
| Tconstr of Path.t * type_expr list * abbrev_memo ref
|
1996-09-23 04:33:27 -07:00
|
|
|
| Tobject of type_expr * (Path.t * type_expr list) option ref
|
1997-05-11 14:48:21 -07:00
|
|
|
| Tfield of string * field_kind * type_expr * type_expr
|
1996-09-23 04:33:27 -07:00
|
|
|
| Tnil
|
|
|
|
| Tlink of type_expr
|
1999-11-30 08:07:38 -08:00
|
|
|
| Tsubst of type_expr (* for copying *)
|
|
|
|
| Tvariant of row_desc
|
|
|
|
|
|
|
|
and row_desc =
|
|
|
|
{ row_fields: (label * row_field) list;
|
|
|
|
row_more: type_expr;
|
|
|
|
row_bound: type_expr list;
|
|
|
|
row_closed: bool;
|
|
|
|
row_name: (Path.t * type_expr list) option }
|
|
|
|
|
|
|
|
and row_field =
|
|
|
|
Rpresent of type_expr option
|
2001-03-02 16:14:35 -08:00
|
|
|
| Reither of bool * type_expr list * bool * row_field option ref
|
|
|
|
(* 1st true denotes a constant constructor *)
|
|
|
|
(* 2nd true denotes a tag in a pattern matching, and
|
|
|
|
is erased later *)
|
1999-11-30 08:07:38 -08:00
|
|
|
| Rabsent
|
1996-09-23 04:33:27 -07:00
|
|
|
|
1997-01-21 09:43:53 -08:00
|
|
|
and abbrev_memo =
|
|
|
|
Mnil
|
1998-06-24 12:22:26 -07:00
|
|
|
| Mcons of Path.t * type_expr * type_expr * abbrev_memo
|
1997-01-21 09:43:53 -08:00
|
|
|
| Mlink of abbrev_memo ref
|
|
|
|
|
1997-05-11 14:48:21 -07:00
|
|
|
and field_kind =
|
|
|
|
Fvar of field_kind option ref
|
|
|
|
| Fpresent
|
|
|
|
| Fabsent
|
|
|
|
|
2001-04-19 01:34:21 -07:00
|
|
|
and commutable =
|
|
|
|
Cok
|
|
|
|
| Cunknown
|
|
|
|
| Clink of commutable ref
|
|
|
|
|
1998-06-24 12:22:26 -07:00
|
|
|
(* Maps of methods and instance variables *)
|
1997-05-11 14:48:21 -07:00
|
|
|
|
|
|
|
module Meths : Map.S with type key = string
|
1998-06-24 12:22:26 -07:00
|
|
|
module Vars : Map.S with type key = string
|
1997-05-11 14:48:21 -07:00
|
|
|
|
1996-09-23 04:33:27 -07:00
|
|
|
(* Value descriptions *)
|
|
|
|
|
|
|
|
type value_description =
|
|
|
|
{ val_type: type_expr; (* Type of the value *)
|
|
|
|
val_kind: value_kind }
|
|
|
|
|
|
|
|
and value_kind =
|
1997-05-19 08:42:21 -07:00
|
|
|
Val_reg (* Regular value *)
|
|
|
|
| Val_prim of Primitive.description (* Primitive *)
|
1998-11-30 05:06:53 -08:00
|
|
|
| Val_ivar of mutable_flag * string (* Instance variable (mutable ?) *)
|
1998-06-24 12:22:26 -07:00
|
|
|
| Val_self of (Ident.t * type_expr) Meths.t ref *
|
1998-11-30 05:06:53 -08:00
|
|
|
(Ident.t * Asttypes.mutable_flag * type_expr) Vars.t ref *
|
|
|
|
string
|
1997-05-11 14:48:21 -07:00
|
|
|
(* Self *)
|
1998-11-30 05:06:53 -08:00
|
|
|
| Val_anc of (string * Ident.t) list * string
|
|
|
|
(* Ancestor *)
|
1998-06-24 12:22:26 -07:00
|
|
|
| Val_unbound (* Unbound variable *)
|
1996-09-23 04:33:27 -07:00
|
|
|
|
|
|
|
(* Constructor descriptions *)
|
|
|
|
|
|
|
|
type constructor_description =
|
|
|
|
{ cstr_res: type_expr; (* Type of the result *)
|
|
|
|
cstr_args: type_expr list; (* Type of the arguments *)
|
|
|
|
cstr_arity: int; (* Number of arguments *)
|
|
|
|
cstr_tag: constructor_tag; (* Tag for heap blocks *)
|
|
|
|
cstr_consts: int; (* Number of constant constructors *)
|
|
|
|
cstr_nonconsts: int } (* Number of non-const constructors *)
|
|
|
|
|
|
|
|
and constructor_tag =
|
|
|
|
Cstr_constant of int (* Constant constructor (an int) *)
|
|
|
|
| Cstr_block of int (* Regular constructor (a block) *)
|
|
|
|
| Cstr_exception of Path.t (* Exception constructor *)
|
|
|
|
|
|
|
|
(* Record label descriptions *)
|
|
|
|
|
|
|
|
type label_description =
|
|
|
|
{ lbl_res: type_expr; (* Type of the result *)
|
|
|
|
lbl_arg: type_expr; (* Type of the argument *)
|
|
|
|
lbl_mut: mutable_flag; (* Is this a mutable field? *)
|
|
|
|
lbl_pos: int; (* Position in block *)
|
|
|
|
lbl_all: label_description array; (* All the labels in this type *)
|
|
|
|
lbl_repres: record_representation } (* Representation for this record *)
|
|
|
|
|
|
|
|
and record_representation =
|
|
|
|
Record_regular (* All fields are boxed / tagged *)
|
|
|
|
| Record_float (* All fields are floats *)
|
|
|
|
|
|
|
|
(* Type definitions *)
|
|
|
|
|
|
|
|
type type_declaration =
|
|
|
|
{ type_params: type_expr list;
|
|
|
|
type_arity: int;
|
|
|
|
type_kind: type_kind;
|
2000-09-06 03:21:07 -07:00
|
|
|
type_manifest: type_expr option;
|
|
|
|
type_variance: (bool * bool) list } (* covariant, contravariant *)
|
1996-09-23 04:33:27 -07:00
|
|
|
|
|
|
|
and type_kind =
|
|
|
|
Type_abstract
|
|
|
|
| Type_variant of (string * type_expr list) list
|
|
|
|
| Type_record of (string * mutable_flag * type_expr) list
|
2000-03-21 06:43:25 -08:00
|
|
|
* record_representation
|
1996-09-23 04:33:27 -07:00
|
|
|
|
|
|
|
type exception_declaration = type_expr list
|
|
|
|
|
1998-06-24 12:22:26 -07:00
|
|
|
(* Type expressions for the class language *)
|
|
|
|
|
|
|
|
module Concr : Set.S with type elt = string
|
|
|
|
|
|
|
|
type class_type =
|
|
|
|
Tcty_constr of Path.t * type_expr list * class_type
|
|
|
|
| Tcty_signature of class_signature
|
1999-11-30 08:07:38 -08:00
|
|
|
| Tcty_fun of label * type_expr * class_type
|
1998-06-24 12:22:26 -07:00
|
|
|
|
|
|
|
and class_signature =
|
|
|
|
{ cty_self: type_expr;
|
|
|
|
cty_vars: (Asttypes.mutable_flag * type_expr) Vars.t;
|
|
|
|
cty_concr: Concr.t }
|
|
|
|
|
|
|
|
type class_declaration =
|
|
|
|
{ cty_params: type_expr list;
|
1998-08-31 12:41:24 -07:00
|
|
|
mutable cty_type: class_type;
|
1998-06-24 12:22:26 -07:00
|
|
|
cty_path: Path.t;
|
|
|
|
cty_new: type_expr option }
|
|
|
|
|
|
|
|
type cltype_declaration =
|
|
|
|
{ clty_params: type_expr list;
|
|
|
|
clty_type: class_type;
|
|
|
|
clty_path: Path.t }
|
|
|
|
|
1996-09-23 04:33:27 -07:00
|
|
|
(* Type expressions for the module language *)
|
|
|
|
|
|
|
|
type module_type =
|
|
|
|
Tmty_ident of Path.t
|
|
|
|
| Tmty_signature of signature
|
|
|
|
| Tmty_functor of Ident.t * module_type * module_type
|
|
|
|
|
|
|
|
and signature = signature_item list
|
|
|
|
|
|
|
|
and signature_item =
|
|
|
|
Tsig_value of Ident.t * value_description
|
|
|
|
| Tsig_type of Ident.t * type_declaration
|
|
|
|
| Tsig_exception of Ident.t * exception_declaration
|
|
|
|
| Tsig_module of Ident.t * module_type
|
|
|
|
| Tsig_modtype of Ident.t * modtype_declaration
|
1998-06-24 12:22:26 -07:00
|
|
|
| Tsig_class of Ident.t * class_declaration
|
|
|
|
| Tsig_cltype of Ident.t * cltype_declaration
|
1996-09-23 04:33:27 -07:00
|
|
|
|
|
|
|
and modtype_declaration =
|
|
|
|
Tmodtype_abstract
|
|
|
|
| Tmodtype_manifest of module_type
|