Skip to content

BinaryExpression

INCLUDE FILE
#include "Expression/BinaryExpression.h"

class BinaryExpression

Expression representing a binary operation.

DEFINITION
class BinaryExpression;

class LabelEntityprivate

DEFINITION
class LabelEntity;

constructor LabelEntity

DEFINITION
LabelEntity ( uint64_t  address );
PARAMETERDESCRIPTION
address

constructor LabelEntity

DEFINITION
LabelEntity ( Entity * entity );
PARAMETERDESCRIPTION
entity

method operator==const

DEFINITION
bool  operator== ( const LabelEntity & other ) const;
PARAMETERDESCRIPTION
other
RETURNSDESCRIPTION
bool

member entity_or_addressprivate

DEFINITION
std::variant< Entity *, uint64_t >  entity_or_address;

enum Operation

The operations supported by the BinaryExpression class.

DEFINITION
enum Operation;
VALUEDESCRIPTION
ADD
BITWISE_AND
BITWISE_OR
BITWISE_XOR
DIVIDE
EQUAL
GREATER
GREATER_EQUAL
LESS
LESS_EQUAL
LOGICAL_AND
LOGICAL_OR
MODULO
MULTIPLY
NOT_EQUAL
SHIFT_LEFT
SHIFT_RIGHT
SUBTRACT

constructor BinaryExpression

Construct a binary expression.

DEFINITION
BinaryExpression ( const Location & location,
Expression  left,
Operation  operation,
Expression  right );
PARAMETERDESCRIPTION
location

The location of the expression in the source code.

left

The left operand.

operation

The binary operation.

right

The right operand.

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 binary operation.

This might not create a BinaryExpression if the operation can be simplified (e. g. if both operands have values).

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

The location of the expression in the source code.

left

The left operand.

operation

The binary operation.

right

The right operand.

RETURNSDESCRIPTION
Expression

The created expression.

method deconstruct_labelstatic private

This deconstructs label expressions.

These are of the form entity or entity + label_offset. entity is an ObjectExpression or a ValueExpression representing an entity's address, and label_offset is a LabelOffsetExpression or ValueExpression.

If the expression is not a label expression, the pair {}, {} is returned.

DEFINITION
static std::pair< std::optional< LabelEntity >, std::optional< Expression > >  deconstruct_label ( const Expression & expression );
PARAMETERDESCRIPTION
expression

The expression to check.

RETURNSDESCRIPTION
std::pair< std::optional< LabelEntity >, std::optional< Expression > >

The referenced entity or its address, or {} if there is none; and the label_offset or {} if there is none.

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 get_label_entitystatic private

Get the label entity referenced by an expression.

If this is an ObjectExpression, return the referenced entity. If it is an unsigned ValueExpression, return its value. If it is a ConstantExpression referencing either, return the referenced entity or value. Otherwise, return {}.

DEFINITION
static std::optional< LabelEntity >  get_label_entity ( const Expression & expression );
PARAMETERDESCRIPTION
expression

The expression to check.

RETURNSDESCRIPTION
std::optional< LabelEntity >

The referenced entity, or {} if there is none.

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.

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

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 operation_nameconst private

Get the name of a binary operation.

DEFINITION
const std::string & operation_name ( ) const;
RETURNSDESCRIPTION
const std::string &

The name of the binary operation.

method operation_namestatic private

Get the name of a binary operation.

DEFINITION
static const std::string & operation_name ( Operation  operation );
PARAMETERDESCRIPTION
operation

The binary operation.

RETURNSDESCRIPTION
const std::string &

The name of the binary operation.

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

Simplify a binary expression if possible.

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

The location of the expression in the source code.

left

The left operand.

operation

The binary operation.

right

The right operand.

always_create

Whether to always create a new expression even if it cannot be simplified.

RETURNSDESCRIPTION
std::optional< Expression >

The simplified expression, or {} if no simplification is possible.

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

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 leftprivate

The left operand of the binary operation.

DEFINITION
Expression  left;

member operationprivate

The binary operation.

DEFINITION
Operation  operation;

member operation_namesstatic private

The names of the binary operations.

DEFINITION
static std::vector< std::string >  operation_names;

member rightprivate

The right operand of the binary operation.

DEFINITION
Expression  right;

class LabelEntityprivate

DEFINITION
class LabelEntity;

constructor LabelEntity

DEFINITION
LabelEntity ( uint64_t  address );
PARAMETERDESCRIPTION
address

constructor LabelEntity

DEFINITION
LabelEntity ( Entity * entity );
PARAMETERDESCRIPTION
entity

method operator==const

DEFINITION
bool  operator== ( const LabelEntity & other ) const;
PARAMETERDESCRIPTION
other
RETURNSDESCRIPTION
bool

member entity_or_addressprivate

DEFINITION
std::variant< Entity *, uint64_t >  entity_or_address;