Module Frontend.Ast

Abstract syntax tree for Stan. Defined with the 'two-level types' pattern, where the variant types are not directly recursive, but rather parametric in some other type.

This type ends up being substituted for the fixpoint of the recursive type itself including metadata. So instead of recursively referencing expression you would instead reference type parameter 'e, which will later be filled in with something like type expr_with_meta = metadata expression

type identifier = {
  1. name : string;
  2. id_loc : Middle.Location_span.t;
}

Our type for identifiers, on which we record a location

val identifier_of_sexp : Sexplib0.Sexp.t -> identifier
val sexp_of_identifier : identifier -> Sexplib0.Sexp.t
val hash_fold_identifier : Ppx_hash_lib.Std.Hash.state -> identifier -> Ppx_hash_lib.Std.Hash.state
val hash_identifier : identifier -> Ppx_hash_lib.Std.Hash.hash_value
val compare_identifier : identifier -> identifier -> int
type 'e index =
  1. | All
  2. | Single of 'e
  3. | Upfrom of 'e
  4. | Downfrom of 'e
  5. | Between of 'e * 'e

Indices for array access

val map_index : ('a -> 'b) -> 'a index -> 'b index
val fold_index : ('a -> 'b -> 'a) -> 'a -> 'b index -> 'a
val index_of_sexp : 'e. (Sexplib0.Sexp.t -> 'e) -> Sexplib0.Sexp.t -> 'e index
val sexp_of_index : 'e. ('e -> Sexplib0.Sexp.t) -> 'e index -> Sexplib0.Sexp.t
val hash_fold_index : 'e. (Ppx_hash_lib.Std.Hash.state -> 'e -> Ppx_hash_lib.Std.Hash.state) -> Ppx_hash_lib.Std.Hash.state -> 'e index -> Ppx_hash_lib.Std.Hash.state
val compare_index : 'e. ('e -> 'e -> int) -> 'e index -> 'e index -> int
type fun_kind =
  1. | StanLib of bool Middle.Fun_kind.suffix
  2. | UserDefined of bool Middle.Fun_kind.suffix

Front-end function kinds

val compare_fun_kind : fun_kind -> fun_kind -> int
val fun_kind_of_sexp : Sexplib0.Sexp.t -> fun_kind
val sexp_of_fun_kind : fun_kind -> Sexplib0.Sexp.t
val hash_fold_fun_kind : Ppx_hash_lib.Std.Hash.state -> fun_kind -> Ppx_hash_lib.Std.Hash.state
val hash_fun_kind : fun_kind -> Ppx_hash_lib.Std.Hash.hash_value
type ('e, 'f) expression =
  1. | TernaryIf of 'e * 'e * 'e
  2. | BinOp of 'e * Middle.Operator.t * 'e
  3. | PrefixOp of Middle.Operator.t * 'e
  4. | PostfixOp of 'e * Middle.Operator.t
  5. | Variable of identifier
  6. | IntNumeral of string
  7. | RealNumeral of string
  8. | ImagNumeral of string
  9. | FunApp of 'f * identifier * 'e list
  10. | CondDistApp of 'f * identifier * 'e list
  11. | Promotion of 'e * Middle.UnsizedType.t * Middle.UnsizedType.autodifftype
  12. | GetTarget
  13. | ArrayExpr of 'e list
  14. | RowVectorExpr of 'e list
  15. | Paren of 'e
  16. | Indexed of 'e * 'e index list
  17. | TupleProjection of 'e * int
  18. | TupleExpr of 'e list

Expression shapes (used for both typed and untyped expressions, where we substitute untyped_expression or typed_expression for 'e

val map_expression : ('a -> 'b) -> ('c -> 'd) -> ('a, 'c) expression -> ('b, 'd) expression
val fold_expression : ('a -> 'b -> 'a) -> ('a -> 'c -> 'a) -> 'a -> ('b, 'c) expression -> 'a
val expression_of_sexp : 'e 'f. (Sexplib0.Sexp.t -> 'e) -> (Sexplib0.Sexp.t -> 'f) -> Sexplib0.Sexp.t -> ('e, 'f) expression
val sexp_of_expression : 'e 'f. ('e -> Sexplib0.Sexp.t) -> ('f -> Sexplib0.Sexp.t) -> ('e, 'f) expression -> Sexplib0.Sexp.t
val hash_fold_expression : 'e 'f. (Ppx_hash_lib.Std.Hash.state -> 'e -> Ppx_hash_lib.Std.Hash.state) -> (Ppx_hash_lib.Std.Hash.state -> 'f -> Ppx_hash_lib.Std.Hash.state) -> Ppx_hash_lib.Std.Hash.state -> ('e, 'f) expression -> Ppx_hash_lib.Std.Hash.state
val compare_expression : 'e 'f. ('e -> 'e -> Core__.Import.int) -> ('f -> 'f -> Core__.Import.int) -> ('e, 'f) expression -> ('e, 'f) expression -> Core__.Import.int
type ('m, 'f) expr_with = {
  1. expr : (('m, 'f) expr_with, 'f) expression;
  2. emeta : 'm;
}
val map_expr_with : ('m -> 'a) -> ('f -> 'b) -> ('m, 'f) expr_with -> ('a, 'b) expr_with
val fold_expr_with : ('a -> 'b -> 'a) -> ('a -> 'c -> 'a) -> 'a -> ('b, 'c) expr_with -> 'a
val expr_with_of_sexp : 'm 'f. (Sexplib0.Sexp.t -> 'm) -> (Sexplib0.Sexp.t -> 'f) -> Sexplib0.Sexp.t -> ('m, 'f) expr_with
val sexp_of_expr_with : 'm 'f. ('m -> Sexplib0.Sexp.t) -> ('f -> Sexplib0.Sexp.t) -> ('m, 'f) expr_with -> Sexplib0.Sexp.t
val compare_expr_with : 'm 'f. ('m -> 'm -> Core__.Import.int) -> ('f -> 'f -> Core__.Import.int) -> ('m, 'f) expr_with -> ('m, 'f) expr_with -> Core__.Import.int
val hash_fold_expr_with : 'm 'f. (Ppx_hash_lib.Std.Hash.state -> 'm -> Ppx_hash_lib.Std.Hash.state) -> (Ppx_hash_lib.Std.Hash.state -> 'f -> Ppx_hash_lib.Std.Hash.state) -> Ppx_hash_lib.Std.Hash.state -> ('m, 'f) expr_with -> Ppx_hash_lib.Std.Hash.state
type located_meta = {
  1. loc : Middle.Location_span.t;
}

Untyped expressions, which have location_spans as meta-data

val map_located_meta : located_meta -> located_meta
val fold_located_meta : 'a -> located_meta -> 'a
val located_meta_of_sexp : Sexplib0.Sexp.t -> located_meta
val sexp_of_located_meta : located_meta -> Sexplib0.Sexp.t
val compare_located_meta : located_meta -> located_meta -> int
val hash_fold_located_meta : Ppx_hash_lib.Std.Hash.state -> located_meta -> Ppx_hash_lib.Std.Hash.state
val hash_located_meta : located_meta -> Ppx_hash_lib.Std.Hash.hash_value
type untyped_expression = (located_meta, unit) expr_with
val map_untyped_expression : 'a -> 'a
val fold_untyped_expression : 'a -> 'b -> 'a
val untyped_expression_of_sexp : Sexplib0.Sexp.t -> untyped_expression
val sexp_of_untyped_expression : untyped_expression -> Sexplib0.Sexp.t
val compare_untyped_expression : untyped_expression -> untyped_expression -> int
val hash_fold_untyped_expression : Ppx_hash_lib.Std.Hash.state -> untyped_expression -> Ppx_hash_lib.Std.Hash.state
val hash_untyped_expression : untyped_expression -> Ppx_hash_lib.Std.Hash.hash_value
type typed_expr_meta = {
  1. loc : Middle.Location_span.t;
  2. ad_level : Middle.UnsizedType.autodifftype;
  3. type_ : Middle.UnsizedType.t;
}

Typed expressions also have meta-data after type checking: a location_span, as well as a type and an origin block (lub of the origin blocks of the identifiers in it)

val map_typed_expr_meta : typed_expr_meta -> typed_expr_meta
val fold_typed_expr_meta : 'a -> typed_expr_meta -> 'a
val typed_expr_meta_of_sexp : Sexplib0.Sexp.t -> typed_expr_meta
val sexp_of_typed_expr_meta : typed_expr_meta -> Sexplib0.Sexp.t
val compare_typed_expr_meta : typed_expr_meta -> typed_expr_meta -> int
val hash_fold_typed_expr_meta : Ppx_hash_lib.Std.Hash.state -> typed_expr_meta -> Ppx_hash_lib.Std.Hash.state
val hash_typed_expr_meta : typed_expr_meta -> Ppx_hash_lib.Std.Hash.hash_value
type typed_expression = (typed_expr_meta, fun_kind) expr_with
val map_typed_expression : 'a -> 'a
val fold_typed_expression : 'a -> 'b -> 'a
val typed_expression_of_sexp : Sexplib0.Sexp.t -> typed_expression
val sexp_of_typed_expression : typed_expression -> Sexplib0.Sexp.t
val compare_typed_expression : typed_expression -> typed_expression -> int
val hash_fold_typed_expression : Ppx_hash_lib.Std.Hash.state -> typed_expression -> Ppx_hash_lib.Std.Hash.state
val hash_typed_expression : typed_expression -> Ppx_hash_lib.Std.Hash.hash_value
val mk_untyped_expression : expr:((located_meta, 'a) expr_with, 'a) expression -> loc:Middle.Location_span.t -> (located_meta, 'a) expr_with
val expr_loc_lub : (typed_expr_meta, 'a) expr_with list -> Middle.Location_span.t
val expr_ad_lub : (typed_expr_meta, 'a) expr_with list -> Middle.UnsizedType.autodifftype option

Least upper bound of expression autodiff types

type assignmentoperator =
  1. | Assign
  2. | OperatorAssign of Middle.Operator.t

Assignment operators

val assignmentoperator_of_sexp : Sexplib0.Sexp.t -> assignmentoperator
val sexp_of_assignmentoperator : assignmentoperator -> Sexplib0.Sexp.t
val hash_fold_assignmentoperator : Ppx_hash_lib.Std.Hash.state -> assignmentoperator -> Ppx_hash_lib.Std.Hash.state
val hash_assignmentoperator : assignmentoperator -> Ppx_hash_lib.Std.Hash.hash_value
val compare_assignmentoperator : assignmentoperator -> assignmentoperator -> int
type 'e truncation =
  1. | NoTruncate
  2. | TruncateUpFrom of 'e
  3. | TruncateDownFrom of 'e
  4. | TruncateBetween of 'e * 'e

Truncations

val map_truncation : ('a -> 'b) -> 'a truncation -> 'b truncation
val fold_truncation : ('a -> 'b -> 'a) -> 'a -> 'b truncation -> 'a
val truncation_of_sexp : 'e. (Sexplib0.Sexp.t -> 'e) -> Sexplib0.Sexp.t -> 'e truncation
val sexp_of_truncation : 'e. ('e -> Sexplib0.Sexp.t) -> 'e truncation -> Sexplib0.Sexp.t
val hash_fold_truncation : 'e. (Ppx_hash_lib.Std.Hash.state -> 'e -> Ppx_hash_lib.Std.Hash.state) -> Ppx_hash_lib.Std.Hash.state -> 'e truncation -> Ppx_hash_lib.Std.Hash.state
val compare_truncation : 'e. ('e -> 'e -> int) -> 'e truncation -> 'e truncation -> int
type 'e printable =
  1. | PString of string
  2. | PExpr of 'e

Things that can be printed

val map_printable : ('a -> 'b) -> 'a printable -> 'b printable
val fold_printable : ('a -> 'b -> 'a) -> 'a -> 'b printable -> 'a
val printable_of_sexp : 'e. (Sexplib0.Sexp.t -> 'e) -> Sexplib0.Sexp.t -> 'e printable
val sexp_of_printable : 'e. ('e -> Sexplib0.Sexp.t) -> 'e printable -> Sexplib0.Sexp.t
val compare_printable : 'e. ('e -> 'e -> Core__.Import.int) -> 'e printable -> 'e printable -> Core__.Import.int
val hash_fold_printable : 'e. (Ppx_hash_lib.Std.Hash.state -> 'e -> Ppx_hash_lib.Std.Hash.state) -> Ppx_hash_lib.Std.Hash.state -> 'e printable -> Ppx_hash_lib.Std.Hash.state
type ('l, 'e) lvalue =
  1. | LVariable of identifier
  2. | LIndexed of 'l * 'e index list
  3. | LTupleProjection of 'l * int
val map_lvalue : ('a -> 'b) -> ('c -> 'd) -> ('a, 'c) lvalue -> ('b, 'd) lvalue
val fold_lvalue : ('a -> 'b -> 'a) -> ('a -> 'c -> 'a) -> 'a -> ('b, 'c) lvalue -> 'a
val lvalue_of_sexp : 'l 'e. (Sexplib0.Sexp.t -> 'l) -> (Sexplib0.Sexp.t -> 'e) -> Sexplib0.Sexp.t -> ('l, 'e) lvalue
val sexp_of_lvalue : 'l 'e. ('l -> Sexplib0.Sexp.t) -> ('e -> Sexplib0.Sexp.t) -> ('l, 'e) lvalue -> Sexplib0.Sexp.t
val hash_fold_lvalue : 'l 'e. (Ppx_hash_lib.Std.Hash.state -> 'l -> Ppx_hash_lib.Std.Hash.state) -> (Ppx_hash_lib.Std.Hash.state -> 'e -> Ppx_hash_lib.Std.Hash.state) -> Ppx_hash_lib.Std.Hash.state -> ('l, 'e) lvalue -> Ppx_hash_lib.Std.Hash.state
val compare_lvalue : 'l 'e. ('l -> 'l -> Core__.Import.int) -> ('e -> 'e -> Core__.Import.int) -> ('l, 'e) lvalue -> ('l, 'e) lvalue -> Core__.Import.int
type 'l lvalue_pack =
  1. | LValue of 'l
  2. | LTuplePack of {
    1. lvals : 'l lvalue_pack list;
    2. loc : Middle.Location_span.t;
    }
val map_lvalue_pack : ('a -> 'b) -> 'a lvalue_pack -> 'b lvalue_pack
val fold_lvalue_pack : ('a -> 'b -> 'a) -> 'a -> 'b lvalue_pack -> 'a
val lvalue_pack_of_sexp : 'l. (Sexplib0.Sexp.t -> 'l) -> Sexplib0.Sexp.t -> 'l lvalue_pack
val sexp_of_lvalue_pack : 'l. ('l -> Sexplib0.Sexp.t) -> 'l lvalue_pack -> Sexplib0.Sexp.t
val hash_fold_lvalue_pack : 'l. (Ppx_hash_lib.Std.Hash.state -> 'l -> Ppx_hash_lib.Std.Hash.state) -> Ppx_hash_lib.Std.Hash.state -> 'l lvalue_pack -> Ppx_hash_lib.Std.Hash.state
val compare_lvalue_pack : 'l. ('l -> 'l -> Core__.Import.int) -> 'l lvalue_pack -> 'l lvalue_pack -> Core__.Import.int
type ('e, 'm) lval_with = {
  1. lval : (('e, 'm) lval_with, 'e) lvalue;
  2. lmeta : 'm;
}
val map_lval_with : ('e -> 'a) -> ('m -> 'b) -> ('e, 'm) lval_with -> ('a, 'b) lval_with
val fold_lval_with : ('a -> 'b -> 'a) -> ('a -> 'c -> 'a) -> 'a -> ('b, 'c) lval_with -> 'a
val lval_with_of_sexp : 'e 'm. (Sexplib0.Sexp.t -> 'e) -> (Sexplib0.Sexp.t -> 'm) -> Sexplib0.Sexp.t -> ('e, 'm) lval_with
val sexp_of_lval_with : 'e 'm. ('e -> Sexplib0.Sexp.t) -> ('m -> Sexplib0.Sexp.t) -> ('e, 'm) lval_with -> Sexplib0.Sexp.t
val hash_fold_lval_with : 'e 'm. (Ppx_hash_lib.Std.Hash.state -> 'e -> Ppx_hash_lib.Std.Hash.state) -> (Ppx_hash_lib.Std.Hash.state -> 'm -> Ppx_hash_lib.Std.Hash.state) -> Ppx_hash_lib.Std.Hash.state -> ('e, 'm) lval_with -> Ppx_hash_lib.Std.Hash.state
val compare_lval_with : 'e 'm. ('e -> 'e -> Core__.Import.int) -> ('m -> 'm -> Core__.Import.int) -> ('e, 'm) lval_with -> ('e, 'm) lval_with -> Core__.Import.int
val map_untyped_lval : 'a -> 'a
val fold_untyped_lval : 'a -> 'b -> 'a
val untyped_lval_of_sexp : Sexplib0.Sexp.t -> untyped_lval
val sexp_of_untyped_lval : untyped_lval -> Sexplib0.Sexp.t
val hash_fold_untyped_lval : Ppx_hash_lib.Std.Hash.state -> untyped_lval -> Ppx_hash_lib.Std.Hash.state
val hash_untyped_lval : untyped_lval -> Ppx_hash_lib.Std.Hash.hash_value
val compare_untyped_lval : untyped_lval -> untyped_lval -> int
type untyped_lval_pack = untyped_lval lvalue_pack
val untyped_lval_pack_of_sexp : Sexplib0.Sexp.t -> untyped_lval_pack
val sexp_of_untyped_lval_pack : untyped_lval_pack -> Sexplib0.Sexp.t
val compare_untyped_lval_pack : untyped_lval_pack -> untyped_lval_pack -> int
val map_typed_lval : 'a -> 'a
val fold_typed_lval : 'a -> 'b -> 'a
val typed_lval_of_sexp : Sexplib0.Sexp.t -> typed_lval
val sexp_of_typed_lval : typed_lval -> Sexplib0.Sexp.t
val hash_fold_typed_lval : Ppx_hash_lib.Std.Hash.state -> typed_lval -> Ppx_hash_lib.Std.Hash.state
val hash_typed_lval : typed_lval -> Ppx_hash_lib.Std.Hash.hash_value
val compare_typed_lval : typed_lval -> typed_lval -> int
type typed_lval_pack = typed_lval lvalue_pack
val typed_lval_pack_of_sexp : Sexplib0.Sexp.t -> typed_lval_pack
val sexp_of_typed_lval_pack : typed_lval_pack -> Sexplib0.Sexp.t
val compare_typed_lval_pack : typed_lval_pack -> typed_lval_pack -> int
type 'e variable = {
  1. identifier : identifier;
  2. initial_value : 'e option;
}
val map_variable : ('e -> 'a) -> 'e variable -> 'a variable
val fold_variable : ('a -> 'b -> 'a) -> 'a -> 'b variable -> 'a
val variable_of_sexp : 'e. (Sexplib0.Sexp.t -> 'e) -> Sexplib0.Sexp.t -> 'e variable
val sexp_of_variable : 'e. ('e -> Sexplib0.Sexp.t) -> 'e variable -> Sexplib0.Sexp.t
val hash_fold_variable : 'e. (Ppx_hash_lib.Std.Hash.state -> 'e -> Ppx_hash_lib.Std.Hash.state) -> Ppx_hash_lib.Std.Hash.state -> 'e variable -> Ppx_hash_lib.Std.Hash.state
val compare_variable : 'e. ('e -> 'e -> Core__.Import.int) -> 'e variable -> 'e variable -> Core__.Import.int
type ('e, 's, 'l, 'f) statement =
  1. | Assignment of {
    1. assign_lhs : 'l lvalue_pack;
    2. assign_op : assignmentoperator;
    3. assign_rhs : 'e;
    }
  2. | NRFunApp of 'f * identifier * 'e list
  3. | TargetPE of 'e
  4. | JacobianPE of 'e
  5. | Tilde of {
    1. arg : 'e;
    2. distribution : identifier;
    3. args : 'e list;
    4. truncation : 'e truncation;
    }
  6. | Break
  7. | Continue
  8. | Return of 'e
  9. | ReturnVoid
  10. | Print of 'e printable list
  11. | Reject of 'e printable list
  12. | FatalError of 'e printable list
  13. | Skip
  14. | IfThenElse of 'e * 's * 's option
  15. | While of 'e * 's
  16. | For of {
    1. loop_variable : identifier;
    2. lower_bound : 'e;
    3. upper_bound : 'e;
    4. loop_body : 's;
    }
  17. | ForEach of identifier * 'e * 's
  18. | Profile of string * 's list
  19. | Block of 's list
  20. | VarDecl of {
    1. decl_type : 'e Middle.SizedType.t;
    2. transformation : 'e Middle.Transformation.t;
    3. is_global : bool;
    4. variables : 'e variable list;
    }
  21. | FunDef of {
    1. returntype : Middle.UnsizedType.returntype;
    2. funname : identifier;
    3. arguments : (Middle.UnsizedType.autodifftype * Middle.UnsizedType.t * identifier) list;
    4. body : 's;
    }

