Module LustreAst
Minimally simplified Lustre abstract syntax tree
The types in this module closely represent the abstract syntax of Lustre. No type checking or simplification is performed when constructing the abstract syntax tree, this is done when producing the intermediate Lustre representation in LustreDeclarations.
Some values are reserved for future use and will cause the translation to intermediate Lustre to fail.
A Lustre file is parsed into a declaration list, where a declaration is either
- a type definition
type t = t', - a constant definition
const c = v, or - a node declaration.
Almost all types are annotated with the position in the input file for better error reporting in the translation.
- author
- Christoph Sticksel
Types
type clock_expr=|ClockTrue|ClockPos of ident|ClockNeg of ident|ClockConstr of ident * identA clock expression
type conversion_operator=|ToInt|ToReal|ToInt8|ToInt16|ToInt32|ToInt64|ToUInt8|ToUInt16|ToUInt32|ToUInt64type unary_operator=|Not|Uminus|BVNottype binary_operator=|And|Or|Xor|Impl|Mod|Minus|Plus|Div|Times|IntDiv|BVAnd|BVOr|BVShiftL|BVShiftRtype ternary_operator=|Ite|Withtype n_arity_operator=|OneHottype comparison_operator=|Eq|Neq|Lte|Lt|Gte|Gttype constant=|True|False|Num of string|Dec of stringtype quantifier=|Forall|Existstype group_expr=|ExprList|TupleExpr|ArrayExprtype expr=A Lustre expression
and lustre_type=|Bool of Lib.position|Int of Lib.position|UInt8 of Lib.position|UInt16 of Lib.position|UInt32 of Lib.position|UInt64 of Lib.position|Int8 of Lib.position|Int16 of Lib.position|Int32 of Lib.position|Int64 of Lib.position|IntRange of Lib.position * expr * expr|Real of Lib.position|UserType of Lib.position * ident|AbstractType of Lib.position * ident|TupleType of Lib.position * lustre_type list|RecordType of Lib.position * typed_ident list|ArrayType of Lib.position * lustre_type * expr|EnumType of Lib.position * ident option * ident listA Lustre type
and typed_ident= Lib.position * ident * lustre_typeAn identifier with a type
and label_or_index=|Label of Lib.position * index|Index of Lib.position * exprA record field or an array or tuple index
Declarations
type type_decl=|AliasType of Lib.position * ident * lustre_type|FreeType of Lib.position * identA declaration of an alias or free type
type clocked_typed_decl= Lib.position * ident * lustre_type * clock_exprAn identifier with a type and a clock as used for the type of variables
type const_clocked_typed_decl= Lib.position * ident * lustre_type * clock_expr * boolAn identifier, possibly flagged as constant, with a type and a clock as used for the type of variables
type const_decl=|FreeConst of Lib.position * ident * lustre_type|UntypedConst of Lib.position * ident * expr|TypedConst of Lib.position * ident * expr * lustre_typeA constant declaration
type node_param=|TypeParam of identA type parameter of a node
type node_local_decl=|NodeConstDecl of Lib.position * const_decl|NodeVarDecl of Lib.position * clocked_typed_declA local constant or variable declaration of a node
type struct_item=|SingleIdent of Lib.position * ident|TupleStructItem of Lib.position * struct_item list|TupleSelection of Lib.position * ident * expr|FieldSelection of Lib.position * ident * ident|ArraySliceStructItem of Lib.position * ident * (expr * expr) list|ArrayDef of Lib.position * ident * ident listStructural assignment on the left-hand side of an equation
type eq_lhs=|StructDef of Lib.position * struct_item listThe left-hand side of an equation
type transition_to=|TransRestart of Lib.position * Lib.position * ident|TransResume of Lib.position * Lib.position * identtype transition_branch=|Target of transition_to|TransIf of Lib.position * expr * transition_branch * transition_branch optiontype automaton_transition= Lib.position * transition_branchtype auto_returns=|Given of ident list|Inferredtype node_equation=|Assert of Lib.position * expr|Equation of Lib.position * eq_lhs * expr|Automaton of Lib.position * ident option * state list * auto_returnsAn equation or assertion in the node body
and state=|State of Lib.position * ident * bool * node_local_decl list * node_equation list * automaton_transition option * automaton_transition optiontype node_item=|Body of node_equation|AnnotMain of bool|AnnotProperty of Lib.position * string option * exprAn item in a node declaration
type contract_ghost_const= const_decltype contract_ghost_var= const_decltype contract_assume= Lib.position * string option * bool * exprtype contract_guarantee= Lib.position * string option * bool * exprtype contract_require= Lib.position * string option * exprtype contract_ensure= Lib.position * string option * exprtype contract_mode= Lib.position * ident * contract_require list * contract_ensure listtype contract_call= Lib.position * ident * expr list * expr listtype contract_node_equation=|GhostConst of contract_ghost_const|GhostVar of contract_ghost_var|Assume of contract_assume|Guarantee of contract_guarantee|Mode of contract_mode|ContractCall of contract_calltype contract= contract_node_equation listtype node_decl= ident * bool * node_param list * const_clocked_typed_decl list * clocked_typed_decl list * node_local_decl list * node_item list * contract optionDeclaration of a node or function as a tuple of
- its identifier,
- a flag, true if the node / function is extern
- its type parameters,
- the list of its inputs,
- the list of its outputs,
- the list of its local constant and variable declarations,
- its equations, assertions and annotiations, and
- its optional contract specification
type contract_node_decl= ident * node_param list * const_clocked_typed_decl list * clocked_typed_decl list * contractA contract node declaration as a tuple of
- its identifier,
- its type parameters,
- its inputs,
- its outputs,
- its body as a
contract.
type node_param_inst= ident * ident * lustre_type listAn instance of a parametric node as a tuple of the identifier for the instance, the identifier of the parametric node and the list of type parameters
type declaration=|TypeDecl of Lib.position * type_decl|ConstDecl of Lib.position * const_decl|NodeDecl of Lib.position * node_decl|FuncDecl of Lib.position * node_decl|ContractNodeDecl of Lib.position * contract_node_decl|NodeParamInst of Lib.position * node_param_instA declaration of a type, a constant, a node, a function or an instance of a parametric node
type t= declaration listA Lustre program as a list of declarations
val pp_print_node_param_list : Stdlib.Format.formatter -> node_param list -> unitPretty-printers
val pp_print_ident : Stdlib.Format.formatter -> ident -> unitval pp_print_expr : Stdlib.Format.formatter -> expr -> unitval pp_print_array_slice : Stdlib.Format.formatter -> (expr * expr) -> unitval pp_print_field_assign : Stdlib.Format.formatter -> (ident * expr) -> unitval pp_print_clock_expr : Stdlib.Format.formatter -> clock_expr -> unitval pp_print_lustre_type : Stdlib.Format.formatter -> lustre_type -> unitval pp_print_typed_ident : Stdlib.Format.formatter -> typed_ident -> unitval pp_print_clocked_typed_ident : Stdlib.Format.formatter -> (Lib.position * ident * lustre_type * clock_expr) -> unitval pp_print_const_clocked_typed_ident : Stdlib.Format.formatter -> (Lib.position * ident * lustre_type * clock_expr * bool) -> unitval pp_print_type_decl : Stdlib.Format.formatter -> type_decl -> unitval pp_print_var_decl : Stdlib.Format.formatter -> (Lib.position * ident * lustre_type * clock_expr) -> unitval pp_print_const_decl : Stdlib.Format.formatter -> const_decl -> unitval pp_print_node_local_decl_var : Stdlib.Format.formatter -> node_local_decl -> unitval pp_print_node_local_decl_const : Stdlib.Format.formatter -> node_local_decl -> unitval pp_print_node_local_decl : Stdlib.Format.formatter -> node_local_decl list -> unitval pp_print_struct_item : Stdlib.Format.formatter -> struct_item -> unitval pp_print_node_item : Stdlib.Format.formatter -> node_item -> unitval pp_print_declaration : Stdlib.Format.formatter -> declaration -> unitval pp_print_program : Stdlib.Format.formatter -> t -> unitval pp_print_contract_item : Stdlib.Format.formatter -> contract_node_equation -> unitval pp_print_contract_node_decl : Stdlib.Format.formatter -> contract_node_decl -> unit
Helpers
val pos_of_expr : expr -> Lib.positionReturns the position of an expression
val has_unguarded_pre : expr -> boolReturns true if the expression has unguareded pre's
val has_pre_or_arrow : expr -> Lib.position optionReturns true if the expression has a `pre` or a `->`.
val contract_has_pre_or_arrow : contract -> Lib.position optionReturns true iff a contract mentions a `pre` or a `->`.
Does not (cannot) check contract calls recursively, checks only inputs and outputs.
val node_local_decl_has_pre_or_arrow : node_local_decl -> Lib.position optionChecks whether a node local declaration has a `pre` or a `->`.
val node_item_has_pre_or_arrow : node_item -> Lib.position optionChecks whether a node equation has a `pre` or a `->`.
val replace_lasts : string list -> string -> SI.t -> expr -> expr * SI.treplace_lasts allowed prefix acc ereplaceslast xexpressions in ASTeby abstract identifiers prefixed withprefix. Only identifiers that appear in the listallowedare allowed to appear under a last. It returns the new AST expression and a set of identifers for which the last application was replaced.