codac 2.0.0
Loading...
Searching...
No Matches
codac2::ExprBase Class Referenceabstract

Abstract base class for representing an expression. More...

#include <codac2_ExprBase.h>

Collaboration diagram for codac2::ExprBase:

Public Member Functions

 ExprBase ()
 Default constructor.
 
virtual std::shared_ptr< ExprBasecopy () const =0
 Creates a copy of the current expression.
 
virtual void replace_arg (const ExprID &old_arg_id, const std::shared_ptr< ExprBase > &new_expr)=0
 Replaces a variable by a new expression.
 
const ExprIDunique_id () const
 Returns the unique identifier of the expression.
 
bool operator== (const ExprBase &e) const
 Equality operator for comparing two expressions.
 
virtual ~ExprBase ()=default
 Virtual destructor.
 

Protected Attributes

const ExprID _unique_id
 unique identifier for this expression
 

Detailed Description

Abstract base class for representing an expression.

The ExprBase class serves as the base class for all expressions involved in functions. It provides methods for managing expressions, including copying, replacing sub-expressions, and ensuring each expression has a unique identifier.

Constructor & Destructor Documentation

◆ ExprBase()

codac2::ExprBase::ExprBase ( )

Default constructor.

The constructor initializes the expression by generating its unique identifier.

◆ ~ExprBase()

virtual codac2::ExprBase::~ExprBase ( )
virtualdefault

Virtual destructor.

The destructor is virtual to ensure proper cleanup of derived classes when an object of a derived class is deleted through a pointer to ExprBase.

Member Function Documentation

◆ copy()

virtual std::shared_ptr< ExprBase > codac2::ExprBase::copy ( ) const
pure virtual

Creates a copy of the current expression.

This is a pure virtual function that must be implemented by derived classes to create a deep copy of the expression.

Returns
A shared pointer to the new copy of the expression.

◆ replace_arg()

virtual void codac2::ExprBase::replace_arg ( const ExprID & old_arg_id,
const std::shared_ptr< ExprBase > & new_expr )
pure virtual

Replaces a variable by a new expression.

This is a pure virtual function that must be implemented by derived classes to replace, in the current expression, a specific variable (corresponding to the old_arg_id) with a new expression.

Parameters
old_arg_idThe ExprID of the variable to replace.
new_exprA shared pointer to the new expression to insert.

◆ unique_id()

const ExprID & codac2::ExprBase::unique_id ( ) const

Returns the unique identifier of the expression.

Returns
A constant reference to the unique identifier of the expression.

◆ operator==()

bool codac2::ExprBase::operator== ( const ExprBase & e) const

Equality operator for comparing two expressions.

This operator compares two ExprBase objects by their unique identifiers to check if they represent the same expression.

Parameters
eThe ExprBase object to compare with.
Returns
true if the two expressions have the same unique identifier, false otherwise.

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