Statement shapes, where we substitute untyped_expression and untyped_statement for 'e and 's respectively to get untyped_statement and typed_expression and typed_statement to get typed_statement

val map_statement : ('a -> 'b) -> ('c -> 'd) -> ('e -> 'f) -> ('g -> 'h) -> ('a, 'c, 'e, 'g) statement -> ('b, 'd, 'f, 'h) statement
val fold_statement : ('a -> 'b -> 'a) -> ('a -> 'c -> 'a) -> ('a -> 'd -> 'a) -> ('a -> 'e -> 'a) -> 'a -> ('b, 'c, 'd, 'e) statement -> 'a
val statement_of_sexp : 'e 's 'l 'f. (Sexplib0.Sexp.t -> 'e) -> (Sexplib0.Sexp.t -> 's) -> (Sexplib0.Sexp.t -> 'l) -> (Sexplib0.Sexp.t -> 'f) -> Sexplib0.Sexp.t -> ('e, 's, 'l, 'f) statement
val sexp_of_statement : 'e 's 'l 'f. ('e -> Sexplib0.Sexp.t) -> ('s -> Sexplib0.Sexp.t) -> ('l -> Sexplib0.Sexp.t) -> ('f -> Sexplib0.Sexp.t) -> ('e, 's, 'l, 'f) statement -> Sexplib0.Sexp.t
val hash_fold_statement : 'e 's 'l 'f. (Ppx_hash_lib.Std.Hash.state -> 'e -> Ppx_hash_lib.Std.Hash.state) -> (Ppx_hash_lib.Std.Hash.state -> 's -> Ppx_hash_lib.Std.Hash.state) -> (Ppx_hash_lib.Std.Hash.state -> 'l -> Ppx_hash_lib.Std.Hash.state) -> (Ppx_hash_lib.Std.Hash.state -> 'f -> Ppx_hash_lib.Std.Hash.state) -> Ppx_hash_lib.Std.Hash.state -> ('e, 's, 'l, 'f) statement -> Ppx_hash_lib.Std.Hash.state
val compare_statement : 'e 's 'l 'f. ('e -> 'e -> Core__.Import.int) -> ('s -> 's -> Core__.Import.int) -> ('l -> 'l -> Core__.Import.int) -> ('f -> 'f -> Core__.Import.int) -> ('e, 's, 'l, 'f) statement -> ('e, 's, 'l, 'f) statement -> Core__.Import.int
type statement_returntype =
  1. | Incomplete
  2. | NonlocalControlFlow
  3. | Complete

Statement return types which we will decorate statements with during type checking:

  • Complete corresponds to statements that exit the function (return or error) in every branch
  • Incomplete corresponds to statements which pass control flow to following statements in at least some branches
  • NonlocalControlFlow is simila to Incomplete but specifically used when breaks are present in loops. Normally, an infinite loop with Incomplete return type is fine (and considered Complete), since it either returns or diverges. However, in the presence of break statements, control flow may jump to the end of the loop.
val statement_returntype_of_sexp : Sexplib0.Sexp.t -> statement_returntype
val sexp_of_statement_returntype : statement_returntype -> Sexplib0.Sexp.t
val hash_fold_statement_returntype : Ppx_hash_lib.Std.Hash.state -> statement_returntype -> Ppx_hash_lib.Std.Hash.state
val hash_statement_returntype : statement_returntype -> Ppx_hash_lib.Std.Hash.hash_value
val compare_statement_returntype : statement_returntype -> statement_returntype -> int
type ('e, 'm, 'l, 'f) statement_with = {
  1. stmt : ('e, ('e, 'm, 'l, 'f) statement_with, 'l, 'f) statement;
  2. smeta : 'm;
}
val map_statement_with : ('e -> 'a) -> ('m -> 'b) -> ('l -> 'c) -> ('f -> 'd) -> ('e, 'm, 'l, 'f) statement_with -> ('a, 'b, 'c, 'd) statement_with
val fold_statement_with : ('a -> 'b -> 'a) -> ('a -> 'c -> 'a) -> ('a -> 'd -> 'a) -> ('a -> 'e -> 'a) -> 'a -> ('b, 'c, 'd, 'e) statement_with -> 'a
val statement_with_of_sexp : 'e 'm 'l 'f. (Sexplib0.Sexp.t -> 'e) -> (Sexplib0.Sexp.t -> 'm) -> (Sexplib0.Sexp.t -> 'l) -> (Sexplib0.Sexp.t -> 'f) -> Sexplib0.Sexp.t -> ('e, 'm, 'l, 'f) statement_with
val sexp_of_statement_with : 'e 'm 'l 'f. ('e -> Sexplib0.Sexp.t) -> ('m -> Sexplib0.Sexp.t) -> ('l -> Sexplib0.Sexp.t) -> ('f -> Sexplib0.Sexp.t) -> ('e, 'm, 'l, 'f) statement_with -> Sexplib0.Sexp.t
val compare_statement_with : 'e 'm 'l 'f. ('e -> 'e -> Core__.Import.int) -> ('m -> 'm -> Core__.Import.int) -> ('l -> 'l -> Core__.Import.int) -> ('f -> 'f -> Core__.Import.int) -> ('e, 'm, 'l, 'f) statement_with -> ('e, 'm, 'l, 'f) statement_with -> Core__.Import.int
val hash_fold_statement_with : 'e 'm 'l 'f. (Ppx_hash_lib.Std.Hash.state -> 'e -> Ppx_hash_lib.Std.Hash.state) -> (Ppx_hash_lib.Std.Hash.state -> 'm -> Ppx_hash_lib.Std.Hash.state) -> (Ppx_hash_lib.Std.Hash.state -> 'l -> Ppx_hash_lib.Std.Hash.state) -> (Ppx_hash_lib.Std.Hash.state -> 'f -> Ppx_hash_lib.Std.Hash.state) -> Ppx_hash_lib.Std.Hash.state -> ('e, 'm, 'l, 'f) statement_with -> Ppx_hash_lib.Std.Hash.state
type untyped_statement = (untyped_expression, located_meta, untyped_lval, unit) statement_with

Untyped statements, which have location_spans as meta-data

val map_untyped_statement : 'a -> 'a
val untyped_statement_of_sexp : Sexplib0.Sexp.t -> untyped_statement
val sexp_of_untyped_statement : untyped_statement -> Sexplib0.Sexp.t
val compare_untyped_statement : untyped_statement -> untyped_statement -> int
val hash_fold_untyped_statement : Ppx_hash_lib.Std.Hash.state -> untyped_statement -> Ppx_hash_lib.Std.Hash.state
val hash_untyped_statement : untyped_statement -> Ppx_hash_lib.Std.Hash.hash_value
type stmt_typed_located_meta = {
  1. loc : Middle.Location_span.t;
  2. return_type : statement_returntype;
}
val map_stmt_typed_located_meta : stmt_typed_located_meta -> stmt_typed_located_meta
val stmt_typed_located_meta_of_sexp : Sexplib0.Sexp.t -> stmt_typed_located_meta
val sexp_of_stmt_typed_located_meta : stmt_typed_located_meta -> Sexplib0.Sexp.t
val compare_stmt_typed_located_meta : stmt_typed_located_meta -> stmt_typed_located_meta -> int
val hash_fold_stmt_typed_located_meta : Ppx_hash_lib.Std.Hash.state -> stmt_typed_located_meta -> Ppx_hash_lib.Std.Hash.state
val hash_stmt_typed_located_meta : stmt_typed_located_meta -> Ppx_hash_lib.Std.Hash.hash_value

Typed statements also have meta-data after type checking: a location_span, as well as a statement returntype to check that function bodies have the right return type

val map_typed_statement : 'a -> 'a
val typed_statement_of_sexp : Sexplib0.Sexp.t -> typed_statement
val sexp_of_typed_statement : typed_statement -> Sexplib0.Sexp.t
val compare_typed_statement : typed_statement -> typed_statement -> int
val hash_fold_typed_statement : Ppx_hash_lib.Std.Hash.state -> typed_statement -> Ppx_hash_lib.Std.Hash.state
val hash_typed_statement : typed_statement -> Ppx_hash_lib.Std.Hash.hash_value
val mk_typed_statement : stmt: ('a, ('a, stmt_typed_located_meta, 'b, 'c) statement_with, 'b, 'c) statement -> loc:Middle.Location_span.t -> return_type:statement_returntype -> ('a, stmt_typed_located_meta, 'b, 'c) statement_with
type 's block = {
  1. stmts : 's list;
  2. xloc : Middle.Location_span.t;
}

Program shapes, where we obtain types of programs if we substitute typed or untyped statements for 's

and comment_type =
  1. | LineComment of string * Middle.Location_span.t
  2. | Include of string * Middle.Location_span.t
  3. | BlockComment of string list * Middle.Location_span.t
  4. | Separator of Middle.Location.t
    (*

    Separator records the location of items like commas, operators, and keywords which don't have location information stored in the AST but are useful for placing comments in pretty printing

    *)
and 's program = {
  1. functionblock : 's block option;
  2. datablock : 's block option;
  3. transformeddatablock : 's block option;
  4. parametersblock : 's block option;
  5. transformedparametersblock : 's block option;
  6. modelblock : 's block option;
  7. generatedquantitiesblock : 's block option;
  8. comments : comment_type list;
}
val map_block : ('s -> 'a) -> 's block -> 'a block
val map_comment_type : comment_type -> comment_type
val map_program : ('s -> 'a) -> 's program -> 'a program
val fold_block : ('a -> 'b -> 'a) -> 'a -> 'b block -> 'a
val fold_comment_type : 'a -> comment_type -> 'a
val fold_program : ('a -> 'b -> 'a) -> 'a -> 'b program -> 'a
val block_of_sexp : 's. (Sexplib0.Sexp.t -> 's) -> Sexplib0.Sexp.t -> 's block
val comment_type_of_sexp : Sexplib0.Sexp.t -> comment_type
val program_of_sexp : 's. (Sexplib0.Sexp.t -> 's) -> Sexplib0.Sexp.t -> 's program
val sexp_of_block : 's. ('s -> Sexplib0.Sexp.t) -> 's block -> Sexplib0.Sexp.t
val sexp_of_comment_type : comment_type -> Sexplib0.Sexp.t
val sexp_of_program : 's. ('s -> Sexplib0.Sexp.t) -> 's program -> Sexplib0.Sexp.t
val hash_fold_block : 's. (Ppx_hash_lib.Std.Hash.state -> 's -> Ppx_hash_lib.Std.Hash.state) -> Ppx_hash_lib.Std.Hash.state -> 's block -> Ppx_hash_lib.Std.Hash.state
val hash_fold_comment_type : Ppx_hash_lib.Std.Hash.state -> comment_type -> Ppx_hash_lib.Std.Hash.state
val hash_fold_program : 's. (Ppx_hash_lib.Std.Hash.state -> 's -> Ppx_hash_lib.Std.Hash.state) -> Ppx_hash_lib.Std.Hash.state -> 's program -> Ppx_hash_lib.Std.Hash.state
val hash_comment_type : comment_type -> Ppx_hash_lib.Std.Hash.hash_value
val compare_block : 's. ('s -> 's -> Core__.Import.int) -> 's block -> 's block -> Core__.Import.int
val compare_comment_type : comment_type -> comment_type -> int
val compare_program : 's. ('s -> 's -> Core__.Import.int) -> 's program -> 's program -> Core__.Import.int
val get_stmts : 'a block option -> 'a list
type untyped_program = untyped_statement program

Untyped programs (before type checking)

val map_untyped_program : 'a -> 'a
val untyped_program_of_sexp : Sexplib0.Sexp.t -> untyped_program
val sexp_of_untyped_program : untyped_program -> Sexplib0.Sexp.t
val compare_untyped_program : untyped_program -> untyped_program -> int
type typed_program = typed_statement program

Typed programs (after type checking)

val map_typed_program : 'a -> 'a
val typed_program_of_sexp : Sexplib0.Sexp.t -> typed_program
val sexp_of_typed_program : typed_program -> Sexplib0.Sexp.t
val compare_typed_program : typed_program -> typed_program -> int
val untyped_expression_of_typed_expression : typed_expression -> untyped_expression

Forgetful function from typed to untyped expressions

val untyped_lvalue_of_typed_lvalue : typed_lval -> untyped_lval
val untyped_lvalue_of_typed_lvalue_pack : typed_lval lvalue_pack -> untyped_lval lvalue_pack

Forgetful function from typed to untyped statements

val untyped_program_of_typed_program : typed_program -> untyped_program

Forgetful function from typed to untyped programs

val expr_of_lvalue : (('a, 'b) expr_with, 'a) lval_with -> ('a, 'b) expr_with
val extract_ids : ('a, 'b) expr_with -> identifier Base__List.t
val lvalue_of_expr_opt : untyped_expression -> ((located_meta, unit) expr_with, located_meta) lval_with lvalue_pack option
val get_loc_lvalue_pack : typed_lval lvalue_pack -> Middle.Location_span.t
val get_first_loc : untyped_statement -> Middle.Location.t