package mopsa
Install
Dune Dependency
Authors
Maintainers
Sources
md5=fdee20e988343751de440b4f6b67c0f4
sha512=f5cbf1328785d3f5ce40155dada2d95e5de5cce4f084ea30cfb04d1ab10cc9403a26cfb3fa55d0f9da72244482130fdb89c286a9aed0d640bba46b7c00e09500
doc/ast/Ast/Expr/index.html
Module Ast.Expr
Source
Expressions
This module allows adding new expressions to the extensible Mopsa AST.
New expressions are added by extending the type expr_kind
. For example, to add an expression for subscript access to arrays
type expr_kind += E_array_subscript of expr * expr
New expressions need to be registered using register_expr
as follows:
let () = register_expr {
compare = (fun next e1 e2 ->
match ekind e1, ekind e2 with
| E_array_subscript(a1,i1), E_array_subscript(a2,i2) ->
Compare.pair compare_expr compare_expr (a1,i1) (a2,i2)
| _ -> next e1 e2
);
print = (fun next fmt e ->
match ekind e with
| E_array_subscript(a,i) ->
Format.fprintf fmt "%a[%a]"
pp_expr a
pp_expr i
| _ -> next fmt e
);
}
Registered expressions can be compare using function compare_expr
and printed using the function pp_expr
.
Extensible type of expression kinds
type expr = {
ekind : expr_kind;
(*kind of the expression
*)etyp : Typ.typ;
(*type of the expression
*)erange : Mopsa_utils.Location.range;
(*location range of the expression
*)etrans : expr Semantic.SemanticMap.t;
(*translations of the expression into other semantics
*)ehistory : expr list;
(*History of preceding evaluations of the expression
*)
}
Expressions
compare_expr e1 e2
implements a total order between expressions
pp_expr fmt e
pretty-prints expression e
with format fmt
Get the location of an expression
Get the translation map of an expression
val mk_expr :
?etyp:Typ.typ ->
?etrans:expr Semantic.SemanticMap.t ->
?ehistory:expr list ->
expr_kind ->
Mopsa_utils.Location.range ->
expr
Construct an expression
Add a translation of an expression
Get all translations of an expression
Get the translation of an expression into a given semantic
Get the ancestor expression verifying a predicate
Registration
register_expr info
registers new expressions with their comparison function info.compare
and pretty-printer info.print
register_expr_compare compare
registers a new expression comparison
register_expr_compare compare
registers a new expression printer
Some common expressions
Variable expressions
Create a variable expression
Change the access mode of a variable expression to STRONG
Get the overloaded access mode of a variable
Heap addresses expressions
type expr_kind +=
| E_addr of Addr.addr * Var.mode option
(*optional access mode overloading the address access mode
*)| E_alloc_addr of Addr.addr_kind * Var.mode
Heap addresses
val mk_addr :
Addr.addr ->
?etyp:Typ.typ ->
?mode:Var.mode option ->
Mopsa_utils.Location.range ->
expr
Create an address expression
Create an allocation expression
Change the access mode of an address expression to STRONG
Constant expressions
Constants
Create a constant expression
Create ⊤ expression of a given type
Unary expressions
Unary operator expressions
val mk_unop :
?etyp:Typ.typ ->
Operator.operator ->
expr ->
Mopsa_utils.Location.range ->
expr
Create a unary operator expression
mk_not e range
returns the negation of expression e
using the operator Operator.O_log_not
Binary expressions
Binary operator expressions
val mk_binop :
?etyp:Typ.typ ->
expr ->
Operator.operator ->
expr ->
Mopsa_utils.Location.range ->
expr
Create a binary operator expression
Expressions containers
module ExprSet : Mopsa_utils.SetExtSig.S with type elt = expr
Sets of expression
module ExprMap : Mopsa_utils.MapExtSig.S with type key = expr
Maps of expressions