package mopsa

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

Module Ast.OperatorSource

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.

Sourcetype operator = ..

Extensible type of operators

Sourceval compare_operator : operator -> operator -> int

Total order between operators

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

Pretty-printer of operators

Registration

Sourceval 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

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

Register a comparison function for operators

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

Register a pretty-printer for operators

Some common operators

Sourcetype 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

Sourceval is_comparison_op : operator -> bool

Test whether an operator is a comparison operator

Sourceval is_logic_op : operator -> bool

Test whether an is a logical operator

Sourceval negate_comparison_op : operator -> operator

Return the negation of a comparison operator

Sourceval negate_logic_op : operator -> operator

Return the negation of a logical operator

OCaml

Innovation. Community. Security.