ConstantExpression
class ConstantExpression
Represents an expression referring to a constant.
constructor ConstantExpression
| ConstantExpression | ( | const Location & location, | |
| std::shared_ptr< Constant > constant | ); |
| PARAMETER | DESCRIPTION |
|---|---|
location |
|
constant |
destructor ~ConstantExpression
| ~ConstantExpression | ( | ); |
method cloneconst virtual
Create a deep copy of the expression.
A subclass must override this method if it can occur in a macro or function definition, .repeat body, or instruction encoding.
| virtual Expression clone | ( | const CloneContext & context | ) const; |
| PARAMETER | DESCRIPTION |
|---|---|
context |
| RETURNS | DESCRIPTION |
|---|---|
Expression |
A shared pointer to the cloned expression. |
method constantconst
| std::shared_ptr< Constant > constant | ( | ) const; |
| RETURNS | DESCRIPTION |
|---|---|
std::shared_ptr< Constant > |
method createstatic
| static Expression create | ( | const Location & location, | |
| std::shared_ptr< Constant > constant | ); |
| PARAMETER | DESCRIPTION |
|---|---|
location |
|
constant |
| RETURNS | DESCRIPTION |
|---|---|
Expression |
method evaluatevirtual
Evaluate the expression in the given context.
The default implementation calls evaluate() on all sub-expressions using traverse(), and then calls evaluate_process().
Errors during evaluation should either be reported via DiagnosticOutput and result in the expression being marked as invalid, or an exception should be thrown.
| virtual std::optional< Expression > evaluate | ( | const EvaluationContext & context | ); |
| PARAMETER | DESCRIPTION |
|---|---|
context |
The evaluation context. |
| RETURNS | DESCRIPTION |
|---|---|
std::optional< Expression > |
The Expression to replace this expression with, {} if no replacement is needed. |
method has_valueconst virtual
Check if the value of the expression is known.
The default implementation returns true if value() returns a value, false otherwise. If the value is expensive to compute, subclasses may override this method to provide a more efficient implementation.
| virtual bool has_value | ( | ) const; |
| RETURNS | DESCRIPTION |
|---|---|
bool |
|
method is_argument_constantconst
| bool is_argument_constant | ( | ) const; |
| RETURNS | DESCRIPTION |
|---|---|
bool |
method maximum_valueconst virtual protected
Get the minimum possible value of the expression.
The default implementation returns the value of the expression if it is known, or {} otherwise. Subclasses should override this method if they can determine a minimum value without knowing the exact value of the expression.
| virtual std::optional< Value > maximum_value | ( | ) const; |
| RETURNS | DESCRIPTION |
|---|---|
std::optional< Value > |
The minimum possible value of the expression. if it can be determined, {} otherwise. |
method minimum_valueconst virtual protected
Get the maximum possible value of the expression.
The default implementation returns the value of the expression if it is known, or {} otherwise. Subclasses should override this method if they can determine a maximum value without knowing the exact value of the expression.
| virtual std::optional< Value > minimum_value | ( | ) const; |
| RETURNS | DESCRIPTION |
|---|---|
std::optional< Value > |
The maximum possible value of the expression if it can be determined, {} otherwise. |
method serialize_subconst virtual
Serialize the expression to a stream.
This method must be implemented by derived classes.
| virtual void serialize_sub | ( | std::ostream & stream | ) const; |
| PARAMETER | DESCRIPTION |
|---|---|
stream |
The stream to serialize to. |
method simplifystatic private
Try to simplify a constant expression.
If the constant has a known value, return its value.
| static std::optional< Expression > simplify | ( | const Location & location, | |
| std::shared_ptr< Constant > constant, | |||
| bool always_create | ); |
| PARAMETER | DESCRIPTION |
|---|---|
location |
The location of the expression. |
constant |
The constant. |
always_create |
Whether to create a new expression if it can't be simplified. |
| RETURNS | DESCRIPTION |
|---|---|
std::optional< Expression > |
The expression, or {} if it can't be simplified and |
method typeconst virtual
Get the type of the expression's value.
The default implementation returns the type of the value of the expression if it is known, or {} otherwise. Subclasses should override this method if they can determine the type of the expression without knowing the exact value of the expression.
| virtual std::optional< Value::Type > type | ( | ) const; |
| RETURNS | DESCRIPTION |
|---|---|
std::optional< Value::Type > |
The type of the expression's value if it can be determined, {} otherwise. |
method valueconst virtual
Get the value of the expression if it is known.
Subclasses should override this method. The default implementation returns {}.
| virtual std::optional< Value > value | ( | ) const; |
| RETURNS | DESCRIPTION |
|---|---|
std::optional< Value > |
The value of the expression, if it is known. |