B-OCL Evaluator#
Evaluator for OCL constraints using the new visitor-based AST.
- class bocl.evaluator.Evaluator[source]#
Bases:
objectEvaluates 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.
- _handle_loop(tree, obj, logical_exp, source)[source]#
Handle loop expressions (forAll, exists, select, reject, collect).
- _handle_property_set(source, obj, logical_exp, right_side=False)[source]#
Build a set representation for includes/excludes.
- _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), andPropertyCallExpression(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,
Nonewhen nothing resolves.
- 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.