Spicy
Public Types | Public Member Functions | Protected Member Functions | Static Protected Member Functions | Friends | List of all members
hilti::Operator Class Referenceabstract

#include <operator.h>

Inheritance diagram for hilti::Operator:
hilti::BuiltInMemberCall hilti::function::Call hilti::generic::CastedCoercion hilti::struct_::MemberCall

Public Types

template<typename T >
using Result = ::hilti::Result< T >
 

Public Member Functions

 Operator (Meta meta=Meta(), bool builtin=true)
 
virtual ~Operator ()
 
 Operator (const Operator &other)=delete
 
 Operator (Operator &&other)=delete
 
Operatoroperator= (const Operator &other)=delete
 
Operatoroperator= (Operator &&other)=delete
 
auto isInitialized () const
 
auto hasOperands () const
 
const auto & signature () const
 
auto kind () const
 
auto isBuiltIn () const
 
auto operands () const
 
auto op0 () const
 
auto op1 () const
 
auto op2 () const
 
const auto & meta () const
 
const auto & doc () const
 
auto typename_ () const
 
virtual QualifiedTyperesult (Builder *builder, const Expressions &operands, const Meta &meta) const
 
virtual std::optional< operator_::Operands > filter (Builder *builder, const Expressions &operands) const
 
virtual void validate (expression::ResolvedOperator *n) const
 
virtual Result< expression::ResolvedOperator * > instantiate (Builder *builder, Expressions operands, Meta meta) const =0
 
virtual std::string name () const =0
 
virtual std::string print () const
 
virtual std::string dump () const
 

Protected Member Functions

bool init (Builder *builder, Node *scope_root=nullptr)
 
virtual operator_::Signature signature (Builder *builder) const =0
 
virtual std::string _typename () const
 

Static Protected Member Functions

static operator_::OperandoperandForType (Builder *builder, parameter::Kind kind, UnqualifiedType *t, std::string doc="")
 
static operator_::OperandoperandForExpression (Builder *builder, parameter::Kind kind, const Expressions &e, size_t i)
 

Friends

class operator_::Registry
 

Detailed Description

Class representing available HILTI operators.

Operators aren't AST nodes themselves, but they define an operator that's available for instantiation as an AST expression node. Given an operator, one can instantiate a corresponding AST node by passing the concrete operands to the instantiate() method.

Constructor & Destructor Documentation

◆ Operator()

hilti::Operator::Operator ( Meta  meta = Meta(),
bool  builtin = true 
)
inline

Constructor.

Parameters
metameta data associated with the operator
builtintrue if the operator is predefined statically by the compiler; false if it's generated from user code (like functions and methods)

◆ ~Operator()

virtual hilti::Operator::~Operator ( )
inlinevirtual

Destructor.

Member Function Documentation

◆ _typename()

virtual std::string hilti::Operator::_typename ( ) const
inlineprotectedvirtual

Backend for typename_(). Must be overridden by derived classes.

◆ doc()

const auto& hilti::Operator::doc ( ) const
inline

Returns the operator's documentation string.

◆ dump()

std::string Operator::dump ( ) const
virtual

Dumps out the operator's operands in their AST node representation.

◆ filter()

virtual std::optional<operator_::Operands> hilti::Operator::filter ( Builder builder,
const Expressions &  operands 
) const
inlinevirtual

Refines the operator's signature based on the given operands. This can be used to change the signature to more specific types given concreate operands. To not change anything, return an mepty optional

◆ hasOperands()

auto hilti::Operator::hasOperands ( ) const
inline

Returns true if operator's signature has operands defined. If that's not the case, the operator can be instantiated only manually, not through the resolver.

◆ init()

bool Operator::init ( Builder builder,
Node scope_root = nullptr 
)
protected

Initializes the operator. To be called only from the registry.

◆ instantiate()

virtual Result<expression::ResolvedOperator*> hilti::Operator::instantiate ( Builder builder,
Expressions  operands,
Meta  meta 
) const
pure virtual

Instantiates the operator as an AST node, given specific operand expressions.

Implemented in hilti::struct_::MemberCall, hilti::generic::CastedCoercion, and hilti::function::Call.

◆ isBuiltIn()

auto hilti::Operator::isBuiltIn ( ) const
inline

Returns if the operator is predefined statically by the compiler, rather than created through user code (like functions or methods).

◆ isInitialized()

auto hilti::Operator::isInitialized ( ) const
inline

Returns true if init() has run and returned success.

◆ kind()

auto hilti::Operator::kind ( ) const
inline

Returns the operator's kind.

◆ meta()

const auto& hilti::Operator::meta ( ) const
inline

Returns the operator's meta information.

◆ name()

virtual std::string hilti::Operator::name ( ) const
pure virtual

Returns a readable name describing the operator. Must be provided by derived classes.

Implemented in hilti::struct_::MemberCall, hilti::generic::CastedCoercion, and hilti::function::Call.

◆ op0()

auto hilti::Operator::op0 ( ) const
inline

Returns the operator's first operand.

◆ op1()

auto hilti::Operator::op1 ( ) const
inline

Returns the operator's second operand.

◆ op2()

auto hilti::Operator::op2 ( ) const
inline

Returns the operator's third operand.

◆ operandForExpression()

static operator_::Operand* hilti::Operator::operandForExpression ( Builder builder,
parameter::Kind  kind,
const Expressions &  e,
size_t  i 
)
inlinestaticprotected

Helper to create an signature operand matching the type of a given expression.

Parameters
kindkind of the operand specifying passing style
eexpression whose type to use

◆ operandForType()

Operand * Operator::operandForType ( Builder builder,
parameter::Kind  kind,
UnqualifiedType t,
std::string  doc = "" 
)
staticprotected

Helper to create an signature operand matching a given type.

Parameters
kindkind of the operand specifying passing style
ttype of the operand

◆ operands()

auto hilti::Operator::operands ( ) const
inline

Returns the operator's operands.

◆ print()

std::string Operator::print ( ) const
virtual

Prints the operator in a human-readable format.

Reimplemented in hilti::BuiltInMemberCall.

◆ result()

QualifiedType * Operator::result ( Builder builder,
const Expressions &  operands,
const Meta meta 
) const
virtual

Returns the operator's result type, given specific operand expressions. Must be implemented by operators if the signature does not define a static result type.

Reimplemented in hilti::generic::CastedCoercion.

◆ signature() [1/2]

const auto& hilti::Operator::signature ( ) const
inline

Returns the operator's signature.

◆ signature() [2/2]

virtual operator_::Signature hilti::Operator::signature ( Builder builder) const
protectedpure virtual

Returns the operator's signature. Must be overridden by derived classes.

Implemented in hilti::struct_::MemberCall, hilti::generic::CastedCoercion, and hilti::function::Call.

◆ typename_()

auto hilti::Operator::typename_ ( ) const
inline

Returns the C++-level name of the operator's class. Should be used only for debugging purposes.

◆ validate()

virtual void hilti::Operator::validate ( expression::ResolvedOperator n) const
inlinevirtual

Performs semantics validation of an instantiated operator. To record any errors, add them to the given AST node.


The documentation for this class was generated from the following files: