Spicy
Public Member Functions | Static 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
 
template<typename T >
Result< T > valueAs () 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 >
std::vector< T > childs (int begin, int end) const
 
template<typename T >
std::vector< T > childsOfType () const
 
template<typename T >
auto nodesOfType () const
 
template<typename T >
auto nodesOfType ()
 
void addChild (Node n)
 
auto & childs () const
 
auto & childs ()
 
auto & meta () const
 
void setMeta (Meta m)
 
const NodeReforiginalNode () const
 
void setOriginalNode (const NodeRef &n)
 
void clearCache ()
 

Static Public Member Functions

static Attribute setValue (const Attribute &a, Node n)
 

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.

◆ setValue()

static Attribute hilti::Attribute::setValue ( const Attribute a,
Node  n 
)
inlinestatic

Sets or replaces an attributes's associated argument.

Parameters
thenode to assign as the attribute's argument
Returns
a new attribute with the value changed

◆ 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

◆ valueAs()

template<typename T >
Result<T> hilti::Attribute::valueAs ( ) 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: