package mopsa

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

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.

type operator = ..

Extensible type of operators

val compare_operator : operator -> operator -> int

Total order between operators

val pp_operator : Stdlib.Format.formatter -> operator -> unit

Pretty-printer of operators

Registration

val register_operator : operator Mopsa_utils.TypeExt.info -> unit

register_operator info registers a new operator by registering its compare function info.compare and pretty-printer info.print

val register_operator_compare : operator Mopsa_utils.TypeExt.compare -> unit

Register a comparison function for operators

val register_operator_pp : operator Mopsa_utils.TypeExt.print -> unit

Register a pretty-printer for operators

Some common operators

type operator +=
  1. | O_eq
    (*

    equality ==

    *)
  2. | O_ne
    (*

    inequality !=

    *)
  3. | O_lt
    (*

    less than <

    *)
  4. | O_le
    (*

    less or equal <=

    *)
  5. | O_gt
    (*

    greater than >

    *)
  6. | O_ge
    (*

    greater or equal >=

    *)
  7. | O_log_not
    (*

    logical negation

    *)
  8. | O_log_or
    (*

    logical disjunction ||

    *)
  9. | O_log_and
    (*

    logical conjunction &&

    *)
  10. | O_log_xor
    (*

    logical strict disjonction xor

    *)
  11. | O_cast
    (*

    type cast

    *)

Common operators

val is_comparison_op : operator -> bool

Test whether an operator is a comparison operator

val is_logic_op : operator -> bool

Test whether an is a logical operator

val negate_comparison_op : operator -> operator

Return the negation of a comparison operator

val negate_logic_op : operator -> operator

Return the negation of a logical operator

OCaml

Innovation. Community. Security.