Zigbee Protocol Controller 1.6.0
ast::eval< T > Struct Template Reference

AST evaluator. More...

#include <attribute_mapper_ast_eval.hpp>

Public Types

using result_type = boost::optional< T >
 

Public Member Functions

 eval (const attribute_store::attribute context=0)
 Construct a new eval object. More...
 
result_type operator() (const nil &) const
 the undefined keyword More...
 
result_type operator() (const uint32_t n) const
 a literal number More...
 
result_type operator() (const float n) const
 a literal number More...
 
result_type operator() (const operation &x, result_type lhs) const
 An operation. More...
 
result_type operator() (const signed_ &x) const
 Unary operation. More...
 
result_type operator() (const expression &x) const
 Condition. More...
 
result_type operator() (const condition &x) const
 The normal entry point of the evaluator. More...
 
result_type operator() (const attribute &a) const
 an attribute read from the attribute store More...
 
result_type operator() (const function_invokation &f) const
 Evaluates Function invokation. More...
 

Private Attributes

attribute_store::attribute context
 

Detailed Description

template<typename T>
struct ast::eval< T >

AST evaluator.

This evaluator walks though the AST. Usually the evaluator is use to evaluate a toplevel expression, but this can also be applied to other AST nodes.

The evaluation is done in a context such that all attribute paths will be evaluated relative to the context (a common parent node in the attribute store).

The AST evaluator returns a std::optional, because evaluation is not always possible if the the needed attribute are not found within the context.

If the evaluation context is an invalid attribute all evaluations involving an attribute will return no value.

The AST evaluators are implemented as a functor (a function object). This because this allows us to use the boost::apply_visitor, which is able to evaluate the boost::variant objects using functors, through the operator() overloading. The use of the boost::apply_visitor is boost::apply_visitor( functor, variant ), this will call the appropiate operator() overloading for the data type in the variant. See https://www.boost.org/doc/libs/1_76_0/doc/html/boost/apply_visitor.html for details.

Member Typedef Documentation

◆ result_type

template<typename T >
using ast::eval< T >::result_type = boost::optional<T>

Constructor & Destructor Documentation

◆ eval()

template<typename T >
ast::eval< T >::eval ( const attribute_store::attribute  context = 0)
inlineexplicit

Construct a new eval object.

Parameters
contextContext in which this evaluator should work.

Member Function Documentation

◆ operator()() [1/9]

template<typename T >
result_type ast::eval< T >::operator() ( const attribute a) const
inline

an attribute read from the attribute store

◆ operator()() [2/9]

template<typename T >
result_type ast::eval< T >::operator() ( const condition x) const
inline

The normal entry point of the evaluator.

◆ operator()() [3/9]

template<typename T >
result_type ast::eval< T >::operator() ( const expression x) const
inline

Condition.

for if statements

◆ operator()() [4/9]

template<typename T >
result_type ast::eval< T >::operator() ( const float  n) const
inline

a literal number

◆ operator()() [5/9]

template<typename T >
result_type ast::eval< T >::operator() ( const function_invokation f) const
inline

Evaluates Function invokation.

◆ operator()() [6/9]

template<typename T >
result_type ast::eval< T >::operator() ( const nil ) const
inline

the undefined keyword

◆ operator()() [7/9]

template<typename T >
result_type ast::eval< T >::operator() ( const operation x,
result_type  lhs 
) const
inline

An operation.

An operation which should be applied to the current result, can be any operation +,-,*,/,&,| etc.

Parameters
xThe operation
lhsLeft hand side of the operation

◆ operator()() [8/9]

template<typename T >
result_type ast::eval< T >::operator() ( const signed_ x) const
inline

Unary operation.

◆ operator()() [9/9]

template<typename T >
result_type ast::eval< T >::operator() ( const uint32_t  n) const
inline

a literal number

Member Data Documentation

◆ context

template<typename T >
attribute_store::attribute ast::eval< T >::context
private

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