package mopsa
Install
Dune Dependency
Authors
Maintainers
Sources
md5=fdee20e988343751de440b4f6b67c0f4
sha512=f5cbf1328785d3f5ce40155dada2d95e5de5cce4f084ea30cfb04d1ab10cc9403a26cfb3fa55d0f9da72244482130fdb89c286a9aed0d640bba46b7c00e09500
doc/ast/Ast/Var/index.html
Module Ast.Var
Source
Variables
The type var
represents variables in Mopsa. In addition to a unique string name and a type, a variable is decorated with an extensible type var_kind
that allows annotating the variable with extra information that is specific to its language.
New kinds of variables can be added by extending var_kind
with a new variant. For example, for some toy language Toy
in which variables, in addition to a name and a type, have an initial value, a new variable kind can be created with
type var_kind += V_toy of expr
This new variable kind needs to be registered
let () = register_var {
compare = (fun next v1 v2 ->
match vkind v1, vkind v2 with
| V_toy init1, V_toy init2 -> compare_expr init1 init2
| _ -> next v1 v2
);
print = (fun fmt next v ->
match vkind v with
| V_toy v -> Format.pp_print_string fmt v.vname
| _ -> next fmt v
);
}
Another property of variables is their access mode. When a variable represents a single dimension in the concrete, assignments on this variable are performed with strong updates, i.e. the update destroys the previous value.
On the other hand, when an abstract domain summarizes the value of several concrete dimensions into a single variable, only weak updates can be performed to preserve the value of unmodified concrete dimensions.
Access modes
Extensible kind of variables
Access mode of a variable
Variables
type var = {
vname : string;
(*unique name of the variable
*)vkind : var_kind;
(*kind the variable
*)vtyp : Typ.typ;
(*type of the variable
*)vmode : mode;
(*access mode of the variable
*)vsemantic : Semantic.semantic;
(*semantic of the variable
*)
}
Variables
Create a variable with a unique name, a kind, a type and an access mode (STRONG if not given)
Registration
Register a new kind of variables
Register a new variable comparison
Register a new variable pretty-printer
Common variables
type var_kind +=
| V_uniq of string * int
(*Unique ID
*)| V_tmp of int
(*Unique ID
*)| V_var_attr of var * string
(*Attribute
*)| V_range_attr of Mopsa_utils.Location.range * string
(*Attribute
*)
Create a fresh variable with a fresh ID
val mk_attr_var :
var ->
string ->
?mode:mode ->
?semantic:Semantic.semantic ->
Typ.typ ->
var
mk_attr_var v a t
creates a variable representing an attribute a
of another variable v
val mk_range_attr_var :
Mopsa_utils.Location.range ->
string ->
?mode:mode ->
?semantic:Semantic.semantic ->
Typ.typ ->
var
mk_range_attr_var r a t
creates a variable representing an attribute a
of a program location r
Containers for variables
module VarSet : Mopsa_utils.SetExtSig.S with type elt = var
Sets of variables
module VarMap : Mopsa_utils.MapExtSig.S with type key = var
Maps of variables