1995-08-09 08:06:35 -07:00
|
|
|
(***********************************************************************)
|
|
|
|
(* *)
|
2011-07-27 07:17:02 -07:00
|
|
|
(* OCaml *)
|
1995-08-09 08:06:35 -07:00
|
|
|
(* *)
|
|
|
|
(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)
|
|
|
|
(* *)
|
1996-04-30 07:53:58 -07:00
|
|
|
(* 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. *)
|
1995-08-09 08:06:35 -07:00
|
|
|
(* *)
|
|
|
|
(***********************************************************************)
|
|
|
|
|
1995-05-04 03:15:53 -07:00
|
|
|
(* Abstract syntax tree after typing *)
|
|
|
|
|
|
|
|
open Misc
|
|
|
|
open Asttypes
|
1996-09-23 04:33:27 -07:00
|
|
|
open Types
|
1996-04-22 04:15:41 -07:00
|
|
|
|
1995-05-04 03:15:53 -07:00
|
|
|
(* Value expressions for the core language *)
|
|
|
|
|
2012-05-30 07:52:37 -07:00
|
|
|
type partial = Partial | Total
|
|
|
|
type optional = Required | Optional
|
|
|
|
|
2013-03-25 07:16:07 -07:00
|
|
|
type attribute = string * Parsetree.expression
|
|
|
|
|
1995-05-04 03:15:53 -07:00
|
|
|
type pattern =
|
|
|
|
{ pat_desc: pattern_desc;
|
|
|
|
pat_loc: Location.t;
|
2013-03-25 07:16:07 -07:00
|
|
|
pat_extra : (pat_extra * Location.t * attribute list) list;
|
1998-04-06 02:23:01 -07:00
|
|
|
pat_type: type_expr;
|
2013-03-25 07:16:07 -07:00
|
|
|
mutable pat_env: Env.t;
|
|
|
|
pat_attributes: attribute list;
|
|
|
|
}
|
1995-05-04 03:15:53 -07:00
|
|
|
|
2012-05-30 07:52:37 -07:00
|
|
|
and pat_extra =
|
|
|
|
| Tpat_constraint of core_type
|
|
|
|
| Tpat_type of Path.t * Longident.t loc
|
|
|
|
| Tpat_unpack
|
|
|
|
|
1995-05-04 03:15:53 -07:00
|
|
|
and pattern_desc =
|
|
|
|
Tpat_any
|
2012-05-30 07:52:37 -07:00
|
|
|
| Tpat_var of Ident.t * string loc
|
|
|
|
| Tpat_alias of pattern * Ident.t * string loc
|
1995-05-04 03:15:53 -07:00
|
|
|
| Tpat_constant of constant
|
|
|
|
| Tpat_tuple of pattern list
|
2012-05-31 01:07:31 -07:00
|
|
|
| Tpat_construct of
|
2012-10-24 05:03:00 -07:00
|
|
|
Longident.t loc * constructor_description * pattern list * bool
|
2008-01-11 08:13:18 -08:00
|
|
|
| Tpat_variant of label * pattern option * row_desc ref
|
2012-05-31 01:07:31 -07:00
|
|
|
| Tpat_record of
|
2012-10-24 05:03:00 -07:00
|
|
|
(Longident.t loc * label_description * pattern) list *
|
2012-05-31 01:07:31 -07:00
|
|
|
closed_flag
|
1998-04-06 02:23:01 -07:00
|
|
|
| Tpat_array of pattern list
|
2008-01-11 08:13:18 -08:00
|
|
|
| Tpat_or of pattern * pattern * row_desc option
|
2008-07-09 06:03:38 -07:00
|
|
|
| Tpat_lazy of pattern
|
1995-05-04 03:15:53 -07:00
|
|
|
|
2012-05-30 07:52:37 -07:00
|
|
|
and expression =
|
1995-05-04 03:15:53 -07:00
|
|
|
{ exp_desc: expression_desc;
|
|
|
|
exp_loc: Location.t;
|
2013-03-25 07:16:07 -07:00
|
|
|
exp_extra: (exp_extra * Location.t * attribute list) list;
|
1996-09-23 04:33:27 -07:00
|
|
|
exp_type: type_expr;
|
2013-03-25 07:16:07 -07:00
|
|
|
exp_env: Env.t;
|
|
|
|
exp_attributes: attribute list;
|
|
|
|
}
|
1995-05-04 03:15:53 -07:00
|
|
|
|
2012-05-30 07:52:37 -07:00
|
|
|
and exp_extra =
|
|
|
|
| Texp_constraint of core_type option * core_type option
|
|
|
|
| Texp_open of Path.t * Longident.t loc * Env.t
|
2012-07-10 01:25:58 -07:00
|
|
|
| Texp_poly of core_type option
|
|
|
|
| Texp_newtype of string
|
2012-05-30 07:52:37 -07:00
|
|
|
|
1995-05-04 03:15:53 -07:00
|
|
|
and expression_desc =
|
2012-05-30 07:52:37 -07:00
|
|
|
Texp_ident of Path.t * Longident.t loc * Types.value_description
|
1995-05-04 03:15:53 -07:00
|
|
|
| Texp_constant of constant
|
|
|
|
| Texp_let of rec_flag * (pattern * expression) list * expression
|
2012-05-30 07:52:37 -07:00
|
|
|
| Texp_function of label * (pattern * expression) list * partial
|
|
|
|
| Texp_apply of expression * (label * expression option * optional) list
|
1999-11-30 08:07:38 -08:00
|
|
|
| Texp_match of expression * (pattern * expression) list * partial
|
1995-05-04 03:15:53 -07:00
|
|
|
| Texp_try of expression * (pattern * expression) list
|
|
|
|
| Texp_tuple of expression list
|
2012-05-31 01:07:31 -07:00
|
|
|
| Texp_construct of
|
2012-10-24 05:03:00 -07:00
|
|
|
Longident.t loc * constructor_description * expression list *
|
2012-05-31 01:07:31 -07:00
|
|
|
bool
|
1999-11-30 08:07:38 -08:00
|
|
|
| Texp_variant of label * expression option
|
2012-05-31 01:07:31 -07:00
|
|
|
| Texp_record of
|
2012-10-24 05:03:00 -07:00
|
|
|
(Longident.t loc * label_description * expression) list *
|
2012-05-31 01:07:31 -07:00
|
|
|
expression option
|
2012-10-24 05:03:00 -07:00
|
|
|
| Texp_field of expression * Longident.t loc * label_description
|
2012-05-31 01:07:31 -07:00
|
|
|
| Texp_setfield of
|
2012-10-24 05:03:00 -07:00
|
|
|
expression * Longident.t loc * label_description * expression
|
1995-05-04 03:15:53 -07:00
|
|
|
| Texp_array of expression list
|
|
|
|
| Texp_ifthenelse of expression * expression * expression option
|
|
|
|
| Texp_sequence of expression * expression
|
|
|
|
| Texp_while of expression * expression
|
|
|
|
| Texp_for of
|
2012-05-31 01:07:31 -07:00
|
|
|
Ident.t * string loc * expression * expression * direction_flag *
|
|
|
|
expression
|
1995-05-04 03:15:53 -07:00
|
|
|
| Texp_when of expression * expression
|
2012-05-30 07:52:37 -07:00
|
|
|
| Texp_send of expression * meth * expression option
|
|
|
|
| Texp_new of Path.t * Longident.t loc * Types.class_declaration
|
|
|
|
| Texp_instvar of Path.t * Path.t * string loc
|
|
|
|
| Texp_setinstvar of Path.t * Path.t * string loc * expression
|
|
|
|
| Texp_override of Path.t * (Path.t * string loc * expression) list
|
|
|
|
| Texp_letmodule of Ident.t * string loc * module_expr * expression
|
2000-12-04 07:37:05 -08:00
|
|
|
| Texp_assert of expression
|
|
|
|
| Texp_assertfalse
|
2002-01-20 09:39:10 -08:00
|
|
|
| Texp_lazy of expression
|
2012-05-30 07:52:37 -07:00
|
|
|
| Texp_object of class_structure * string list
|
2009-10-26 03:53:16 -07:00
|
|
|
| Texp_pack of module_expr
|
1995-05-04 03:15:53 -07:00
|
|
|
|
1997-05-11 14:48:21 -07:00
|
|
|
and meth =
|
|
|
|
Tmeth_name of string
|
|
|
|
| Tmeth_val of Ident.t
|
|
|
|
|
1998-06-24 12:22:26 -07:00
|
|
|
(* Value expressions for the class language *)
|
|
|
|
|
|
|
|
and class_expr =
|
|
|
|
{ cl_desc: class_expr_desc;
|
|
|
|
cl_loc: Location.t;
|
2012-05-30 07:52:37 -07:00
|
|
|
cl_type: Types.class_type;
|
2003-11-25 01:20:45 -08:00
|
|
|
cl_env: Env.t }
|
1998-06-24 12:22:26 -07:00
|
|
|
|
|
|
|
and class_expr_desc =
|
2013-03-25 07:16:07 -07:00
|
|
|
Tcl_ident of Path.t * Longident.t loc * core_type list
|
2012-05-30 07:52:37 -07:00
|
|
|
| Tcl_structure of class_structure
|
2012-05-31 01:07:31 -07:00
|
|
|
| Tcl_fun of
|
|
|
|
label * pattern * (Ident.t * string loc * expression) list * class_expr *
|
|
|
|
partial
|
2012-05-30 07:52:37 -07:00
|
|
|
| Tcl_apply of class_expr * (label * expression option * optional) list
|
|
|
|
| Tcl_let of rec_flag * (pattern * expression) list *
|
|
|
|
(Ident.t * string loc * expression) list * class_expr
|
2012-05-31 01:07:31 -07:00
|
|
|
| Tcl_constraint of
|
|
|
|
class_expr * class_type option * string list * string list * Concr.t
|
2012-05-30 07:52:37 -07:00
|
|
|
(* Visible instance variables, methods and concretes methods *)
|
1998-06-24 12:22:26 -07:00
|
|
|
|
|
|
|
and class_structure =
|
2012-05-30 07:52:37 -07:00
|
|
|
{ cstr_pat : pattern;
|
|
|
|
cstr_fields: class_field list;
|
|
|
|
cstr_type : Types.class_signature;
|
|
|
|
cstr_meths: Ident.t Meths.t }
|
1996-04-22 04:15:41 -07:00
|
|
|
|
1998-02-26 04:54:44 -08:00
|
|
|
and class_field =
|
2012-05-30 07:52:37 -07:00
|
|
|
{
|
|
|
|
cf_desc : class_field_desc;
|
|
|
|
cf_loc : Location.t;
|
|
|
|
}
|
|
|
|
|
|
|
|
and class_field_kind =
|
|
|
|
Tcfk_virtual of core_type
|
|
|
|
| Tcfk_concrete of expression
|
|
|
|
|
|
|
|
and class_field_desc =
|
2012-05-31 01:07:31 -07:00
|
|
|
Tcf_inher of
|
|
|
|
override_flag * class_expr * string option * (string * Ident.t) list *
|
|
|
|
(string * Ident.t) list
|
2012-05-30 07:52:37 -07:00
|
|
|
(* Inherited instance variables and concrete methods *)
|
2012-05-31 01:07:31 -07:00
|
|
|
| Tcf_val of
|
|
|
|
string * string loc * mutable_flag * Ident.t * class_field_kind * bool
|
2012-05-30 07:52:37 -07:00
|
|
|
(* None = virtual, true = override *)
|
|
|
|
| Tcf_meth of string * string loc * private_flag * class_field_kind * bool
|
|
|
|
| Tcf_constr of core_type * core_type
|
|
|
|
(* | Tcf_let of rec_flag * (pattern * expression) list *
|
|
|
|
(Ident.t * string loc * expression) list *)
|
|
|
|
| Tcf_init of expression
|
1996-04-22 04:15:41 -07:00
|
|
|
|
1995-05-04 03:15:53 -07:00
|
|
|
(* Value expressions for the module language *)
|
|
|
|
|
1998-02-26 04:54:44 -08:00
|
|
|
and module_expr =
|
1995-05-04 03:15:53 -07:00
|
|
|
{ mod_desc: module_expr_desc;
|
|
|
|
mod_loc: Location.t;
|
2012-05-30 07:52:37 -07:00
|
|
|
mod_type: Types.module_type;
|
2013-03-25 10:47:28 -07:00
|
|
|
mod_env: Env.t;
|
|
|
|
mod_attributes: attribute list;
|
|
|
|
}
|
1995-05-04 03:15:53 -07:00
|
|
|
|
2012-05-30 07:52:37 -07:00
|
|
|
and module_type_constraint =
|
|
|
|
Tmodtype_implicit
|
|
|
|
| Tmodtype_explicit of module_type
|
|
|
|
|
1995-05-04 03:15:53 -07:00
|
|
|
and module_expr_desc =
|
2012-05-30 07:52:37 -07:00
|
|
|
Tmod_ident of Path.t * Longident.t loc
|
1995-05-04 03:15:53 -07:00
|
|
|
| Tmod_structure of structure
|
2012-05-30 07:52:37 -07:00
|
|
|
| Tmod_functor of Ident.t * string loc * module_type * module_expr
|
1995-05-04 03:15:53 -07:00
|
|
|
| Tmod_apply of module_expr * module_expr * module_coercion
|
2012-05-31 01:07:31 -07:00
|
|
|
| Tmod_constraint of
|
|
|
|
module_expr * Types.module_type * module_type_constraint * module_coercion
|
2012-05-30 07:52:37 -07:00
|
|
|
| Tmod_unpack of expression * Types.module_type
|
1995-05-04 03:15:53 -07:00
|
|
|
|
2012-05-30 07:52:37 -07:00
|
|
|
and structure = {
|
|
|
|
str_items : structure_item list;
|
|
|
|
str_type : Types.signature;
|
|
|
|
str_final_env : Env.t;
|
|
|
|
}
|
1995-05-04 03:15:53 -07:00
|
|
|
|
|
|
|
and structure_item =
|
2012-05-30 07:52:37 -07:00
|
|
|
{ str_desc : structure_item_desc;
|
|
|
|
str_loc : Location.t;
|
|
|
|
str_env : Env.t
|
|
|
|
}
|
|
|
|
|
|
|
|
and structure_item_desc =
|
1995-05-04 03:15:53 -07:00
|
|
|
Tstr_eval of expression
|
|
|
|
| Tstr_value of rec_flag * (pattern * expression) list
|
2013-03-25 11:04:40 -07:00
|
|
|
| Tstr_primitive of value_description
|
2013-03-25 11:20:11 -07:00
|
|
|
| Tstr_type of type_declaration list
|
2013-03-25 11:42:45 -07:00
|
|
|
| Tstr_exception of constructor_declaration
|
2013-03-25 07:16:07 -07:00
|
|
|
| Tstr_exn_rebind of Ident.t * string loc * Path.t * Longident.t loc * attribute list
|
2013-03-26 01:09:26 -07:00
|
|
|
| Tstr_module of module_binding
|
|
|
|
| Tstr_recmodule of module_binding list
|
2012-05-30 07:52:37 -07:00
|
|
|
| Tstr_modtype of Ident.t * string loc * module_type
|
2013-03-25 07:16:07 -07:00
|
|
|
| Tstr_open of Path.t * Longident.t loc * attribute list
|
2012-05-30 07:52:37 -07:00
|
|
|
| Tstr_class of (class_declaration * string list * virtual_flag) list
|
|
|
|
| Tstr_class_type of (Ident.t * string loc * class_type_declaration) list
|
2013-03-25 07:16:07 -07:00
|
|
|
| Tstr_include of module_expr * Ident.t list * attribute list
|
|
|
|
| Tstr_attribute of attribute
|
1995-05-04 03:15:53 -07:00
|
|
|
|
2013-03-26 01:09:26 -07:00
|
|
|
and module_binding =
|
|
|
|
{
|
|
|
|
mb_id: Ident.t;
|
|
|
|
mb_name: string loc;
|
|
|
|
mb_expr: module_expr;
|
|
|
|
mb_attributes: attribute list;
|
|
|
|
}
|
|
|
|
|
1995-05-04 03:15:53 -07:00
|
|
|
and module_coercion =
|
|
|
|
Tcoerce_none
|
|
|
|
| Tcoerce_structure of (int * module_coercion) list
|
|
|
|
| Tcoerce_functor of module_coercion * module_coercion
|
1995-10-23 09:59:41 -07:00
|
|
|
| Tcoerce_primitive of Primitive.description
|
1995-05-04 03:15:53 -07:00
|
|
|
|
2012-05-30 07:52:37 -07:00
|
|
|
and module_type =
|
|
|
|
{ mty_desc: module_type_desc;
|
|
|
|
mty_type : Types.module_type;
|
2013-03-25 07:16:07 -07:00
|
|
|
mty_env : Env.t;
|
|
|
|
mty_loc: Location.t;
|
|
|
|
mty_attributes: attribute list;
|
|
|
|
}
|
2012-05-30 07:52:37 -07:00
|
|
|
|
|
|
|
and module_type_desc =
|
|
|
|
Tmty_ident of Path.t * Longident.t loc
|
|
|
|
| Tmty_signature of signature
|
|
|
|
| Tmty_functor of Ident.t * string loc * module_type * module_type
|
|
|
|
| Tmty_with of module_type * (Path.t * Longident.t loc * with_constraint) list
|
|
|
|
| Tmty_typeof of module_expr
|
|
|
|
|
|
|
|
and signature = {
|
|
|
|
sig_items : signature_item list;
|
|
|
|
sig_type : Types.signature;
|
|
|
|
sig_final_env : Env.t;
|
|
|
|
}
|
|
|
|
|
|
|
|
and signature_item =
|
|
|
|
{ sig_desc: signature_item_desc;
|
|
|
|
sig_env : Env.t; (* BINANNOT ADDED *)
|
|
|
|
sig_loc: Location.t }
|
|
|
|
|
|
|
|
and signature_item_desc =
|
2013-03-25 11:04:40 -07:00
|
|
|
Tsig_value of value_description
|
2013-03-25 11:20:11 -07:00
|
|
|
| Tsig_type of type_declaration list
|
2013-03-25 11:42:45 -07:00
|
|
|
| Tsig_exception of constructor_declaration
|
2013-03-25 10:47:28 -07:00
|
|
|
| Tsig_module of module_declaration
|
|
|
|
| Tsig_recmodule of module_declaration list
|
|
|
|
| Tsig_modtype of module_type_declaration
|
2013-03-25 07:16:07 -07:00
|
|
|
| Tsig_open of Path.t * Longident.t loc * attribute list
|
|
|
|
| Tsig_include of module_type * Types.signature * attribute list
|
2012-05-30 07:52:37 -07:00
|
|
|
| Tsig_class of class_description list
|
|
|
|
| Tsig_class_type of class_type_declaration list
|
2013-03-25 07:16:07 -07:00
|
|
|
| Tsig_attribute of attribute
|
2012-05-30 07:52:37 -07:00
|
|
|
|
2013-03-25 10:47:28 -07:00
|
|
|
and module_declaration =
|
|
|
|
{
|
|
|
|
md_id: Ident.t;
|
|
|
|
md_name: string loc;
|
|
|
|
md_type: module_type;
|
|
|
|
md_attributes: attribute list;
|
|
|
|
}
|
|
|
|
|
|
|
|
and module_type_declaration =
|
|
|
|
{
|
|
|
|
mtd_id: Ident.t;
|
|
|
|
mtd_name: string loc;
|
|
|
|
mtd_type: module_type option;
|
|
|
|
mtd_attributes: attribute list;
|
|
|
|
}
|
2012-05-30 07:52:37 -07:00
|
|
|
|
|
|
|
and with_constraint =
|
|
|
|
Twith_type of type_declaration
|
|
|
|
| Twith_module of Path.t * Longident.t loc
|
|
|
|
| Twith_typesubst of type_declaration
|
|
|
|
| Twith_modsubst of Path.t * Longident.t loc
|
|
|
|
|
|
|
|
and core_type =
|
|
|
|
(* mutable because of [Typeclass.declare_method] *)
|
|
|
|
{ mutable ctyp_desc : core_type_desc;
|
|
|
|
mutable ctyp_type : type_expr;
|
|
|
|
ctyp_env : Env.t; (* BINANNOT ADDED *)
|
2013-03-25 07:16:07 -07:00
|
|
|
ctyp_loc : Location.t;
|
|
|
|
ctyp_attributes: attribute list;
|
|
|
|
}
|
2012-05-30 07:52:37 -07:00
|
|
|
|
|
|
|
and core_type_desc =
|
|
|
|
Ttyp_any
|
|
|
|
| Ttyp_var of string
|
|
|
|
| Ttyp_arrow of label * core_type * core_type
|
|
|
|
| Ttyp_tuple of core_type list
|
|
|
|
| Ttyp_constr of Path.t * Longident.t loc * core_type list
|
|
|
|
| Ttyp_object of core_field_type list
|
|
|
|
| Ttyp_class of Path.t * Longident.t loc * core_type list * label list
|
|
|
|
| Ttyp_alias of core_type * string
|
|
|
|
| Ttyp_variant of row_field list * bool * label list option
|
|
|
|
| Ttyp_poly of string list * core_type
|
|
|
|
| Ttyp_package of package_type
|
|
|
|
|
|
|
|
and package_type = {
|
|
|
|
pack_name : Path.t;
|
|
|
|
pack_fields : (Longident.t loc * core_type) list;
|
|
|
|
pack_type : Types.module_type;
|
|
|
|
pack_txt : Longident.t loc;
|
|
|
|
}
|
|
|
|
|
|
|
|
and core_field_type =
|
|
|
|
{ field_desc: core_field_desc;
|
|
|
|
field_loc: Location.t }
|
|
|
|
|
|
|
|
and core_field_desc =
|
|
|
|
Tcfield of string * core_type
|
|
|
|
| Tcfield_var
|
|
|
|
|
|
|
|
and row_field =
|
|
|
|
Ttag of label * bool * core_type list
|
|
|
|
| Tinherit of core_type
|
|
|
|
|
|
|
|
and value_description =
|
2013-03-25 11:04:40 -07:00
|
|
|
{ val_id: Ident.t;
|
|
|
|
val_name: string loc;
|
|
|
|
val_desc: core_type;
|
|
|
|
val_val: Types.value_description;
|
|
|
|
val_prim: string list;
|
|
|
|
val_loc: Location.t;
|
2013-03-25 07:16:07 -07:00
|
|
|
val_attributes: attribute list;
|
2012-05-30 07:52:37 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
and type_declaration =
|
2013-03-25 11:20:11 -07:00
|
|
|
{ typ_id: Ident.t;
|
|
|
|
typ_name: string loc;
|
|
|
|
typ_params: string loc option list;
|
|
|
|
typ_type: Types.type_declaration;
|
2012-05-30 07:52:37 -07:00
|
|
|
typ_cstrs: (core_type * core_type * Location.t) list;
|
|
|
|
typ_kind: type_kind;
|
|
|
|
typ_private: private_flag;
|
|
|
|
typ_manifest: core_type option;
|
|
|
|
typ_variance: (bool * bool) list;
|
2013-03-25 07:16:07 -07:00
|
|
|
typ_loc: Location.t;
|
|
|
|
typ_attributes: attribute list;
|
|
|
|
}
|
2012-05-30 07:52:37 -07:00
|
|
|
|
|
|
|
and type_kind =
|
|
|
|
Ttype_abstract
|
2013-03-25 07:56:56 -07:00
|
|
|
| Ttype_variant of constructor_declaration list
|
|
|
|
| Ttype_record of label_declaration list
|
|
|
|
|
|
|
|
and label_declaration =
|
|
|
|
{
|
|
|
|
ld_id: Ident.t;
|
|
|
|
ld_name: string loc;
|
|
|
|
ld_mutable: mutable_flag;
|
|
|
|
ld_type: core_type;
|
|
|
|
ld_loc: Location.t;
|
|
|
|
ld_attributes: attribute list;
|
|
|
|
}
|
|
|
|
|
|
|
|
and constructor_declaration =
|
|
|
|
{
|
|
|
|
cd_id: Ident.t;
|
|
|
|
cd_name: string loc;
|
|
|
|
cd_args: core_type list;
|
|
|
|
cd_res: core_type option;
|
|
|
|
cd_loc: Location.t;
|
|
|
|
cd_attributes: attribute list;
|
|
|
|
}
|
2012-05-30 07:52:37 -07:00
|
|
|
|
|
|
|
and class_type =
|
|
|
|
{ cltyp_desc: class_type_desc;
|
|
|
|
cltyp_type : Types.class_type;
|
|
|
|
cltyp_env : Env.t; (* BINANNOT ADDED *)
|
|
|
|
cltyp_loc: Location.t }
|
|
|
|
|
|
|
|
and class_type_desc =
|
|
|
|
Tcty_constr of Path.t * Longident.t loc * core_type list
|
|
|
|
| Tcty_signature of class_signature
|
|
|
|
| Tcty_fun of label * core_type * class_type
|
|
|
|
|
|
|
|
and class_signature = {
|
|
|
|
csig_self : core_type;
|
|
|
|
csig_fields : class_type_field list;
|
|
|
|
csig_type : Types.class_signature;
|
|
|
|
csig_loc : Location.t;
|
|
|
|
}
|
|
|
|
|
|
|
|
and class_type_field = {
|
|
|
|
ctf_desc : class_type_field_desc;
|
|
|
|
ctf_loc : Location.t;
|
|
|
|
}
|
|
|
|
|
|
|
|
and class_type_field_desc =
|
|
|
|
Tctf_inher of class_type
|
|
|
|
| Tctf_val of (string * mutable_flag * virtual_flag * core_type)
|
|
|
|
| Tctf_virt of (string * private_flag * core_type)
|
|
|
|
| Tctf_meth of (string * private_flag * core_type)
|
|
|
|
| Tctf_cstr of (core_type * core_type)
|
|
|
|
|
|
|
|
and class_declaration =
|
|
|
|
class_expr class_infos
|
|
|
|
|
|
|
|
and class_description =
|
|
|
|
class_type class_infos
|
|
|
|
|
|
|
|
and class_type_declaration =
|
|
|
|
class_type class_infos
|
|
|
|
|
|
|
|
and 'a class_infos =
|
|
|
|
{ ci_virt: virtual_flag;
|
|
|
|
ci_params: string loc list * Location.t;
|
|
|
|
ci_id_name : string loc;
|
|
|
|
ci_id_class: Ident.t;
|
|
|
|
ci_id_class_type : Ident.t;
|
|
|
|
ci_id_object : Ident.t;
|
|
|
|
ci_id_typesharp : Ident.t;
|
|
|
|
ci_expr: 'a;
|
|
|
|
ci_decl: Types.class_declaration;
|
|
|
|
ci_type_decl : Types.class_type_declaration;
|
|
|
|
ci_variance: (bool * bool) list;
|
2013-03-25 07:16:07 -07:00
|
|
|
ci_loc: Location.t;
|
|
|
|
ci_attributes: attribute list;
|
|
|
|
}
|
2012-05-30 07:52:37 -07:00
|
|
|
|
1995-05-04 03:15:53 -07:00
|
|
|
(* Auxiliary functions over the a.s.t. *)
|
|
|
|
|
2003-08-11 20:11:38 -07:00
|
|
|
let iter_pattern_desc f = function
|
2012-05-30 07:52:37 -07:00
|
|
|
| Tpat_alias(p, _, _) -> f p
|
2003-08-11 20:11:38 -07:00
|
|
|
| Tpat_tuple patl -> List.iter f patl
|
2012-10-24 05:03:00 -07:00
|
|
|
| Tpat_construct(_, cstr, patl, _) -> List.iter f patl
|
2003-08-11 20:11:38 -07:00
|
|
|
| Tpat_variant(_, pat, _) -> may f pat
|
2012-05-30 07:52:37 -07:00
|
|
|
| Tpat_record (lbl_pat_list, _) ->
|
2012-10-24 05:03:00 -07:00
|
|
|
List.iter (fun (_, lbl, pat) -> f pat) lbl_pat_list
|
2003-08-11 20:11:38 -07:00
|
|
|
| Tpat_array patl -> List.iter f patl
|
|
|
|
| Tpat_or(p1, p2, _) -> f p1; f p2
|
2008-07-09 06:03:38 -07:00
|
|
|
| Tpat_lazy p -> f p
|
2003-08-11 20:11:38 -07:00
|
|
|
| Tpat_any
|
|
|
|
| Tpat_var _
|
|
|
|
| Tpat_constant _ -> ()
|
|
|
|
|
|
|
|
let map_pattern_desc f d =
|
|
|
|
match d with
|
2012-05-30 07:52:37 -07:00
|
|
|
| Tpat_alias (p1, id, s) ->
|
|
|
|
Tpat_alias (f p1, id, s)
|
2003-08-11 20:11:38 -07:00
|
|
|
| Tpat_tuple pats ->
|
|
|
|
Tpat_tuple (List.map f pats)
|
2012-05-30 07:52:37 -07:00
|
|
|
| Tpat_record (lpats, closed) ->
|
2012-10-24 05:03:00 -07:00
|
|
|
Tpat_record (List.map (fun (lid, l,p) -> lid, l, f p) lpats, closed)
|
|
|
|
| Tpat_construct (lid, c,pats, arity) ->
|
|
|
|
Tpat_construct (lid, c, List.map f pats, arity)
|
2003-08-11 20:11:38 -07:00
|
|
|
| Tpat_array pats ->
|
|
|
|
Tpat_array (List.map f pats)
|
2008-07-09 06:03:38 -07:00
|
|
|
| Tpat_lazy p1 -> Tpat_lazy (f p1)
|
2003-08-11 20:11:38 -07:00
|
|
|
| Tpat_variant (x1, Some p1, x2) ->
|
|
|
|
Tpat_variant (x1, Some (f p1), x2)
|
|
|
|
| Tpat_or (p1,p2,path) ->
|
|
|
|
Tpat_or (f p1, f p2, path)
|
|
|
|
| Tpat_var _
|
|
|
|
| Tpat_constant _
|
|
|
|
| Tpat_any
|
|
|
|
| Tpat_variant (_,None,_) -> d
|
|
|
|
|
1995-05-04 03:15:53 -07:00
|
|
|
(* List the identifiers bound by a pattern or a let *)
|
|
|
|
|
2012-05-30 07:52:37 -07:00
|
|
|
let idents = ref([]: (Ident.t * string loc) list)
|
1995-05-04 03:15:53 -07:00
|
|
|
|
|
|
|
let rec bound_idents pat =
|
|
|
|
match pat.pat_desc with
|
2012-05-30 07:52:37 -07:00
|
|
|
| Tpat_var (id,s) -> idents := (id,s) :: !idents
|
|
|
|
| Tpat_alias(p, id, s ) ->
|
|
|
|
bound_idents p; idents := (id,s) :: !idents
|
2001-09-25 02:54:18 -07:00
|
|
|
| Tpat_or(p1, _, _) ->
|
2000-10-02 07:18:05 -07:00
|
|
|
(* Invariant : both arguments binds the same variables *)
|
|
|
|
bound_idents p1
|
2003-08-11 20:11:38 -07:00
|
|
|
| d -> iter_pattern_desc bound_idents d
|
1995-05-04 03:15:53 -07:00
|
|
|
|
|
|
|
let pat_bound_idents pat =
|
|
|
|
idents := []; bound_idents pat; let res = !idents in idents := []; res
|
|
|
|
|
2012-05-30 07:52:37 -07:00
|
|
|
let rev_let_bound_idents_with_loc pat_expr_list =
|
1995-05-04 03:15:53 -07:00
|
|
|
idents := [];
|
|
|
|
List.iter (fun (pat, expr) -> bound_idents pat) pat_expr_list;
|
|
|
|
let res = !idents in idents := []; res
|
|
|
|
|
2012-05-30 07:52:37 -07:00
|
|
|
let let_bound_idents_with_loc pat_expr_list =
|
|
|
|
List.rev(rev_let_bound_idents_with_loc pat_expr_list)
|
|
|
|
|
|
|
|
let rev_let_bound_idents pat = List.map fst (rev_let_bound_idents_with_loc pat)
|
|
|
|
let let_bound_idents pat = List.map fst (let_bound_idents_with_loc pat)
|
2000-10-02 07:18:05 -07:00
|
|
|
|
|
|
|
let alpha_var env id = List.assoc id env
|
|
|
|
|
|
|
|
let rec alpha_pat env p = match p.pat_desc with
|
2012-05-30 07:52:37 -07:00
|
|
|
| Tpat_var (id, s) -> (* note the ``Not_found'' case *)
|
2000-10-02 07:18:05 -07:00
|
|
|
{p with pat_desc =
|
2012-05-30 07:52:37 -07:00
|
|
|
try Tpat_var (alpha_var env id, s) with
|
2000-10-02 07:18:05 -07:00
|
|
|
| Not_found -> Tpat_any}
|
2012-05-30 07:52:37 -07:00
|
|
|
| Tpat_alias (p1, id, s) ->
|
2002-05-16 20:58:35 -07:00
|
|
|
let new_p = alpha_pat env p1 in
|
2000-10-02 07:18:05 -07:00
|
|
|
begin try
|
2012-05-30 07:52:37 -07:00
|
|
|
{p with pat_desc = Tpat_alias (new_p, alpha_var env id, s)}
|
2000-10-02 07:18:05 -07:00
|
|
|
with
|
|
|
|
| Not_found -> new_p
|
|
|
|
end
|
2003-08-11 20:11:38 -07:00
|
|
|
| d ->
|
|
|
|
{p with pat_desc = map_pattern_desc (alpha_pat env) d}
|
2012-05-30 07:52:37 -07:00
|
|
|
|
|
|
|
let mkloc = Location.mkloc
|
|
|
|
let mknoloc = Location.mknoloc
|