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

#include <attribute.h>

Inheritance diagram for hilti::Attribute:
hilti::Node

Public Member Functions

const auto & kind () const
 
auto hasValue () const
 
Nodevalue () const
 
Result< Expression * > valueAsExpression () const
 
Result< std::string > valueAsString () const
 
Result< int64_t > valueAsInteger () const
 
Result< bool > coerceValueTo (Builder *builder, QualifiedType *dst)
 
node::Properties properties () const final
 
- Public Member Functions inherited from hilti::Node
node::Tag nodeTag () const
 
bool hasParent () const
 
Nodeparent (int i=1) const
 
template<typename T >
T * parent () const
 
auto pathLength () const
 
const auto & meta () const
 
const auto & location () const
 
void setMeta (Meta m)
 
auto scope () const
 
auto getOrCreateScope ()
 
void clearScope ()
 
Result< std::pair< Declaration *, ID > > lookupID (const ID &id, const std::string_view &what) const
 
virtual bool inheritScope () const
 
std::string typename_ () const
 
uint64_t identity () const
 
const auto & children () const
 
template<typename T >
T * child (unsigned int i) const
 
template<typename T >
T * childTryAs (unsigned int i) const
 
Nodechild (unsigned int i) const
 
template<typename T >
auto children (int begin, std::optional< int > end) const
 
template<typename T >
auto children (int begin, std::optional< int > end)
 
template<typename T >
node::Set< T > childrenOfType () const
 
bool hasChild (const Node *n, bool recurse=false) const
 
Nodesibling (Node *n) const
 
void addChild (ASTContext *ctx, Node *n)
 
void addChildren (ASTContext *ctx, const Nodes &children)
 
void removeChild (Node *n)
 
void removeChildren (int begin, std::optional< int > end)
 
void setChild (ASTContext *ctx, size_t idx, Node *n)
 
void replaceChildren (ASTContext *ctx, const Nodes &children)
 
void replaceChild (ASTContext *ctx, Node *old, Node *new_)
 
template<typename T >
bool isA () const
 
template<typename T >
bool isA_ () const
 
template<typename T >
T * as () const
 
template<typename T >
T * as ()
 
template<typename T >
const T * tryAs () const
 
template<typename T >
T * tryAs ()
 
template<typename T >
T * tryAs_ ()
 
void print (std::ostream &out, bool compact, bool user_visible) const
 
std::string print () const
 
std::string printRaw () const
 
 operator std::string () const
 
std::string dump () const
 
std::string renderSelf (bool include_location=true) const
 
void addError (std::string msg, std::vector< std::string > context={})
 
void addError (std::string msg, node::ErrorPriority priority, std::vector< std::string > context={})
 
void addError (std::string msg, const Location &l, std::vector< std::string > context={})
 
void addError (std::string msg, Location l, node::ErrorPriority priority, std::vector< std::string > context={})
 
bool hasErrors () const
 
const auto & errors () const
 
void clearErrors ()
 
void clearChildren ()
 
void retain ()
 
void release ()
 
bool isRetained () const
 
virtual void dispatch (visitor::Dispatcher &v)=0
 
virtual std::string_view branchTag () const
 
Nodeoperator= (const Node &other)=delete
 
Nodeoperator= (Node &&other) noexcept=delete
 

Static Public Member Functions

static auto create (ASTContext *ctx, const attribute::Kind &kind, Expression *v, const Meta &m=Meta())
 
static auto create (ASTContext *ctx, const attribute::Kind &kind, const Meta &m=Meta())
 

Protected Member Functions

 Attribute (ASTContext *ctx, Nodes children, attribute::Kind kind, Meta m=Meta())
 
std::string _dump () const override
 
 HILTI_NODE_0 (Attribute, final)
 
- Protected Member Functions inherited from hilti::Node
 Node (ASTContext *ctx, node::Tags node_tags, Nodes children, Meta meta)
 
 Node (ASTContext *ctx, node::Tags node_tags, Meta meta)
 
 Node (Node &&other)=default
 
 Node (const Node &other)
 
virtual std::string _typename () const
 
virtual Node_clone (ASTContext *ctx) const =0
 

Additional Inherited Members

- Static Public Attributes inherited from hilti::Node
static constexpr uint16_t NodeLevel = 0
 
static constexpr ::hilti::node::Tag NodeTag = ::hilti::node::tag::Node
 
static constexpr ::hilti::node::Tags NodeTags = {::hilti::node::tag::Node}
 

Detailed Description

AST node for an attribute.

Member Function Documentation

◆ _dump()

std::string Attribute::_dump ( ) const
overrideprotectedvirtual

Returns additional information to include into the node's dump() output, as provided by derived classes.

Reimplemented from hilti::Node.

◆ coerceValueTo()

Result< bool > Attribute::coerceValueTo ( Builder builder,
QualifiedType dst 
)

Coerce the attribute's expression value to a specified type, modifying the node in place.

Returns
A successful return value if either the coercion succeeded (then the result's value is true), or nothing was to be done (then the result's value is false); a failure if a coercion would have been necessary, but failed, or the attribute does not have a expression value.

◆ create() [1/2]

static auto hilti::Attribute::create ( ASTContext ctx,
const attribute::Kind kind,
const Meta m = Meta() 
)
inlinestatic

Factory for an attribute with no argument.

Parameters
kindthe attribute's internal representation
mmeta data to associate with the node

◆ create() [2/2]

static auto hilti::Attribute::create ( ASTContext ctx,
const attribute::Kind kind,
Expression v,
const Meta m = Meta() 
)
inlinestatic

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

Parameters
kindthe attribute's internal representation
vnode representing the argument to associate with the attribute; must be an expression
mmeta data to associate with the node

◆ hasValue()

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

Returns true if an argument is associated with the attribute.

◆ kind()

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

Returns the kind of the attribute, derived from its tag.

◆ properties()

node::Properties hilti::Attribute::properties ( ) const
inlinefinalvirtual

Returns any instance properties associated with the node. These are used (only) for debug logging. Derived classes should override this to add any properties they retain inside internal node member variables.

Reimplemented from hilti::Node.

◆ value()

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< Expression * > Attribute::valueAsExpression ( ) const

Returns the expression argument associated with the attribute.

Returns
the argument, or an error if the attribute does not have an argument, or if it's not an expression.

◆ valueAsInteger()

Result< int64_t > Attribute::valueAsInteger ( ) const

Returns the expression argument associated with the attribute as a signed integer, assuming it represents a constant integer value. Both signed and unsigned integer values are accepted, with the latter cased into signed for the return value

Returns
the argument, or an error if the attribute does not have an argument, or if it's not a constant integer.

◆ valueAsString()

Result< std::string > Attribute::valueAsString ( ) const

Returns the expression argument associated with the attribute as a string, assuming it represents a constant integer value.

Returns
the argument, or an error if the attribute does not have an argument, or if it's not a constant string.

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