Stan_math_backend.Cpp
A set of data types representing the C++ we generate
val identifier_of_sexp : Sexplib0.Sexp.t -> identifier
val sexp_of_identifier : identifier -> Sexplib0.Sexp.t
type type_ =
| Auto
| Void
| Int
| Double
| Complex of type_
| TemplateType of identifier
| StdVector of type_
A std::vector. For Eigen Vectors, use Matrix
with a row or column size of 1
| Array of type_ * int
| Tuple of type_ list
| TypeLiteral of identifier
Used for things like Eigen::Index
*)| Matrix of type_ * int * int * Middle.Mem_pattern.t
| Ref of type_
| Const of type_
| Pointer of type_
| TypeTrait of identifier * type_ list
e.g. stan::promote_scalar, stan:base_type
*)C++ types
val type__of_sexp : Sexplib0.Sexp.t -> type_
val sexp_of_type_ : type_ -> Sexplib0.Sexp.t
module Types : sig ... end
Helpers for constructing types
val operator_of_sexp : Sexplib0.Sexp.t -> operator
val sexp_of_operator : operator -> Sexplib0.Sexp.t
type expr =
| Literal of string
printed as-is
*)| Var of identifier
| VarRef of identifier
| Parens of expr
| FunCall of identifier * type_ list * expr list
| MethodCall of expr * identifier * type_ list * expr list
| StaticMethodCall of type_ * identifier * type_ list * expr list
| Constructor of type_ * expr list
printed as type(expr1, expr2, ...)
| InitializerExpr of type_ * expr list
printed as type{expr1, expr2, ...}
| ArrayLiteral of expr list
| TernaryIf of expr * expr * expr
| Cast of type_ * expr
| Index of expr * expr
| Deref of expr
| AllocNew of type_ * expr list
| OperatorNew of identifier * type_ * expr list
| Assign of expr * expr
NB: Not all exprs are valid lvalues!
*)| StreamInsertion of expr * expr list
Corresponds to operator<<
| BinOp of expr * operator * expr
| PMinus of expr
| Increment of expr
val expr_of_sexp : Sexplib0.Sexp.t -> expr
val sexp_of_expr : expr -> Sexplib0.Sexp.t
module Exprs : sig ... end
Some helper values and functions
module Expression_syntax : sig ... end
Some operators to make streams and method calls look more like the resultant C++
val init_of_sexp : Sexplib0.Sexp.t -> init
val sexp_of_init : init -> Sexplib0.Sexp.t
val make_variable_defn :
?static:bool ->
?constexpr:bool ->
type_:type_ ->
name:identifier ->
?init:init ->
unit ->
variable_defn
val variable_defn_of_sexp : Sexplib0.Sexp.t -> variable_defn
val sexp_of_variable_defn : variable_defn -> Sexplib0.Sexp.t
type stmt =
| Expression of expr
| VariableDefn of variable_defn
| For of variable_defn * expr * expr * stmt
| ForEach of type_ * identifier * expr * stmt
| While of expr * stmt
| IfElse of expr * stmt * stmt option
| TryCatch of stmt list * type_ * identifier * stmt list
| Block of stmt list
| Return of expr option
| Throw of expr
| Break
| Continue
| Using of string * type_ option
| Comment of string
val stmt_of_sexp : Sexplib0.Sexp.t -> stmt
val sexp_of_stmt : stmt -> Sexplib0.Sexp.t
module Stmts : sig ... end
Helpers for common statement constructs
module Decls : sig ... end
Declarations which get re-used often in the generated model
type template_parameter =
| Typename of string
The name of a template typename
*)| RequireAllCondition of [ `Exact of string | `OneOf of string list ] * type_
A C++ type trait (e.g. is_arithmetic) and the template name which needs to satisfy that. These are collated into one require_all_t<>
*)| Require of string * string list
| Bool of string
A named boolean template type
*)val template_parameter_of_sexp : Sexplib0.Sexp.t -> template_parameter
val sexp_of_template_parameter : template_parameter -> Sexplib0.Sexp.t
val cv_qualifiers_of_sexp : Sexplib0.Sexp.t -> cv_qualifiers
val sexp_of_cv_qualifiers : cv_qualifiers -> Sexplib0.Sexp.t
type fun_defn = {
templates_init : template_parameter list list * bool;
Double list since some functions (mainly reduce_sum functors) need two sets of templates
*)inline : bool;
return_type : type_;
name : identifier;
args : (type_ * string) list;
cv_qualifiers : cv_qualifiers list;
body : stmt list option;
}
val make_fun_defn :
?templates_init:(template_parameter list list * bool) ->
?inline:bool ->
return_type:type_ ->
name:identifier ->
?args:(type_ * string) list ->
?cv_qualifiers:cv_qualifiers list ->
?body:stmt list ->
unit ->
fun_defn
val fun_defn_of_sexp : Sexplib0.Sexp.t -> fun_defn
val sexp_of_fun_defn : fun_defn -> Sexplib0.Sexp.t
type constructor = {
args : (type_ * string) list;
init_list : (identifier * expr list) list;
body : stmt list;
}
val make_constructor :
?args:(type_ * string) list ->
?init_list:(identifier * expr list) list ->
?body:stmt list ->
unit ->
constructor
val constructor_of_sexp : Sexplib0.Sexp.t -> constructor
val sexp_of_constructor : constructor -> Sexplib0.Sexp.t
type directive =
| Include of string
| IfNDef of string * defn list
| MacroApply of string * string list
Incomplete list of C++ preprocessor directives
and class_defn = {
class_name : identifier;
final : bool;
public_base : type_;
private_members : defn list;
public_members : defn list;
constructor : constructor;
destructor_body : stmt list;
}
The Stan model class always has a non-default constructor and destructor
and defn =
| FunDef of fun_defn
| Class of class_defn
| Struct of struct_defn
| GlobalVariableDefn of variable_defn
| GlobalComment of string
| GlobalUsing of string * type_ option
| Namespace of identifier * defn list
| Preprocessor of directive
val directive_of_sexp : Sexplib0.Sexp.t -> directive
val class_defn_of_sexp : Sexplib0.Sexp.t -> class_defn
val struct_defn_of_sexp : Sexplib0.Sexp.t -> struct_defn
val defn_of_sexp : Sexplib0.Sexp.t -> defn
val sexp_of_directive : directive -> Sexplib0.Sexp.t
val sexp_of_class_defn : class_defn -> Sexplib0.Sexp.t
val sexp_of_struct_defn : struct_defn -> Sexplib0.Sexp.t
val sexp_of_defn : defn -> Sexplib0.Sexp.t
val make_class_defn :
name:identifier ->
public_base:type_ ->
?final:bool ->
private_members:defn list ->
public_members:defn list ->
constructor:constructor ->
?destructor_body:stmt list ->
unit ->
class_defn
val make_struct_defn :
param:template_parameter option ->
name:identifier ->
body:defn list ->
unit ->
struct_defn
type program = defn list
Much like in C++, we define a translation unit as a list of definitions
val program_of_sexp : Sexplib0.Sexp.t -> program
val sexp_of_program : program -> Sexplib0.Sexp.t
module Printing : sig ... end
Pretty-printing of the C++ type
module Tests : sig ... end