package mopsa
Install
Dune Dependency
Authors
Maintainers
Sources
md5=9f673f79708b44a7effb3b6bb3618d2c
sha512=cb91cb428e43a22f1abbcb8219710d0c10a5b3756d0da392d4084b3b3a6157350776c596983e63def344f617d39964e91f244f60c07958695ee5c8c809a9f0f4
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