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

#include <module.h>

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

Public Member Functions

 Module (ID id={}, Meta m=Meta())
 
 Module (ID id, std::vector< Declaration > decls, Meta m=Meta())
 
 Module (ID id, std::vector< Declaration > decls, std::vector< Statement > stmts, const Meta &m=Meta())
 
const auto & id () const
 
const auto & statements () const
 
const auto & declarations () const
 
const auto & preserved () const
 
auto & preserved ()
 
bool isEmpty () const
 
void clear ()
 
Result< declaration::PropertymoduleProperty (const ID &id) const
 
std::vector< declaration::PropertymoduleProperties (const ID &id) const
 
void add (Declaration n)
 
void add (Statement s)
 
void add (Expression e)
 
NodeRef preserve (Node n)
 
auto properties () const
 
void clearCache ()
 
- 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 ()
 

Detailed Description

AST node representing a HILTI module.

Member Function Documentation

◆ add() [1/3]

void hilti::Module::add ( Declaration  n)
inline

Adds a declaration to the module. It will be appended to the current list of declarations.

Note this is a mutating function. Module is an exception among AST classes in that we allow to modify existing instances. Changes will be reflected in all copies of this instance.

◆ add() [2/3]

void hilti::Module::add ( Statement  s)
inline

Adds a top-level statement to the module. It will be appended to the end of the current list of statements and execute at module initialize time.

Note this is a mutating function. Module is an exception among AST classes in that we allow to modify existing instances. Changes will be reflected in all copies of this instance.

◆ add() [3/3]

void hilti::Module::add ( Expression  e)
inline

Adds a top-level expression to the module. It will be appended to the end of the current list of statements and be evaluated at module initialize time.

Note this is a mutating function. Module is an exception among AST classes in that we allow to modify existing instances. Changes will be reflected in all copies of this instance.

◆ clear()

void Module::clear ( )

Removes any content from the module. The result is an empty module just as if it had just been created. (The ID remains in place.)

◆ moduleProperties()

std::vector< declaration::Property > Module::moduleProperties ( const ID id) const

Returns all of module's property declarations of a given name. If there's no property declaration of that ID, return an empty container.

Parameters
idname of the property to return

◆ moduleProperty()

Result< declaration::Property > Module::moduleProperty ( const ID id) const

Returns a module's property declaration of a given name. If there's no property declaration of that name, return an error. If there's more than one of that name, it's undefined which one is returned.

Parameters
idname of the property to return

◆ preserve()

NodeRef Module::preserve ( Node  n)

Saves a node along with the module, but outside of the actual AST. This allows keeping references to the node valid while not making the node itself part of the AST. That's especially useful when transforming nodes from one representation to another, but wanting to retain a link to the original one through Node::setOriginalNode().

Returns
reference to the preserved node

◆ properties()

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

Implements the Node interface.


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