Clingo
Loading...
Searching...
No Matches
Clingo::AST::Node Class Reference

Node capturing expressions in logic programs. More...

#include <ast.hh>

Public Member Functions

 Node (clingo_ast_t *ast, bool copy=false)
 Construct a node form its C representation.
 
template<NodeType Type, class Updater >
auto update (Library const &lib, Updater const &fun) const -> Node
 Visit a node of the given type.
 
void accept (Visitor const &fun) const
 Visit the direct children of the node with the given visitor.
 
auto accept (Library const &lib, Transformer const &fun) const -> std::optional< Node >
 Transform the direct children of the node with the given transformer.
 
auto type () const -> NodeType
 Get the type of the node.
 
auto number (Attribute attribute) const -> int
 Get the numeric value of the given attribute.
 
auto symbol (Attribute attribute) const -> Symbol
 Get the symbolic value of the given attribute.
 
auto symbols (Attribute attribute) const -> SymbolVector
 Get the symbolic values of the given attribute.
 
auto location (Attribute attribute) const -> Location
 Get the location value of the given attribute.
 
auto string (Attribute attribute) const -> std::string_view
 Get the string value of the given attribute.
 
auto strings (Attribute attribute) const -> std::vector< std::string_view >
 Get the string values of the given attribute.
 
auto node (Attribute attribute) const -> Node
 Get the node value of the given attribute.
 
auto optional_node (Attribute attribute) const -> std::optional< Node >
 Get the optional node value of the given attribute.
 
auto nodes (Attribute attribute) const -> std::vector< Node >
 Get the node values of the given attribute.
 
auto to_string () const -> std::string
 Get a string representation of the node.
 
auto hash () const noexcept -> size_t
 Get a hash for the node.
 

Static Public Member Functions

template<NodeType Type, class... Args>
static auto create (Library const &lib, Args const &...args) -> Node
 Construct a node of the given type.
 

Friends

auto c_cast (Node const &x) -> clingo_ast_t *
 Cast the node to its underlying C representation.
 
auto operator== (Node const &a, Node const &b) noexcept -> bool
 Equality compare two nodes.
 
auto operator<=> (Node const &a, Node const &b) noexcept -> std::strong_ordering
 Compare two nodes.
 

Detailed Description

Node capturing expressions in logic programs.

Nodes are immutable objects supporting record updates.

Refer to lib/c-api/src/ast_yaml.cc for node types and their arguments.

Constructor & Destructor Documentation

◆ Node()

Clingo::AST::Node::Node ( clingo_ast_t ast,
bool  copy = false 
)
inlineexplicit

Construct a node form its C representation.

If copy is true copies the given node or otherwise takes ownership. Copying itself is cheap and just involves updating reference counts.

For internal sue.

Parameters
astthe C ast
copywhether to copy

Member Function Documentation

◆ accept() [1/2]

auto Clingo::AST::Node::accept ( Library const &  lib,
Transformer const &  fun 
) const -> std::optional<Node>
inline

Transform the direct children of the node with the given transformer.

Parameters
libthe library object to store symbols
funthe transformer

◆ accept() [2/2]

void Clingo::AST::Node::accept ( Visitor const &  fun) const
inline

Visit the direct children of the node with the given visitor.

Note that the visitor is in charge of recursively visiting further nodes.

Parameters
funthe visitor

◆ create()

template<NodeType Type, class... Args>
static auto Clingo::AST::Node::create ( Library const &  lib,
Args const &...  args 
) -> Node
inlinestatic

Construct a node of the given type.

Template Parameters
Typethe type of the node
Parameters
libthe library object to store symbols
argsthe attributes that make up the nodes
Returns
the constructed node

◆ hash()

auto Clingo::AST::Node::hash ( ) const -> size_t
inlinenoexcept

Get a hash for the node.

The hash is designed for usage in hash tables. There is also an associated specialization for std::hash.

Returns
the hash

◆ location()

auto Clingo::AST::Node::location ( Attribute  attribute) const -> Location
inline

Get the location value of the given attribute.

Parameters
attributethe attribute
Returns
the value

◆ node()

auto Clingo::AST::Node::node ( Attribute  attribute) const -> Node
inline

Get the node value of the given attribute.

Parameters
attributethe attribute
Returns
the value

◆ nodes()

auto Clingo::AST::Node::nodes ( Attribute  attribute) const -> std::vector<Node>
inline

Get the node values of the given attribute.

Parameters
attributethe attribute
Returns
the value

◆ number()

auto Clingo::AST::Node::number ( Attribute  attribute) const -> int
inline

Get the numeric value of the given attribute.

Parameters
attributethe attribute
Returns
the value

◆ optional_node()

auto Clingo::AST::Node::optional_node ( Attribute  attribute) const -> std::optional<Node>
inline

Get the optional node value of the given attribute.

Parameters
attributethe attribute
Returns
the value

◆ string()

auto Clingo::AST::Node::string ( Attribute  attribute) const -> std::string_view
inline

Get the string value of the given attribute.

Parameters
attributethe attribute
Returns
the value

◆ strings()

auto Clingo::AST::Node::strings ( Attribute  attribute) const -> std::vector<std::string_view>
inline

Get the string values of the given attribute.

Parameters
attributethe attribute
Returns
the value

◆ symbol()

auto Clingo::AST::Node::symbol ( Attribute  attribute) const -> Symbol
inline

Get the symbolic value of the given attribute.

Parameters
attributethe attribute
Returns
the value

◆ symbols()

auto Clingo::AST::Node::symbols ( Attribute  attribute) const -> SymbolVector
inline

Get the symbolic values of the given attribute.

Parameters
attributethe attribute
Returns
the value

◆ to_string()

auto Clingo::AST::Node::to_string ( ) const -> std::string
inline

Get a string representation of the node.

The string representation is intended to be parsable.

Returns
the string representation

◆ type()

auto Clingo::AST::Node::type ( ) const -> NodeType
inline

Get the type of the node.

Returns
the type

◆ update()

template<NodeType Type, class Updater >
auto Clingo::AST::Node::update ( Library const &  lib,
Updater const &  fun 
) const -> Node
inline

Visit a node of the given type.

The given type must correspond to the actual type of the node. The given updater must be templated for the attributes of the node that are to be changed. If the return type of this function is not void, it will be used to update the respective attribute.

Template Parameters
Typethe type of the node
Parameters
libthe library object to store symbols
funthe templated updater
Returns
the updated node

Friends And Related Symbol Documentation

◆ operator<=>

auto operator<=> ( Node const &  a,
Node const &  b 
) -> std::strong_ordering
friend

Compare two nodes.

Parameters
athe first node
bthe second node
Returns
the result of the comparison

◆ operator==

auto operator== ( Node const &  a,
Node const &  b 
) -> bool
friend

Equality compare two nodes.

Parameters
athe first node
bthe second node
Returns
whether the nodes are equal

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