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

Manages the set of builtins used by an interpreter to resolve built-in calls. More...

#include <rego.hh>

Public Member Functions

 BuiltInsDef () noexcept
 Constructor.
 
bool is_builtin (const Location &name) const
 Determines whether the provided name refers to a built-in.
 
Node decl (const Location &name) const
 Gets the declaration node for the specified built-in.
 
bool is_deprecated (const Location &version, const Location &name) const
 Determines whether the provided builtin name is deprecated in the provided version.
 
Node call (const Location &name, const Location &version, const Nodes &args)
 Calls the built-in with the provided name and arguments.
 
void clear ()
 Called to clear any persistent state or caching.
 
BuiltInsDefregister_builtin (const BuiltIn &built_in)
 Registers a built-in.
 
const BuiltInat (const Location &name) const
 Gets the built-in with the provided name.
 
bool strict_errors () const
 Whether to throw built-in errors.
 
BuiltInsDefstrict_errors (bool strict_errors)
 Sets whether to throw built-in errors.
 
template<typename T >
BuiltInsDefregister_builtins (const T &built_ins)
 Registers a set of built-ins.
 
BuiltInsDefregister_standard_builtins ()
 This registers the "standard library" of built-ins.
 
std::map< Location, BuiltIn >::const_iterator begin () const
 Gets the beginning iterator for the built-ins map.
 
std::map< Location, BuiltIn >::const_iterator end () const
 Gets the ending iterator for the built-ins map.
 

Static Public Member Functions

static std::shared_ptr< BuiltInsDefcreate ()
 Creates the standard builtin set.
 

Detailed Description

Manages the set of builtins used by an interpreter to resolve built-in calls.

Member Function Documentation

◆ at()

const BuiltIn & rego::BuiltInsDef::at ( const Location & name) const

Gets the built-in with the provided name.

Parameters
nameThe name of the built-in to retrieve.
Returns
The built-in with the specified name.

◆ begin()

std::map< Location, BuiltIn >::const_iterator rego::BuiltInsDef::begin ( ) const

Gets the beginning iterator for the built-ins map.

Returns
The beginning iterator for the built-ins map.

◆ call()

Node rego::BuiltInsDef::call ( const Location & name,
const Location & version,
const Nodes & args )

Calls the built-in with the provided name and arguments.

Parameters
nameThe name of the built-in to call.
versionThe Rego version.
argsThe arguments to pass to the built-in.
Returns
The result of the built-in call.

◆ create()

static std::shared_ptr< BuiltInsDef > rego::BuiltInsDef::create ( )
static

Creates the standard builtin set.

Returns
A shared pointer to the created BuiltInsDef.

◆ decl()

Node rego::BuiltInsDef::decl ( const Location & name) const

Gets the declaration node for the specified built-in.

Parameters
nameThe name of the built-in.
Returns
The declaration node for the built-in, or an empty node if not found.

◆ end()

std::map< Location, BuiltIn >::const_iterator rego::BuiltInsDef::end ( ) const

Gets the ending iterator for the built-ins map.

Returns
The ending iterator for the built-ins map.

◆ is_builtin()

bool rego::BuiltInsDef::is_builtin ( const Location & name) const

Determines whether the provided name refers to a built-in.

Parameters
nameThe name to check.
Returns
True if the name refers to a built-in, otherwise false.

◆ is_deprecated()

bool rego::BuiltInsDef::is_deprecated ( const Location & version,
const Location & name ) const

Determines whether the provided builtin name is deprecated in the provided version.

Parameters
versionThe version to check.
nameThe name to check.
Returns
True if the builtin is deprecated in the specified version, otherwise false.

◆ register_builtin()

BuiltInsDef & rego::BuiltInsDef::register_builtin ( const BuiltIn & built_in)

Registers a built-in.

Parameters
built_inThe built-in to register.
Returns
A reference to this instance.

◆ register_builtins()

template<typename T >
BuiltInsDef & rego::BuiltInsDef::register_builtins ( const T & built_ins)
inline

Registers a set of built-ins.

Parameters
built_insThe built-ins to register.
Returns
A reference to this instance.

◆ register_standard_builtins()

BuiltInsDef & rego::BuiltInsDef::register_standard_builtins ( )

This registers the "standard library" of built-ins.

There are a number of built-ins which are provided by default. These built-ins are those documented in the OPA docs.

Returns
A reference to this instance.

◆ strict_errors() [1/2]

bool rego::BuiltInsDef::strict_errors ( ) const

Whether to throw built-in errors.

Returns
True if built-in errors will be thrown as exceptions, false otherwise. If true, built-in errors will be thrown as exceptions. If false, built-in errors will result in Undefined nodes.

◆ strict_errors() [2/2]

BuiltInsDef & rego::BuiltInsDef::strict_errors ( bool strict_errors)

Sets whether to throw built-in errors.

Parameters
strict_errorsTrue to throw built-in errors as exceptions, false to return Undefined nodes.
Returns
A reference to this instance.

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