rego-cpp 1.0.0
A C++ implementation of the Rego language and runtime
Loading...
Searching...
No Matches
rego::bundle::Operand Struct Reference

Represents an operand in the IR. More...

#include <rego.hh>

Public Member Functions

 Operand ()
 Constructs an Operand with type None.
 

Static Public Member Functions

static Operand from_op (const Node &n)
 Constructs an Operand from the specified node.
 
static Operand from_index (const Node &n)
 Constructs an Operand from the specified node. Will have a type of Index.
 
static Operand from_value (const Node &n)
 Constructs an Operand from the specified node. Will have a type of Value.
 

Public Attributes

OperandType type
 The type of the operand.
 
union { 
 
   std::int64_t   value 
 An integer value (if type is Value).
 
   size_t   index 
 A local index (if type is Local, String, or Index).
 
};  
 

Friends

std::ostream & operator<< (std::ostream &stream, const Operand &op)
 Writes the operand to a stream (used for debugging purposes).
 

Detailed Description

Represents an operand in the IR.

In this implementation of the IR the operand is overloaded slightly. It is either (as in the specification) a local index, a string index, or a boolean value (true or false). However, to simplify the implementation, it can also be a raw local index (OperandType::Index) or a raw integer value (OperandType::Value). These two additional types allow for more flexibility in the IR representation. A type of None indicates that the operand is not used.

Member Function Documentation

◆ from_index()

static Operand rego::bundle::Operand::from_index ( const Node & n)
static

Constructs an Operand from the specified node. Will have a type of Index.

Note
The node must be an integer scalar.
Parameters
nThe node to construct the operand from.
Returns
The constructed operand.

◆ from_op()

static Operand rego::bundle::Operand::from_op ( const Node & n)
static

Constructs an Operand from the specified node.

Note
Will have a type of Local, String, True, or False.
Parameters
nThe node to construct the operand from.
Returns
The constructed operand.

◆ from_value()

static Operand rego::bundle::Operand::from_value ( const Node & n)
static

Constructs an Operand from the specified node. Will have a type of Value.

Note
The node must be an integer scalar.
Parameters
nThe node to construct the operand from.
Returns
The constructed operand.

Friends And Related Symbol Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream & stream,
const Operand & op )
friend

Writes the operand to a stream (used for debugging purposes).

Parameters
streamThe stream to write to.
opThe operand to write.
Returns
The stream.

The documentation for this struct was generated from the following file: