IfBody
class IfBody
Represents a conditional body. Parts of this body will be discarded, based on the evaluation of the conditions.
constructor IfBody
Construct a new IfBody.
| IfBody | ( | std::vector< IfBodyClause > clauses | ); |
| PARAMETER | DESCRIPTION |
|---|---|
clauses |
The clauses for the conditional body. |
method cloneconst virtual
| virtual Body clone | ( | const CloneContext & context | ) const; |
| PARAMETER | DESCRIPTION |
|---|---|
context |
| RETURNS | DESCRIPTION |
|---|---|
Body |
method createstatic
Create an IfBody from a list of clauses.
This might not create an IfBody if the clauses can be simplified.
| static Body create | ( | const std::vector< IfBodyClause > & clauses | ); |
| PARAMETER | DESCRIPTION |
|---|---|
clauses |
The clauses for the conditional body. |
| RETURNS | DESCRIPTION |
|---|---|
Body |
The created IfBody. |
method encodevirtual
Encode the BodyElement into a byte string.
The default implementation does nothing. Subclasses that represent data or instructions should override this method.
| virtual void encode | ( | std::string & bytes, | |
| const Memory * memory | ); |
| PARAMETER | DESCRIPTION |
|---|---|
bytes |
The byte string to encode into. |
memory |
The memory context for encoding. |
method evaluatevirtual
Evaluate the BodyElement in a given context.
Subclasses must implement this method.
If an error occurs during evaluation, either an error should be reported via DiagnosticOutput and the BodyElement marked as invalid, or an exception should be thrown.
| virtual std::optional< Body > evaluate | ( | const EvaluationContext & context | ); |
| PARAMETER | DESCRIPTION |
|---|---|
context |
The evaluation context. |
| RETURNS | DESCRIPTION |
|---|---|
std::optional< Body > |
The Body to replace this BodyElement with, {} if no replacement is needed. |
method serializeconst virtual
Serialize the BodyElement to a stream.
Subclasses must implement this method.
| virtual void serialize | ( | std::ostream & stream, | |
| const std::string & prefix | ) const; |
| PARAMETER | DESCRIPTION |
|---|---|
stream |
The stream to serialize to. |
prefix |
The prefix for each line of the serialized output. |
method simplifystatic private
Simplify the clauses of the IfBody.
| static std::optional< Body > simplify | ( | std::vector< IfBodyClause > & clauses, | |
| bool always_create | ); |
| PARAMETER | DESCRIPTION |
|---|---|
clauses |
|
always_create |
| RETURNS | DESCRIPTION |
|---|---|
std::optional< Body > |
method traversevirtual
Traverse the BodyElement.
This function is used by the default implementations of resolve() and expand_calls(). Unless a subclass overrides both of these methods, it should override traverse().
| virtual void traverse | ( | std::function< void(Body &)> body_callable, | |
| std::function< void(Expression &)> expression_callable | ); |
| PARAMETER | DESCRIPTION |
|---|---|
body_callable |
A callable to apply to each sub-body-element. |
expression_callable |
A callable to apply to each sub-expression. |
member clausesprivate
The clauses for the conditional body.
class IfBodyClause
Represents a clause in an IfBody, consisting of a condition and a body.
If no condition is provided, the clause is considered the "else" clause and will be executed if all previous conditions are false.
constructor IfBodyClause
Construct a new IfBodyClause.
| IfBodyClause | ( | std::optional< Expression > condition, | |
| Body body | ); |
| PARAMETER | DESCRIPTION |
|---|---|
condition |
The condition for the clause. If not provided, this is the "else" clause. |
body |
The body to execute if the condition is true. |
method cloneconst
| IfBodyClause clone | ( | const CloneContext & context | ) const; |
| PARAMETER | DESCRIPTION |
|---|---|
context |
| RETURNS | DESCRIPTION |
|---|---|
IfBodyClause |
method is_falseconst
Check if the clause's condition evaluates to false.
| bool is_false | ( | ) const; |
| RETURNS | DESCRIPTION |
|---|---|
bool |
|
method is_trueconst
Check if the clause's condition evaluates to true.
| bool is_true | ( | ) const; |
| RETURNS | DESCRIPTION |
|---|---|
bool |
|
member body
The body to execute if the condition is true.
member condition
The condition for the clause. If not provided, this is the "else" clause.