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
 
auto declarations () const
 
auto declarationRefs () const
 
bool isEmpty () const
 
void clear ()
 
hilti::optional_ref< const declaration::PropertymoduleProperty (const ID &id) const
 
hilti::node::Set< declaration::PropertymoduleProperties (const std::optional< ID > &id) const
 
void add (Declaration n)
 
void add (Statement s)
 
void add (Expression e)
 
NodeRef preserve (const Node &n)
 
void destroyPreservedNodes ()
 
auto properties () 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 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.)

◆ destroyPreservedNodes()

void Module::destroyPreservedNodes ( )

Destroys any nodes retained previously through preserve().

◆ moduleProperties()

node::Set< declaration::Property > Module::moduleProperties ( const std::optional< 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; leave unset for returning all

◆ moduleProperty()

hilti::optional_ref< const 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 hilti::Module::preserve ( const Node n)
inline

Saves a node along with the module, but outside of the actual AST. This allows keeping references to the node's sub-AST valid while not making the node itself part of the AST. That's especially useful when transforming nodes from one representation to another while other parts of the AST are still refering to the original once.

Parameters
nnode to retain with all of its children
Returns
a reference to the internally stored node

◆ properties()

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

Implements the Node interface.


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