package mopsa
Install
Dune Dependency
Authors
Maintainers
Sources
md5=fdee20e988343751de440b4f6b67c0f4
sha512=f5cbf1328785d3f5ce40155dada2d95e5de5cce4f084ea30cfb04d1ab10cc9403a26cfb3fa55d0f9da72244482130fdb89c286a9aed0d640bba46b7c00e09500
doc/ast/Ast/Constant/index.html
Module Ast.Constant
Source
Constant
This module allows adding new constants to the extensible Mopsa AST.
To add a new constant, first extend type constant
with a new variant constructor. For instance,
type constant += C_int of int
adds a new constructor for integer constants.
The new constant needs to be registered by declaring a comparison and pretty-printing functions. For the previous example, the registration is as follows:
let () = register_constant {
compare = (fun next c1 c2 ->
match c1, c2 with
| C_int n1, C_int n2 -> compare n1 n2
| _ -> next n1 n2
);
print = (fun next fmt c ->
match c with
| C_int n -> Format.pp_print_int fmt n
| _ -> next fmt c
);
}
Any registered constant can be compared and printed with functions compare_constant
and pp_constant
.
Extensible constants
compare_constant c1 c2
provides a total order between any pair c1
and c2
of registered constants
pp_constant fmt c
pretty-prints a registered constant c
with formatter fmt
Registration
register_constant info
registers a new constant with a comparison function info.compare
and a pretty-printer info.print
register_constant_compare compare
registers a new comparison function for constants
register_constant_compare compare
registers a new pretty-printer for constants