package mopsa

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

Python AST

Constants

type Mopsa.constant +=
  1. | C_py_ellipsis
  2. | C_py_none
  3. | C_py_not_implemented
  4. | C_py_imag of float

Types

type py_type =
  1. | Bool
  2. | NotImplemented
  3. | Complex
  4. | NoneType
  5. | Bytes
  6. | Str
  7. | Int
  8. | Float of Universal.Ast.float_prec
type Mopsa.typ +=
  1. | T_py of py_type option

Python-specific types

val is_py_exp : Mopsa.expr -> bool

Expressions

type py_object = Mopsa.addr * Mopsa.expr option

Python objects

optional value representation

val compare_py_object : py_object -> py_object -> int
type Mopsa.operator +=
  1. | O_py_and
    (*

    and

    *)
  2. | O_py_or
    (*

    or

    *)
  3. | O_py_floor_div
    (*

    //

    *)
  4. | O_py_is
    (*

    is

    *)
  5. | O_py_is_not
    (*

    is not

    *)
  6. | O_py_in
    (*

    in

    *)
  7. | O_py_not_in
    (*

    not in

    *)
  8. | O_py_mat_mult
    (*

    @

    *)
  9. | O_py_not
val is_arith_op : Mopsa.operator -> bool
val is_arith_binop_fun : string -> string -> bool
val is_arith_div_fun : string -> string -> bool
val is_reverse_operator : string -> bool
val is_comp_op : Mopsa.operator -> bool
val is_compare_op_fun : string -> string -> bool
type py_lambda = {
  1. py_lambda_body : Mopsa.expr;
    (*

    Body.

    *)
  2. py_lambda_parameters : Mopsa.var list;
    (*

    list of parameters variables

    *)
  3. py_lambda_defaults : Mopsa.expr option list;
    (*

    list of default parameters values

    *)
}

Lambda functions.

type Mopsa.expr_kind +=
  1. | E_py_undefined of bool
  2. | E_py_object of py_object
  3. | E_py_list of Mopsa.expr list
  4. | E_py_index_subscript of Mopsa.expr * Mopsa.expr
    (*

    index

    *)
  5. | E_py_slice_subscript of Mopsa.expr * Mopsa.expr * Mopsa.expr * Mopsa.expr
    (*

    step

    *)
  6. | E_py_attribute of Mopsa.expr * string
    (*

    attribute name

    *)
  7. | E_py_dict of Mopsa.expr list * Mopsa.expr list
    (*

    values

    *)
  8. | E_py_set of Mopsa.expr list
  9. | E_py_generator_comprehension of Mopsa.expr * (Mopsa.expr * Mopsa.expr * Mopsa.expr list) list
    (*

    list of comprehensions

    *)
  10. | E_py_list_comprehension of Mopsa.expr * (Mopsa.expr * Mopsa.expr * Mopsa.expr list) list
    (*

    list of comprehensions

    *)
  11. | E_py_set_comprehension of Mopsa.expr * (Mopsa.expr * Mopsa.expr * Mopsa.expr list) list
    (*

    list of comprehensions

    *)
  12. | E_py_dict_comprehension of Mopsa.expr * Mopsa.expr * (Mopsa.expr * Mopsa.expr * Mopsa.expr list) list
    (*

    list of comprehensions

    *)
  13. | E_py_call of Mopsa.expr * Mopsa.expr list * (string option * Mopsa.expr) list
    (*

    keywords (None id for **kwargs)

    *)
  14. | E_py_yield of Mopsa.expr
  15. | E_py_yield_from of Mopsa.expr
  16. | E_py_if of Mopsa.expr * Mopsa.expr * Mopsa.expr
    (*

    orelse

    *)
  17. | E_py_tuple of Mopsa.expr list
  18. | E_py_bytes of string
  19. | E_py_lambda of py_lambda
  20. | E_py_multi_compare of Mopsa.expr * Mopsa.operator list * Mopsa.expr list
  21. | E_py_annot of Mopsa.expr
  22. | E_py_check_annot of Mopsa.expr * Mopsa.expr
    (*

    low-level hasattribute working at the object level only

    *)
  23. | E_py_ll_hasattr of Mopsa.expr * Mopsa.expr
    (*

    attribute name

    *)
  24. | E_py_ll_getattr of Mopsa.expr * Mopsa.expr
    (*

    attribute name

    *)
  25. | E_py_ll_setattr of Mopsa.expr * Mopsa.expr * Mopsa.expr option

