ocaml-base-compiler
  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

Abstract syntax tree after typing

By comparison with Parsetree:

  • Every Longindent.t is accompanied by a resolved Path.t.
type partial =
  1. | Partial
  2. | Total

Extension points

type attribute = Parsetree.attribute
type attributes = attribute list

Core language

type value =
  1. | Value_pattern
type computation =
  1. | Computation_pattern
type _ pattern_category =
  1. | Value : value pattern_category
  2. | Computation : computation pattern_category
type pattern = value general_pattern
and 'k general_pattern = 'k pattern_desc pattern_data
and 'a pattern_data = {
  1. pat_desc : 'a;
  2. pat_loc : Location.t;
  3. pat_extra : (pat_extra * Location.t * attributes) list;
  4. pat_type : Types.type_expr;
  5. pat_env : Env.t;
  6. pat_attributes : attributes;
}
and pat_extra =
  1. | Tpat_constraint of core_type
    (*

    P : T pat_desc = P ; pat_extra = (Tpat_constraint T, _, _) :: ...

    *)
  2. | Tpat_type of Path.t * Longident.t Asttypes.loc
    (*

    #tconst pat_desc = disjunction ; pat_extra = (Tpat_type (P, "tconst"), _, _) :: ...

    where disjunction is a Tpat_or _ representing the branches of tconst.

    *)
  3. | Tpat_open of Path.t * Longident.t Asttypes.loc * Env.t
  4. | Tpat_unpack
    (*

    (module P) pat_desc = Tpat_var "P" ; pat_extra = (Tpat_unpack, _, _) :: ...

    *)
and 'k pattern_desc =
  1. | Tpat_any : value pattern_desc
    (*

    _

    *)
  2. | Tpat_var : Ident.t * string Asttypes.loc -> value pattern_desc
    (*

    x

    *)
  3. | Tpat_alias : value general_pattern * Ident.t * string Asttypes.loc -> value pattern_desc
    (*

    P as a

    *)
  4. | Tpat_constant : Asttypes.constant -> value pattern_desc
    (*

    1, 'a', "true", 1.0, 1l, 1L, 1n

    *)
  5. | Tpat_tuple : value general_pattern list -> value pattern_desc
    (*

    (P1, ..., Pn)

    Invariant: n >= 2

    *)
  6. | Tpat_construct : Longident.t Asttypes.loc * Types.constructor_description * value general_pattern list * (Ident.t Asttypes.loc list * core_type) option -> value pattern_desc
    (*

    C (, None) C P (P, None) C (P1, ..., Pn) (P1; ...; Pn, None) C (P : t) (P, Some (, t)) C (P1, ..., Pn : t) (P1; ...; Pn, Some (, t)) C (type a) (P : t) (P, Some (a, t)) C (type a) (P1, ..., Pn : t) (P1; ...; Pn, Some (a, t))

    *)
  7. | Tpat_variant : Asttypes.label * value general_pattern option * Types.row_desc ref -> value pattern_desc
    (*

    `A (None) `A P (Some P)

    See Types.row_desc for an explanation of the last parameter.

    *)
  8. | Tpat_record : (Longident.t Asttypes.loc * Types.label_description * value general_pattern) list * Asttypes.closed_flag -> value pattern_desc
    (*

    l1=P1; ...; ln=Pn (flag = Closed) l1=P1; ...; ln=Pn; _ (flag = Open)

    Invariant: n > 0

    *)
  9. | Tpat_array : value general_pattern list -> value pattern_desc
    (*

    | P1; ...; Pn |

    *)
  10. | Tpat_lazy : value general_pattern -> value pattern_desc
    (*

    lazy P

    *)
  11. | Tpat_value : tpat_value_argument -> computation pattern_desc
    (*

    P

    Invariant: Tpat_value pattern should not carry pat_attributes or pat_extra metadata coming from user syntax, which must be on the inner pattern node -- to facilitate searching for a certain value pattern constructor with a specific attributed.

    To enforce this restriction, we made the argument of the Tpat_value constructor a private synonym of pattern, requiring you to use the as_computation_pattern function below instead of using the Tpat_value constructor directly.

    *)
  12. | Tpat_exception : value general_pattern -> computation pattern_desc
    (*

    exception P

    *)
  13. | Tpat_or : 'k general_pattern * 'k general_pattern * Types.row_desc option -> 'k pattern_desc
    (*

    P1 | P2

    row_desc = Some _ when translating Ppat_type _, None otherwise.

    *)
