package mopsa

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

Context - Storage for flow-insensitive information

The context is a heterogeneous key-value map that stores non-semantical information, such as a description of the program being currently analyzed, the callstack, etc.

For instance, to create a new kind of entries for storing strings, first generate a new context key:

module K = GenContextKey
    (struct
      type 'a t = string
      let print pp fmt s = fprintf fmt "string: %s" s
    end)
let string_key = K.key

Then, given a context 'a ctx, you can add/remove elements as follows:

let ctx'  = add_ctx string_key "a" ctx in
let ctx'' = remove_ctx string_key ctx'

Note that the context can contain the abstract state. For instance, to store a cache of input/output states for each function, you can do:

module K = GenContextKey
    (struct
      type 'a t = (string*'a flow*'a post) list
      let print pp fmt cache =
        fprintf fmt "functions I/O cache:@,  @[<v>%a@]"
          (pp_print_list
            ~pp_sep:(fun fmt () -> fprintf fmt "@,")
            (fun (f,input,output) ->
               fprintf "%s:@, input:@[%a]@, output:@[%a@]"
                 f
                 (Flow.print pp) input
                 (Post.print pp) output
            )
          ) cache
    end)
let cache_key = K.key
type ('a, _) ctx_key = ..

Key to access an element in the context

type 'a ctx

The context

val empty_ctx : 'a ctx

Empty context

val singleton_ctx : ('a, 'v) ctx_key -> 'v -> 'a ctx

Context with one element

val mem_ctx : ('a, 'v) ctx_key -> 'a ctx -> bool

mem_ctx k ctx returns true when an element at key k is in the context ctx.

val find_ctx : ('a, 'v) ctx_key -> 'a ctx -> 'v

find_ctx k ctx returns the element at key k in the context ctx. Raises Not_found if no element is found.

val find_ctx_opt : ('a, 'v) ctx_key -> 'a ctx -> 'v option

find_ctx k ctx returns the element of the key k in the context ctx. Returns None if no element is found.

val add_ctx : ('a, 'v) ctx_key -> 'v -> 'a ctx -> 'a ctx

add_ctx k v ctx add element v at key k in the context ctx. The previous element is overwritten if present.

val remove_ctx : ('a, 'v) ctx_key -> 'a ctx -> 'a ctx

add_ctx k v ctx removes the element at key k in the context ctx. If key k was not in ctx, ctx is returned unchanged.

val most_recent_ctx : 'a ctx -> 'a ctx -> 'a ctx

Get the most recent context between two

val pp_ctx : (Print.printer -> 'a -> unit) -> Stdlib.Format.formatter -> 'a ctx -> unit

Print a context

type ctx_pool = {
  1. ctx_pool_equal : 'a 'v 'w. ('a, 'v) ctx_key -> ('a, 'w) ctx_key -> ('v, 'w) Mopsa_utils.Eq.eq option;
  2. ctx_pool_print : 'a 'v. (Print.printer -> 'a -> unit) -> Stdlib.Format.formatter -> ('a, 'v) ctx_key -> 'v -> unit;
}

Pool registered keys

type ctx_info = {
  1. ctx_equal : 'a 'v 'w. ctx_pool -> ('a, 'v) ctx_key -> ('a, 'w) ctx_key -> ('v, 'w) Mopsa_utils.Eq.eq option;
  2. ctx_print : 'a 'v. ctx_pool -> (Print.printer -> 'a -> unit) -> Stdlib.Format.formatter -> ('a, 'v) ctx_key -> 'v -> unit;
}

Registration information for a new key

val register_ctx : ctx_info -> unit

Register a new key

module GenContextKey (Value : sig ... end) : sig ... end

Generate a new key

val callstack_ctx_key : ('a, Mopsa_utils.Callstack.callstack) ctx_key

Key for storing the callstack

OCaml

Innovation. Community. Security.