package mopsa

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

Copyright (c) 2017-2019 Aymeric Fromherz and The MOPSA Project

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

AST - A more abstract representation than the original Python CST.

Contains some additional static information, such as unique variables IDs and the list of local variables of functions.

type var = {
  1. name : string;
    (*

    original name in the source code

    *)
  2. uid : int;
    (*

    a unique identifier at the scope level

    *)
}

A variable with a unique identifier

type program = {
  1. prog_body : stmt;
  2. prog_globals : var list;
}
and stmt = {
  1. skind : stmt_kind;
  2. srange : Mopsa_utils.Location.range;
}

Statements

and binop =
  1. | O_arithmetic of Cst.binop
  2. | O_comparison of Cst.cmpop
  3. | O_bool of Cst.boolop
and stmt_kind =
  1. | S_assign of expr * expr
    (*

    value

    *)
  2. | S_type_annot of expr * expr
    (*

    value

    *)
  3. | S_expression of expr
    (*

    expression statements

    *)
  4. | S_while of expr * stmt * stmt option
    (*

    else

    *)
  5. | S_break
  6. | S_continue
  7. | S_block of stmt list
  8. | S_aug_assign of expr * binop * expr
    (*

    value

    *)
  9. | S_if of expr * stmt * stmt option
    (*

    optional else branch

    *)
  10. | S_function of func
  11. | S_class of cls
  12. | S_for of expr * expr * stmt * stmt option
    (*

    else

    *)
  13. | S_return of expr
    (*

    return expression. Empty returns are equivalent to return None

    *)
  14. | S_raise of expr option * expr option
    (*

    cause

    *)
  15. | S_try of stmt * except list * stmt option * stmt option
    (*

    final body

    *)
  16. | S_import of string * var option * var
    (*

    root module var

    *)
  17. | S_import_from of string * string * var * var
    (*

    module var

    *)
  18. | S_delete of expr
  19. | S_assert of expr * expr option
  20. | S_with of expr * expr option * stmt
    (*

    body

    *)
  21. | S_pass
and except = expr option * var option * stmt

Exception handler

body

and func = {
  1. func_var : var;
    (*

    function object variable

    *)
  2. func_parameters : var list;
    (*

    list of parameters variables

    *)
  3. func_defaults : expr option list;
    (*

    list of default parameters values

    *)
  4. func_vararg : var option;
  5. func_kwonly_args : var list;
  6. func_kwonly_defaults : expr option list;
  7. func_kwarg : var option;
  8. func_locals : var list;
    (*

    list of local variables

    *)
  9. func_globals : var list;
    (*

    list of variables declared as global

    *)
  10. func_nonlocals : var list;
    (*

    list of variables declared as nonlocal

    *)
  11. func_body : stmt;
    (*

    function body

    *)
  12. func_is_generator : bool;
    (*

    is the function a generator?

    *)
  13. func_decors : expr list;
  14. func_types_in : expr option list;
  15. func_type_out : expr option;
  16. func_range : Mopsa_utils.Location.range;
}

Function declaration

and cls = {
  1. cls_var : var;
    (*

    class object variable

    *)
  2. cls_body : stmt;
    (*

    class body

    *)
  3. cls_static_attributes : var list;
  4. cls_bases : expr list;
    (*

    inheritance base classes

    *)
  5. cls_decors : expr list;
  6. cls_keywords : (string option * expr) list;
    (*

    keywords (None id for **kwargs)

    *)
  7. cls_range : Mopsa_utils.Location.range;
}

Class definition

and lambda = {
  1. lambda_body : expr;
  2. lambda_parameters : var list;
    (*

    list of parameters variables

    *)
  3. lambda_defaults : expr option list;
    (*

    list of default parameters values

    *)
}
and expr = {
  1. ekind : expr_kind;
  2. erange : Mopsa_utils.Location.range;
}

Expressions

and expr_kind =
  1. | E_ellipsis
  2. | E_true
  3. | E_false
  4. | E_none
  5. | E_notimplemented
  6. | E_num of Cst.number
  7. | E_str of string
  8. | E_bytes of string
  9. | E_attr of expr * string
    (*

    attribute name

    *)
  10. | E_id of var
  11. | E_call of expr * expr list * (string option * expr) list
    (*

    keywords (None id for **kwargs)

    *)
  12. | E_list of expr list
    (*

    list of elements

    *)
  13. | E_index_subscript of expr * expr
    (*

    index

    *)
  14. | E_slice_subscript of expr * expr * expr * expr
    (*

    Step. None if not specified

    *)
  15. | E_tuple of expr list
  16. | E_set of expr list
  17. | E_dict of expr list * expr list
    (*

    values

    *)
  18. | E_generator_comp of expr * comprehension list
    (*

    list of comprehensions

    *)
  19. | E_list_comp of expr * comprehension list
    (*

    list of comprehensions

    *)
  20. | E_set_comp of expr * comprehension list
    (*

    list of comprehensions

    *)
  21. | E_dict_comp of expr * expr * comprehension list
    (*

    list of comprehensions

    *)
  22. | E_if of expr * expr * expr
  23. | E_yield of expr
  24. | E_yield_from of expr
    (*

    Binary operator expressions

    *)
  25. | E_binop of expr * binop * expr
    (*

    right operand

    *)
  26. | E_multi_compare of expr * binop list * expr list
  27. | E_unop of Cst.unop * expr
  28. | E_lambda of lambda
and comprehension = expr * expr * expr list

Comprehensions

list of conditions

module VarSet : sig ... end
module VarMap : sig ... end
module VarSetMap : sig ... end
OCaml

Innovation. Community. Security.