B-OCL Evaluator#

Evaluator for OCL constraints using the new visitor-based AST.

class bocl.evaluator.Evaluator[source]#

Bases: object

Evaluates OCL constraints against an object model.

The evaluator builds a Python expression string from the AST and uses eval() to compute the result. This preserves the original evaluation strategy while supporting the new AST structure produced by the visitor.

_emit_value(arg, obj, logical_exp)[source]#

Emit a value into the logical expression.

_handle_date_literal(date_expr)[source]#
_handle_excludes(tree, obj, logical_exp)[source]#
_handle_filter_loop(tree, all_objs)[source]#

Handle collect/select/reject for size() counting.

_handle_if(tree, obj, logical_exp)[source]#
_handle_includes(tree, obj, logical_exp)[source]#
_handle_loop(tree, obj, logical_exp, source)[source]#

Handle loop expressions (forAll, exists, select, reject, collect).

_handle_ocl_is_type_of(tree, logical_exp)[source]#
_handle_operation(tree, obj, logical_exp)[source]#

Handle comparison and arithmetic operations.

_handle_property_set(source, obj, logical_exp, right_side=False)[source]#

Build a set representation for includes/excludes.

_handle_size(tree, obj, logical_exp)[source]#

Handle size() operations.

_preprocess(exp)[source]#

Preprocess the logical expression before eval.

_resolve_chain(expr, obj)[source]#

Walk a navigation chain and return the final scalar or object(s).

Handles VariableExp (self / iterator), Property (attribute slot or association end on obj), and PropertyCallExpression (recursively resolves the source, then reads the leaf property on the resulting object). Returns:

  • a scalar (already-quoted string for str types) for attribute reads,

  • a single object or a list of objects for association traversal,

  • None when nothing resolves.

_resolve_source_objects(source, obj)[source]#

Resolve a source expression to a list of objects.

_safe_add(logical_exp, connector)[source]#

Add a connector (and/or) only if not already present.

check_in_obj(obj, source)[source]#
evaluate(ast_root, object_model, context_name)[source]#

Evaluate a constraint AST against the object model.

Parameters:
  • ast_root – Root AST node from the visitor.

  • object_model – BUML ObjectModel instance.

  • context_name – Name of the context class (e.g. ‘Library’).

Returns:

Boolean result of the constraint evaluation.

get_valid_objects(context_name, objs)[source]#
get_value(name, obj)[source]#
update_logical_exp(tree, logical_exp, obj)[source]#