Module M_ir.Com

Categories

module CatVar : sig ... end

High level representation of categories of variable. In practice, there only are two types of categories: * "calculee" (Input) variables, with several sub categories; * "saisie" (Computed) variable, that can either be base or non-base.

type value_typ =
| Boolean
| DateYear
| DateDayMonthYear
| DateMonth
| Integer
| Real

Here are all the types a value can have. Used for the M function type.

Variables

type loc_tgv = {
loc_cat : CatVar.loc;

Its category kind

loc_idx : int;

TODO

loc_tab_idx : int;

TODO

loc_cat_id : CatVar.t;

Full details on its category

loc_cat_str : string;

String representation of its category

loc_cat_idx : int;

The variable's identifier in its category.

}

Location of a TGV variable in the compiler's context.

type loc_tmp = {
loc_idx : int;

TODO

loc_tab_idx : int;

TODO

loc_cat_idx : int;

The variable's identifier in its category

}

Location of a temporary variable in the compiler's context.

type loc =
| LocTgv of string * loc_tgv

A TGV variable

| LocTmp of string * loc_tmp

A temporary variable

| LocRef of string * int

A reference (the integer is the 'loc_idx')

The different kinds of variables; the 'string' is the variable's name.

module Var : sig ... end
type event_field = {
name : string Utils.Pos.marked;

The field name

index : int;

Position of the event field. Set in the validator.

is_var : bool;

Is a reference to a variable or a value?

}

Data on an event field.

type ('n, 'v) event_value =
| Numeric of 'n
| RefVar of 'v

The values of an event.

module DomainId : Utils.StrSet.T
module DomainIdSet : Utils.SetSetExt.T with type base_elt = string and type T.elt = DomainId.t
module DomainIdMap : Utils.MapExt.T with type T.key = DomainId.t
type 'a domain = {
dom_id : DomainId.t Utils.Pos.marked;
dom_names : Utils.Pos.t DomainIdMap.t;
dom_by_default : bool;
dom_min : DomainIdSet.t;
dom_max : DomainIdSet.t;
dom_rov : Utils.IntSet.t;
dom_data : 'a;
dom_used : int Utils.Pos.marked option;
}
type rule_domain_data = {
rdom_computable : bool;
}
type rule_domain = rule_domain_data domain
type verif_domain_data = {
vdom_auth : Utils.Pos.t CatVar.Map.t;
vdom_verifiable : bool;
}
type variable_space = {
vs_id : int;
vs_name : string Utils.Pos.marked;
vs_cats : CatVar.loc Utils.Pos.marked CatVar.LocMap.t;
vs_by_default : bool;
}
type verif_domain = verif_domain_data domain

Values and expressions

type literal =
| Float of float
| Undefined

A literal can either be a float value or undefined.

type unop =
| Not
| Minus

Unary operators

type binop =
| And
| Or
| Add
| Sub
| Mul
| Div
| Mod

Binary operators.

type comp_op =
| Gt
| Gte
| Lt
| Lte
| Eq
| Neq

Comparison operators. Comparison always return 0 or 1 when the compared values are both defined; otherwise, it returns 'undefined'.

Note that this is even true when comparing undefined with undefined: the proper way to test if a value is undefined is through the function 'PresentFunc' (present).

type func =
| SumFunc

Sums the arguments

| AbsFunc

Absolute value

| MinFunc

Minimum of a list of values

| MaxFunc

Maximum of a list of values

| GtzFunc

Greater than zero (strict) ?

| GtezFunc

Greater or equal than zero ?

| NullFunc

Equal to zero

| ArrFunc

Round to nearest integer

| InfFunc

Truncate to integer

| PresentFunc

Different than undefined

| Multimax

Max of a subset of a table

| Supzero

Identity if > 0, undefined otherwise

| VerifNumber

-- unsupported --

| ComplNumber

-- unsupported --

| NbEvents

Total number of events

| Func of string

A M function

Functions callable in M. There is only a subset of the whole M functions; some are translated into dedicated expressions at parsing (champ_evenement for example is directly transformed into an access to a variable).

type var_name_generic = {
base : string;
parameters : char list;
}

For generic variables, we record the list of their lowercase parameters

type var_name =
| Normal of string
| Generic of var_name_generic

A variable is either generic (with loop parameters) or normal

type m_var_name = var_name Utils.Pos.marked
type var_space = (m_var_name * int) option

The prefix of a variable that defines its space. No space is equivalent to the default space.

type 'v var_id = var_space * 'v
type 'v access =
| VarAccess of 'v var_id

Simple variable occurence

| TabAccess of 'v var_id * 'v m_expression

Access to a cell of a table

