rego-cpp 1.2.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)
 Determines whether the provided name refers to a built-in.
 
Node decl (const Location &name)
 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.
 
BuiltIn at (const Location &name)
 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 method no longer needs to be called.
 
template<typename T >
BuiltInsDefwhitelist (const std::initializer_list< T > &allowed)
 Sets a whitelist of built-in names that are allowed to be loaded.
 
template<typename T >
BuiltInsDefwhitelist (T begin, T end)
 Sets a whitelist of built-in names that are allowed to be loaded.
 
template<typename T >
BuiltInsDefblacklist (const std::initializer_list< T > &forbidden)
 Sets a blacklist of built-in names that are forbidden from being loaded.
 
template<typename T >
BuiltInsDefblacklist (T begin, T end)
 Sets a blacklist of built-in names that are forbidden from being loaded.
 
BuiltInsDefallow_all ()
 Allow all built-ins to be loaded from the standard library.
 

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.

This object provides all lookup for builtins. Users can add their own custom builtins using BuiltInsDef::register_builtin. Built-ins from the Rego standard library.) will be loaded as needed. Control over what parts of the standard library are available to policies is available via the BuiltInsDef::whitelist and BuiltInsDef::blacklist methods.

Member Function Documentation

◆ allow_all()

BuiltInsDef & rego::BuiltInsDef::allow_all ( )

Allow all built-ins to be loaded from the standard library.

Returns
A reference to this instance

◆ at()

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

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.

◆ blacklist() [1/2]

template<typename T >
BuiltInsDef & rego::BuiltInsDef::blacklist ( const std::initializer_list< T > & forbidden)
inline

Sets a blacklist of built-in names that are forbidden from being loaded.

Built-ins whose names are in this list will be forbidden. Any previous list and behavior will be overridden.

Parameters
forbiddenthe forbidden built-in names
Returns
A reference to this instance

◆ blacklist() [2/2]

template<typename T >
BuiltInsDef & rego::BuiltInsDef::blacklist ( T begin,
T end )
inline

Sets a blacklist of built-in names that are forbidden from being loaded.

Built-ins whose names are in this list will be forbidden. Any previous list and behavior will be overridden.

Parameters
beginiterator pointing to the beginning of a range of forbidden names
enditerator pointing to the end of a range of forbidden names
Returns
A reference to this instance

◆ 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)

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.

◆ is_builtin()

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

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 method no longer needs to be called.

Deprecated
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.

◆ whitelist() [1/2]

template<typename T >
BuiltInsDef & rego::BuiltInsDef::whitelist ( const std::initializer_list< T > & allowed)
inline

Sets a whitelist of built-in names that are allowed to be loaded.

Only built-ins whose names are in this list will be allowed. Any previous list and behavior will be overridden.

Parameters
allowedthe allowed built-in names
Returns
A reference to this instance

◆ whitelist() [2/2]

template<typename T >
BuiltInsDef & rego::BuiltInsDef::whitelist ( T begin,
T end )
inline

Sets a whitelist of built-in names that are allowed to be loaded.

Only built-ins whose names are in this list will be allowed. Any previous list and behavior will be overridden.

Parameters
beginiterator pointing to the beginning of a range of allowed names
enditerator pointing to the end of a range of allowed names
Returns
A reference to this instance

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