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