Statements

type py_fundec = {
  1. py_func_var : Mopsa.var;
    (*

    function object variable

    *)
  2. py_func_parameters : Mopsa.var list;
    (*

    list of parameters variables

    *)
  3. py_func_defaults : Mopsa.expr option list;
    (*

    list of default parameters values

    *)
  4. py_func_vararg : Mopsa.var option;
  5. py_func_kwonly_args : Mopsa.var list;
  6. py_func_kwonly_defaults : Mopsa.expr option list;
  7. py_func_kwarg : Mopsa.var option;
  8. py_func_locals : Mopsa.var list;
    (*

    list of local variables

    *)
  9. py_func_body : Mopsa.stmt;
    (*

    function body

    *)
  10. py_func_is_generator : bool;
    (*

    is the function a generator?

    *)
  11. py_func_decors : Mopsa.expr list;
  12. py_func_types_in : Mopsa.expr option list;
  13. py_func_type_out : Mopsa.expr option;
  14. py_func_range : Mopsa.range;
    (*

    range of the function

    *)
  15. py_func_ret_var : Mopsa.var;
  16. py_func_cellvars : Mopsa.var list;
  17. py_func_freevars : Mopsa.var list;
}

Python function descriptor

type py_func_sig = {
  1. py_funcs_parameters : Mopsa.var list;
  2. py_funcs_defaults : bool list;
  3. py_funcs_exceptions : Mopsa.expr list;
  4. py_funcs_types_in : Mopsa.expr option list;
  5. py_funcs_type_out : Mopsa.expr option;
}
type py_func_annot = {
  1. py_funca_var : Mopsa.var;
  2. py_funca_decors : Mopsa.expr list;
  3. py_funca_range : Mopsa.range;
  4. py_funca_ret_var : Mopsa.var;
  5. py_funca_sig : py_func_sig list;
}
val pp_py_func_sig : Stdlib.Format.formatter -> py_func_sig -> unit
val compare_py_func_sig : py_func_sig -> py_func_sig -> int
val pp_py_func_annot : Stdlib.Format.formatter -> py_func_annot -> unit
type py_clsdec = {
  1. py_cls_var : Mopsa.var;
    (*

    class object variable

    *)
  2. py_cls_body : Mopsa.stmt;
  3. py_cls_static_attributes : Mopsa.var list;
    (*

    list of declared attributes: static variables and methods

    *)
  4. py_cls_bases : Mopsa.expr list;
    (*

    base classes

    *)
  5. py_cls_decors : Mopsa.expr list;
  6. py_cls_keywords : (string option * Mopsa.expr) list;
    (*

    keywords (None id for **kwargs)

    *)
  7. py_cls_range : Mopsa.range;
    (*

    range of the class

    *)
}

A Python class

type py_cls_annot = {
  1. py_cls_a_var : Mopsa.var;
  2. py_cls_a_body : Mopsa.stmt;
  3. py_cls_a_bases : Mopsa.expr list;
  4. py_cls_a_abases : Mopsa.expr list;
  5. py_cls_a_static_attributes : Mopsa.var list;
  6. py_cls_a_range : Mopsa.range;
}
type py_excpt = {
  1. py_excpt_type : Mopsa.expr option;
    (*

    exception class. None is used for the default except

    *)
  2. py_excpt_name : Mopsa.var option;
    (*

    optional name of exception instance

    *)
  3. py_excpt_body : Mopsa.stmt;
    (*

    body of the except handler

    *)
}

Exception handler

