Skip to content

UnaryExpression

INCLUDE FILE
#include "Expression/UnaryExpression.h"

class UnaryExpression

Expression node representing a unary operation.

DEFINITION
class UnaryExpression;

enum Operation

DEFINITION
enum Operation;
VALUEDESCRIPTION
BANK_BYTE
BITWISE_NOT
HIGH_BYTE
LOW_BYTE
MINUS
NOT
PLUS

constructor UnaryExpression

Create a unary expression.

DEFINITION
UnaryExpression ( const Location & location,
Operation  operation,
Expression  operand );
PARAMETERDESCRIPTION
location

The location of the expression in the source code.

operation

The unary operation.

operand

The operand of the unary operation.

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.

DEFINITION
virtual Expression  clone ( const CloneContext & context ) const;
PARAMETERDESCRIPTION
context
RETURNSDESCRIPTION
Expression

A shared pointer to the cloned expression.

method createstatic

Create an expression from a unary operation.

This might not create a UnaryExpression if the operation can be simplified (e.g. if the operand has a value).

DEFINITION
static Expression  create ( const Location & location,
Operation  operation,
Expression  operand );
PARAMETERDESCRIPTION
location

The location of the expression in the source code.

operation

The unary operation.

operand

The operand of the unary operation.

RETURNSDESCRIPTION
Expression

The created expression.

method evaluate_processvirtual protected

Process the evaluation of the expression.

This method is called by the default implementation of evaluate() after calling evaluate() on all sub-expressions.

DEFINITION
virtual std::optional< Expression >  evaluate_process ( const EvaluationContext & context );
PARAMETERDESCRIPTION
context

The evaluation context.

RETURNSDESCRIPTION
std::optional< Expression >

If the expression changed, returns the new expression, otherwise {}.

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.

DEFINITION
virtual std::optional< Value >  maximum_value ( ) const;
RETURNSDESCRIPTION
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.

DEFINITION
virtual std::optional< Value >  minimum_value ( ) const;
RETURNSDESCRIPTION
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.

DEFINITION
virtual void  serialize_sub ( std::ostream & stream ) const;
PARAMETERDESCRIPTION
stream

The stream to serialize to.

method simplifystatic private

DEFINITION
static std::optional< Expression >  simplify ( const Location & location,
Operation  operation,
const Expression & operand,
bool  always_create );
PARAMETERDESCRIPTION
location
operation
operand
always_create
RETURNSDESCRIPTION
std::optional< Expression >

method traversevirtual protected

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().

DEFINITION
virtual void  traverse ( std::function< void(Expression &)>  callable );
PARAMETERDESCRIPTION
callable

A callable to apply to each sub-expression.

method typeconst virtual protected

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.

DEFINITION
virtual std::optional< Value::Type >  type ( ) const;
RETURNSDESCRIPTION
std::optional< Value::Type >

The type of the expression's value if it can be determined, {} otherwise.

member operandprivate

The operand of the unary operation.

DEFINITION
Expression  operand;

member operationprivate

The unary operation.

DEFINITION
Operation  operation;