package mopsa
Install
Dune Dependency
Authors
Maintainers
Sources
md5=fdee20e988343751de440b4f6b67c0f4
sha512=f5cbf1328785d3f5ce40155dada2d95e5de5cce4f084ea30cfb04d1ab10cc9403a26cfb3fa55d0f9da72244482130fdb89c286a9aed0d640bba46b7c00e09500
doc/ast/Ast/Operator/index.html
Module Ast.Operator
Source
Operators
This module allows adding new operators to the extensible Mopsa AST.
To add a new operator, first extend type operator
with a new variant constructor. For instance,
type operator += O_eq
adds a new constructor for an equality operator.
After adding the new variant, register it by declaring a compare and a print function:
let () = register_operator {
compare = (fun next o1 o2 ->
match o1, o2 with
| O_eq, O_eq -> 0
| _ -> next o1 o2
);
print = (fun next -> function
| O_eq -> Format.pp_print_string fmt "=="
| _ -> next fmt o
);
}
Note that the comparison function can be reduced in this cast to compare = (fun next -> next)
because the operator O_eq
doesn't have a structure and the pervasive compare
used by default is sufficient.
Any registered constant can be compared and printed with functions compare_constant
and pp_constant
.
Extensible type of operators
Registration
register_operator info
registers a new operator by registering its compare function info.compare
and pretty-printer info.print
Register a comparison function for operators
Register a pretty-printer for operators
Some common operators
type operator +=
| O_eq
(*equality ==
*)| O_ne
(*inequality !=
*)| O_lt
(*less than <
*)| O_le
(*less or equal <=
*)| O_gt
(*greater than >
*)| O_ge
(*greater or equal >=
*)| O_log_not
(*logical negation
*)| O_log_or
(*logical disjunction ||
*)| O_log_and
(*logical conjunction &&
*)| O_log_xor
(*logical strict disjonction xor
*)| O_cast
(*type cast
*)
Common operators