Module LustreExpr
Internal reperesentation of a Lustre expression
A LustreExpr.t does not contain node calls, temporal operators or expressions under a pre operator.
There is exactly one -> operator at the top of the expression, thus an expression can be represented as a pair of expressions (i, t) without -> operators.
The argument of a pre operator is always a variable, therefore an expression pre x can be represented by the variable x at the previous state.
A non-variable expression under a pre has to be abstracted to a fresh variable that is defined by this expression. There are no node calls in a Lustre expression. They have to be abstracted out and the results are captured in fresh variables. See LustreSimplify for details about how the input file is translates
The offsets of state variable instances are zero for the initial state and zero for the current state, see the constants init_offset and trans_offset and pre_offset. These are different from the offsets in the transition system, because here we want to know if the initial and the step expressions are equal without bumping offsets. Use the functions base_term_of_expr, cur_term_of_expr, and pre_term_of_expr to take the expression on one side of the -> operator and adjust to the variable offsets to the given base.
Expressions can only be constructed with the constructors which do type checking and some easy simplifications with constants.
- author
- Christoph Sticksel, Arjun Viswanathan
Types
type expr= private Term.tA
Term.trepresenting a Lustre expression, state variable offsets refer to the current and the previous instant.Cannot be constructed outside this module to enforce invariants about allowed offsets of state variable instants, see the constructors below.
type 'a bound_or_fixed=|Bound of 'aEquation is for each value of the index variable between zero and the upper bound
|Fixed of 'aFixed value for index variable
|Unbound of 'aunbounded index variable
Type of index in an equation for an array
val is_true_expr : expr -> boolReturns true iff the expr is the constant true.
type t= private{expr_init : expr;Lustre expression for initial state
expr_step : expr;Lustre expression after initial state
expr_type : Type.t;Common type of both initial and the step expression
}A Lustre expression
The
->operator is moved to the top of the expression, the expression is to be interpreted asexpr_init -> expr_step.
module LustreExprHashtbl : Stdlib.Hashtbl.S with type LustreExprHashtbl.key = tHash table over Lustre expressions
val hash : t -> intEquality of expressions
Pretty-printers
All pretty-printers take a Boolean flag as first argument, indicating if identifiers should be valid Lustre identifiers. If the flag is false, indexed identifiers are printed with [, ] and .. These characters are replaced with _ if the flag is true.
val pp_print_lustre_type : bool -> Stdlib.Format.formatter -> Type.t -> unitPretty-print a Lustre type
val pp_print_lustre_var : bool -> Stdlib.Format.formatter -> StateVar.t -> unitPretty-print a Lustre variable
val pp_print_lustre_var_typed : bool -> Stdlib.Format.formatter -> StateVar.t -> unitPretty-print a Lustre variable with its type
val pp_print_lustre_expr : bool -> Stdlib.Format.formatter -> t -> unitPretty-print a Lustre expression
val pp_print_expr : ?as_type:Type.t -> bool -> Stdlib.Format.formatter -> expr -> unitPretty-print a Lustre expression. The optional parameter
as_typeindicates that the expression should be printed as if it had this type (used for encoded enumerated datatypes).
val pp_print_expr_pvar : ?as_type:Type.t -> bool -> (Stdlib.Format.formatter -> StateVar.t -> unit) -> Stdlib.Format.formatter -> expr -> unitval pp_print_term_as_expr : ?as_type:Type.t -> bool -> Stdlib.Format.formatter -> Term.t -> unitPretty-print a term as an expr.
val pp_print_term_as_expr_pvar : ?as_type:Type.t -> bool -> (Stdlib.Format.formatter -> StateVar.t -> unit) -> Stdlib.Format.formatter -> Term.t -> unitPretty-print a term as an expr using the given printing function for state vars *
val pp_print_term_as_expr_mvar : ?as_type:Type.t -> bool -> string StateVar.StateVarMap.t -> Stdlib.Format.formatter -> Term.t -> unitPretty-print a term as an expr using the given map from state vars to strings If a state variable is not in the map, the name of the state variable is used instead
Predicates
val has_pre_var : Numeral.t -> t -> boolReturn true if the expression contains a previous state variable
val is_var : t -> boolReturn true if expression is a current state variable
val is_const_var : t -> boolReturn true if expression is a constant state variable
val is_pre_var : t -> boolReturn true if expression is a previous state variable
val pre_is_unguarded : t -> boolReturn
trueif there is an unguardedpreoperator in the expression.
val is_const_expr : expr -> boolReturn true if the expression is constant
val is_const : t -> boolReturn true if the expression is constant
Conversions to terms
val base_offset : Numeral.tOffset of state variable at first instant
val cur_offset : Numeral.tOffset of state variable at current instant
val pre_offset : Numeral.tOffset of state variable at previous instant
val base_var_of_state_var : Numeral.t -> StateVar.t -> Var.tInstance of state variable at first instant with the given offset as zero
val cur_var_of_state_var : Numeral.t -> StateVar.t -> Var.tInstance of state variable at current instant with the given offset as zero
val pre_var_of_state_var : Numeral.t -> StateVar.t -> Var.tInstance of state variable at previous instant with the given offset as zero
val base_term_of_state_var : Numeral.t -> StateVar.t -> Term.tTerm of instance of state variable at first instant with the given offset as zero
val cur_term_of_state_var : Numeral.t -> StateVar.t -> Term.tTerm of instance of state variable at current instant with the given offset as zero
val pre_term_of_state_var : Numeral.t -> StateVar.t -> Term.tTerm of instance of state variable at previous instant with the given offset as zero
val base_term_of_expr : Numeral.t -> expr -> Term.tTerm at first instant with the given offset as zero
val cur_term_of_expr : Numeral.t -> expr -> Term.tTerm at current instant with the given offset as zero
val pre_term_of_expr : Numeral.t -> expr -> Term.tTerm at previous instant with the given offset as zero
val state_var_of_expr : t -> StateVar.tReturn the state variable of a variable
Fail with
Invalid_argument "state_var_of_expr"if the expression is not a variable at the current or previous offset.
val var_of_expr : t -> Var.tReturn the free variable of a variable
Fail with
Invalid_argument "var_of_expr"if the expression is not a free variable.
val state_vars_of_expr : t -> StateVar.StateVarSet.tReturn all state variables occurring in the expression in a set
val vars_of_expr : t -> Var.VarSet.tval base_state_vars_of_init_expr : t -> StateVar.StateVarSet.tReturn all state variables of the initial state expression at the base instant
val cur_state_vars_of_step_expr : t -> StateVar.StateVarSet.tReturn all state variables of the step expression at the current instant
val indexes_of_state_vars_in_init : StateVar.t -> t -> expr list listval indexes_of_state_vars_in_step : StateVar.t -> t -> expr list listval split_expr_list : t list -> expr list * expr listSplit a list of Lustre expressions into a list of pairs of expressions for the initial step and the transition steps, respectively
Constants
val t_true : tThe propositional constant true
val t_false : tThe propositional constant false
Constructors
val mk_var : StateVar.t -> tReturn an expression of a variable.
val mk_free_var : Var.t -> tval mk_index_var : int -> tReturn an expression for the i-th index variable.
val int_of_index_var : t -> intReturn the number/position of the index variable.
val has_indexes : t -> boolReturns
trueif the expression has index variables.
val mk_pre : ('a -> t -> 'b * 'a) -> ('b -> Term.t) -> 'a -> bool -> t -> t * 'aApply the
preoperator to the expression, abstract the expression to a fresh variable if it is not a variable at the current state.mk_pre f c b ereturns the expressioneand contextcunchanged if it is a constant, and the previous state variable if the expression is a current state variable, again together withcunchanged.Otherwise the expression
eis abstracted to a fresh variable obtained by calling the functionf, which returns a fresh state variable and a changed contextcthat records the association between the fresh variable and the expression. Then return an expression of the fresh state variable and the changed context.bis used to denote that we're in a context where there are unguarded pres and so we should always introduce fresh intermediate variables.
val is_select : t -> boolReturns true if the expression is a selection in an array
val is_select_array_var : t -> boolReturns true if the expression is a selection of an array variable
val is_store : t -> boolReturns true if this is a store in an array
val mk_let_cur : (StateVar.t * t) list -> t -> tSubstitute state variable at current instant with expression
val mk_let_pre : (StateVar.t * t) list -> t -> tSubstitute state variable at previous instant with expression
val mk_of_expr : ?as_type:Type.t -> expr -> tReturn an expression with the same term on both sides of the
->
val is_const : t -> boolReturn true if the expression is constant