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

Dedicated handler for complex number operations in the Python frontend. More...

#include <complex_handler.h>

Public Member Functions

 complex_handler (python_converter &converter, contextt &symbol_table, type_handler &type_handler_ref)
exprt handle_binary_op (const std::string &op, const exprt &lhs, const exprt &rhs, const nlohmann::json &element) const
 Handles binary operations when at least one operand is complex.
exprt handle_unary_op (const std::string &op, const exprt &operand) const
 Handles unary +/- on complex values.
exprt handle_attribute (const nlohmann::json &element) const
 Handles attribute access / method calls on complex objects.
exprt handle_attribute_access (const exprt &obj, const std::string &attr) const
 Handles direct attribute access on a complex object: .real, .imag.
exprt handle_abs (const exprt &z) const
 Computes abs(z) = sqrt(real^2 + imag^2).
exprt handle_cmath_log (const std::string &func_name, const nlohmann::json &call, const nlohmann::json &args, const nlohmann::json &keywords) const
 Handles cmath.log / cmath.log10 with complex arguments.
exprt normalize_numeric_expr (const exprt &value) const
 Normalises a numeric expression for use in complex arithmetic.

Detailed Description

Dedicated handler for complex number operations in the Python frontend.

Centralises complex arithmetic (mul, div, pow, log, exp), unary operations, attribute access (.real, .imag, .conjugate()), abs(), and numeric normalisation that were previously scattered across python_converter.cpp and function_call_expr.cpp.

Follows the pattern established by string_handler and python_math.

Constructor & Destructor Documentation

◆ complex_handler()

complex_handler::complex_handler ( python_converter & converter,
contextt & symbol_table,
type_handler & type_handler_ref )

Member Function Documentation

◆ handle_abs()

exprt complex_handler::handle_abs ( const exprt & z) const

Computes abs(z) = sqrt(real^2 + imag^2).

◆ handle_attribute()

exprt complex_handler::handle_attribute ( const nlohmann::json & element) const

Handles attribute access / method calls on complex objects.

Dispatches conjugate() when the method name matches.

Parameters
elementThe full JSON node of the Call expression (must contain func.attr and func.value).
Returns
The resulting expression, or nil_exprt if the call is not a recognised complex method.

◆ handle_attribute_access()

exprt complex_handler::handle_attribute_access ( const exprt & obj,
const std::string & attr ) const

Handles direct attribute access on a complex object: .real, .imag.

Returns
The member expression, or nil_exprt for unrecognised attributes.

◆ handle_binary_op()

exprt complex_handler::handle_binary_op ( const std::string & op,
const exprt & lhs,
const exprt & rhs,
const nlohmann::json & element ) const

Handles binary operations when at least one operand is complex.

Covers Add, Sub, Mult, Div, Pow, Eq, NotEq and rejects unsupported comparisons/floor ops with proper TypeErrors.

◆ handle_cmath_log()

exprt complex_handler::handle_cmath_log ( const std::string & func_name,
const nlohmann::json & call,
const nlohmann::json & args,
const nlohmann::json & keywords ) const

Handles cmath.log / cmath.log10 with complex arguments.

Parameters
func_name"log" or "log10".
callThe full Call JSON node (used for location info).
argsPositional arguments array.
keywordsKeyword arguments array.
Returns
The resulting complex expression, or a TypeError throw.

◆ handle_unary_op()

exprt complex_handler::handle_unary_op ( const std::string & op,
const exprt & operand ) const

Handles unary +/- on complex values.

UAdd returns the operand unchanged; USub negates both components.

◆ normalize_numeric_expr()

exprt complex_handler::normalize_numeric_expr ( const exprt & value) const

Normalises a numeric expression for use in complex arithmetic.

Integer/bool trees are recursively promoted to IEEE double; complex values pass through unchanged.


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