codac 2.0.0
|
Abstract base class for representing an expression. More...
#include <codac2_ExprBase.h>
Public Member Functions | |
ExprBase () | |
Default constructor. | |
virtual std::shared_ptr< ExprBase > | copy () 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 ExprID & | unique_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 | |
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.
codac2::ExprBase::ExprBase | ( | ) |
Default constructor.
The constructor initializes the expression by generating its unique identifier.
|
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
.
|
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.
|
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.
old_arg_id | The ExprID of the variable to replace. |
new_expr | A shared pointer to the new expression to insert. |
const ExprID & codac2::ExprBase::unique_id | ( | ) | const |
Returns the unique identifier of the expression.
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.
e | The ExprBase object to compare with. |
true
if the two expressions have the same unique identifier, false
otherwise.