MinMaxExpression
class MinMaxExpression
Expression representing the minimum or maximum of two sub-expressions: .min(a, b) or .max(a, b).
constructor MinMaxExpression
Create a minimum or maximum expression.
| MinMaxExpression | ( | const Location & location, | |
| Expression a, | |||
| Expression b, | |||
| bool minimum | ); |
| PARAMETER | DESCRIPTION |
|---|---|
location |
The location of the expression in the source code. |
a |
The first sub-expression. |
b |
The second sub-expression. |
minimum |
Whether this is a minimum expression ( |
method createstatic
Create an expression representing the minimum or maximum of two sub-expressions.
This might not create a MinMaxExpression if the operation can be simplified (e.g. if both operands have values).
| static Expression create | ( | const Location & location, | |
| const Expression & a, | |||
| const Expression & b, | |||
| bool minimum | ); |
| PARAMETER | DESCRIPTION |
|---|---|
location |
The location of the expression in the source code. |
a |
The first sub-expression. |
b |
The second sub-expression. |
minimum |
Whether this is a minimum expression ( |
| RETURNS | DESCRIPTION |
|---|---|
Expression |
The created expression. |
method createstatic private
Create an expression representing a minimum or maximum expression from arguments.
| static Expression create | ( | const Location & location, | |
| bool minimum, | |||
| const std::vector< Expression > & arguments | ); |
| PARAMETER | DESCRIPTION |
|---|---|
location |
The location of the expression in the source code. |
minimum |
Whether this is a minimum expression ( |
arguments |
The arguments of the expression. Must contain exactly two expressions. |
| RETURNS | DESCRIPTION |
|---|---|
Expression |
The created expression. |
method create_maxstatic
Create a maximum expression from arguments.
| static Expression create_max | ( | const Location & location, | |
| const std::vector< Expression > & arguments | ); |
| PARAMETER | DESCRIPTION |
|---|---|
location |
The location of the expression in the source code. |
arguments |
The arguments of the expression. Must contain exactly two expressions. |
| RETURNS | DESCRIPTION |
|---|---|
Expression |
The created expression. |
method create_minstatic
Create a minimum expression from arguments.
| static Expression create_min | ( | const Location & location, | |
| const std::vector< Expression > & arguments | ); |
| PARAMETER | DESCRIPTION |
|---|---|
location |
The location of the expression in the source code. |
arguments |
The arguments of the expression. Must contain exactly two expressions. |
| RETURNS | DESCRIPTION |
|---|---|
Expression |
The created expression. |
method evaluate_processvirtual
Process the evaluation of the expression.
This method is called by the default implementation of evaluate() after calling evaluate() on all sub-expressions.
| virtual std::optional< Expression > evaluate_process | ( | const EvaluationContext & context | ); |
| PARAMETER | DESCRIPTION |
|---|---|
context |
The evaluation context. |
| RETURNS | DESCRIPTION |
|---|---|
std::optional< Expression > |
If the expression changed, returns the new expression, otherwise {}. |
method maximum_valueconst virtual
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 min_maxstatic private
Get the minimum or maximum of two values.
| static Value min_max | ( | bool minimum, | |
| const Value & a, | |||
| const Value & b | ); |
| PARAMETER | DESCRIPTION |
|---|---|
minimum |
Whether to get the minimum ( |
a |
The first value. |
b |
The second value. |
| RETURNS | DESCRIPTION |
|---|---|
Value |
The minimum or maximum of the two values. |
method minimum_valueconst virtual
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 protected
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
| static std::optional< Expression > simplify | ( | const Location & location, | |
| const Expression & a, | |||
| const Expression & b, | |||
| bool minimum, | |||
| bool always_create | ); |
| PARAMETER | DESCRIPTION |
|---|---|
location |
|
a |
|
b |
|
minimum |
|
always_create |
| RETURNS | DESCRIPTION |
|---|---|
std::optional< Expression > |
method traversevirtual
Call a method on all sub-expressions of this expression.
It is used by the default implementations of resolve() and expand_calls(). Unless a subclass has no sub-expressions or overrides both of these methods, it should override traverse().
| virtual void traverse | ( | std::function< void(Expression &)> callable | ); |
| PARAMETER | DESCRIPTION |
|---|---|
callable |
A callable to apply to each sub-expression. |
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. |
member aprivate
The first sub-expression.
member bprivate
The second sub-expression.
member minimumprivate
Whether this is a minimum expression (true) or a maximum expression (false).