ESBMC
Efficient SMT-based Context-Bounded Model Checker
Loading...
Searching...
No Matches
python_consteval Class Reference

Lightweight Python AST evaluator for compile-time function evaluation. More...

#include <python_consteval.h>

Public Member Functions

 python_consteval (const nlohmann::json &ast, int max_iterations=50000)
std::optional< PyConstValue > try_eval_call (const std::string &func_name, const std::vector< PyConstValue > &args)
 Try to evaluate a function call with constant arguments.
std::optional< PyConstValue > try_eval_global_expr (const nlohmann::json &expr)
 Try to evaluate an arbitrary expression at module scope, seeding the environment with module-level constant globals first.

Detailed Description

Lightweight Python AST evaluator for compile-time function evaluation.

When a pure function is called with all-constant arguments, this evaluator interprets the function body at conversion time and returns the result, eliminating loops from the GOTO program entirely.

Constructor & Destructor Documentation

◆ python_consteval()

python_consteval::python_consteval ( const nlohmann::json & ast,
int max_iterations = 50000 )
explicit

Member Function Documentation

◆ try_eval_call()

std::optional< PyConstValue > python_consteval::try_eval_call ( const std::string & func_name,
const std::vector< PyConstValue > & args )

Try to evaluate a function call with constant arguments.

Returns std::nullopt if evaluation cannot be completed (unsupported construct, timeout, recursion limit, etc.).

◆ try_eval_global_expr()

std::optional< PyConstValue > python_consteval::try_eval_global_expr ( const nlohmann::json & expr)

Try to evaluate an arbitrary expression at module scope, seeding the environment with module-level constant globals first.

Used to fold whole assertion tests such as f(GLOBAL) == [literal] whose operands reference module globals (which try_eval_call alone cannot see). Returns std::nullopt if any sub-expression is not constant-foldable.


The documentation for this class was generated from the following files: