Ast.ExprSourceExpressions
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 * exprNew 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 ->
exprConstruct 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
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
Create a variable expression
Change the access mode of a variable expression to STRONG
Get the overloaded access mode of a variable
type expr_kind += | E_addr of Addr.addr * Var.mode optionoptional access mode overloading the address access mode
*)| E_alloc_addr of Addr.addr_kind * Var.modeHeap addresses
val mk_addr :
Addr.addr ->
?etyp:Typ.typ ->
?mode:Var.mode option ->
Mopsa_utils.Location.range ->
exprCreate an address expression
Create an allocation expression
Change the access mode of an address expression to STRONG
Constants
Create a constant expression
Create ⊤ expression of a given type
Unary operator expressions
val mk_unop :
?etyp:Typ.typ ->
Operator.operator ->
expr ->
Mopsa_utils.Location.range ->
exprCreate a unary operator expression
mk_not e range returns the negation of expression e using the operator Operator.O_log_not
Binary operator expressions
val mk_binop :
?etyp:Typ.typ ->
expr ->
Operator.operator ->
expr ->
Mopsa_utils.Location.range ->
exprCreate a binary operator expression
module ExprSet : Mopsa_utils.SetExtSig.S with type elt = exprSets of expression
module ExprMap : Mopsa_utils.MapExtSig.S with type key = exprMaps of expressions