Module LustreContext
Context information used in and obtained from parsing
- author
- Christoph Sticksel
exceptionNode_not_found of LustreIdent.t * Lib.positionNode or function not found, possible forward reference
exceptionType_not_found of LustreIdent.t * Lib.positionexceptionContract_not_found of LustreIdent.t * Lib.position
Scopes and Nodes
val mk_empty_context : unit -> tCreate an initial empty context.
val set_guard_flag : t -> bool -> tSets the flag indicating there are unguarded pre's in the lustre code, and we need to guard them.
val reset_guard_flag : t -> tResets the flag indicating there are unguarded pre's in the lustre code, and we need to guard them.
val guard_flag : t -> boolThe value of the flag indicating there are unguarded pre's in the lustre code, and we need to guard them.
val in_automaton : t -> boolThe value of the flag indicating we are evaluating an automaton.
val push_scope : t -> string -> tAdd scope to context
The scopes are added to the name of the node to create scope for variables
val push_contract_scope : t -> string -> tAdd contract scope to context.
Contract scopes are used for scoping of mode references and ghost variables.
val contract_scope_of : t -> string listThe contract scope of a context.
val scope_of_context : t -> string listval create_node : t -> LustreIdent.t -> bool -> tReturn a copy of the context with an empty node of the given name and is extern flag in the context
val current_node_name : t -> LustreIdent.t optionReturns the name of the current node, if any.
val current_node_map : t -> (LustreNode.t -> LustreNode.t) -> tMaps something to the current node.
val current_node_calls : t -> LustreNode.node_call listReturns the calls made by the current node, if any.
val current_node_modes : t -> LustreContract.mode list option optionReturns the modes of the current node.
val create_function : t -> LustreIdent.t -> tReturn a copy of the context with an empty function of the given name in the context
val add_node_to_context : t -> t -> tReturn a context that is identical to the previous context with the node constructed in the current context added
val solve_fref : t -> LustreAst.declaration -> (LustreDependencies.decl * LustreIdent.t * Lib.position) -> LustreAst.declaration list -> LustreAst.declaration listResolve a forward reference, fails if a circular dependency is detected.
val add_free_constant : t -> LustreIdent.t -> Var.t LustreIndex.t -> unitRegister a free constant, shadows previous declarations
val get_free_constants : t -> (LustreIdent.t * Var.t LustreIndex.t) listReturn declared free constants
val free_constant_expr_of_ident : t -> LustreIdent.t -> LustreExpr.t LustreIndex.tReturn the free constant corresponding to an identifier if any
val add_expr_for_ident : ?shadow:bool -> t -> LustreIdent.t -> LustreExpr.t LustreIndex.t -> tAdd a binding of an identifier to an expression to context
If the labeled argument
shadowis true, allow overwriting a previous binding to the identifier. Otherwise raise the exceptionInvalid_argument "add_expr_for_ident".
val remove_expr_for_ident : t -> LustreIdent.t -> tRemove the binding of an identifier from the context
If the identifier is not bound to an expression, raise the exception
Invalid_argument "remove_expr_for_ident". Otherwise, remove the most recent binding to the identifier, which may make a previous binding visible, which was shadowed by a call toadd_expr_for_identwith the labeled argumentshadowset to true.
val add_type_for_ident : t -> LustreIdent.t -> Type.t LustreIndex.t -> tAdd a binding of an identifier to a type to context
val get_nodes : t -> LustreNode.t listReturn the nodes in the context
val get_node : t -> LustreNode.t optionReturn the current node in context.
val get_state_var_bounds : t -> LustreExpr.expr LustreExpr.bound_or_fixed list StateVar.StateVarHashtbl.tReturn state vars bounds hash table
val contract_nodes : t -> LustreAst.contract_node_decl listThe contract nodes in the context.
val trace_svars_of : t -> LustreExpr.t -> StateVar.StateVarSet.t optionThe svars in the COI of the input expression, in the current node.
Returns
Noneif there's no current node. RaisesNot_foundif some svars in the COI do not have an equation and are not outputs of node calls.Used to check that the assumes and requires of a contract do not mention the outputs in
LustreDeclarations.
val add_contract_node_decl_to_context : t -> (Lib.position * LustreAst.contract_node_decl) -> tAdd a contract node to the context for inlining later
val contract_node_decl_of_ident : t -> string -> Lib.position * LustreAst.contract_node_declReturn a contract node by its identifier
val fail_on_new_definition : t -> Lib.position -> string -> tReturn a context that raises an error when defining an expression.
fail_on_new_definition ctx pos msgwill evaluatefail_at_positionwith the locationposand the messagemsgas arguments
val raise_no_new_definition_exc : t -> 'aval expr_of_ident : t -> LustreIdent.t -> LustreExpr.t LustreIndex.tResolve an indentifier to an expression.
val assignable_state_var_of_ident : t -> LustreIdent.t -> StateVar.t LustreIndex.tReturn the respective state variable if the expression denotes an output or a local variable of the node in the context
val type_of_ident : t -> LustreIdent.t -> Type.t LustreIndex.tResolve an indentifier to a type.
val expr_in_context : t -> LustreIdent.t -> boolReturn
trueif the identifier denotes an expression in the contextRaise an
Invalid_argumentexception if the identifier is reserved.
val type_in_context : t -> LustreIdent.t -> boolReturn
trueif the identifier denotes a type in the context
val node_in_context : t -> LustreIdent.t -> boolReturn
trueif the identifier denotes a node in the context
val prop_name_in_context : t -> string -> boolReturn
trueif the identifier denotes a property in the context
val mk_state_var : ?is_input:bool -> ?is_const:bool -> ?for_inv_gen:bool -> ?shadow:bool -> t -> Ident.t list -> LustreIdent.t -> LustreIndex.index -> Type.t -> LustreNode.state_var_source option -> StateVar.t * tval mk_fresh_local : ?is_input:bool -> ?is_const:bool -> ?for_inv_gen:bool -> ?bounds:LustreExpr.expr LustreExpr.bound_or_fixed list -> t -> Type.t -> StateVar.t * tCreate a fresh local state variable in the context.
val set_state_var_source : t -> StateVar.t -> LustreNode.state_var_source -> tval mk_local_for_expr : ?is_input:bool -> ?is_const:bool -> ?for_inv_gen:bool -> ?bounds:LustreExpr.expr LustreExpr.bound_or_fixed list -> ?reuse:bool -> ?is_ghost:bool -> ?original:LustreAst.expr -> Lib.position -> t -> LustreExpr.t -> LustreNode.equation_lhs * tDefine the expression with a fresh state variable, or the variable previously used for the same expression (if the optinal argument
reuseis set to true), record the definition in the context and return the context.The
is_input,is_constandfor_inv_genflags are relevant, and the state variable returned has the combination of flags asked for. If a state variable was previously created for the same expression but with different flags, a new state variable is created.
val mk_fresh_oracle : ?is_input:bool -> ?is_const:bool -> ?for_inv_gen:bool -> ?bounds:LustreExpr.expr LustreExpr.bound_or_fixed list -> t -> Type.t -> StateVar.t * tCreate a fresh oracle state variable in the context.
val mk_fresh_oracle_for_state_var : ?bounds:LustreExpr.expr LustreExpr.bound_or_fixed list -> t -> StateVar.t -> StateVar.t * tCreate a fresh oracle state variable for the pre-initial value of the given state variable in the context, or return a previously created oracle for this state variable.
val node_of_name : t -> LustreIdent.t -> LustreNode.tReturn the node of the given name from the context
val call_outputs_of_node_call : t -> LustreIdent.t -> LustreNode.call_cond list -> StateVar.t LustreIndex.t -> LustreExpr.t LustreIndex.t option -> StateVar.t LustreIndex.t optionReturn variables capturing outputs of node call if a node call with the same input parameters and activation condition is in the context.
call_outputs_of_node_call c n ar i dcompares all node calls in contextcif the identifier of the node matchesn, the activation or restart condition matchesarall input variables are idential toa, and all default values are identical tod. It returnsNoneif no such call was found, and its output variables otherwise.
val add_node_input : ?is_const:bool -> t -> LustreIdent.t -> Type.t LustreIndex.t -> tAdd node input to context
val add_node_output : ?is_single:bool -> t -> LustreIdent.t -> Lib.position -> Type.t LustreIndex.t -> tAdd node output to context
val outputs_of_current_node : t -> StateVar.t LustreIndex.tThe output state variables of the current node.
val add_node_local : ?ghost:bool -> t -> LustreIdent.t -> Lib.position -> Type.t LustreIndex.t -> tAdd node local to context
val add_node_ass : t -> LustreContract.svar list -> tAdds assumptions to a node.
val add_node_gua : t -> (LustreContract.svar * bool) list -> tAdds guarantees to a node (boolean is the candidate flag).
val add_node_mode : t -> LustreContract.mode -> tAdd modes to node
val add_node_assert : t -> Lib.position -> StateVar.t -> tAdd assertion to context
val add_node_sofar_assumption : t -> tval add_node_property : t -> Property.prop_source -> string -> LustreExpr.t -> tAdd property to context
val add_node_equation : t -> Lib.position -> StateVar.t -> LustreExpr.expr LustreExpr.bound_or_fixed list -> int -> LustreExpr.t -> tAdd equation to context
val add_node_call : t -> Lib.position -> LustreNode.node_call -> tAdd node call to context
val get_node_function_flag : t -> boolChecks if the current node, if any, is a function.
val close_expr : ?bounds:LustreExpr.expr LustreExpr.bound_or_fixed list -> ?original:LustreAst.expr -> Lib.position -> (LustreExpr.t * t) -> LustreExpr.t * tReplace unguarded pre operators with oracle constants and return expression and modified context.
close_expr pos (expr, ctx)introduces or uses a previously introduced fresh oracle constant for eachpreoperator applied to a variable that is not under a->.The second argument is a pair so that it can take the output of
LustreSimplify.eval_ast_exprdirectly.
val check_vars_defined : t -> unitCheck that the node being defined has no undefined local or output variables
Helpers
val fail_at_position : Lib.position -> string -> 'aOutput a fatal error at position and raise an error
val warn_at_position : Lib.position -> string -> unitOutput a warning at position
val fail_no_position : string -> 'aOutput a fatal error without reporting a position and raise an error
val are_definitions_allowed : t -> boolReturns true if new definitions are allowed in the context