Spicy
Public Member Functions | Friends | List of all members
hilti::Node Class Referencefinal

#include <node.h>

Inheritance diagram for hilti::Node:

Public Member Functions

template<typename T , typename std::enable_if_t< std::is_base_of< trait::isNode, T >::value > * = nullptr>
 Node (T t)
 
 Node (const Node &other)
 
 Node (Node &&other) noexcept
 
uint64_t rid () const
 
std::string renderedRid () const
 
IntrusivePtr< Scopescope () const
 
void setScope (IntrusivePtr< Scope > new_scope)
 
void clearScope ()
 
std::vector< node::Errorerrors () const
 
bool hasErrors () const
 
void clearErrors ()
 
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, Location l, std::vector< std::string > context={})
 
void addError (std::string msg, Location l, node::ErrorPriority priority, std::vector< std::string > context={})
 
void destroyChilds ()
 
std::string render (bool include_location=true) const
 
void print (std::ostream &out, bool compact=false) const
 
std::string print () const
 
const Locationlocation () const
 
template<typename T >
void assertIsA ()
 
 operator std::string () const
 
Nodeoperator= (const Node &n)
 
Nodeoperator= (Node &&n) noexcept
 
template<typename T >
Nodeoperator= (const T &t)
 

Friends

class NodeRef
 

Detailed Description

AST node. This is a type-erased class that wraps all AST nodes.

Note
Do not derive from this class. Derive from NodeBase instead and then implement the Node interface.

Constructor & Destructor Documentation

◆ Node()

template<typename T , typename std::enable_if_t< std::is_base_of< trait::isNode, T >::value > * = nullptr>
hilti::Node::Node ( t)
inline

Constructs a node from an instance of a class implementing the Node interface.

Member Function Documentation

◆ addError() [1/4]

void hilti::Node::addError ( std::string  msg,
std::vector< std::string >  context = {} 
)
inline

Associate an error message with the node. The error's location will be that of the current node, and it will have normal priority.

Parameters
msgerror message to report
contextfurther lines of context to show along with error

◆ addError() [2/4]

void hilti::Node::addError ( std::string  msg,
node::ErrorPriority  priority,
std::vector< std::string >  context = {} 
)
inline

Associate an error message with the node. The error's location will be that of the current node.

Parameters
msgerror message to report
priorityimportance of showing the error
contextfurther lines of context to show along with error

◆ addError() [3/4]

void hilti::Node::addError ( std::string  msg,
Location  l,
std::vector< std::string >  context = {} 
)
inline

Associate an error message with the node. The error will have normal priority.

Parameters
msgerror message to report
lcustom location to associate with the error
contextfurther lines of context to show along with error

◆ addError() [4/4]

void hilti::Node::addError ( std::string  msg,
Location  l,
node::ErrorPriority  priority,
std::vector< std::string >  context = {} 
)
inline

Associate an error message with the node.

Parameters
msgerror message to report
lcustom location to associate with the error
priorityimportance of showing the error
contextfurther lines of context to show along with error

◆ assertIsA()

template<typename T >
void hilti::Node::assertIsA ( )
inline

Aborts execution if node is not of a given type T.

◆ clearErrors()

void hilti::Node::clearErrors ( )
inline

Clears any error message associated with the node.

◆ clearScope()

void hilti::Node::clearScope ( )
inline

Clears out the current scope.

◆ destroyChilds()

void Node::destroyChilds ( )

Recursively clears all child nodes and then deletes them from this node. This helps to break reference cycles.

◆ errors()

std::vector<node::Error> hilti::Node::errors ( ) const
inline

Returns any error messages associated with the node.

◆ hasErrors()

bool hilti::Node::hasErrors ( ) const
inline

Returns true if there are any errors associated with the node.

◆ location()

const Location& hilti::Node::location ( ) const
inline

Convenience method to return the meta data's location information.

◆ operator std::string()

hilti::Node::operator std::string ( ) const
inline

Renders the node as HILTI source code.

◆ operator=() [1/3]

Node& hilti::Node::operator= ( const Node n)
inline

Replaces the node with another one. Existing NodeRef pointing to this node will remain valid and reflect the new value.

◆ operator=() [2/3]

Node& hilti::Node::operator= ( Node &&  n)
inlinenoexcept

Replaces the node with another one. Existing NodeRef pointing to this node will remain valid and reflect the new value.

◆ operator=() [3/3]

template<typename T >
Node& hilti::Node::operator= ( const T &  t)
inline

Replaces the node with an instance of a class implementing the Node interface. Existing NodeRef pointing to this node will remain valid and reflect the new value.

◆ print() [1/2]

void Node::print ( std::ostream &  out,
bool  compact = false 
) const

Print out a HILTI source code representation of the node and all its children. If the node is not the root of an AST, it's not guaranteed that the result will form valid HILTI source code (but it can still be used, e.g., in error messages).

Parameters
outoutput stream
compactcreate a one-line representation

◆ print() [2/2]

std::string Node::print ( ) const

Returns a HILTI source code representation of the node and all its children. This can be called from inside a debugger.

◆ render()

std::string Node::render ( bool  include_location = true) const

Returns an internal string representation of the node and all its children.

Parameters
include_locationif true, include source code locations into the output

◆ renderedRid()

std::string hilti::Node::renderedRid ( ) const
inline

Returns a string representation of rid().

Note
This is primarily for internal usage.

◆ rid()

uint64_t hilti::Node::rid ( ) const
inline

Returns the node's unique control ID if there's at least NodeRef has been created that refers to it. If there's no such NodeRef, returns zero.

Note
This is primarily for internal usage.

◆ scope()

IntrusivePtr<Scope> hilti::Node::scope ( ) const
inline

Returns the scope associated with the node. All nodes have a scope used for ID resolution. Initially, a new node receive its own, empty scope. However, scopes can be shared across nodes through setScope().

◆ setScope()

void hilti::Node::setScope ( IntrusivePtr< Scope new_scope)
inline

Resets the node's scope to point to another one.


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