| FieldAccess of var_space * 'v m_expression * string Utils.Pos.marked * int

Call to 'champ_evenement'

A generic representation of an access to a variable, read or write.

and 'v m_access = 'v access Utils.Pos.marked
and 'v case =
| CDefault
| CValue of literal
| CVar of 'v m_access
and 'v atom =
| AtomVar of 'v
| AtomLiteral of literal

Values that can be substituted for loop parameters

and 'v set_value_loop =
| Single of 'v atom Utils.Pos.marked
| Range of 'v atom Utils.Pos.marked * 'v atom Utils.Pos.marked
| Interval of 'v atom Utils.Pos.marked * 'v atom Utils.Pos.marked
and 'v loop_variable = char Utils.Pos.marked * 'v set_value_loop list

A loop variable is the character that should be substituted in variable names inside the loop plus the set of value to substitute.

and 'v loop_variables =
| ValueSets of 'v loop_variable list
| Ranges of 'v loop_variable list

There are two kind of loop variables declaration, but they are semantically the same though they have different concrete syntax.

and 'v set_value =
| FloatValue of float Utils.Pos.marked

A literal singleton

| VarValue of 'v m_access

A variable singleton

| IntervalValue of int Utils.Pos.marked * int Utils.Pos.marked

A literal interval

A set of values.

and 'v expression =
| TestInSet of bool * 'v m_expression * 'v set_value list

Test if an expression is in a set of value (or not in the set if the flag is set to false)

| Unop of unop * 'v m_expression
| Comparison of comp_op Utils.Pos.marked * 'v m_expression * 'v m_expression
| Binop of binop Utils.Pos.marked * 'v m_expression * 'v m_expression
| Conditional of 'v m_expression * 'v m_expression * 'v m_expression option
| FuncCall of func Utils.Pos.marked * 'v m_expression list
| FuncCallLoop of func Utils.Pos.marked * 'v loop_variables Utils.Pos.marked * 'v m_expression
| Literal of literal
| Var of 'v access
| Loop of 'v loop_variables Utils.Pos.marked * 'v m_expression

The loop is prefixed with the loop variables declarations

| NbCategory of Utils.Pos.t CatVar.Map.t
| Attribut of 'v m_access * string Utils.Pos.marked
| Size of 'v m_access
| Type of 'v m_access * value_typ Utils.Pos.marked
| SameVariable of 'v m_access * 'v m_access
| InDomain of 'v m_access * Utils.Pos.t CatVar.Map.t
| NbAnomalies
| NbDiscordances
| NbInformatives
| NbBloquantes

Basic M expressions.

and 'v m_expression = 'v expression Utils.Pos.marked
module Error : sig ... end

Handling of errors.

Printing in M

type print_std =
| StdOut
| StdErr

Where to print

type print_info =
| Name
| Alias

How to print a variable

type 'v print_arg =
| PrintString of string
| PrintAccess of print_info * 'v m_access
| PrintIndent of 'v m_expression

Evaluates the expression and indents as much

| PrintExpr of 'v m_expression * int * int

Prints an expression with a minimal and maximal precision.

Something to print

Loops

type 'v formula_loop = 'v loop_variables Utils.Pos.marked
type 'v formula_decl =
| VarDecl of 'v access Utils.Pos.marked * 'v m_expression
| EventFieldRef of 'v m_expression * string Utils.Pos.marked * int * 'v
type 'v formula =
| SingleFormula of 'v formula_decl
| MultipleFormulaes of 'v formula_loop * 'v formula_decl

Stopping

type stop_kind =
| SKApplication

Leave the whole application

| SKTarget

Leave the current target

| SKFun

Leave the current function

| SKId of string option

Leave the iterator with the selected var (or the current if None)

Instructions

