Spicy
Public Member Functions | List of all members
hilti::Attribute Class Reference

#include <attribute.h>

Inheritance diagram for hilti::Attribute:
hilti::NodeBase hilti::trait::isNode

Public Member Functions

 Attribute (std::string tag, Meta m=Meta())
 
 Attribute (std::string tag, Node v, Meta m=Meta())
 
const auto & tag () const
 
bool hasValue () const
 
const Nodevalue () const
 
Result< std::reference_wrapper< const Expression > > valueAsExpression () const
 
Result< std::string > valueAsString () const
 
Result< int64_t > valueAsInteger () const
 
auto properties () const
 
bool operator== (const Attribute &other) const
 
- Public Member Functions inherited from hilti::NodeBase
 NodeBase (Meta meta)
 
 NodeBase (std::vector< Node > childs, Meta meta)
 
template<typename T >
const T & child (int i) const
 
template<typename T >
void assertChildIsA (int i)
 
template<typename T >
auto childs (int begin, int end) const
 
auto childRefs (int begin, int end)
 
template<typename T >
hilti::node::Set< T > childsOfType () const
 
template<typename T >
std::vector< NodeRefchildRefsOfType () const
 
void addChild (Node n)
 
const auto & childs () const
 
auto & childs ()
 
auto & meta () const
 
void setMeta (Meta m)
 
bool pruneWalk () const
 

Detailed Description

AST node captures an &<tag> attribute along with an optional argument.

Constructor & Destructor Documentation

◆ Attribute() [1/2]

hilti::Attribute::Attribute ( std::string  tag,
Meta  m = Meta() 
)
inline

Constructor for an attribute with no argument.

Parameters
tagname of the attribute, including the leading &
mmeta data to associate with the node

◆ Attribute() [2/2]

hilti::Attribute::Attribute ( std::string  tag,
Node  v,
Meta  m = Meta() 
)
inline

Constructor for an attribute coming with an argument. The argument must be either an AST node representing an expression.

Parameters
tagname of the attribute, including the leading &
vnode representing the argument to associate with the attribute; must be an expression
mmeta data to associate with the node

Member Function Documentation

◆ hasValue()

bool hilti::Attribute::hasValue ( ) const
inline

Returns true if an argument is associated with the attribute.

◆ properties()

auto hilti::Attribute::properties ( ) const
inline

Implements the Node interface.

◆ tag()

const auto& hilti::Attribute::tag ( ) const
inline

Returns the name of the attribute, including the leading &.

◆ value()

const Node& hilti::Attribute::value ( ) const
inline

Returns the attribute associated with the node.

Exceptions
<tt>std::out_of_range</tt>if the attribute does not have an argument

◆ valueAsExpression()

Result<std::reference_wrapper<const Expression> > hilti::Attribute::valueAsExpression ( ) const
inline

Returns the attributes argument as type T. T must be either an Expression, or std::string. In the former case, the value must be an AST expression node. In the latter case, the argument must be a string constructor expression, and the returned value will be the string it represents.

Template Parameters
Teither Expression or std::string
Returns
the argument, or an error if the argument could not be interpreted as type T
Exceptions
<tt>std::out_of_range</tt>if the attribute does not have an argument

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