and tpat_value_argument = private value general_pattern
and expression = {
  1. exp_desc : expression_desc;
  2. exp_loc : Location.t;
  3. exp_extra : (exp_extra * Location.t * attributes) list;
  4. exp_type : Types.type_expr;
  5. exp_env : Env.t;
  6. exp_attributes : attributes;
}
and exp_extra =
  1. | Texp_constraint of core_type
    (*

    E : T

    *)
  2. | Texp_coerce of core_type option * core_type
    (*

    E :> T Texp_coerce (None, T) E : T0 :> T Texp_coerce (Some T0, T)

    *)
  3. | Texp_poly of core_type option
    (*

    Used for method bodies.

    *)
  4. | Texp_newtype of string
    (*

    fun (type t) ->

    *)
and expression_desc =
  1. | Texp_ident of Path.t * Longident.t Asttypes.loc * Types.value_description
    (*

    x M.x

    *)
  2. | Texp_constant of Asttypes.constant
    (*

    1, 'a', "true", 1.0, 1l, 1L, 1n

    *)
  3. | Texp_let of Asttypes.rec_flag * value_binding list * expression
    (*

    let P1 = E1 and ... and Pn = EN in E (flag = Nonrecursive) let rec P1 = E1 and ... and Pn = EN in E (flag = Recursive)

    *)
  4. | Texp_function of {
    1. arg_label : Asttypes.arg_label;
    2. param : Ident.t;
    3. cases : value case list;
    4. partial : partial;
    }
    (*

    Pexp_fun and Pexp_function both translate to Texp_function. See Parsetree for more details.

    param is the identifier that is to be used to name the parameter of the function.

    partial = Partial if the pattern match is partial Total otherwise.

    *)
  5. | Texp_apply of expression * (Asttypes.arg_label * expression option) list
    (*

    E0 ~l1:E1 ... ~ln:En

    The expression can be None if the expression is abstracted over this argument. It currently appears when a label is applied.

    For example: let f x ~y = x + y in f ~y:3

    The resulting typedtree for the application is: Texp_apply (Texp_ident "f/1037", (Nolabel, None); (Labelled "y", Some (Texp_constant Const_int 3)) )

    *)
  6. | Texp_match of expression * computation case list * partial
    (*

    match E0 with | P1 -> E1 | P2 | exception P3 -> E2 | exception P4 -> E3

    Texp_match (E0, [(P1, E1); (P2 | exception P3, E2); (exception P4, E3)], _)

    *)
  7. | Texp_try of expression * value case list
    (*

    try E with P1 -> E1 | ... | PN -> EN

    *)
  8. | Texp_tuple of expression list
    (*

    (E1, ..., EN)

    *)
  9. | Texp_construct of Longident.t Asttypes.loc * Types.constructor_description * expression list
    (*

    C C E E C (E1, ..., En) E1;...;En

    *)
  10. | Texp_variant of Asttypes.label * expression option
  11. | Texp_record of {
    1. fields : (Types.label_description * record_label_definition) array;
    2. representation : Types.record_representation;
    3. extended_expression : expression option;
    }
    (*

    l1=P1; ...; ln=Pn (extended_expression = None) E0 with l1=P1; ...; ln=Pn (extended_expression = Some E0)

    Invariant: n > 0

    If the type is l1: t1; l2: t2 , the expression E0 with t2=P2 is represented as Texp_record fields = [| l1, Kept t1; l2 Override P2 |]; representation; extended_expression = Some E0

    *)
  12. | Texp_field of expression * Longident.t Asttypes.loc * Types.label_description
  13. | Texp_setfield of expression * Longident.t Asttypes.loc * Types.label_description * expression
  14. | Texp_array of expression list
  15. | Texp_ifthenelse of expression * expression * expression option
  16. | Texp_sequence of expression * expression
  17. | Texp_while of expression * expression
  18. | Texp_for of Ident.t * Parsetree.pattern * expression * expression * Asttypes.direction_flag * expression
  19. | Texp_send of expression * meth * expression option
  20. | Texp_new of Path.t * Longident.t Asttypes.loc * Types.class_declaration
  21. | Texp_instvar of Path.t * Path.t * string Asttypes.loc
  22. | Texp_setinstvar of Path.t * Path.t * string Asttypes.loc * expression
  23. | Texp_override of Path.t * (Path.t * string Asttypes.loc * expression) list
  24. | Texp_letmodule of Ident.t option * string option Asttypes.loc * Types.module_presence * module_expr * expression
  25. | Texp_letexception of extension_constructor * expression
  26. | Texp_assert of expression
  27. | Texp_lazy of expression
  28. | Texp_object of class_structure * string list
  29. | Texp_pack of module_expr
  30. | Texp_letop of {
    1. let_ : binding_op;
    2. ands : binding_op list;
    3. param : Ident.t;
    4. body : value case;
    5. partial : partial;
    }
  31. | Texp_unreachable
  32. | Texp_extension_constructor of Longident.t Asttypes.loc * Path.t
  33. | Texp_open of open_declaration * expression
    (*

    let open! M in e

    *)
and meth =
  1. | Tmeth_name of string
  2. | Tmeth_val of Ident.t
and 'k case = {
  1. c_lhs : 'k general_pattern;
  2. c_guard : expression option;
  3. c_rhs : expression;
}
and record_label_definition =
  1. | Kept of Types.type_expr
  2. | Overridden of Longident.t Asttypes.loc * expression
and binding_op = {
  1. bop_op_path : Path.t;
  2. bop_op_name : string Asttypes.loc;
  3. bop_op_val : Types.value_description;
  4. bop_op_type : Types.type_expr;
  5. bop_exp : expression;
  6. bop_loc : Location.t;
}
and class_expr = {
  1. cl_desc : class_expr_desc;
  2. cl_loc : Location.t;
  3. cl_type : Types.class_type;
  4. cl_env : Env.t;
  5. cl_attributes : attributes;
}
and class_expr_desc =
  1. | Tcl_ident of Path.t * Longident.t Asttypes.loc * core_type list
  2. | Tcl_structure of class_structure
  3. | Tcl_fun of Asttypes.arg_label * pattern * (Ident.t * expression) list * class_expr * partial
  4. | Tcl_apply of class_expr * (Asttypes.arg_label * expression option) list
  5. | Tcl_let of Asttypes.rec_flag * value_binding list * (Ident.t * expression) list * class_expr
  6. | Tcl_constraint of class_expr * class_type option * string list * string list * Types.Concr.t
  7. | Tcl_open of open_description * class_expr
and class_structure = {
  1. cstr_self : pattern;
  2. cstr_fields : class_field list;
  3. cstr_type : Types.class_signature;
  4. cstr_meths : Ident.t Types.Meths.t;
}
and class_field = {
  1. cf_desc : class_field_desc;
  2. cf_loc : Location.t;
  3. cf_attributes : attributes;
}
and class_field_kind =
  1. | Tcfk_virtual of core_type
  2. | Tcfk_concrete of Asttypes.override_flag * expression
and class_field_desc =
  1. | Tcf_inherit of Asttypes.override_flag * class_expr * string option * (string * Ident.t) list * (string * Ident.t) list
  2. | Tcf_val of string Asttypes.loc * Asttypes.mutable_flag * Ident.t * class_field_kind * bool
  3. | Tcf_method of string Asttypes.loc * Asttypes.private_flag * class_field_kind
  4. | Tcf_constraint of core_type * core_type
  5. | Tcf_initializer of expression
  6. | Tcf_attribute of attribute
and module_expr = {
  1. mod_desc : module_expr_desc;
  2. mod_loc : Location.t;
  3. mod_type : Types.module_type;
  4. mod_env : Env.t;
  5. mod_attributes : attributes;
}
and module_type_constraint =
  1. | Tmodtype_implicit
    (*

    The module type constraint has been synthesized during typechecking.

    *)
  2. | Tmodtype_explicit of module_type
    (*

    The module type was in the source file.

    *)

Annotations for Tmod_constraint.

and functor_parameter =
  1. | Unit
  2. | Named of Ident.t option * string option Asttypes.loc * module_type
and module_expr_desc =
  1. | Tmod_ident of Path.t * Longident.t Asttypes.loc
  2. | Tmod_structure of structure
  3. | Tmod_functor of functor_parameter * module_expr
  4. | Tmod_apply of module_expr * module_expr * module_coercion
  5. | Tmod_constraint of module_expr * Types.module_type * module_type_constraint * module_coercion
    (*

    ME (constraint = Tmodtype_implicit) (ME : MT) (constraint = Tmodtype_explicit MT)

    *)
  6. | Tmod_unpack of expression * Types.module_type
and structure = {
  1. str_items : structure_item list;
  2. str_type : Types.signature;
  3. str_final_env : Env.t;
}
and structure_item = {
  1. str_desc : structure_item_desc;
  2. str_loc : Location.t;
  3. str_env : Env.t;
}
and structure_item_desc =
  1. | Tstr_eval of expression * attributes
  2. | Tstr_value of Asttypes.rec_flag * value_binding list
  3. | Tstr_primitive of value_description
  4. | Tstr_type of Asttypes.rec_flag * type_declaration list
  5. | Tstr_typext of type_extension
  6. | Tstr_exception of type_exception
  7. | Tstr_module of module_binding