type 'v switch_expression =
| SEValue of 'v m_expression
| SESameVariable of 'v m_access
type ('v, 'e) instruction =
| Affectation of 'v formula Utils.Pos.marked
| IfThenElse of 'v m_expression * ('v'e) m_instruction list * ('v'e) m_instruction list
| WhenDoElse of ('v m_expression * ('v'e) m_instruction list * Utils.Pos.t) list * ('v'e) m_instruction list Utils.Pos.marked
| ComputeDomain of string Utils.Pos.marked list Utils.Pos.marked * var_space
| ComputeChaining of string Utils.Pos.marked * var_space
| ComputeVerifs of string Utils.Pos.marked list Utils.Pos.marked * 'v m_expression * var_space
| ComputeTarget of string Utils.Pos.marked * 'v m_access list * var_space
| VerifBlock of ('v'e) m_instruction list
| Print of print_std * 'v print_arg Utils.Pos.marked list
| Iterate of 'v * 'v m_access list * (Utils.Pos.t CatVar.Map.t * 'v m_expression * var_space) list * ('v'e) m_instruction list
| Iterate_values of 'v * ('v m_expression * 'v m_expression * 'v m_expression) list * ('v'e) m_instruction list
| Restore of 'v m_access list * ('v * Utils.Pos.t CatVar.Map.t * 'v m_expression * var_space) list * 'v m_expression list * ('v * 'v m_expression) list * ('v'e) m_instruction list
| ArrangeEvents of ('v * 'v * 'v m_expression) option * ('v * 'v m_expression) option * 'v m_expression option * ('v'e) m_instruction list
| Switch of 'v switch_expression * ('v case list * ('v'e) m_instruction list) list
| RaiseError of 'e Utils.Pos.marked * string Utils.Pos.marked option
| CleanErrors
| CleanFinalizedErrors
| ExportErrors
| FinalizeErrors
| Stop of stop_kind
and ('v, 'e) m_instruction = ('v'e) instruction Utils.Pos.marked
type ('v, 'e) target = {
target_name : string Utils.Pos.marked;
target_file : string option;
target_apps : string Utils.Pos.marked Utils.StrMap.t;
target_args : 'v list;
target_result : 'v option;
target_tmp_vars : 'v Utils.StrMap.t;
target_nb_tmps : int;
target_sz_tmps : int;
target_nb_refs : int;
target_prog : ('v'e) m_instruction list;
}

A target is a list of instructions. They are very similar to rules, except targets are entrypoints of the M program.

Utils

val target_is_function : ('v'e) target -> bool
val expr_map_var : ('v -> 'w) -> 'v expression -> 'w expression
val m_expr_map_var : ('v -> 'w) -> 'v m_expression -> 'w m_expression
val instr_map_var : ('v -> 'w) -> ('e -> 'f) -> ('v'e) instruction -> ('w'f) instruction
val m_instr_map_var : ('v -> 'w) -> ('e -> 'f) -> ('v'e) m_instruction -> ('w'f) m_instruction
type var_usage =
| Read
| Write
| Info
| DeclRef
| ArgRef
| DeclLocal
| Macro
val expr_fold_var : (var_usage -> var_space -> 'v option -> 'a -> 'a) -> 'v expression -> 'a -> 'a
val m_expr_fold_var : (var_usage -> var_space -> 'v option -> 'a -> 'a) -> 'v m_expression -> 'a -> 'a
val instr_fold_var : (var_usage -> var_space -> 'v option -> 'a -> 'a) -> ('v'e) instruction -> 'a -> 'a
val m_instr_fold_var : (var_usage -> var_space -> 'v option -> 'a -> 'a) -> ('v'e) m_instruction -> 'a -> 'a
val get_var_name : var_name -> string
val get_normal_var : var_name -> string

Pretty printing functions

val format_value_typ : Utils.Pp.t -> value_typ -> unit
val format_literal : Utils.Pp.t -> literal -> unit
val format_case : (Utils.Pp.t -> 'v -> unit) -> (Utils.Pp.t -> 'v expression -> unit) -> Utils.Pp.t -> 'v case -> unit
val format_atom : (Utils.Pp.t -> 'v -> unit) -> Utils.Pp.t -> 'v atom -> unit
val format_loop_variables : (Utils.Pp.t -> 'v -> unit) -> Utils.Pp.t -> 'v loop_variables -> unit
val format_unop : Utils.Pp.t -> unop -> unit
val format_binop : Utils.Pp.t -> binop -> unit
val format_comp_op : Utils.Pp.t -> comp_op -> unit
val format_set_value : (Utils.Pp.t -> 'v -> unit) -> (Utils.Pp.t -> 'v expression -> unit) -> Utils.Pp.t -> 'v set_value -> unit
val format_func : Utils.Pp.t -> func -> unit
val format_expression : (Utils.Pp.t -> 'v -> unit) -> Utils.Pp.t -> 'v expression -> unit
val format_print_arg : (Utils.Pp.t -> 'v -> unit) -> Utils.Pp.t -> 'v print_arg -> unit
val format_formula : (Utils.Pp.t -> 'v -> unit) -> Utils.Pp.t -> 'v formula -> unit
val format_instruction : (Utils.Pp.t -> 'v -> unit) -> (Utils.Pp.t -> 'e -> unit) -> Utils.Pp.t -> ('v'e) instruction -> unit
val format_instructions : (Utils.Pp.t -> 'v -> unit) -> (Utils.Pp.t -> 'e -> unit) -> Utils.Pp.t -> ('v'e) m_instruction list -> unit