type Mopsa.stmt_kind +=
  1. | S_py_class of py_clsdec
  2. | S_py_function of py_fundec
  3. | S_py_try of Mopsa.stmt * py_excpt list * Mopsa.stmt * Mopsa.stmt
    (*

    final body

    *)
  4. | S_py_raise of Mopsa.expr option
  5. | S_py_if of Mopsa.expr * Mopsa.stmt * Mopsa.stmt
  6. | S_py_while of Mopsa.expr * Mopsa.stmt * Mopsa.stmt
  7. | S_py_multi_assign of Mopsa.expr list * Mopsa.expr
  8. | S_py_aug_assign of Mopsa.expr * Mopsa.operator * Mopsa.expr
  9. | S_py_annot of Mopsa.expr * Mopsa.expr
  10. | S_py_check_annot of Mopsa.expr * Mopsa.expr
  11. | S_py_for of Mopsa.expr * Mopsa.expr * Mopsa.stmt * Mopsa.stmt
    (*

    else

    *)
  12. | S_py_import of string * Mopsa.var option * Mopsa.var
    (*

    root module

    *)
  13. | S_py_import_from of string * string * Mopsa.var * Mopsa.var
    (*

    module var

    *)
  14. | S_py_delete of Mopsa.expr
  15. | S_py_assert of Mopsa.expr * Mopsa.expr option
    (*

    message

    *)
  16. | S_py_with of Mopsa.expr * Mopsa.expr option * Mopsa.stmt
    (*

    body

    *)

Statements

Programs

type Mopsa.prog_kind +=
  1. | Py_program of string * Mopsa.var list * Mopsa.stmt
    (*

    body

    *)
module K : sig ... end

Flow-insensitive context to keep the analyzed C program

val py_program_ctx : ('a, string * Mopsa.var list * Mopsa.stmt) Core__Context.ctx_key
val set_py_program : (string * Mopsa.var list * Mopsa.stmt) -> 'a Mopsa.Flow.flow -> 'a Mopsa.Flow.flow

Set the Python program in the flow

val get_py_program : 'a Mopsa.Flow.flow -> string * Mopsa.var list * Mopsa.stmt

Get the Python program from the flow

Utility functions

val mk_py_in : ?strict:bool -> ?left_strict:bool -> ?right_strict:bool -> Mopsa.expr -> Mopsa.expr -> Mopsa.expr -> Mopsa_utils.Location.range -> Mopsa.expr
val mk_except : Mopsa.expr option -> Mopsa.var option -> Mopsa.stmt -> py_excpt
val mk_py_kall : Mopsa.expr -> Mopsa.expr list -> (string option * Mopsa.expr) list -> Mopsa_utils.Location.range -> Mopsa.expr
val mk_py_attr : Mopsa.expr -> string -> ?etyp:Mopsa.typ -> Mopsa_utils.Location.range -> Mopsa.expr
val mk_py_index_subscript : Mopsa.expr -> Mopsa.expr -> ?etyp:Mopsa.typ -> Mopsa_utils.Location.range -> Mopsa.expr
val mk_py_object : (Mopsa.addr * Mopsa.expr option) -> Mopsa_utils.Location.range -> Mopsa.expr
val mk_py_object_attr : (Mopsa.addr * Mopsa.expr option) -> string -> ?etyp:Mopsa.typ -> Mopsa_utils.Location.range -> Mopsa.expr
val mk_py_bool : bool -> Mopsa_utils.Location.range -> Mopsa.expr
val object_of_expr : Mopsa.expr -> py_object

Decorators

val is_stub_fundec : py_fundec -> bool
val is_builtin_fundec : py_fundec -> bool
val is_builtin_clsdec : py_clsdec -> bool
val is_unsupported_fundec : py_fundec -> bool
val is_unsupported_clsdec : py_clsdec -> bool
val builtin_fundec_name : py_fundec -> string
val builtin_clsdec_name : py_clsdec -> string
val builtin_type_name : string -> py_fundec -> string
OCaml

Innovation. Community. Security.